### Run Unity Accelerator Installer with Custom Directories and TLS Configuration Source: https://docs.unity3d.com/Manual/accelerator-install-installer.html Configure installation and storage directories, and specify TLS settings for unattended installations. This example sets TLS to 'none'. ```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 ``` -------------------------------- ### Example Unity Installer Missing Dependencies List Source: https://docs.unity3d.com/Manual/ent-unpriv-install.html This is an example of the text file generated by the Unity Installer listing missing runtime dependencies and their download/local installation paths. Administrators should use this to install necessary components. ```text Dependency: Visual C++ 2010 runtime (x64) Download location: https://www.microsoft.com/en-ca/download/details.aspx?id=26999 Local Installer: C:\Users\nonadmin\AppData\Local\Unity 2023.1.0a5\MissingDependencies\vcredist_x64_2010.exe Dependency: Visual C++ 2013 runtime (x64) Download location: https://www.microsoft.com/en-ca/download/details.aspx?id=40784 Local Installer: C:\Users\nonadmin\AppData\Local\Unity 2023.1.0a5\MissingDependencies\vcredist_x64_2013.exe Dependency: Visual C++ 2015 runtime (x64) Download location: https://www.microsoft.com/en-ca/download/details.aspx?id=48145 Local Installer: C:\Users\nonadmin\AppData\Local\Unity 2023.1.0a5\MissingDependencies\vcredist_x64_2015.exe ``` -------------------------------- ### Text Mode Installation Example Source: https://docs.unity3d.com/Manual/accelerator-download.html This command initiates a text-based installation for the Unity Accelerator on Linux and macOS. This mode is useful for environments where a graphical interface is not available. ```bash unity-accelerator-v1.5.99+g262ce04b-linux-x64-installer.run --mode text ``` -------------------------------- ### Unattended Installation Example Source: https://docs.unity3d.com/Manual/accelerator-download.html Use this command to perform an unattended installation of the Unity Accelerator. Ensure you replace 'pwd' with your actual password and adjust TLS configuration as needed. ```bash unity-accelerator-v1.5.99+g262ce04b-linux-x64-installer.run --mode unattended --admin-username admin --admin-password pwd --tls-config none ``` -------------------------------- ### Base and Derived Class Test Setup/Teardown Example Source: https://docs.unity3d.com/Manual/test-framework/reference-unitysetup-and-unityteardown.html Demonstrates the execution order of UnitySetUp, UnityTearDown, SetUp, TearDown, OneTimeSetUp, and OneTimeTearDown attributes across base and derived classes. Use this to understand how setup and teardown methods are invoked in a hierarchical test structure. ```csharp public class BaseClass { [OneTimeSetUp] public void OneTimeSetUp() { Debug.Log("OneTimeSetUp Base"); } [SetUp] public void SetUp() { Debug.Log("SetUp Base"); } [UnitySetUp] public IEnumerator UnitySetUp() { Debug.Log("UnitySetup Base"); yield return null; } [TearDown] public void TearDown() { Debug.Log("TearDown Base"); } [UnityTearDown] public IEnumerator UnityTearDown() { Debug.Log("UnityTearDown Base"); yield return null; } } public class DerivedClass: BaseClass { [OneTimeSetUp] public new void OneTimeSetUp() { Debug.Log("OneTimeSetUp"); } [SetUp] public new void SetUp() { Debug.Log("SetUp"); } [UnitySetUp] public new IEnumerator UnitySetUp() { Debug.Log("UnitySetup"); yield return null; } [Test] public void UnitTest() { Debug.Log("Test"); } [UnityTest] public IEnumerator UnityTest() { Debug.Log("UnityTest before yield"); yield return null; Debug.Log("UnityTest after yield"); } [TearDown] public new void TearDown() { Debug.Log("TearDown"); } [UnityTearDown] public new IEnumerator UnityTearDown() { Debug.Log("UnityTearDown"); yield return null; } [OneTimeTearDown] public void OneTimeTearDown() { Debug.Log("OneTimeTearDown"); } } ``` -------------------------------- ### Unity Test Domain Reload Setup and Teardown Example Source: https://docs.unity3d.com/Manual/test-framework/reference-unitysetup-and-unityteardown.html Illustrates the execution order of OneTimeSetup, Setup, UnitySetUp, Test, UnityTest, TearDown, UnityTearDown, and OneTimeTearDown methods in base and derived classes when a domain reload occurs during a UnityTest. ```csharp public class BaseClass { [OneTimeSetUp] public void OneTimeSetUp() { Debug.Log("OneTimeSetUp Base"); } [SetUp] public void SetUp() { Debug.Log("SetUp Base"); } [UnitySetUp] public IEnumerator UnitySetUp() { Debug.Log("UnitySetup Base"); yield return null; } [TearDown] public void TearDown() { Debug.Log("TearDown Base"); } [UnityTearDown] public IEnumerator UnityTearDown() { Debug.Log("UnityTearDown Base"); yield return null; } } public class DerivedClass: BaseClass { [OneTimeSetUp] public new void OneTimeSetUp() { Debug.Log("OneTimeSetUp"); } [SetUp] public new void SetUp() { Debug.Log("SetUp"); } [UnitySetUp] public new IEnumerator UnitySetUp() { Debug.Log("UnitySetup"); yield return null; } [Test] public void UnitTest() { Debug.Log("Test"); } [UnityTest] public IEnumerator UnityTest() { Debug.Log("UnityTest before yield"); yield return new EnterPlayMode(); //Domain reload happening yield return new ExitPlayMode(); Debug.Log("UnityTest after yield"); } [TearDown] public new void TearDown() { Debug.Log("TearDown"); } [UnityTearDown] public new IEnumerator UnityTearDown() { Debug.Log("UnityTearDown"); yield return null; } [OneTimeTearDown] public void OneTimeTearDown() { Debug.Log("OneTimeTearDown"); } } ``` -------------------------------- ### Sample services-config.json for Standard User Installation Source: https://docs.unity3d.com/Manual/ent-unpriv-install.html This is a sample `services-config.json` file that enables standard user installations and specifies a shared installation directory. ```json { "hubDisableElevate": true, "machineWideSecondaryInstallLocation": "C:\\UnityEditors" } ``` -------------------------------- ### Example Git LFS Version Output Source: https://docs.unity3d.com/Manual/upm-errors.html This is an example of the output you should see if Git LFS is installed correctly. It confirms the presence and version of the Git LFS installation. ```text git-lfs/2.8.0 (GitHub; darwin amd64; go 1.12.7) ``` -------------------------------- ### Unity Object Reference Example in YAML Source: https://docs.unity3d.com/Manual/assets-direct-reference.html This example shows how a MonoBehaviour field references a Prefab asset using fileID, GUID, and type. The fileID points to the specific object within the asset, and the GUID identifies the asset file itself. ```yaml MonoBehaviour: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 100100000} # Reference to the GameObject this component is on (internal fileID) m_Enabled: 1 m_EditorHideFlags: 1 m_Script: {fileID: 11500000, guid: f5ee4a4c1e4c3b448a97448840cdf0f41, type: 3} # Reference to the MonoBehaviour script asset (GUID of script file, fileID 11500000 often for MonoBehaviour) myTargetPrefab: {fileID: 100100000, guid: 61da4d63ca179b54a97448840cdf0f41, type: 3} # Reference to an external Prefab asset (GUID of Prefab file, fileID 100100000 for the root GameObject within the Prefab) ``` -------------------------------- ### Return Unity License (Windows Example) Source: https://docs.unity3d.com/Manual/ManagingYourUnityLicense.html Example command to return a Unity license on Windows. ```bash "C:\Program Files\Unity\Hub\Editor\2022.2.0b4\Editor\Unity.exe" -quit -batchmode -returnlicense -username name@example.com -password XXXXXXXXXXXXX ``` -------------------------------- ### Starting a Coroutine in Unity Source: https://docs.unity3d.com/Manual/Coroutines.html This example shows how to initiate a coroutine named 'Fade' when the 'f' key is pressed. Coroutines are started using the StartCoroutine method. ```csharp void Update() { if (Input.GetKeyDown("f")) { StartCoroutine(Fade()); } } ``` -------------------------------- ### Get Runtime Memory Size Example Source: https://docs.unity3d.com/Manual/profiler-counters-reference.html Demonstrates how to find objects of specific types and get their memory size using Profiler methods. This approach is recommended for release builds. ```csharp long meshMemory = Profiler.GetRuntimeMemorySizeLong(Object.FindObjectsByType().Length); long meshCount = Object.FindObjectsByType().Length; ``` -------------------------------- ### Install Unity components on Windows Source: https://docs.unity3d.com/Manual/InstallingUnity.html Install additional components like platform build support to the Unity root folder. ```bash UnitySetup-Android-Support-for-Editor-6000.0.23f1.exe /S /D=C:\Program Files\Unity 6000.0.23f1 ``` -------------------------------- ### Full Nginx Configuration Example Source: https://docs.unity3d.com/Manual/web-server-config-nginx.html Comprehensive example covering pre-compressed Brotli and Gzip assets, MIME types, and optional security headers. ```nginx http { # ... server { # Add the following config within the existing http server configuration # Nest inside existing location rule location / { # ... # On-disk Brotli-precompressed data files should be served with compression enabled: location ~ .+\.(data|symbols\.json)\.br$ { # Because this file is already pre-compressed on disk, disable the on-demand compression on it. # Otherwise nginx would attempt double compression. gzip off; add_header Content-Encoding br; default_type application/octet-stream; } # On-disk Brotli-precompressed JavaScript code files: location ~ .+\.js\.br$ { gzip off; # Do not attempt dynamic gzip compression on an already compressed file add_header Content-Encoding br; default_type application/javascript; } # On-disk Brotli-precompressed WebAssembly files: location ~ .+\.wasm\.br$ { gzip off; # Do not attempt dynamic gzip compression on an already compressed file add_header Content-Encoding br; # Enable streaming WebAssembly compilation by specifying the correct MIME type for # Wasm files. default_type application/wasm; } # On-disk gzip-precompressed data files should be served with compression enabled: location ~ .+\.(data|symbols\.json)\.gz$ { gzip off; # Do not attempt dynamic gzip compression on an already compressed file add_header Content-Encoding gzip; default_type application/gzip; } # On-disk gzip-precompressed JavaScript code files: location ~ .+\.js\.gz$ { gzip off; # Do not attempt dynamic gzip compression on an already compressed file add_header Content-Encoding gzip; # The correct MIME type here would be application/octet-stream, but due to Safari bug https://bugs.webkit.org/show_bug.cgi?id=247421, it's preferable to use MIME Type application/gzip instead. default_type application/javascript; } # On-disk gzip-precompressed WebAssembly files: location ~ .+\.wasm\.gz$ { gzip off; # Do not attempt dynamic gzip compression on an already compressed file add_header Content-Encoding gzip; # Enable streaming WebAssembly compilation by specifying the correct MIME type for # Wasm files. default_type application/wasm; } # Uncomment the following lines if build was created with "Enable Native C/C++ Multithreading" player settings # location ~ .+\.(htm|html|js|js\.gz|js\.br)$ { # add_header Cross-Origin-Opener-Policy same-origin; # add_header Cross-Origin-Embedder-Policy require-corp; # add_header Cross-Origin-Resource-Policy cross-origin; # } # Uncomment the following line to allow CORS requests # add_header Access-Control-Allow-Origin *; } } } ``` -------------------------------- ### C# Example for ObjectField Customization Source: https://docs.unity3d.com/Manual/UIE-uxml-element-ObjectField.html This C# example shows how to get a reference to an ObjectField from UXML, assign a value, create a new field, disable it, apply styles, and mirror values between fields. ```csharp // Get a reference to the field from UXML and assign a value to it. var uxmlField = container.Q("the-uxml-field"); uxmlField.value = new Texture2D(10, 10) { name = "new_texture" }; // Create a new field, disable it, and give it a style class. var csharpField = new ObjectField("C# Field"); csharpField.SetEnabled(false); csharpField.AddToClassList("some-styled-field"); csharpField.value = uxmlField.value; container.Add(csharpField); // Mirror the value of the UXML field into the C# field. uxmlField.RegisterCallback>((evt) => { csharpField.value = evt.newValue; }); ``` -------------------------------- ### Example: Pack and Sign a Package Source: https://docs.unity3d.com/Manual/upm-cli-pack.html This example demonstrates how to pack a package located in the './package' subfolder, sign it with a specific organization ID, and save the output tarball to the './output' subfolder. ```bash upm pack ./package --organization-id 1234567890123 --destination ./output ``` -------------------------------- ### Example URP Dependency in manifest.json Source: https://docs.unity3d.com/Manual/urp/upgrade-lwrp-to-urp.html This is an example of how the dependencies section in your project's manifest.json file should look after adding the URP dependency. Ensure the version number matches the URP version installed in your project. ```json "dependencies": { "com.unity.render-pipelines.universal": "7.1.1", ... } ``` -------------------------------- ### Return Unity License (Linux Example) Source: https://docs.unity3d.com/Manual/ManagingYourUnityLicense.html Example command to return a Unity license on Linux. ```bash /home/username/Unity/Hub/Editor/2022.2.0b4/Unity -quit -batchmode -returnlicense -username 'name@example.com' -password 'XXXXXXXXXXXXX' ``` -------------------------------- ### Require a Package Version Source: https://docs.unity3d.com/Manual/writing-shader-tags-require-package.html This example shows how to set a shader to compile only if `com.my.package` is installed with version 2.2 or higher. ```csharp Shader "Examples/ExampleShader" { SubShader { PackageRequirements { "com.my.package": "2.2" } Pass { PackageRequirements { "com.unity.render-pipelines.universal": "[16.2.1,17.0]" "com.unity.textmeshpro": "3.2" } ... } } } ``` -------------------------------- ### Minimal Package Setup with Metadata Source: https://docs.unity3d.com/Manual/adaptive-performance/create-custom-provider.html This snippet demonstrates the basic structure for a custom Adaptive Performance package, including placeholder classes for settings and loaders, and metadata definitions for the package and its loaders. It's a starting point for creating your own provider. ```csharp using System.Collections.Generic; using UnityEditor; using UnityEngine; using UnityEngine.AdaptivePerformance; using UnityEngine.AdaptivePerformance.Editor.Metadata; // The following are minimal placeholder classes required for this snippet to compile. // In your project, 'MyPackageSettings' and 'MyLoader' would contain your actual custom logic and definitions. public class MyPackageSettings : ScriptableObject { } public class MyLoader : AdaptivePerformanceLoader { public override bool Initialize() { return true; } public override bool Start() { return true; } public override bool Stop() { return true; } public override bool Deinitialize() { return true; } public override T GetLoadedSubsystem() { return null; } public override ISubsystem GetDefaultSubsystem() { return null; } public override IAdaptivePerformanceSettings GetSettings() { return null; } } class MyPackage : IAdaptivePerformancePackage { private class MyLoaderMetadata : IAdaptivePerformanceLoaderMetadata { public string loaderName { get; } = "My Loader"; public string loaderType { get; } = typeof(MyLoader).AssemblyQualifiedName; public List supportedBuildTargets { get; } = new List() { BuildTargetGroup.Standalone, BuildTargetGroup.Android, BuildTargetGroup.iOS }; } private class MyPackageMetadata : IAdaptivePerformancePackageMetadata { public string packageName { get; } = "My AdaptivePerformance Provider"; public string packageId { get; } = "my.adaptiveperformance.package"; public string settingsType { get; } = typeof(MyPackageSettings).AssemblyQualifiedName; public List loaderMetadata { get; } = new List() { new MyLoaderMetadata() }; } private static IAdaptivePerformancePackageMetadata s_Metadata = new MyPackageMetadata(); public IAdaptivePerformancePackageMetadata metadata => s_Metadata; public bool PopulateNewSettingsInstance(ScriptableObject obj) { MyPackageSettings packageSettings = obj as MyPackageSettings; if (packageSettings != null) { return true; } return false; } } ``` -------------------------------- ### Return Unity License (macOS Example) Source: https://docs.unity3d.com/Manual/ManagingYourUnityLicense.html Example command to return a Unity license on macOS. ```bash /Applications/Unity/Hub/Editor/2022.2.0b4/Unity.app/Contents/MacOS/Unity -quit -batchmode -returnlicense -username 'name@example.com' -password 'XXXXXXXXXXXXX' ``` -------------------------------- ### Run All Play Mode Tests Source: https://docs.unity3d.com/Manual/test-framework/extension-run-tests.html Execute all Play mode tests in the project. This is a basic example to start running tests programmatically. ```csharp var testRunnerApi = ScriptableObject.CreateInstance(); var filter = new Filter() { testMode = TestMode.PlayMode }; testRunnerApi.Execute(new ExecutionSettings(filter)); ``` -------------------------------- ### Basic SetUp and TearDown Structure Source: https://docs.unity3d.com/Manual/test-framework/course/setup-teardown.html Illustrates the basic structure of a test class using [SetUp] and [TearDown] attributes for methods that run before and after tests, respectively. This pattern is useful for initializing and cleaning up resources. ```csharp public class TestClass { [SetUp] public void MySetUp() { ... } [Test] public void MyFirstTest() { ... } [Test] public void MySecondTest() { ... } [TearDown] public void MyTearDown() { ... } } ``` -------------------------------- ### Initialize BatchRendererGroup with OnPerformCulling Source: https://docs.unity3d.com/Manual/batch-renderer-group-initializing.html This example demonstrates the minimal setup for a BatchRendererGroup, including the required OnPerformCulling callback and proper disposal of the object. ```csharp using System; using Unity.Collections; using Unity.Collections.LowLevel.Unsafe; using Unity.Jobs; using UnityEngine; using UnityEngine.Rendering; public class SimpleBRGExample : MonoBehaviour { private BatchRendererGroup m_BRG; private void Start() { m_BRG = new BatchRendererGroup(this.OnPerformCulling, IntPtr.Zero); } private void OnDisable() { m_BRG.Dispose(); } public unsafe JobHandle OnPerformCulling( BatchRendererGroup rendererGroup, BatchCullingContext cullingContext, BatchCullingOutput cullingOutput, IntPtr userContext) { // This example doesn't use jobs, so it can return an empty JobHandle. // Performance-sensitive applications should use Burst jobs to implement // culling and draw command output. In this case, this function would return a // handle here that completes when the Burst jobs finish. return new JobHandle(); } } ``` -------------------------------- ### Start Unity Player with environment variables on sh Source: https://docs.unity3d.com/Manual/qnx-deploy.html Example of setting environment variables directly when launching the Unity player in an sh shell. ```bash run SDL_VIDEO_EGL_DRIVER=libEGL_viv.so SDL_VIDEO_GL_DRIVER=libGLESv2_viv.so ./qnxplayer ```