### USS :root Matching Example Setup Source: https://docs.unity3d.com/6000.0/Documentation/Manual/UIE-USS-Selectors-Pseudo-Classes.html Demonstrates the setup of VisualElements in C# for testing USS :root pseudo-class matching behavior. ```csharp var myElement = new VisualElement(); var myElementChild = new VisualElement(); myElement.Add(myElementChild); var myOtherElement = new VisualElement(); ``` -------------------------------- ### Example: Activate Unity License (macOS) Source: https://docs.unity3d.com/6000.0/Documentation/Manual/ManualActivationCmdMac.html This is a concrete example for macOS, assuming specific editor and `.ulf` file paths. Ensure the paths provided match your installation and generated license file. ```bash /Applications/Unity/Hub/Editor/2022.2.0b4/Unity.app/Contents/MacOS/Unity -batchmode -manualLicenseFile /Users/myAccount/Downloads/Unity_v2017.x.ulf -logfile ``` -------------------------------- ### macOS Example: Create Manual Activation File Source: https://docs.unity3d.com/6000.0/Documentation/Manual/ManualActivationCmdMac.html This is a concrete example of the command to create a manual activation file on macOS, assuming a specific Unity Editor version and installation path. ```bash /Applications/Unity/Hub/Editor/2022.2.0b4/Unity.app/Contents/MacOS/Unity -batchmode -createManualActivationFile -logfile ``` -------------------------------- ### Example: Activate Unity License Source: https://docs.unity3d.com/6000.0/Documentation/Manual/ManualActivationCmdWin.html An example demonstrating the command line activation with specific paths for the Unity editor and the license file. ```bash "C:\Program Files\Unity\Hub\Editor\2022.2.0b4\Editor\Unity.exe" -batchmode -manualLicenseFile "C:\Users\myAccount\Downloads\Unity_v2017.x.ulf" -logfile ``` -------------------------------- ### QNX Startup Time Log Output Source: https://docs.unity3d.com/6000.0/Documentation/Manual/qnx-optional-features.html Example of standard QNX startup time logging output, showing real and user time for various initialization stages. ```text [TIMING::STARTUP] Initial probing done: Real: 19 ms | User: 11 ms [TIMING::STARTUP] SDL Initialized: Real: 64 ms | User: 54 ms [TIMING::STARTUP] Scripting runtime loaded: Real: 97 ms | User: 86 ms [TIMING::STARTUP] Plugins loaded: Real: 97 ms | User: 87 ms [TIMING::STARTUP] Engine initialized (nogfx): Real: 104 ms | User: 94 ms [TIMING::STARTUP] Player Prefs loaded: Real: 104 ms | User: 94 ms [TIMING::STARTUP] Screen initialized: Real: 139 ms | User: 112 ms [TIMING::STARTUP] Engine initialized (gfx): Real: 187 ms | User: 161 ms [TIMING::STARTUP] Gfx initialized: Real: 190 ms | User: 163 ms [TIMING::STARTUP] Input initialized: Real: 190 ms | User: 163 ms [TIMING::STARTUP] SPLASH - Begin: Real: 190 ms | User: 164 ms [TIMING::STARTUP] SPLASH - Primary scene assets loaded (async): Real: 2197 ms | User: 1670 ms [TIMING::STARTUP] SPLASH - All engine initial states established: Real: 2197 ms | User: 1670 ms ``` -------------------------------- ### Run Installer in Unattended Mode Source: https://docs.unity3d.com/6000.0/Documentation/Manual/accelerator-install-installer.html Use the `--mode unattended` argument for automated installations. Provide necessary credentials and paths for a seamless setup. ```bash $ unity-accelerator-installer.run --mode unattended --admin-username mark --admin-password xxxxx ``` ```bash $ unity-accelerator-installer.run --mode unattended --admin-username mark --admin-password xxxxx --install-dir /opt/Unity/accelerator/ --storage-dir /var/lib/unity-accelerator --tls-config none ``` -------------------------------- ### Get Mesh Count and Memory Example Source: https://docs.unity3d.com/6000.0/Documentation/Manual/profiler-counters-reference.html Demonstrates how to get Mesh Count and Mesh Memory using Object.FindObjectsByType and Profiler.GetRuntimeMemorySizeLong. This approach is recommended for release players. ```csharp int meshCount = Object.FindObjectsByType().Length; long meshMemory = Profiler.GetRuntimeMemorySizeLong(Object.FindObjectsByType()); ``` -------------------------------- ### Example Built-In Render Pipeline custom shader Source: https://docs.unity3d.com/6000.0/Documentation/Manual/urp/urp-shaders/birp-urp-custom-shader-upgrade-guide.html This is an example of a custom unlit shader written for the Built-In Render Pipeline. It serves as the starting point for the upgrade process to URP compatibility. ```hlsl // Upgrade custom shaders for URP compatibility // Make the custom shader URP compatible // Enable tiling and offset for the shader // Complete shader code Shader "Custom/URPUnlitShader" { Properties { _MainTex ("Texture", 2D) = "white" {} _Color ("Color", Color) = (1,1,1,1) } SubShader { Tags { "RenderType" = "Opaque" } LOD 100 Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag // make fog work #pragma multi_compile_fog #include "UnityCG.cginc" struct appdata { float4 vertex : POSITION; float2 uv : TEXCOORD0; }; struct v2f { float2 uv : TEXCOORD0; float4 vertex : SV_POSITION; UNITY_FOG_COORDS(1) }; sampler2D _MainTex; float4 _MainTex_ST; fixed4 _Color; v2f vert (appdata v) { v2f o; o.vertex = UnityObjectToClipPos(v.vertex); o.uv = TRANSFORM_TEX(v.uv, _MainTex); UNITY_TRANSFER_FOG(o,o.vertex); return o; } fixed4 frag (v2f i) : SV_Target { // sample the texture fixed4 col = tex2D(_MainTex, i.uv) * _Color; // apply fog UNITY_APPLY_FOG(i.fogCoord, col); return col; } ENDCG } } } ``` -------------------------------- ### Example Startup Timing Log Output Source: https://docs.unity3d.com/6000.0/Documentation/Manual/embedded-linux-optional-features.html This is an example of the log output generated by the startup timing system, showing real (wall) and user (CPU) time in milliseconds for various initialization stages. ```text [TIMING::STARTUP] Initial probing done: Real: 19 ms | User: 11 ms [TIMING::STARTUP] SDL Initialized: Real: 64 ms | User: 54 ms [TIMING::STARTUP] Scripting runtime loaded: Real: 97 ms | User: 86 ms [TIMING::STARTUP] Plugins loaded: Real: 97 ms | User: 87 ms [TIMING::STARTUP] Engine initialized (nogfx): Real: 104 ms | User: 94 ms [TIMING::STARTUP] Player Prefs loaded: Real: 104 ms | User: 94 ms [TIMING::STARTUP] Screen initialized: Real: 139 ms | User: 112 ms [TIMING::STARTUP] Engine initialized (gfx): Real: 187 ms | User: 161 ms [TIMING::STARTUP] Gfx initialized: Real: 190 ms | User: 163 ms [TIMING::STARTUP] Input initialized: Real: 190 ms | User: 163 ms [TIMING::STARTUP] SPLASH - Begin: Real: 190 ms | User: 164 ms [TIMING::STARTUP] SPLASH - Primary scene assets loaded (async): Real: 2197 ms | User: 1670 ms [TIMING::STARTUP] SPLASH - All engine initial states established: Real: 2197 ms | User: 1670 ms ``` -------------------------------- ### Create a batch with metadata and instance data Source: https://docs.unity3d.com/6000.0/Documentation/Manual/batch-renderer-group-creating-batches.html This example demonstrates how to create a batch with metadata values and a GraphicsBuffer containing instance data. It builds upon the mesh and material registration example. ```csharp using System; using Unity.Collections; using Unity.Collections.LowLevel.Unsafe; using Unity.Jobs; using UnityEngine; using UnityEngine.Rendering; public class SimpleBRGExample : MonoBehaviour { public Mesh mesh; public Material material; private BatchRendererGroup m_BRG; private GraphicsBuffer m_InstanceData; private BatchID m_BatchID; private BatchMeshID m_MeshID; private BatchMaterialID m_MaterialID; ``` -------------------------------- ### Sample Third Party Notices File Source: https://docs.unity3d.com/6000.0/Documentation/Manual/cus-legal.html This example shows how to structure a `Third Party Notices.md` file to list third-party software components and their licenses. ```text This package contains third-party software components governed by the license(s) indicated below: Component Name: Semver License Type: "MIT" [SemVer License](https://github.com/myusername/semver/blob/master/License.txt) Component Name: MyComponent License Type: "MyLicense" [MyComponent License](https://www.mycompany.com/licenses/License.txt) ``` -------------------------------- ### Scroller Functionality Example Source: https://docs.unity3d.com/6000.0/Documentation/Manual/UIE-uxml-element-Scroller.html Demonstrates getting a Scroller from UXML, setting its value, creating a new Scroller programmatically, disabling it, applying a style class, and mirroring values between Scrollers. This example shows advanced interaction and configuration. ```csharp // Get a reference to the scroller from UXML and assign it its value. var uxmlField = container.Q("the-uxml-scroller"); uxmlField.valueChanged += (v) => {}; uxmlField.value = 42; // Create a new scroller, disable it, and give it a style class. var csharpField = new Scroller(0, 100, (v) => {}, SliderDirection.Vertical); csharpField.SetEnabled(false); csharpField.AddToClassList("some-styled-scroller"); csharpField.value = uxmlField.value; container.Add(csharpField); // Mirror value of uxml scroller into the C# field. uxmlField.RegisterCallback>((evt) => { csharpField.value = evt.newValue; }); ``` -------------------------------- ### Get Left Hand Device by XR Node Source: https://docs.unity3d.com/6000.0/Documentation/Manual/xr_input.html Retrieve devices associated with the `XRNode.LeftHand` to get controllers or other input devices designated for the user's left hand. This example checks for a single device and logs its name and role. ```csharp var leftHandDevices = new List(); UnityEngine.XR.InputDevices.GetDevicesAtXRNode(UnityEngine.XR.XRNode.LeftHand, leftHandDevices); if(leftHandDevices.Count == 1) { UnityEngine.XR.InputDevice device = leftHandDevices[0]; Debug.Log(string.Format("Device name '{0}' with role '{1}'", device.name, device.role.ToString())); } else if(leftHandDevices.Count > 1) { Debug.Log("Found more than one left hand!"); } ``` -------------------------------- ### Search by Area (Index) Source: https://docs.unity3d.com/6000.0/Documentation/Manual/search-assets.html Filter assets by their location: within the Assets folder, installed packages, or both. This example finds materials. ```text p: a: ``` -------------------------------- ### Example Package Asset Path Source: https://docs.unity3d.com/6000.0/Documentation/Manual/upm-assets.html Illustrates the full path to an image file within a specific package and subfolder. ```text Packages/com.unity.images-library/Example/Images/image.png ``` -------------------------------- ### Get ADB Path on Windows PowerShell Source: https://docs.unity3d.com/6000.0/Documentation/Manual/RenderDocIntegration.html Use this command in Windows PowerShell to find the installation path of the ADB executable. ```powershell Get-Command adb | Select-Object Path ``` -------------------------------- ### Samples Example Source: https://docs.unity3d.com/6000.0/Documentation/Manual/upm-manifestPkg.html Defines a list of samples included in the package, each with a display name, description, and path. ```json { "displayName": "My Sample", "description": "A sample demonstrating a feature.", "path": "Samples~/MySampleFolder" } ``` -------------------------------- ### C# Script Calling Quality Level Switch on Start Source: https://docs.unity3d.com/6000.0/Documentation/Manual/urp/quality/quality-settings-through-code.html Integrates the quality level switching logic into the Start method, ensuring the quality settings are adjusted when the scene initially loads. This example demonstrates how to trigger the quality change automatically. ```csharp using System.Collections; using System.Collections.Generic; using UnityEngine; public class QualityControls : MonoBehaviour { void Start() { SwitchQualityLevel(); } private void SwitchQualityLevel() { // Select Quality settings level (URP Asset) based on the size of the device's graphics memory switch (SystemInfo.graphicsMemorySize) { case <= 2048: QualitySettings.SetQualityLevel(1); break; case <= 4096: QualitySettings.SetQualityLevel(2); break; default: QualitySettings.SetQualityLevel(0); break; } } } ``` -------------------------------- ### Unity Initialization and Configuration Source: https://docs.unity3d.com/6000.0/Documentation/Manual/UnityasaLibrary-iOS.html Methods for configuring and launching the Unity runtime. ```APIDOC ## - (void)setDataBundleId:(const char*)bundleId ### Description Sets the Bundle where the Unity runtime should look for the _Data_ folder. Call this method before calling `runUIApplicationMainWithArgc` or `runEmbeddedWithArgc`. ### Method `- (void)setDataBundleId:(const char*)bundleId;` ``` ```APIDOC ## - (void)runUIApplicationMainWithArgc:(int)argc argv:(char*[])argv ### Description The default way to run Unity from the main method where there are no other Views. ### Method `- (void)runUIApplicationMainWithArgc:(int)argc argv:(char*[])argv;` ``` ```APIDOC ## - (void)runEmbeddedWithArgc:(int)argc argv:(char*[])argv appLaunchOpts:(NSDictionary*)appLaunchOpts ### Description Call this method when you need to run Unity when other Views exist. ### Method `- (void)runEmbeddedWithArgc:(int)argc argv:(char*[])argv appLaunchOpts:(NSDictionary*)appLaunchOpts;` ``` ```APIDOC ## - (void)setExecuteHeader:(const MachHeader*)header ### Description You must call this before running Unity in order for CrashReporter to work properly. ### Method `- (void)setExecuteHeader:(const MachHeader*)header;` ``` -------------------------------- ### Package Namespace Examples for Multi-Package Products Source: https://docs.unity3d.com/6000.0/Documentation/Manual/asset-store-upm-create-draft.html Examples of namespaces for packages within a multi-package product. ```text product.package1 ``` ```text product.package2 ``` -------------------------------- ### Find Textures in Packages Source: https://docs.unity3d.com/6000.0/Documentation/Manual/search-assets.html Use the `a` filter to specify the area to search. This example finds all textures located specifically within installed packages. ```text p: a:packages t:texture ``` -------------------------------- ### Find Materials in Packages Source: https://docs.unity3d.com/6000.0/Documentation/Manual/search-assets.html Use the `a` filter to specify the area to search. This example finds all materials located specifically within installed packages. ```text p: a:packages t:material ``` -------------------------------- ### Start Unity Accelerator Service Source: https://docs.unity3d.com/6000.0/Documentation/Manual/accelerator-stop-restart.html Use the `net start` command in a Windows terminal to start the Unity Accelerator service. ```bash C:\> net start "Unity Accelerator" ```