### Static Methods Source: https://docs.unity3d.com/ScriptReference/AMD Outlines the static methods for initializing and managing the GraphicsDevice. ```APIDOC ## Static Methods ### Description Outlines the static methods for initializing and managing the GraphicsDevice. ### Methods - **CreateGraphicsDevice()** - Creates the main API object. Call this method only once in your application. ``` -------------------------------- ### Advanced Animation Event setup in C# Source: https://docs.unity3d.com/ScriptReference/AnimationEvent Complex example showing how to programmatically create and configure animation events. This example accesses the Animator component, gets an animation clip, creates an AnimationEvent with parameters, and adds it to the clip. The event is configured to call PrintEvent function with an integer parameter at 1.3 seconds into a 2-second animation cycle. ```C# // Add an Animation Event to a GameObject that has an Animator using UnityEngine; using System.Collections; public class Example : MonoBehaviour { public void Start() { // existing components on the GameObject AnimationClip clip; Animator anim; // new event created AnimationEvent evt; evt = new AnimationEvent(); // put some parameters on the AnimationEvent // - call the function called PrintEvent() // - the animation on this object lasts 2 seconds // and the new animation created here is // set up to happen 1.3s into the animation evt.intParameter = 12345; evt.time = 1.3f; evt.functionName = "PrintEvent"; // get the animation clip and add the AnimationEvent anim = GetComponent(); clip = anim.runtimeAnimatorController.animationClips[0]; clip.AddEvent(evt); } // the function to be called as an event public void PrintEvent(int i) { print("PrintEvent: " + i + " called at: " + Time.time); } } ``` -------------------------------- ### Get and Log Application Data Path in Unity C# Source: https://docs.unity3d.com/ScriptReference/Application-dataPath This C# script demonstrates how to retrieve the application data path using Application.dataPath in Unity and output it to the console. Attach this script to a GameObject in your scene to execute on Start(). The example is platform-agnostic and will log the path specific to the target device where it runs. ```C# //Attach this script to a GameObject //This script outputs the Application's path to the Console //Run this on the target device to find the application data path for the platform using UnityEngine; public class Example : MonoBehaviour { string m_Path; void Start() { //Get the path of the Game data folder m_Path = Application.dataPath; //Output the Game data path to the console Debug.Log("dataPath : " + m_Path); } } ``` -------------------------------- ### Check for Help Page and Show - Unity Editor Script Source: https://docs.unity3d.com/ScriptReference/Help This C# script demonstrates how to create a Unity Editor window that allows users to select an object and search for its corresponding help page. If a page exists, it's displayed; otherwise, the Unity forum is opened. It uses Help.HasHelpForObject and Help.ShowHelpForObject. ```csharp using UnityEngine; using UnityEditor; // EditorScript that quickly searchs for a help page // of the selected Object. // // If there is no page found on the Manual it opens the Unity forum. class QuickHelper : EditorWindow { Object source; [MenuItem("Example/QuickHelper _h")] static void Init() { EditorWindow window = EditorWindow.GetWindowWithRect(typeof(QuickHelper), new Rect(0, 0, 165, 100)); window.Show(); } void OnGUI() { EditorGUILayout.BeginHorizontal(); source = EditorGUILayout.ObjectField(source, typeof(Object)); EditorGUILayout.EndHorizontal(); if (GUILayout.Button("Search!")) { if (source == null) { this.ShowNotification(new GUIContent("No object selected for searching")); } else { if (Help.HasHelpForObject(source)) { Help.ShowHelpForObject(source); } else { Help.BrowseURL("http://forum.unity3d.com/search.php"); } } } } } ``` -------------------------------- ### Implement SettingsProvider OnGUI with IMGUI in Unity Source: https://docs.unity3d.com/ScriptReference/SettingsProvider This C# example demonstrates creating a custom SettingsProvider that uses IMGUI for rendering editor settings. It initializes a SerializedObject from an asset path in OnActivate, renders property fields in OnGUI, and cleans up resources in OnDeactivate. The implementation requires UnityEditor namespace and works with custom ScriptableObject settings assets. ```C# using UnityEditor; using UnityEngine; using UnityEngine.UIElements; class SimpleIMGUISettingsProvider : SettingsProvider { SerializedObject m_Settings; const string k_MyCustomSettingsPath = "Assets/Editor/MyCustomSettings.asset"; public SimpleIMGUISettingsProvider(string path, SettingsScope scope = SettingsScope.User) : base(path, scope) {} public override void OnActivate(string searchContext, VisualElement rootElement) { // Called when the user clicks on the MyCustom element in the Settings window. m_Settings = new SerializedObject(AssetDatabase.LoadAssetAtPath(k_MyCustomSettingsPath)); } public override void OnDeactivate() { // User selected another setting or closed the Settings window. m_Settings = null; } public override void OnGUI(string searchContext) { // Use IMGUI to display UI: EditorGUILayout.PropertyField(m_Settings.FindProperty("m_Number"), new GUIContent("My Number")); EditorGUILayout.PropertyField(m_Settings.FindProperty("m_SomeString"), new GUIContent("Some string")); m_Settings.ApplyModifiedPropertiesWithoutUndo(); } } ``` -------------------------------- ### Get Count of Enabled Cameras - C# Unity Source: https://docs.unity3d.com/ScriptReference/Camera-allCameras Demonstrates how to use Camera.allCameras to retrieve the number of enabled cameras in the scene. The example accesses the Length property of the returned array and prints the count to the console. This pattern is useful for debugging camera setup, implementing camera management systems, or validating scene state. ```csharp using UnityEngine; public class ExampleScript : MonoBehaviour { private int count; void Start() { count = Camera.allCameras.Length; print("We've got " + count + " cameras"); } } ``` -------------------------------- ### Demonstrate didStart property usage in Unity MonoBehaviour Source: https://docs.unity3d.com/ScriptReference/MonoBehaviour-didStart Shows how the didStart property returns false before Start() is called and true during Start() execution. This example uses Awake() and Start() lifecycle methods to illustrate the property's behavior in Unity's component system. ```C# using UnityEngine; public class NewBehaviourScript : MonoBehaviour { void Awake() { // Awake gets called before Start, therefore will print 'false'. Debug.Log(this.didStart); } void Start() { // Code is within Start, therefore will print 'true', as Start was called. Debug.Log(this.didStart); } } ```