### Start Coroutine with IEnumerator - Unity C# Source: https://docs.unity3d.com/2023.2/Documentation/ScriptReference/Coroutine This C# example shows how to start a coroutine by directly passing an IEnumerator instance to 'StartCoroutine'. This method allows for passing parameters to the coroutine and provides more control. Dependencies: UnityEngine, System.Collections. ```csharp using UnityEngine; using System.Collections; // In this example we show how to invoke a coroutine and execute // the function in parallel. Start does not need IEnumerator. public class ExampleClass : MonoBehaviour { private IEnumerator coroutine; void Start() { // - After 0 seconds, prints "Starting 0.0 seconds" // - After 0 seconds, prints "Coroutine started" // - After 2 seconds, prints "Coroutine ended: 2.0 seconds" print("Starting " + Time.time + " seconds"); // Start function WaitAndPrint as a coroutine. coroutine = WaitAndPrint(2.0f); StartCoroutine(coroutine); print("Coroutine started"); } private IEnumerator WaitAndPrint(float waitTime) { yield return new WaitForSeconds(waitTime); print("Coroutine ended: " + Time.time + " seconds"); } } ``` -------------------------------- ### Setup Camera Properties with CommandBuffer (C#) Source: https://docs.unity3d.com/2023.2/Documentation/ScriptReference/Rendering.CommandBuffer Schedules the setup of Camera specific global Shader variables using CommandBuffer in Unity. This C# function takes a Camera object as input and configures shader variables for rendering. ```csharp public void SetupCameraProperties(Camera camera); ``` -------------------------------- ### BuildPlayerProcessor.PrepareForBuild Source: https://docs.unity3d.com/2023.2/Documentation/ScriptReference/Build.BuildPlayerProcessor Implement this function to receive a callback before a player build starts. The function takes a BuildPlayerContext as a parameter, which provides context tied to the scheduled player build. ```APIDOC ## BuildPlayerProcessor.PrepareForBuild ### Description Implement this function to receive a callback before a player build starts. ### Method `void` ### Endpoint N/A (This is a method within a class, not a REST endpoint) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```csharp public void PrepareForBuild(Build.BuildPlayerContext buildPlayerContext) { // Implementation here } ``` ### Response #### Success Response (void) This method does not return a value. #### Response Example N/A ``` -------------------------------- ### Start Coroutine with Yield - Unity C# Source: https://docs.unity3d.com/2023.2/Documentation/ScriptReference/Coroutine This C# example demonstrates how to start a coroutine using 'yield return StartCoroutine("CoroutineName")'. It suspends execution until the 'WaitAndPrint' coroutine completes. Dependencies: UnityEngine, System.Collections. ```csharp using UnityEngine; using System.Collections; public class ExampleClass : MonoBehaviour { IEnumerator WaitAndPrint() { // suspend execution for 5 seconds yield return new WaitForSeconds(5); print("WaitAndPrint " + Time.time); } IEnumerator Start() { print("Starting " + Time.time); // Start function WaitAndPrint as a coroutine yield return StartCoroutine("WaitAndPrint"); print("Done " + Time.time); } } ``` -------------------------------- ### Shader.renderQueue API Documentation Source: https://docs.unity3d.com/2023.2/Documentation/ScriptReference/Shader-renderQueue Provides details on the Shader.renderQueue property, including its function, parameters, and examples. ```APIDOC ## Shader.renderQueue ### Description Render queue of this shader. (Read Only) Since different Render Pipelines require different render passes a shader's render queue depends on the active Render Pipeline. Note: When Unity runs in batch mode, it does not load Scriptable Render Pipelines (SRPs) until the first time something renders. Loading an SRP modifies the sub-shader selected for a given material which can lead to the value this function returns being different than expected. Additional resources: Material.renderQueue, RenderQueue enum, subshader tags. ### Method Read Only (Property) ### Endpoint N/A (This is a property within a script, not an API endpoint) ### Parameters N/A ### Request Example N/A (This is a property, not a request-based API) ### Response #### Success Response - **renderQueue** (int) - The integer value representing the shader's render queue. #### Response Example ```csharp int currentRenderQueue = myShader.renderQueue; Debug.Log("Current Render Queue: " + currentRenderQueue); ``` ``` -------------------------------- ### CommandBuffer.SetupCameraProperties Source: https://docs.unity3d.com/2023.2/Documentation/ScriptReference/Rendering.CommandBuffer Schedules the setup of camera-specific global shader variables, including view, projection, and clipping planes. This is similar to ScriptableRenderContext.SetupCameraProperties. ```APIDOC ## POST /CommandBuffer/SetupCameraProperties ### Description Schedules the setup of camera specific global Shader variables. This function sets up view, projection and clipping planes global shader variables. This command is essentially the same to ScriptableRenderContext.SetupCameraProperties. ### Method POST ### Endpoint /CommandBuffer/SetupCameraProperties ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **camera** (Camera) - Required - Camera to setup shader variables for. ### Request Example ```json { "camera": { "name": "MainCamera" } } ``` ### Response #### Success Response (200) - **status** (string) - Indicates success. #### Response Example ```json { "status": "Success" } ``` ``` -------------------------------- ### EditorUserBuildSettings.wsaBuildAndRunDeployTarget Source: https://docs.unity3d.com/2023.2/Documentation/ScriptReference/EditorUserBuildSettings-wsaBuildAndRunDeployTarget Sets and gets the Windows device to launch the UWP app when using Build and Run. ```APIDOC ## EditorUserBuildSettings.wsaBuildAndRunDeployTarget ### Description Sets and gets the Windows device to launch the UWP app when using Build and Run. ### Method GET / SET (Implicit for property) ### Endpoint EditorUserBuildSettings ### Parameters This is a static property and does not take direct parameters for setting or getting. ### Request Example // Setting the deploy target ```csharp EditorUserBuildSettings.wsaBuildAndRunDeployTarget = WSABuildAndRunDeployTarget.Local; ``` // Getting the deploy target ```csharp WSABuildAndRunDeployTarget currentTarget = EditorUserBuildSettings.wsaBuildAndRunDeployTarget; ``` ### Response #### Success Response (Implicit for property) Returns the current WSABuildAndRunDeployTarget enum value. #### Response Example ```json { "currentTarget": "Local" } ``` ``` -------------------------------- ### UQueryExtensions.Query with root element only Source: https://docs.unity3d.com/2023.2/Documentation/ScriptReference/UIElements.UQueryExtensions Initializes a UQueryBuilder starting from a given root VisualElement. ```APIDOC ## UQueryExtensions.Query(UIElements.VisualElement e) ### Description Initializes a QueryBuilder with the specified selection rules, starting the query from the provided root VisualElement. ### Method static ### Endpoint N/A (This is a static method in a C# library) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```csharp // Example usage: VisualElement rootElement = new VisualElement(); var queryBuilder = UQueryExtensions.Query(rootElement); ``` ### Response #### Success Response (200) Returns a `UQueryBuilder` configured with the associated selection rules. #### Response Example ```json // The return type is a UQueryBuilder object, not a JSON response. // Example of a UQueryBuilder object in concept: { "elementType": "UQueryBuilder", "selectionRules": { "rootElement": "rootElement" } } ``` ``` -------------------------------- ### ObjectFactory.CreateGameObject Source: https://docs.unity3d.com/2023.2/Documentation/ScriptReference/ObjectFactory Provides documentation for the ObjectFactory.CreateGameObject method, including its declarations, parameters, return value, and usage examples. ```APIDOC ## POST /ObjectFactory/CreateGameObject ### Description Creates a new GameObject. This method has two overloads to accommodate different creation scenarios. ### Method POST ### Endpoint /ObjectFactory/CreateGameObject ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body This endpoint does not have a request body. Parameters are passed via the method signature in the code. ### Request Example ```json { "name": "string", "types": "Array of Type", "scene": "SceneManagement.Scene", "hideFlags": "HideFlags" } ``` ### Response #### Success Response (200) - **GameObject** (GameObject) - The newly created GameObject. #### Response Example ```json { "name": "MyGameObject", "transform": { "position": {"x": 0, "y": 0, "z": 0}, "rotation": {"x": 0, "y": 0, "z": 0, "w": 1} }, "components": [] } ``` ``` -------------------------------- ### Execute Custom Code Before Camera Render (C#) Source: https://docs.unity3d.com/2023.2/Documentation/ScriptReference/Camera-onPreRender This C# script demonstrates how to subscribe a callback function to the Camera.onPreRender delegate. This callback executes just before any camera starts rendering the scene. The example shows how to add and remove the callback, and how to check if the callback is being invoked for the main camera. ```csharp using UnityEngine; public class CameraCallbackExample : MonoBehaviour { // Add your callback to the delegate's invocation list void Start() { Camera.onPreRender += OnPreRenderCallback; } // Unity calls the methods in this delegate's invocation list before rendering any camera void OnPreRenderCallback(Camera cam) { Debug.Log("Camera callback: Camera name is " + cam.name); // Unity calls this for every active Camera. // If you're only interested in a particular Camera, // check whether the Camera is the one you're interested in if (cam == Camera.main) { // Put your custom code here } } // Remove your callback from the delegate's invocation list void OnDestroy() { Camera.onPreRender -= OnPreRenderCallback; } } ``` -------------------------------- ### Unity C# Logger.Log Examples Source: https://docs.unity3d.com/2023.2/Documentation/ScriptReference/Logger Demonstrates logging messages to the Unity Console using `ILogger` and `Debug.unityLogger`. This snippet shows how to log messages with and without a tag, utilizing the default logger. ```csharp using UnityEngine; using System.Collections; public class MyGameClass : MonoBehaviour { private static ILogger logger = Debug.unityLogger; private static string kTAG = "MyGameTag"; void MyGameMethod() { logger.Log(kTAG, "Hello"); Debug.unityLogger.Log(kTAG, "World"); logger.Log("Hello Logger"); } } ``` -------------------------------- ### SearchService.GetItems Source: https://docs.unity3d.com/2023.2/Documentation/ScriptReference/Search.SearchService Initiates a search and returns all search items matching the search context. This method is synchronous and typically requires more context setup compared to SearchService.Request. ```APIDOC ## GET /api/search/items ### Description Initiates a search and returns all search items matching the search context. Other items can be found later using asynchronous searches. Unity suggests using SearchService.Request to execute a search query. `GetItems` usually requires setting up more context to achieve a good result. ### Method GET ### Endpoint /api/search/items ### Parameters #### Query Parameters - **context** (Search.SearchContext) - Required - The current search context. - **options** (Search.SearchFlags) - Required - Options defining how the query is performed. ### Request Example ```json { "context": { "query": "is:leaf", "scope": "scene" }, "options": "WantsMore | Synchronous" } ``` ### Response #### Success Response (200) - **List** - A list of search items matching the search query. #### Response Example ```json [ { "description": "Example Search Item Description", "id": "item_id_1" }, { "description": "Another Search Item Description", "id": "item_id_2" } ] ``` ``` -------------------------------- ### Rigidbody.MoveRotation API Source: https://docs.unity3d.com/2023.2/Documentation/ScriptReference/Rigidbody Provides details on the Rigidbody.MoveRotation method, including its declaration, parameters, description, and a C# example. ```APIDOC ## Rigidbody.MoveRotation ### Description Rotates the rigidbody to `rotation`. Use Rigidbody.MoveRotation to rotate a Rigidbody, complying with the Rigidbody's interpolation setting. If Rigidbody interpolation is enabled on the Rigidbody, calling Rigidbody.MoveRotation will result in a smooth transition between the two rotations in any intermediate frames rendered. This should be used if you want to continuously rotate a rigidbody in each FixedUpdate. Set Rigidbody.rotation instead, if you want to teleport a rigidbody from one rotation to another, with no intermediate positions being rendered. ### Method `public void MoveRotation(Quaternion rot);` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) None #### Response Example None ### Code Example ```csharp using UnityEngine; public class Example : MonoBehaviour { Rigidbody m_Rigidbody; Vector3 m_EulerAngleVelocity; void Start() { //Fetch the Rigidbody from the GameObject with this script attached m_Rigidbody = GetComponent(); //Set the angular velocity of the Rigidbody (rotating around the Y axis, 100 deg/sec) m_EulerAngleVelocity = new Vector3(0, 100, 0); } void FixedUpdate() { Quaternion deltaRotation = Quaternion.Euler(m_EulerAngleVelocity * Time.fixedDeltaTime); m_Rigidbody.MoveRotation(m_Rigidbody.rotation * deltaRotation); } } ``` ``` -------------------------------- ### SystemInfo.constantBufferOffsetAlignment API Source: https://docs.unity3d.com/2023.2/Documentation/ScriptReference/SystemInfo-constantBufferOffsetAlignment Details about the SystemInfo.constantBufferOffsetAlignment property, including its description, usage, and example. ```APIDOC ## SystemInfo.constantBufferOffsetAlignment ### Description Minimum buffer offset (in bytes) when binding a constant buffer using Shader.SetConstantBuffer or Material.SetConstantBuffer. If the currently active renderer supports binding constant buffers directly (see SystemInfo.supportsSetConstantBuffer), and supports binding constant buffers with an offset, this property specifies the minimum required alignment in bytes for the offset parameter given to Shader.SetConstantBuffer etc. If this property is 0, the current renderer only supports binding constant buffers at offset 0 (for example, DX11 devices that do not expose DX11.1 features). ### Method `public static int constantBufferOffsetAlignment;` ### Endpoint N/A (This is a static property in the Unity API) ### Parameters N/A ### Request Example ```csharp int alignment = SystemInfo.constantBufferOffsetAlignment; Debug.Log("Constant buffer offset alignment: " + alignment); ``` ### Response #### Success Response (200) - **constantBufferOffsetAlignment** (int) - The minimum buffer offset alignment in bytes. ``` -------------------------------- ### UnityWebRequestMultimedia.GetAudioClip Source: https://docs.unity3d.com/2023.2/Documentation/ScriptReference/Networking.UnityWebRequestMultimedia Creates a UnityWebRequest to download an audio clip via HTTP GET and converts it to an AudioClip. ```APIDOC ## UnityWebRequestMultimedia.GetAudioClip ### Description Create a UnityWebRequest to download an audio clip via HTTP GET and create an AudioClip based on the retrieved data. This method creates a UnityWebRequest and sets the target URL to the string `uri` argument. This method sets no other flags or custom headers. This method attaches a DownloadHandlerAudioClip object to the UnityWebRequest. DownloadHandlerAudioClip is a specialized DownloadHandler. It is optimized for storing data which is to be used as an audio clip in the Unity Engine. Using this class significantly reduces memory reallocation compared to downloading raw bytes and creating an audio clip manually in script. This method attaches no UploadHandler to the UnityWebRequest. ### Method GET ### Endpoint `/uri` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```csharp using UnityEngine; using UnityEngine.Networking; using System.Collections; public class MyBehaviour : MonoBehaviour { void Start() { StartCoroutine(GetAudioClip()); } IEnumerator GetAudioClip() { using (UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip("https://www.my-server.com/audio.ogg", AudioType.OGGVORBIS)) { yield return www.SendWebRequest(); if (www.result == UnityWebRequest.Result.ConnectionError) { Debug.Log(www.error); } else { AudioClip myClip = DownloadHandlerAudioClip.GetContent(www); } } } } ``` ### Response #### Success Response (200) **AudioClip** - The downloaded audio clip. ``` -------------------------------- ### Initialize ProfilerRecorder with Category and Name (C#) Source: https://docs.unity3d.com/2023.2/Documentation/ScriptReference/Unity.Profiling This C# code demonstrates how to initialize a ProfilerRecorder using a specific ProfilerCategory and a string for the statistic name. It shows how to set capacity and options, including starting the recorder immediately. It also includes proper disposal of the recorder in OnDisable. ```csharp using Unity.Profiling; using UnityEngine; public class ExampleScript : MonoBehaviour { ProfilerRecorder systemMemoryRecorder; ProfilerRecorder gcMemoryRecorder; ProfilerRecorder mainThreadTimeRecorder; void OnEnable() { systemMemoryRecorder = new ProfilerRecorder(ProfilerCategory.Memory, "System Used Memory", 1, ProfilerRecorderOptions.Default | ProfilerRecorderOptions.StartImmediately); gcMemoryRecorder = new ProfilerRecorder(ProfilerCategory.Memory, "GC Reserved Memory", 1, ProfilerRecorderOptions.Default | ProfilerRecorderOptions.StartImmediately); mainThreadTimeRecorder = new ProfilerRecorder(ProfilerCategory.Internal, "Main Thread", 15); mainThreadTimeRecorder.Start(); } void OnDisable() { systemMemoryRecorder.Dispose(); gcMemoryRecorder.Dispose(); mainThreadTimeRecorder.Dispose(); } } ``` -------------------------------- ### Example Usage of CustomYieldInstruction in Unity Source: https://docs.unity3d.com/2023.2/Documentation/ScriptReference/CustomYieldInstruction Demonstrates how to use a custom yield instruction by inheriting from MonoBehaviour and starting a coroutine. This example waits for the left mouse button to be released, then starts a coroutine that waits for the right mouse button to be pressed down. ```csharp using System.Collections; using UnityEngine; public class ExampleScript : MonoBehaviour { void Update() { if (Input.GetMouseButtonUp(0)) { Debug.Log("Left mouse button up"); StartCoroutine(waitForMouseDown()); } } public IEnumerator waitForMouseDown() { yield return new WaitForMouseDown(); Debug.Log("Right mouse button pressed"); } } ``` -------------------------------- ### PackagingOptions.RemoveDoNotStrip Source: https://docs.unity3d.com/2023.2/Documentation/ScriptReference/Unity.Android.Gradle.PackagingOptions This section details the `RemoveDoNotStrip` method within the `PackagingOptions` class. It explains its purpose, parameters, and provides an example of its usage. ```APIDOC ## PackagingOptions.RemoveDoNotStrip ### Description Removes all "doNotStrip" properties with a given value. This method is relevant for Android packaging and refers to Android's documentation for 'doNotStrip'. ### Method `void RemoveDoNotStrip(string value)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```csharp PackagingOptions.RemoveDoNotStrip("some_value"); ``` ### Response #### Success Response (200) This method does not return a value. #### Response Example N/A ``` -------------------------------- ### Get Sprite GUID in C# Source: https://docs.unity3d.com/2023.2/Documentation/ScriptReference/U2D.SpriteEditorExtension Retrieves the unique GUID of a Sprite asset in Unity. This method is part of the `SpriteEditorExtension` class and is primarily used during Sprite asset generation to match Sprites with their source data via `SpriteRect.spriteID`. It takes a `Sprite` object as input and returns its `GUID`. ```csharp public static GUID GetSpriteID(Sprite sprite); ``` -------------------------------- ### BindableElement.UxmlTraits.Init Method Source: https://docs.unity3d.com/2023.2/Documentation/ScriptReference/UIElements.BindableElement.UxmlTraits Provides documentation for the Init method of BindableElement.UxmlTraits, including its signature and purpose. ```APIDOC ## BindableElement.UxmlTraits.Init ### Description Initialize BindableElement properties using values from the attribute bag. ### Method public void Init(UIElements.VisualElement ve, UIElements.IUxmlAttributes bag, UIElements.CreationContext cc) ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) Void return type, no specific response body. #### Response Example None ``` -------------------------------- ### ReflectionProbe.RenderProbe API Source: https://docs.unity3d.com/2023.2/Documentation/ScriptReference/ReflectionProbe This section details the ReflectionProbe.RenderProbe method, used to refresh the probe's cubemap. It includes information on parameters, return values, and provides a code example. ```APIDOC ## POST /api/reflectionprobe/renderprobe ### Description Refreshes the probe's cubemap. ### Method POST ### Endpoint /api/reflectionprobe/renderprobe ### Parameters #### Request Body - **targetTexture** (RenderTexture) - Optional - Target RenderTexture in which rendering should be done. Specifying null will update the probe's default texture. ### Request Example ```json { "targetTexture": null } ``` ### Response #### Success Response (200) - **renderID** (int) - An integer representing a RenderID which can subsequently be used to check if the probe has finished rendering while rendering in time-slice mode. #### Response Example ```json { "renderID": 12345 } ``` ### Additional Resources - IsFinishedRendering - timeSlicingMode ``` -------------------------------- ### Initialize ProfilerRecorder with Marker Instance (C#) Source: https://docs.unity3d.com/2023.2/Documentation/ScriptReference/Unity.Profiling This C# declaration illustrates initializing a ProfilerRecorder using an existing Unity.Profiling.ProfilerMarker instance, along with capacity and options for data collection. ```csharp public ProfilerRecorder(Unity.Profiling.ProfilerMarker marker, int capacity, Unity.Profiling.ProfilerRecorderOptions options); ``` -------------------------------- ### RenderTargetSetup Constructor Overloads Source: https://docs.unity3d.com/2023.2/Documentation/ScriptReference/RenderTargetSetup-ctor This section details the various overloads for the RenderTargetSetup constructor, allowing for different configurations of color and depth buffers, mip levels, and cubemap faces. ```APIDOC ## RenderTargetSetup Constructor ### Description Constructs RenderTargetSetup. ### Method `public RenderTargetSetup(RenderBuffer color, RenderBuffer depth)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) None #### Response Example None --- ## RenderTargetSetup Constructor ### Description Constructs RenderTargetSetup. ### Method `public RenderTargetSetup(RenderBuffer color, RenderBuffer depth, int mipLevel)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) None #### Response Example None --- ## RenderTargetSetup Constructor ### Description Constructs RenderTargetSetup. ### Method `public RenderTargetSetup(RenderBuffer color, RenderBuffer depth, int mipLevel, CubemapFace face)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) None #### Response Example None --- ## RenderTargetSetup Constructor ### Description Constructs RenderTargetSetup. ### Method `public RenderTargetSetup(RenderBuffer[] color, RenderBuffer depth)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) None #### Response Example None --- ## RenderTargetSetup Constructor ### Description Constructs RenderTargetSetup. ### Method `public RenderTargetSetup(RenderBuffer[] color, RenderBuffer depth, int mipLevel)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) None #### Response Example None --- ## RenderTargetSetup Constructor ### Description Constructs RenderTargetSetup. ### Method `public RenderTargetSetup(RenderBuffer[] color, RenderBuffer depth, int mip, CubemapFace face)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) None #### Response Example None ``` -------------------------------- ### Provider.UpdateSettings API Source: https://docs.unity3d.com/2023.2/Documentation/ScriptReference/VersionControl.Provider Starts a task that sends the version control settings to the version control system. This includes password, username, server, and workspace details. It can be used to reconnect after credential changes. ```APIDOC ## Provider.UpdateSettings ### Description Starts a task that sends the version control settings to the version control system. The settings can be found in the Project Settings, Version Control tab and include version control password, username, server, workspace etc. The task can be used to reconnect to an existing version control system after making changes to the version control credentials. ### Method `static` ### Endpoint `Provider.UpdateSettings()` ### Parameters None ### Request Example ```json { "method": "Provider.UpdateSettings" } ``` ### Response #### Success Response (200) - **Task** (VersionControl.Task) - A task object representing the ongoing operation. #### Response Example ```json { "taskStatus": "InProgress", "taskId": "some-unique-task-id" } ``` ``` -------------------------------- ### Configure Global Audio Settings and Callbacks with C# Source: https://context7.com/context7/unity3d_2023_2_scriptreference/llms.txt Allows querying and configuring global audio system settings, including sample rate, speaker mode, and DSP buffer size. It also demonstrates subscribing to audio configuration change events. Requires Unity's Audio module. ```csharp using UnityEngine; public class GlobalAudioSetup : MonoBehaviour { void Start() { // Query audio system Debug.Log($"Output sample rate: {AudioSettings.outputSampleRate}"); Debug.Log($"Speaker mode: {AudioSettings.speakerMode}"); Debug.Log($"DSP buffer size: {AudioSettings.GetConfiguration().dspBufferSize}"); // Check driver capabilities if ((AudioSettings.driverCapabilities & AudioSpeakerMode.Surround) != 0) { Debug.Log("Surround sound supported"); } // Configure audio var config = AudioSettings.GetConfiguration(); config.sampleRate = 48000; config.speakerMode = AudioSpeakerMode.Stereo; config.numRealVoices = 32; config.numVirtualVoices = 64; AudioSettings.Reset(config); // Subscribe to configuration changes AudioSettings.OnAudioConfigurationChanged += OnAudioConfigChanged; } void OnAudioConfigChanged(bool deviceWasChanged) { if (deviceWasChanged) { Debug.Log("Audio device changed - reinitializing audio"); // Reload audio clips or adjust settings } } double GetCurrentDSPTime() { // Get precise audio timing return AudioSettings.dspTime; } void OnDestroy() { AudioSettings.OnAudioConfigurationChanged -= OnAudioConfigChanged; } } ``` -------------------------------- ### Get Application Build GUID (C#) Source: https://docs.unity3d.com/2023.2/Documentation/ScriptReference/Application-buildGUID This snippet demonstrates how to access the build GUID of a Unity application using C#. The buildGUID property is static and read-only, meaning it can be accessed directly via the Application class without needing an instance. It does not require any specific Unity version or external dependencies. ```csharp using UnityEngine; public class BuildGUIDExample : MonoBehaviour { void Start() { string guid = Application.buildGUID; Debug.Log("Build GUID: " + guid); } } ``` -------------------------------- ### Unity Keyframe outWeight Example Source: https://docs.unity3d.com/2023.2/Documentation/ScriptReference/Keyframe-outWeight Demonstrates how to set the outgoing weight for keyframes in a Unity AnimationCurve. This affects the slope of the curve segment starting from the keyframe. The example utilizes C# and the UnityEngine namespace, creating keyframes with specific weighted modes and outWeights to define the animation curve's behavior. ```csharp using UnityEngine; public class KeyFrameWeightExample : MonoBehaviour { AnimationCurve animCurve = null; void Start() { Keyframe[] ks = new Keyframe[3]; ks[0] = new Keyframe(0, 0); ks[0].weightedMode = WeightedMode.Out; ks[0].outWeight = 0.5f; ks[1] = new Keyframe(4, 0); ks[1].weightedMode = WeightedMode.Out; ks[1].outWeight = 0f; ks[2] = new Keyframe(6, 0); ks[2].weightedMode = WeightedMode.Out; ks[2].outWeight = 1f / 3f; animCurve = new AnimationCurve(ks); } void Update() { if (animCurve != null) transform.position = new Vector3(Time.time, animCurve.Evaluate(Time.time), 0); } } ``` -------------------------------- ### Get Texture Mipmap Upload Count (C#) Source: https://docs.unity3d.com/2023.2/Documentation/ScriptReference/Texture-streamingMipmapUploadCount Retrieves the total number of times a Texture has been uploaded due to mipmap streaming since the game started. This is a static property that can be accessed directly. ```csharp public static ulong streamingMipmapUploadCount; ``` -------------------------------- ### Initialize ProfilerRecorder with Recorder Handle (C#) Source: https://docs.unity3d.com/2023.2/Documentation/ScriptReference/Unity.Profiling This C# declaration shows how to initialize a ProfilerRecorder using a Unity.Profiling.LowLevel.Unsafe.ProfilerRecorderHandle, specifying the capacity and desired options for recording. ```csharp public ProfilerRecorder(Unity.Profiling.LowLevel.Unsafe.ProfilerRecorderHandle statHandle, int capacity, Unity.Profiling.ProfilerRecorderOptions options); ``` -------------------------------- ### AssetImporter.userData C# Example Source: https://docs.unity3d.com/2023.2/Documentation/ScriptReference/AssetImporter-userData Demonstrates how to get or set user-defined data associated with an asset importer. This can be used to store auxiliary information, such as configuration for post-processing steps, directly within the asset's import settings. ```csharp public string userData; // Example usage within a custom AssetPostprocessor: public class MyAssetPostprocessor : AssetPostprocessor { void OnPostprocessAllAssets(string[] importedAssets, AssetMoveResult[] moveResults) { foreach (string assetPath in importedAssets) { AssetImporter importer = AssetImporter.GetAtPath(assetPath); if (importer != null) { // Set user data importer.userData = "your_xml_here"; // Get user data string data = importer.userData; Debug.Log("User data for " + assetPath + ": " + data); } } } } ``` -------------------------------- ### Get and Set Rigidbody2D Inertia - C# Source: https://docs.unity3d.com/2023.2/Documentation/ScriptReference/Rigidbody2D-inertia Demonstrates how to access and modify the inertia property of a Rigidbody2D component in Unity using C#. Inertia controls the resistance to angular velocity changes. This example shows a basic getter and setter. ```csharp public float inertia; // Example of getting the inertia: float currentInertia = rigidbody2D.inertia; // Example of setting the inertia: rigidbody2D.inertia = 5.0f; ``` -------------------------------- ### Unity C# Example: Using SearchService.GetItems Source: https://docs.unity3d.com/2023.2/Documentation/ScriptReference/Search.SearchService Demonstrates how to use `SearchService.GetItems` to perform a synchronous search within Unity. It requires the `UnityEditor` and `UnityEditor.Search` namespaces and creates a search context to find scene items. ```csharp using System.Collections.Generic; using UnityEditor; using UnityEditor.Search; using UnityEngine; static class Example_SearchService_GetItems { [MenuItem("Examples/SearchService/GetItems")] public static void Run() { // Create a container to hold found items. var results = new List(); // Create the search context that will be used to execute the query. using (var searchContext = SearchService.CreateContext("scene", "is:leaf")) { // Initiate the query and get the results. // Note: it is recommended to use SearchService.Request if you wish to fetch the items asynchronously. results = SearchService.GetItems(searchContext, SearchFlags.WantsMore | SearchFlags.Synchronous); // Print results foreach (var searchItem in results) Debug.Log(searchItem.GetDescription(searchContext)); } } } ``` -------------------------------- ### FlowId - Unity C# Code Example Source: https://docs.unity3d.com/2023.2/Documentation/ScriptReference/Profiling.RawFrameDataView.FlowEvent The FlowId property is a public unsigned integer used to track all profiler samples belonging to the same logical flow. It functions as a global counter, starting from 1 and incrementing for each new ProfilerFlowEventType.Begin event. ```csharp public uint FlowId; ``` -------------------------------- ### PhraseRecognitionSystem.StatusDelegate Documentation Source: https://docs.unity3d.com/2023.2/Documentation/ScriptReference/Windows.Speech.PhraseRecognitionSystem Documentation for the PhraseRecognitionSystem.StatusDelegate, including its parameters and purpose. ```APIDOC ## PhraseRecognitionSystem.StatusDelegate ### Description Delegate for OnStatusChanged event. ### Method N/A (Delegate Declaration) ### Endpoint N/A ### Parameters #### Parameters - **status** (Windows.Speech.SpeechSystemStatus) - The new status of the phrase recognition system. ``` -------------------------------- ### Deprecated AudioSettings.speakerMode in C# Source: https://docs.unity3d.com/2023.2/Documentation/ScriptReference/AudioSettings-speakerMode The `AudioSettings.speakerMode` property is deprecated in Unity. It was used to get or set the current speaker mode for audio output. Developers should now use `AudioSettings.GetConfiguration()` to retrieve audio settings and `AudioSettings.Reset()` to apply changes, as shown in the example. ```csharp public static AudioSpeakerMode speakerMode; // Deprecated. Use AudioSettings.GetConfiguration and AudioSettings.Reset instead. // Example of how it might have been used (conceptually): // AudioSpeakerMode currentMode = AudioSettings.speakerMode; // AudioSettings.speakerMode = AudioSpeakerMode.Stereo; // Recommended approach: // AudioConfiguration config = AudioSettings.GetConfiguration(); // config.speakerOutput = AudioSpeakerMode.Stereo; // AudioSettings.Reset(config); ``` -------------------------------- ### Check if WebCamTexture is Playing (C#) Source: https://docs.unity3d.com/2023.2/Documentation/ScriptReference/WebCamTexture-isPlaying This C# code snippet demonstrates how to initialize a WebCamTexture, start its playback, and then check if it is currently playing using the `isPlaying` property. It logs the boolean result to the Unity console. This example requires the `UnityEngine` namespace. ```csharp using UnityEngine; public class Example : MonoBehaviour { // Tries to start the camera and outputs to the console if is was sucessful or not. void Start() { WebCamTexture webcamTexture = new WebCamTexture(); webcamTexture.Play(); Debug.Log(webcamTexture.isPlaying); } } ``` -------------------------------- ### IPropertyAccept.Accept Method Source: https://docs.unity3d.com/2023.2/Documentation/ScriptReference/Unity.Properties.IPropertyAccept_1 Details on how to use the Accept method within the IPropertyAccept interface, which is used for visitor pattern implementations. ```APIDOC ## public void Accept(Unity.Properties.IPropertyVisitor visitor, ref TContainer container); ### Description Call this method to invoke IPropertyVisitor.Visit_2 with the strongly typed container and value. ### Method public void ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```csharp // Example usage would depend on the specific implementation of IPropertyVisitor and TContainer ``` ### Response #### Success Response (void) This method does not return a value. #### Response Example N/A ### Error Handling N/A ``` -------------------------------- ### ProfilerRecorder Constructor Overloads Source: https://docs.unity3d.com/2023.2/Documentation/ScriptReference/Unity.Profiling This section details the various overloads for the ProfilerRecorder constructor, allowing for initialization with different combinations of category, stat name, capacity, and options. ```APIDOC ## ProfilerRecorder Constructor ### Description Constructs a ProfilerRecorder instance. ### Declaration `public ProfilerRecorder(string categoryName, string statName, int capacity, Unity.Profiling.ProfilerRecorderOptions options);` `public ProfilerRecorder(Unity.Profiling.ProfilerCategory category, string statName, int capacity, Unity.Profiling.ProfilerRecorderOptions options);` `public ProfilerRecorder(string statName, int capacity, Unity.Profiling.ProfilerRecorderOptions options);` `public ProfilerRecorder(Unity.Profiling.ProfilerCategory category, char* statName, int statNameLen, int capacity, Unity.Profiling.ProfilerRecorderOptions options);` `public ProfilerRecorder(Unity.Profiling.ProfilerMarker marker, int capacity, Unity.Profiling.ProfilerRecorderOptions options);` `public ProfilerRecorder(Unity.Profiling.LowLevel.Unsafe.ProfilerRecorderHandle statHandle, int capacity, Unity.Profiling.ProfilerRecorderOptions options);` ### Parameters #### Path Parameters - **categoryName** (string) - Profiler category name. - **statName** (string) - Profiler marker or counter name. - **capacity** (int) - Maximum amount of samples to be collected. - **options** (Unity.Profiling.ProfilerRecorderOptions) - Profiler recorder options. - **category** (Unity.Profiling.ProfilerCategory) - Profiler category identifier. - **statName** (char*) - Profiler marker or counter name pointer. - **statNameLen** (int) - Profiler marker or counter name length. - **marker** (Unity.Profiling.ProfilerMarker) - Profiler marker instance. - **statHandle** (Unity.Profiling.LowLevel.Unsafe.ProfilerRecorderHandle) - Profiler recorder handle. ### Description Constructs ProfilerRecorder instance with a Profiler metric name and category. Use to initialize ProfilerRecorder and associate it with a specific Profiler metric. By default, ProfilerRecorder does not start collecting data immediately. Use ProfilerRecorderOptions.StartImmediately to enable collection together with ProfilerRecorder construction. Alternatively, use Start method after construction. If the CurrentValue is the only data you are interested in, you do not need to start ProfilerRecorder or allocate sample storage. In this case, use 0 as a capacity parameter when creating ProfilerRecorder. **Note:** ProfilerRecorder allocates memory and must be disposed when it is no longer needed. ### Request Example ```csharp using Unity.Profiling; using UnityEngine; public class ExampleScript : MonoBehaviour { ProfilerRecorder systemMemoryRecorder; ProfilerRecorder gcMemoryRecorder; ProfilerRecorder mainThreadTimeRecorder; void OnEnable() { systemMemoryRecorder = new ProfilerRecorder(ProfilerCategory.Memory, "System Used Memory", 1, ProfilerRecorderOptions.Default | ProfilerRecorderOptions.StartImmediately); gcMemoryRecorder = new ProfilerRecorder(ProfilerCategory.Memory, "GC Reserved Memory", 1, ProfilerRecorderOptions.Default | ProfilerRecorderOptions.StartImmediately); mainThreadTimeRecorder = new ProfilerRecorder(ProfilerCategory.Internal, "Main Thread", 15); mainThreadTimeRecorder.Start(); } void OnDisable() { systemMemoryRecorder.Dispose(); gcMemoryRecorder.Dispose(); mainThreadTimeRecorder.Dispose(); } } ``` ### Response #### Success Response (200) - **ProfilerRecorder** (object) - A new instance of ProfilerRecorder. ``` -------------------------------- ### Get Pixels from a CubemapArray Slice in C# Source: https://docs.unity3d.com/2023.2/Documentation/ScriptReference/CubemapArray This example demonstrates how to retrieve pixel data from a specific slice (cubemap) of a CubemapArray. The GetPixels method returns an array of Color structs. This is useful for reading texture data back from the GPU. ```csharp using UnityEngine; public class CubemapArrayGetter : MonoBehaviour { public CubemapArray targetCubemapArray; public int sliceIndex = 0; void Start() { if (targetCubemapArray == null || sliceIndex < 0 || sliceIndex >= targetCubemapArray.cubemapCount) { Debug.LogError("Invalid CubemapArray or slice index."); return; } int width = targetCubemapArray.width; int height = targetCubemapArray.height; // Get the pixel data for the specified slice (face is ignored for GetPixels on CubemapArray) Color[] pixels = targetCubemapArray.GetPixels(sliceIndex, 0); Debug.Log("Retrieved " + pixels.Length + " pixels from slice " + sliceIndex); // You can now process the 'pixels' array. // For example, check the color of the first pixel: if (pixels.Length > 0) { Debug.Log("First pixel color: " + pixels[0]); } } } ``` -------------------------------- ### Set and Modify Rigidbody2D Rotation in Unity Source: https://docs.unity3d.com/2023.2/Documentation/ScriptReference/Rigidbody2D-rotation This C# script demonstrates how to get and set the rotation of a Rigidbody2D component in Unity. It initializes the rotation in Start() and modifies it incrementally in FixedUpdate(). Ensure a Rigidbody2D component is attached to the GameObject for this script to function correctly. ```csharp using UnityEngine; // Rotate rigidBody2D every frame. Start at 45 degrees. public class ExampleScript : MonoBehaviour { public Rigidbody2D rigidBody2D; void Start() { rigidBody2D = GetComponent(); rigidBody2D.rotation = 45f; } void FixedUpdate() { rigidBody2D.rotation += 1.0f; } } ``` -------------------------------- ### LightingWindowTab.OnSummaryGUI Source: https://docs.unity3d.com/2023.2/Documentation/ScriptReference/LightingWindowTab Documentation for the OnSummaryGUI method, a callback for drawing the bottom section of a tab. ```APIDOC ## LightingWindowTab.OnSummaryGUI ### Description A callback that is called when drawing the bottom section of the tab. ### Method `void OnSummaryGUI()` ### Endpoint N/A (This is a class method, not an API endpoint) ### Parameters This method does not take any parameters. ### Request Example N/A (This is a C# method call within the Unity editor) ### Response This method does not return a value. It is a callback for UI rendering. ``` -------------------------------- ### Get Current Animator Clip Info in C# Source: https://docs.unity3d.com/2023.2/Documentation/ScriptReference/AnimatorClipInfo This C# script demonstrates how to retrieve and log the name of the currently playing animation clip from an Animator component attached to a GameObject. It requires an Animator component and a setup Animator Controller on the GameObject. ```csharp //Create a GameObject and attach an Animator component (Click the Add Component button in the Inspector of the GameObject and go to Miscellaneous>Animator). Set up the Animator how you would like. //Attach this script to the GameObject //This script outputs the current clip from the Animator to the console using UnityEngine; public class AnimationClipInfoClipExample : MonoBehaviour { Animator m_Animator; AnimatorClipInfo[] m_AnimatorClipInfo; // Use this for initialization void Start() { //Fetch the Animator component from the GameObject m_Animator = GetComponent(); //Get the animator clip information from the Animator Controller m_AnimatorClipInfo = m_Animator.GetCurrentAnimatorClipInfo(0); //Output the name of the starting clip Debug.Log("Starting clip : " + m_AnimatorClipInfo[0].clip); } } ``` -------------------------------- ### Unity Coroutine WaitWhile Example in C# Source: https://docs.unity3d.com/2023.2/Documentation/ScriptReference/WaitWhile Demonstrates how to use WaitWhile in a Unity coroutine to pause execution until a condition (frame count) is met. This script requires a MonoBehaviour to run. It logs messages indicating the start of the wait, the frame count during the wait, and the completion of the wait. ```csharp using UnityEngine; using System.Collections; public class WaitWhileExample : MonoBehaviour { public int frame; void Start() { StartCoroutine(Example()); } IEnumerator Example() { Debug.Log("Waiting for prince/princess to rescue me..."); yield return new WaitWhile(() => frame < 10); Debug.Log("Finally I have been rescued!"); } void Update() { if (frame <= 10) { Debug.Log("Frame: " + frame); frame++; } } } ``` -------------------------------- ### Set Profiler Log File and Enable Profiling in C# Source: https://docs.unity3d.com/2023.2/Documentation/ScriptReference/Profiling This C# snippet demonstrates how to set the profiling log file, enable binary logging, and enable the profiler. It also shows how to optionally increase the buffer memory and how to disable and re-enable profiling with a new log file. Dependencies include `UnityEngine` and `UnityEngine.Profiling`. ```csharp using UnityEngine; using System.Collections; using UnityEngine.Profiling; public class ExampleClass : MonoBehaviour { void Start() { Profiler.logFile = "mylog"; //Also supports passing "myLog.raw" Profiler.enableBinaryLog = true; Profiler.enabled = true; // Optional, if more memory is needed for the buffer Profiler.maxUsedMemory = 256 * 1024 * 1024; // ... // Optional, to close the file when done Profiler.enabled = false; Profiler.logFile = ""; // To start writing to a new log file Profiler.logFile = "myOtherLog"; Profiler.enabled = true; // ... } } ``` -------------------------------- ### WindZone Constructor Source: https://docs.unity3d.com/2023.2/Documentation/ScriptReference/WindZone-ctor Provides information about the declaration and basic description of the WindZone constructor. ```APIDOC ## WindZone Constructor ### Description The constructor. ### Method public ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### RenderTexture.height - C# Example Source: https://docs.unity3d.com/2023.2/Documentation/ScriptReference/RenderTexture-height This snippet demonstrates how to access and modify the height of a RenderTexture. The `height` property is read and write, meaning you can get the current height and also set a new height to resize the texture. Ensure the RenderTexture is properly initialized before attempting to access or modify its properties. ```csharp public int height; // Example of accessing the height: int currentHeight = renderTexture.height; // Example of setting the height: renderTexture.height = 512; // Note: Setting a new height resizes the RenderTexture. ```