### Unity Namespace and Assembly Integration Source: https://context7.com/v0lt13/editorattributesdocs/llms.txt This C# code illustrates how to properly integrate the EditorAttributes namespace and reference the EditorAttributes assembly in Unity projects. It shows examples of using attributes like Button and Dropdown, including referencing external methods and namespaced classes. It also provides guidance on Assembly Definition file setup and correct usage of string literals for external references. ```csharp using UnityEngine; using EditorAttributes; // Main namespace for attributes public class NamespaceExample : MonoBehaviour { // All attributes available after importing namespace [SerializeField, Button] private void ExampleMethod() { } } // Assembly Definition setup: // If using Assembly Definitions (.asmdef files), reference "EditorAttributes" assembly // in your assembly definition file: /* { "name": "MyGameAssembly", "references": [ "EditorAttributes" ], "includePlatforms": [], "excludePlatforms": [], "allowUnsafeCode": false } */ // External type reference example public class ExternalReferences : MonoBehaviour { // Reference static members from other classes [Dropdown("DatabaseClass.GetOptions")] [SerializeField] private string option; // Reference members from namespaced classes [Dropdown("MyNamespace.ConfigClass.GetValues")] [SerializeField] private int configValue; } // Database in separate file public static class DatabaseClass { public static string[] GetOptions() => new string[] { "Option A", "Option B", "Option C" }; } // Namespaced configuration namespace MyNamespace { public static class ConfigClass { public static int[] GetValues() => new int[] { 10, 20, 30, 40, 50 }; } } // NOTE: Do NOT use nameof() for external class references // WRONG: [Dropdown(nameof(ExternalClass.Method))] - returns only "Method" // RIGHT: [Dropdown("ExternalClass.Method")] - returns full path ``` -------------------------------- ### TryGetProperty Method Source: https://github.com/v0lt13/editorattributesdocs/blob/main/docs/source/Scripting API/reflectionutility.md Tries to get a property from the target type. ```APIDOC ## Method: TryGetProperty ### Description Tries to get a property from the target type. ### Declaration ```csharp public static bool TryGetProperty(string name, Type targetType, BindingFlags bindingFlags, out PropertyInfo propertyInfo) ``` ### Parameters #### Path Parameters - **name** (string) - Required - The name of the field to search for - **targetType** (Type) - Required - The type to get the property from - **bindingFlags** (BindingFlags) - Required - The binding flags - **propertyInfo** (out PropertyInfo) - Output - The property info of the desired field ### Returns `bool`: True if the field was succesfully found, false otherwise ``` -------------------------------- ### TryGetMethod Method Source: https://github.com/v0lt13/editorattributesdocs/blob/main/docs/source/Scripting API/reflectionutility.md Tries to get a function (method) from the target type. ```APIDOC ## Method: TryGetMethod ### Description Tries to get a function from the target type. ### Declaration ```csharp public static bool TryGetMethod(string name, Type targetType, BindingFlags bindingFlags, out MethodInfo methodInfo) ``` ### Parameters #### Path Parameters - **name** (string) - Required - The name of the field to search for - **targetType** (Type) - Required - The type to get the function from - **bindingFlags** (BindingFlags) - Required - The binding flags - **methodInfo** (out MethodInfo) - Output - The method info of the desired field ### Returns `bool`: True if the field was succesfully found, false otherwise ``` -------------------------------- ### Basic Button and Tall Button in C# Source: https://github.com/v0lt13/editorattributesdocs/blob/main/docs/source/Attributes/ButtonAttributes/button.md Demonstrates how to create a simple button and a taller button using the [Button] attribute. The second example shows how to specify a label and height for the button. ```csharp using UnityEngine; using EditorAttributes; public class AttributesExample : MonoBehaviour { [Button] public void Button() => print("Hello World!"); [Button("Button", 30f)] public void TallButton() => print("Im Tall!"); } ``` -------------------------------- ### TryGetField Method Source: https://github.com/v0lt13/editorattributesdocs/blob/main/docs/source/Scripting API/reflectionutility.md Tries to get a field from the target type. ```APIDOC ## Method: TryGetField ### Description Tries to get a field from the target type. ### Declaration ```csharp public static bool TryGetField(string name, Type targetType, BindingFlags bindingFlags, out FieldInfo fieldInfo) ``` ### Parameters #### Path Parameters - **name** (string) - Required - The name of the field to search for - **targetType** (Type) - Required - The type to get the field from - **bindingFlags** (BindingFlags) - Required - The binding flags - **fieldInfo** (out FieldInfo) - Output - The field info of the desired field ### Returns `bool`: True if the field was succesfully found, false otherwise ``` -------------------------------- ### Inherit Custom Inspector from EditorExtension Source: https://github.com/v0lt13/editorattributesdocs/blob/main/docs/source/GettingStarted/faq&issues.md This example shows how a custom inspector class in Unity should inherit from `EditorExtension` instead of the base `UnityEditor.Editor` to ensure compatibility with specific attributes like Button, ShowInInspector, GUIColor, and PropertyOrder. It highlights the need to call appropriate functions within the custom inspector's implementation. ```csharp using UnityEditor; // Assuming EditorExtension is defined elsewhere and inherits from UnityEditor.Editor public class MyCustomInspector : EditorExtension { public override void OnInspectorGUI() { // Your custom inspector GUI logic here // Ensure you call base class methods or specific attribute handling logic if needed base.OnInspectorGUI(); // Example: If ButtonAttribute needs explicit handling // ButtonAttributeLogic(); } // If other attributes require specific calls: // private void ButtonAttributeLogic() { ... } // private void ShowInInspectorAttributeLogic() { ... } } ``` -------------------------------- ### Apply Suffix Attribute to Fields (C#) Source: https://github.com/v0lt13/editorattributesdocs/blob/main/docs/source/Attributes/DecorativeAttributes/suffix.md Demonstrates how to apply the Suffix attribute to integer fields in Unity. The first example shows a basic suffix, while the second includes an offset. ```csharp using UnityEngine; using EditorAttributes; public class AttributesExample : MonoBehaviour { [SerializeField, Suffix("suffix")] private int field01; [SerializeField, Suffix("suffix with offset", 20f)] private int field02; } ``` -------------------------------- ### Example of Void Struct Usage with Attributes (C#) Source: https://github.com/v0lt13/editorattributesdocs/blob/main/docs/source/GettingStarted/voidstruct.md Illustrates a common scenario where a Void struct is used as a holder for an attribute like HelpBox, potentially causing a namespace conflict. It shows the initial problematic code and explains how to fix it. ```csharp using System; using UnityEngine; using EditorAttributes; public class AttributesExample : MonoBehaviour { [Serializable] private struct ExampleStruct { public int data01; public int data02; } [SerializeField] private ExampleStruct exampleStruct; [HelpBox("This is a help box")] [SerializeField] private Void helpBoxHolder; // This line will throw an error } ``` -------------------------------- ### Unity C# AssetPreview Attribute Example Source: https://github.com/v0lt13/editorattributesdocs/blob/main/docs/source/Attributes/DecorativeAttributes/assetpreview.md Demonstrates how to use the AssetPreview attribute in C# for Unity. This attribute enables the display of previews for various asset types (Sprite, Material, GameObject, Mesh) directly in the inspector. Optional parameters can be provided to specify the width and height of the preview. ```csharp using UnityEngine; using EditorAttributes; public class AttributesExample : MonoBehaviour { [SerializeField, AssetPreview] private Sprite spriteAsset01; [SerializeField, AssetPreview] private Material materialAsset02; [SerializeField, AssetPreview(64f, 64f)] private GameObject gameObjectAsset03; [SerializeField, AssetPreview(64f, 64f)] private Mesh meshAsset04; } ``` -------------------------------- ### ColorField Attribute Usage Example Source: https://github.com/v0lt13/editorattributesdocs/blob/main/docs/source/Attributes/DecorativeAttributes/colorfield.md Demonstrates how to use the ColorField attribute in a Unity C# script to color integer fields in the inspector. It shows examples of using predefined GUIColor values, RGB float values, and hexadecimal color strings. This attribute is deprecated and GUIColor is recommended. ```csharp using UnityEngine; using EditorAttributes; public class AttributesExample : MonoBehaviour { [SerializeField, ColorField(GUIColor.Green)] private int field01; [SerializeField] private int field02; [SerializeField, ColorField(255f, 0f, 123f)] private int field03; [SerializeField, ColorField("#00f2ff")] private int field04; [SerializeField] private int field05; } ``` -------------------------------- ### GetStaticMemberInfoFromPath Method Source: https://github.com/v0lt13/editorattributesdocs/blob/main/docs/source/Scripting API/reflectionutility.md Gets the info of a const or static member from the type specified in the path. ```APIDOC ## Method: GetStaticMemberInfoFromPath ### Description Gets the info of a const or static member from the type specified in the path. ### Declaration ```csharp public static MemberInfo GetStaticMemberInfoFromPath(string path, MemberTypes memberType) ``` ### Parameters #### Path Parameters - **path** (string) - Required - The path on which to locate the member - **memberType** (MemberTypes) - Required - The type of the member to look for. Only Field, Property and Method types are supported ### Returns `MemberInfo`: The member info of the specified member type ``` -------------------------------- ### Attribute Order and Execution in C# Source: https://github.com/v0lt13/editorattributesdocs/blob/main/docs/source/GettingStarted/howtouse.md Illustrates how the order of attributes affects their execution and potential overrides. The example shows how 'TimeField' can override 'Suffix' if placed before it. It also demonstrates using the 'order' parameter to control execution sequence, with lower values executing first. ```csharp using UnityEngine; using EditorAttributes; public class AttributesExample : MonoBehaviour { [TimeField(TimeFormat.YearMonthWeek, ConvertTo.Days), Suffix("to days")] [SerializeField] private int field; } ``` ```csharp using UnityEngine; using EditorAttributes; public class AttributesExample : MonoBehaviour { [TimeField(TimeFormat.YearMonthWeek, ConvertTo.Days), Suffix("to days", order = -1)] [SerializeField] private int field; } ``` -------------------------------- ### SelectionButtons Attribute Example - C# Source: https://github.com/v0lt13/editorattributesdocs/blob/main/docs/source/Attributes/ButtonAttributes/selectionbuttons.md Demonstrates the usage of the SelectionButtons attribute in C# for Unity. It showcases how to apply the attribute to enum and string fields, with various optional parameters like 'showLabel' and 'buttonsHeight'. ```csharp using System; using UnityEngine; using EditorAttributes; public class AttributesExample : MonoBehaviour { public enum States { State01, State02, State03 } [Flags] public enum Flags { Nothing = 0, Flag01 = 1, Flag02 = 2, Flag03 = 4, Flag04 = 8 } [Header("SelectionButtons Attribute:")] [SerializeField, SelectionButtons] private States states; [SerializeField, SelectionButtons(showLabel: false)] private Flags flags; [SerializeField, SelectionButtons(nameof(stringValues), buttonsHeight: 30f)] private string stringField; private string[] stringValues = new string[] { "Value01", "Value02", "Value03", "Value04", "Value05", "Value06" }; } ``` -------------------------------- ### C# ProgressBar Attribute Example Source: https://github.com/v0lt13/editorattributesdocs/blob/main/docs/source/Attributes/NumericalAttributes/progressbar.md Demonstrates how to use the ProgressBar attribute in Unity. It requires the 'EditorAttributes' namespace and allows customization of maxValue and barHeight. The attribute cannot be applied to vector fields. ```csharp using UnityEngine; using EditorAttributes; public class AttributesExample : MonoBehaviour { [SerializeField, Range(0f, 100f)] private float value; [SerializeField, ProgressBar] private int intBar; [SerializeField, ProgressBar(100f, 50f)] private float floatBar; void OnValidate() { intBar = (int)value; floatBar = value; } } ``` -------------------------------- ### UnitField Attribute Usage with Custom Units (C#) Source: https://github.com/v0lt13/editorattributesdocs/blob/main/docs/source/Attributes/NumericalAttributes/unitfield.md Illustrates the use of the UnitField attribute with custom-defined units. This requires prior setup of custom units in the EditorAttributes settings. ```csharp using UnityEngine; using EditorAttributes; public class AttributesExample : MonoBehaviour { [SerializeField, UnitField("HalfMeter", Unit.Meter)] private float meters; [SerializeField, UnitField("Coins", "Gems")] private int gems; } ``` -------------------------------- ### FilePath Attribute: Basic Usage and Filters (C#) Source: https://github.com/v0lt13/editorattributesdocs/blob/main/docs/source/Attributes/MiscellaneousAttributes/filepath.md Demonstrates the basic usage of the FilePath attribute to get relative and absolute file paths. It also shows how to filter files by specifying extensions using the 'filters' parameter. This attribute requires the EditorAttributes package and should be attached to a string variable. ```csharp using UnityEngine; using EditorAttributes; public class AttributesExample : MonoBehaviour { [SerializeField, FilePath] private string relativeFilePath; [SerializeField, FilePath(false)] private string absoluteFilePath; [SerializeField, FilePath(filters: "cs")] private string fileFilter; // Will only find C# files // Make sure you don't include any spaces when passing multiple file extensions [SerializeField, FilePath(filters: "cs,unity")] private string multipleFileFilters; // Will only find C# and Unity Scene files } ``` -------------------------------- ### Apply GUIColor Attribute in C# Source: https://github.com/v0lt13/editorattributesdocs/blob/main/docs/source/Attributes/DecorativeAttributes/guicolor.md Demonstrates how to use the GUIColor attribute in C# to color serialized fields in the Unity Inspector. It shows examples using GUIColor constants, RGB float values, and hexadecimal color strings. This attribute requires the EditorAttributes namespace. ```csharp using UnityEngine; using EditorAttributes; public class AttributesExample : MonoBehaviour { [GUIColor(GUIColor.Lime)] [SerializeField] private int field01; [SerializeField] private int field02; [SerializeField] private int field03; [GUIColor(144f, 151f, 222f)] [SerializeField] private int field04; [SerializeField] private int field05; [SerializeField] private int field06; [GUIColor("#8c508b")] [SerializeField] private int field07; [SerializeField] private int field08; [SerializeField] private int field09; } ``` -------------------------------- ### Managing Multiple Attributes in C# Source: https://github.com/v0lt13/editorattributesdocs/blob/main/docs/source/GettingStarted/goodpractices.md Demonstrates techniques for organizing code when a field has numerous attributes, especially those with many parameters. Options include placing attributes on separate lines or grouping built-in Unity attributes distinctly from package attributes to improve readability. ```csharp using UnityEngine; using EditorAttributes; public class AttributesExample : MonoBehaviour { [SerializeField] private bool condition01; [SerializeField] private bool condition02; [SerializeField] private bool condition03; [SerializeField, ReadOnly, ConditionalField(ConditionType.AND, new bool[] { false, true, false }, nameof(condition01), nameof(condition02), nameof(condition03))] private int field; } ``` ```csharp [SerializeField, ReadOnly, ConditionalField(ConditionType.AND, new bool[] { false, true, false }, nameof(condition01), nameof(condition02), nameof(condition03))] private int field; ``` ```csharp [ReadOnly, ConditionalField(ConditionType.AND, new bool[] { false, true, false }, nameof(condition01), nameof(condition02), nameof(condition03))] [SerializeField] private int field; ``` ```csharp [ConditionalField(ConditionType.AND, new bool[] { false, true, false }, nameof(condition01), nameof(condition02), nameof(condition03))] [SerializeField, ReadOnly] private int field; ``` -------------------------------- ### Add Prefix to Fields (C#) Source: https://github.com/v0lt13/editorattributesdocs/blob/main/docs/source/Attributes/DecorativeAttributes/prefix.md Demonstrates how to use the Prefix attribute to add a static string prefix to integer fields. It shows basic usage and usage with an optional pixel offset for the prefix. ```csharp using UnityEngine; using EditorAttributes; public class AttributesExample : MonoBehaviour { [SerializeField, Prefix("prefix")] private int field01; [SerializeField, Prefix("prefix with offset", 50f)] private int field02; } ``` -------------------------------- ### ReflectionUtility Class Overview Source: https://github.com/v0lt13/editorattributesdocs/blob/main/docs/source/Scripting API/reflectionutility.md Provides utility functions for reflection operations, including finding fields, properties, methods, and members. ```APIDOC ## Class: ReflectionUtility ### Description An utility class containing useful functions related to reflection. ### Namespace EditorAttributes.Editor.Utility ### Assembly EditorAttributes.Editor.asmdef ### Syntax ```csharp public static class ReflectionUtility ``` ``` -------------------------------- ### C# - TryGetMethod Method Source: https://github.com/v0lt13/editorattributesdocs/blob/main/docs/source/Scripting API/reflectionutility.md Attempts to retrieve the `MethodInfo` for a method with a given name from a target type, using specified binding flags. Returns `true` and the `MethodInfo` if found, otherwise `false`. This method facilitates safe method lookup. ```csharp public static bool TryGetMethod(string name, Type targetType, BindingFlags bindingFlags, out MethodInfo methodInfo) ``` -------------------------------- ### Get Field Value (C#) Source: https://github.com/v0lt13/editorattributesdocs/blob/main/docs/source/Scripting API/propertydrawerbase.md Retrieves the current value of a VisualElement representing a field. The value is returned as an object. ```csharp public static object GetFieldValue(VisualElement field) { // Implementation details... return null; } ``` -------------------------------- ### Get Field Label (C#) Source: https://github.com/v0lt13/editorattributesdocs/blob/main/docs/source/Scripting API/propertydrawerbase.md Retrieves the user-facing label associated with a given VisualElement that represents a field. Returns the label as a string. ```csharp public static string GetFieldLabel(VisualElement field) { // Implementation details... return ""; } ``` -------------------------------- ### Unity Editor Validation Initialization Source: https://github.com/v0lt13/editorattributesdocs/blob/main/docs/source/Scripting API/editorvalidation.md Demonstrates the structure for an editor script that integrates with Unity's build process. The EditorExtension class implements IPreprocessBuildWithReport, allowing it to hook into pre-build events. The InitializeOnLoad attribute ensures the class is initialized when the editor loads. ```csharp [InitializeOnLoad] public class EditorExtension : IPreprocessBuildWithReport { public int callbackOrder { get; } public void OnPreprocessBuild(BuildReport report) { // Implementation details for pre-build actions } } ``` -------------------------------- ### Get Texture Size in C# Source: https://github.com/v0lt13/editorattributesdocs/blob/main/docs/source/Scripting API/propertydrawerbase.md Retrieves the dimensions (width and height) of a Texture2D. Returns the size as a Vector2 object. Requires a Texture2D object as input. ```csharp public static Vector2 GetTextureSize(Texture2D texture) ``` -------------------------------- ### SimpleTransform QuaternionRotation Property (C#) Source: https://github.com/v0lt13/editorattributesdocs/blob/main/docs/source/Scripting API/simpletransform.md Provides a read-only property to get the rotation of the SimpleTransform as a Quaternion. This offers an alternative to the Euler angle representation. ```csharp public readonly Quaternion QuaternionRotation; ``` -------------------------------- ### SimpleTransform Constructors (C#) Source: https://github.com/v0lt13/editorattributesdocs/blob/main/docs/source/Scripting API/simpletransform.md Provides three constructors for the SimpleTransform struct: one accepting Vector3 for position, rotation, and scale; another accepting a Quaternion for rotation; and a third accepting a Unity Transform object. ```csharp public SimpleTransform(Vector3 position, Vector3 rotation, Vector3 scale) public SimpleTransform(Vector3 position, Quaternion rotation, Vector3 scale) public SimpleTransform(Transform transform) ``` -------------------------------- ### SimpleTransform Methods (C#) Source: https://github.com/v0lt13/editorattributesdocs/blob/main/docs/source/Scripting API/simpletransform.md Includes methods for the SimpleTransform struct: ToString() for string representation, ToTransform() to apply values to a Transform in world space, and ToLocalTransform() to apply values in local space. ```csharp public override readonly string ToString(); public readonly void ToTransform(Transform transform); public readonly void ToLocalTransform(Transform transform); ``` -------------------------------- ### HelpBox Attribute with Dynamic String Input (C#) Source: https://github.com/v0lt13/editorattributesdocs/blob/main/docs/source/Attributes/DecorativeAttributes/helpbox.md Illustrates using the HelpBox attribute with the StringInputMode set to 'Dynamic'. This allows the message content to be fetched from another member (specified by name) at runtime, enabling dynamic content updates in the Unity inspector. Requires 'EditorAttributes' and 'UnityEngine' namespaces. ```csharp using UnityEngine; using EditorAttributes; public class AttributesExample : MonoBehaviour { [HelpBox(nameof(helpBox), MessageMode.Log, StringInputMode.Dynamic)] [SerializeField] private string helpBox; } ``` -------------------------------- ### Filter by Multiple Types with TypeFilter Attribute (C#) Source: https://github.com/v0lt13/editorattributesdocs/blob/main/docs/source/Attributes/MiscellaneousAttributes/typefilter.md This C# example shows how to use the TypeFilter attribute to allow assignment of components that are either SphereCollider or BoxCollider. Multiple types are passed as arguments to the attribute. ```csharp using UnityEngine; using EditorAttributes; public class AttributesExample : MonoBehaviour { [SerializeField, TypeFilter(typeof(SphereCollider), typeof(BoxCollider))] private Component colliderComponent; } ``` -------------------------------- ### Filter by Single Type with TypeFilter Attribute (C#) Source: https://github.com/v0lt13/editorattributesdocs/blob/main/docs/source/Attributes/MiscellaneousAttributes/typefilter.md This example demonstrates how to use the TypeFilter attribute to restrict a component field to only accept objects of a specific type, such as SphereCollider. It requires the 'EditorAttributes' and 'UnityEngine' namespaces. ```csharp using UnityEngine; using EditorAttributes; public class AttributesExample : MonoBehaviour { [SerializeField, TypeFilter(typeof(SphereCollider))] private Component colliderComponent; } ``` -------------------------------- ### VectorUtils Methods Source: https://github.com/v0lt13/editorattributesdocs/blob/main/docs/source/Scripting API/vectorutils.md This section details the various methods provided by the VectorUtils class for vector manipulation and conversion. ```APIDOC ## AddVector(Vector3, float) ### Description Adds a value to a vector. ### Method static ### Endpoint N/A (Class method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```csharp Vector3 result = VectorUtils.AddVector(new Vector3(1, 2, 3), 5.0f); ``` ### Response #### Success Response (Vector3) - **result** (Vector3) - A vector with the value added to all axis #### Response Example ```json { "x": 6.0, "y": 7.0, "z": 8.0 } ``` ## SubtractVector(Vector3, float) ### Description Subtracts a value from a vector. ### Method static ### Endpoint N/A (Class method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```csharp Vector3 result = VectorUtils.SubtractVector(new Vector3(10, 20, 30), 5.0f); ``` ### Response #### Success Response (Vector3) - **result** (Vector3) - A vector with the value subtracted from all axis #### Response Example ```json { "x": 5.0, "y": 15.0, "z": 25.0 } ``` ## Vector3IntToVector2Int(Vector3Int) ### Description Converts a `Vector3Int` to a `Vector2Int`. ### Method static ### Endpoint N/A (Class method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```csharp Vector2Int result = VectorUtils.Vector3IntToVector2Int(new Vector3Int(1, 2, 3)); ``` ### Response #### Success Response (Vector2Int) - **result** (Vector2Int) - The converted Vector2Int #### Response Example ```json { "x": 1, "y": 2 } ``` ## Vector2IntToVector2(Vector2Int) ### Description Converts a `Vector2Int` to a `Vector2`. ### Method static ### Endpoint N/A (Class method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```csharp Vector2 result = VectorUtils.Vector2IntToVector2(new Vector2Int(1, 2)); ``` ### Response #### Success Response (Vector2) - **result** (Vector2) - The converted Vector2 #### Response Example ```json { "x": 1.0, "y": 2.0 } ``` ## Vector2ToVector2Int(Vector2) ### Description Converts a `Vector2` to a `Vector2Int`. ### Method static ### Endpoint N/A (Class method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```csharp Vector2Int result = VectorUtils.Vector2ToVector2Int(new Vector2(1.5f, 2.5f)); ``` ### Response #### Success Response (Vector2Int) - **result** (Vector2Int) - The converted Vector2Int #### Response Example ```json { "x": 1, "y": 2 } ``` ## Vector3ToVector3Int(Vector3) ### Description Converts a `Vector3` to a `Vector3Int`. ### Method static ### Endpoint N/A (Class method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```csharp Vector3Int result = VectorUtils.Vector3ToVector3Int(new Vector3(1.5f, 2.5f, 3.5f)); ``` ### Response #### Success Response (Vector3Int) - **result** (Vector3Int) - The converted Vector3Int #### Response Example ```json { "x": 1, "y": 2, "z": 3 } ``` ## ParseVector2(string) ### Description Parses a `string` to a `Vector2`. ### Method static ### Endpoint N/A (Class method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```csharp Vector2 result = VectorUtils.ParseVector2("(1.0, 2.0)"); ``` ### Response #### Success Response (Vector2) - **result** (Vector2) - The vector value from the string #### Response Example ```json { "x": 1.0, "y": 2.0 } ``` ## ParseVector2Int(string) ### Description Parses a `string` to a `Vector2Int`. ### Method static ### Endpoint N/A (Class method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```csharp Vector2Int result = VectorUtils.ParseVector2Int("(1, 2)"); ``` ### Response #### Success Response (Vector2Int) - **result** (Vector2Int) - The vector value from the string #### Response Example ```json { "x": 1, "y": 2 } ``` ## ParseVector3(string) ### Description Parses a `string` to a `Vector3`. ### Method static ### Endpoint N/A (Class method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```csharp Vector3 result = VectorUtils.ParseVector3("(1.0, 2.0, 3.0)"); ``` ### Response #### Success Response (Vector3) - **result** (Vector3) - The vector value from the string #### Response Example ```json { "x": 1.0, "y": 2.0, "z": 3.0 } ``` ## ParseVector3Int(string) ### Description Parses a `string` to a `Vector3Int`. ### Method static ### Endpoint N/A (Class method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```csharp Vector3Int result = VectorUtils.ParseVector3Int("(1, 2, 3)"); ``` ### Response #### Success Response (Vector3Int) - **result** (Vector3Int) - The vector value from the string #### Response Example ```json { "x": 1, "y": 2, "z": 3 } ``` ## ParseVector4(string) ### Description Parses a `string` to a `Vector4`. ### Method static ### Endpoint N/A (Class method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```csharp Vector4 result = VectorUtils.ParseVector4("(1.0, 2.0, 3.0, 4.0)"); ``` ### Response #### Success Response (Vector4) - **result** (Vector4) - The vector value from the string #### Response Example ```json { "x": 1.0, "y": 2.0, "z": 3.0, "w": 4.0 } ``` ``` -------------------------------- ### C# HideInChildren Attribute Example Source: https://github.com/v0lt13/editorattributesdocs/blob/main/docs/source/Attributes/MiscellaneousAttributes/hideinchildren.md Demonstrates the usage of the HideInChildren attribute in C# for Unity. This attribute hides inherited fields in child classes. It requires the 'EditorAttributes' namespace and is applied to fields declared with 'SerializeField'. ```csharp using UnityEngine; using EditorAttributes; public class AttributesExample : MonoBehaviour { [SerializeField, HideInChildren] private int intField; [SerializeField, HideInChildren] private float floatField; [SerializeField, HideInChildren] private string stringField; } // In a separate file public class AttributeExampleChild : AttributesExample { } ``` -------------------------------- ### Filter by Interface with TypeFilter Attribute (C#) Source: https://github.com/v0lt13/editorattributesdocs/blob/main/docs/source/Attributes/MiscellaneousAttributes/typefilter.md This example illustrates using the TypeFilter attribute to filter component assignments based on whether they implement a specific interface, such as IFilter. This is a powerful way to ensure components adhere to a contract. ```csharp using UnityEngine; using EditorAttributes; public class AttributesExample : MonoBehaviour { [SerializeField, TypeFilter(typeof(IFilter))] private Component interfaceComponent; } ``` -------------------------------- ### C# - Define ReflectionUtility Class Source: https://github.com/v0lt13/editorattributesdocs/blob/main/docs/source/Scripting API/reflectionutility.md Defines the static class ReflectionUtility, a utility for reflection operations. It contains constants and methods for inspecting types and members. No external dependencies are required beyond standard .NET. ```csharp public static class ReflectionUtility ``` -------------------------------- ### ConditionalField with negated boolean in C# Source: https://github.com/v0lt13/editorattributesdocs/blob/main/docs/source/Attributes/ConditionalAttributes/conditionalfield.md Shows how to use the ConditionalField attribute to negate a specific boolean condition. In this example, 'condition02' is negated, so the field is shown when 'condition01' is true and 'condition02' is false. Uses EditorAttributes and UnityEngine namespaces. ```csharp using UnityEngine; using EditorAttributes; public class AttributesExample : MonoBehaviour { [SerializeField] private bool condition01; [SerializeField] private bool condition02; [SerializeField, ConditionalField(ConditionType.AND, new bool[] { false, true }, nameof(condition01), nameof(condition02))] private int field; } ``` -------------------------------- ### EditorExtension Methods Declaration (C#) Source: https://github.com/v0lt13/editorattributesdocs/blob/main/docs/source/Scripting API/editorextension.md Declarations for key methods in the EditorExtension class, including lifecycle methods like OnEnable and OnDisable, and methods for drawing custom inspectors and properties. ```csharp protected virtual void OnEnable() protected virtual void OnDisable() public override VisualElement CreateInspectorGUI() protected virtual new VisualElement DrawDefaultInspector() protected VisualElement DrawNonSerilizedMembers() protected VisualElement DrawButtons() ``` -------------------------------- ### Apply Box Style to Visual Element (C#) Source: https://github.com/v0lt13/editorattributesdocs/blob/main/docs/source/Scripting API/propertydrawerbase.md Applies a predefined 'help box' style to a given VisualElement. This is useful for standardizing the appearance of elements within the editor. ```csharp public static void ApplyBoxStyle(VisualElement visualElement) { // Implementation details... } ``` -------------------------------- ### Line Attribute Usage in C# Source: https://github.com/v0lt13/editorattributesdocs/blob/main/docs/source/Attributes/DecorativeAttributes/line.md Demonstrates how to apply the Line attribute to fields in a Unity MonoBehaviour script. It shows different ways to initialize the attribute with color (RGB, hex, GUIColor) and line thickness. ```csharp using UnityEngine; using EditorAttributes; public class AttributesExample : MonoBehaviour { [SerializeField] private int field01; [Line] [SerializeField] private int field02; [Line(GUIColor.Green)] [SerializeField] private int field03; [Line(GUIColor.Cyan, 0.3f, 10f)] [SerializeField] private int field04; [Line(250f, 129f, 120f)] [SerializeField] private int field05; [Line("#a86c2f")] [SerializeField] private int field06; } ``` -------------------------------- ### Customized Dropdown Display with String Array Source: https://github.com/v0lt13/editorattributesdocs/blob/main/docs/source/Attributes/DropdownAttributes/dropdown.md This C# example shows how to customize the display names of dropdown items using a string array alongside the Dropdown attribute. It associates a Vector3 field with a dropdown where display names are explicitly provided. ```csharp using UnityEngine; using EditorAttributes; public class AttributesExample : MonoBehaviour { [Dropdown(nameof(dropdownValues), new string[] { "Directions/Forward", "Directions/Up", "Directions/Down", "One", "Zero" })] [SerializeField] private Vector3 vectorDropdown; private Vector3[] dropdownValues = new Vector3[] { Vector3.forward, Vector3.up, Vector3.down, Vector3.one, Vector3.zero }; } ``` -------------------------------- ### Get Type and Value of Nested Serialized Object Source: https://github.com/v0lt13/editorattributesdocs/blob/main/docs/source/Scripting API/reflectionutility.md Retrieves the Type of a nested object within a SerializedProperty and outputs the actual nested object instance. This is useful when dealing with complex or polymorphic data structures in serialized fields. It takes the SerializedProperty and an out parameter for the object. ```csharp public static Type GetNestedObjectType(SerializedProperty property, out object nestedObject) { // Implementation details omitted for brevity nestedObject = null; return null; } ``` -------------------------------- ### Import EditorAttributes Namespace in C# Source: https://github.com/v0lt13/editorattributesdocs/blob/main/docs/source/GettingStarted/howtouse.md To utilize the custom editor attributes, you must include the 'EditorAttributes' namespace at the beginning of your C# script. Ensure your project references the 'EditorAttributes' Assembly Definition if you are using assembly definitions. ```csharp using EditorAttributes; ``` -------------------------------- ### ToggleGroup Attribute with Boolean Control in C# Source: https://github.com/v0lt13/editorattributesdocs/blob/main/docs/source/Attributes/GroupingAttributes/togglegroup.md Illustrates using the ToggleGroup Attribute where its visibility is directly controlled by a boolean field ('toggleGroup'). The 'drawInBox: true' parameter is also shown, which renders the group within a visual box. This example also uses a MessageBox attribute. ```csharp using UnityEngine; using EditorAttributes; public class AttributesExample : MonoBehaviour { [ToggleGroup("ToggleGroup", drawInBox: true, nameof(intField), nameof(stringField), nameof(boolField))] [SerializeField] private bool toggleGroup; [MessageBox("The group is toggled", nameof(toggleGroup))] [SerializeField, HideProperty] private int intField; [SerializeField, HideProperty] private string stringField; [SerializeField, HideProperty] private bool boolField; } ``` -------------------------------- ### Button with Parameters in C# Source: https://github.com/v0lt13/editorattributesdocs/blob/main/docs/source/Attributes/ButtonAttributes/button.md Illustrates how to create a button that accepts parameters. When the function has parameters, they will be displayed under the button as a foldout in the inspector. ```csharp using UnityEngine; using EditorAttributes; public class AttributesExample : MonoBehaviour { [Button] public void ButtonParams(int param01) => print(param01); } ``` -------------------------------- ### Dropdown with Dictionary for Value Mapping Source: https://github.com/v0lt13/editorattributesdocs/blob/main/docs/source/Attributes/DropdownAttributes/dropdown.md This C# code illustrates using a Dictionary with the Dropdown attribute to map display names to values. The keys of the dictionary are used as the dropdown's display options, providing a flexible way to manage dropdown items. ```csharp using UnityEngine; using EditorAttributes; using System.Collections.Generic; public class AttributesExample : MonoBehaviour { [Dropdown(nameof(dropdownValues))] [SerializeField] private Vector3 vectorDropdown; private Dictionary dropdownValues = new() { { "Directions/Forward", Vector3.forward }, { "Directions/Up", Vector3.up }, { "Directions/Down", Vector3.down }, { "One", Vector3.one }, { "Zero", Vector3.zero } }; } ``` -------------------------------- ### Unity Custom Editor with EditorExtension Source: https://context7.com/v0lt13/editorattributesdocs/llms.txt This C# code demonstrates how to create a custom Unity editor using the EditorExtension base class. It shows how to override OnEnable, OnDisable, and CreateInspectorGUI to draw default inspectors, non-serialized members, and buttons, while also allowing for custom UI elements. It requires the UnityEditor and EditorAttributes namespaces. ```csharp using UnityEngine; using UnityEditor; using EditorAttributes.Editor; // Custom editor example [CustomEditor(typeof(MyCustomComponent))] public class MyCustomComponentEditor : EditorExtension { protected override void OnEnable() { base.OnEnable(); // Must call base } protected override void OnDisable() { base.OnDisable(); // Must call base } public override VisualElement CreateInspectorGUI() { var root = new VisualElement(); // Draw default inspector with EditorAttributes support root.Add(DrawDefaultInspector()); // Draw non-serialized members with ShowInInspector root.Add(DrawNonSerilizedMembers()); // Draw buttons from methods with Button attribute root.Add(DrawButtons()); // Add custom UI elements var customButton = new Button(() => { Debug.Log("Custom button clicked"); }) { text = "Custom Button" }; root.Add(customButton); return root; } protected override VisualElement DrawDefaultInspector() { // Custom property drawing logic var container = base.DrawDefaultInspector(); return container; } } // Component that uses the custom editor public class MyCustomComponent : MonoBehaviour { [SerializeField] private int value = 10; [Button] public void TestButton() => print("Button clicked!"); [SerializeField, GUIColor(1f, 0.5f, 0.5f)] private string coloredField; } // Global color manipulation public class ColorExample : MonoBehaviour { private void Start() { // Access global color settings Color defaultColor = EditorExtension.DEFAULT_GLOBAL_COLOR; // Modify global color (affects all GUI elements) EditorExtension.GLOBAL_COLOR = Color.cyan; } } ``` -------------------------------- ### Unity C# ValueButtons Attribute with Custom String Array Display Source: https://github.com/v0lt13/editorattributesdocs/blob/main/docs/source/Attributes/ButtonAttributes/valuebuttons.md Illustrates how to use the ValueButtons attribute in C# for Unity with a custom string array to define the display text for each button. This example showcases setting custom names like 'Forward', 'Up', etc., for a Vector3 field. ```csharp using UnityEngine; using EditorAttributes; public class AttributesExample : MonoBehaviour { [ValueButtons(nameof(buttonValues), new string[] { "Forward", "Up", "Right", "One", "Zero" })] [SerializeField] private Vector3 vectorSelection; private Vector3[] buttonValues = new Vector3[] { Vector3.forward, Vector3.up, Vector3.right, Vector3.one, Vector3.zero }; } ``` -------------------------------- ### C# Method: CreatePropertyGUI(SerializedProperty) Source: https://github.com/v0lt13/editorattributesdocs/blob/main/docs/source/Scripting API/propertydrawerbase.md This C# code snippet shows the override declaration for the CreatePropertyGUI method. This method is intended to be overridden by derived classes to create custom UI Toolkit-based GUIs for serialized properties, returning the root VisualElement of the custom GUI. ```csharp public override VisualElement CreatePropertyGUI(SerializedProperty property) ``` -------------------------------- ### HelpBox Attribute Usage with Different Message Types (C#) Source: https://github.com/v0lt13/editorattributesdocs/blob/main/docs/source/Attributes/DecorativeAttributes/helpbox.md Demonstrates how to use the HelpBox attribute with different message types (None, Log, Warning, Error) in Unity. This attribute requires the 'EditorAttributes' and 'UnityEngine' namespaces. It is applied to serialized fields to display messages in the inspector. ```csharp using UnityEngine; using EditorAttributes; public class AttributesExample : MonoBehaviour { [SerializeField, HelpBox("This is a normal help box", MessageMode.None)] private string helpBox; [SerializeField, HelpBox("This is a log help box", MessageMode.Log)] private string helpBoxLog; [SerializeField, HelpBox("This is a warning help box", MessageMode.Warning)] private string helpBoxWarning; [SerializeField, HelpBox("This is a error help box", MessageMode.Error)] private string helpBoxError; } ``` -------------------------------- ### Get Color from Property or Attribute (C#) Source: https://github.com/v0lt13/editorattributesdocs/blob/main/docs/source/Scripting API/colorutils.md Retrieves color values from SerializedProperties or IColorAttributes. GetColorFromProperty extracts color if the property has a color attribute, returning null if not found. GetColorFromAttribute retrieves the color value from an IColorAttribute, with overloads supporting custom alpha values and an optional HelpBox for errors. ```csharp public static Color? GetColorFromProperty(SerializedProperty property) { // Implementation details... } public static Color GetColorFromAttribute(IColorAttribute attribute, HelpBox errorBox) { // Implementation details... } public static Color GetColorFromAttribute(IColorAttribute attribute, float alpha, HelpBox errorBox) { // Implementation details... } ``` -------------------------------- ### Basic InlineButton Usage in C# Source: https://github.com/v0lt13/editorattributesdocs/blob/main/docs/source/Attributes/ButtonAttributes/inlinebutton.md Demonstrates the fundamental usage of the InlineButton attribute to attach methods to properties. It shows how to link a button to a single function and how to associate multiple buttons with a single property for increment/decrement operations. Requires the EditorAttributes and UnityEngine namespaces. ```csharp using UnityEngine; using EditorAttributes; public class AttributesExample : MonoBehaviour { [InlineButton(nameof(PrintString))] [SerializeField] private string stringField; [InlineButton(nameof(IncreaseValue), "+", 30f), InlineButton(nameof(DecreaseValue), "-", 30f)] [SerializeField] private int intField; private void IncreaseValue() => intField++; private void DecreaseValue() => intField--; private void PrintString() => print(stringField); } ``` -------------------------------- ### FolderPath Attribute Usage in C# (Unity) Source: https://github.com/v0lt13/editorattributesdocs/blob/main/docs/source/Attributes/MiscellaneousAttributes/folderpath.md Demonstrates how to use the FolderPath attribute in C# scripts within the Unity game engine. This attribute is applied to string fields to enable folder selection in the Inspector. It supports specifying whether to get the relative or absolute path of the selected folder. ```csharp using UnityEngine; using EditorAttributes; public class AttributesExample : MonoBehaviour { [SerializeField, FolderPath] private string relativeFolderPath; [SerializeField, FolderPath(false)] private string absoluteFolderPath; } ``` -------------------------------- ### C# - TryGetField Method Source: https://github.com/v0lt13/editorattributesdocs/blob/main/docs/source/Scripting API/reflectionutility.md Attempts to retrieve the `FieldInfo` for a field with a given name from a target type, using specified binding flags. Returns `true` and the `FieldInfo` if found, otherwise `false`. This provides a safe way to access fields. ```csharp public static bool TryGetField(string name, Type targetType, BindingFlags bindingFlags, out FieldInfo fieldInfo) ``` -------------------------------- ### Create Field for Type (C#) Source: https://github.com/v0lt13/editorattributesdocs/blob/main/docs/source/Scripting API/propertydrawerbase.md Creates a VisualElement representing a field for a given type, name, and initial value. Supports generic type and an option to show mixed values. ```csharp public static VisualElement CreateFieldForType(string fieldName, object fieldValue, bool showMixedValue = false) { // Implementation details... return null; } ``` ```csharp public static VisualElement CreateFieldForType(Type fieldType, string fieldName, object fieldValue, bool showMixedValue = false) { // Implementation details... return null; } ``` -------------------------------- ### C# - TryGetProperty Method Source: https://github.com/v0lt13/editorattributesdocs/blob/main/docs/source/Scripting API/reflectionutility.md Attempts to retrieve the `PropertyInfo` for a property with a given name from a target type, using specified binding flags. Returns `true` and the `PropertyInfo` if found, otherwise `false`. This is a safe method for property introspection. ```csharp public static bool TryGetProperty(string name, Type targetType, BindingFlags bindingFlags, out PropertyInfo propertyInfo) ``` -------------------------------- ### Print Message in C# Source: https://github.com/v0lt13/editorattributesdocs/blob/main/docs/source/Scripting API/propertydrawerbase.md A simplified method for printing messages, acting as a convenient wrapper around Debug.Log. Accepts any object as the message payload. ```csharp protected void Print(object message) ``` -------------------------------- ### Create Repeatable ButtonField on Hold - C# Source: https://github.com/v0lt13/editorattributesdocs/blob/main/docs/source/Attributes/ButtonAttributes/buttonfield.md Shows how to create a ButtonField that executes its associated function repeatedly when held down. This is achieved by setting the `isRepetable` parameter to true and optionally configuring `pressDelay` and `repetitionInterval`. ```csharp using UnityEngine; using EditorAttributes; public class AttributesExample : MonoBehaviour { [ButtonField(nameof(PrintRandomValue), true)] [SerializeField] private Void buttonHolder01; [ButtonField(nameof(PrintRandomValue), true, 100, 500, "Slow Button")] [SerializeField] private Void buttonHolder02; public void PrintRandomValue() => print(Random.value); } ``` -------------------------------- ### IsTypeCollection Method Source: https://github.com/v0lt13/editorattributesdocs/blob/main/docs/source/Scripting API/reflectionutility.md Checks to see if a type is a list or array. ```APIDOC ## Method: IsTypeCollection ### Description Checks to see if a type is a list or array. ### Declaration ```csharp public static bool IsTypeCollection(Type type) ``` ### Parameters #### Path Parameters - **type** (Type) - Required - The type to check ### Returns `bool`: True if the type is a list or array ``` -------------------------------- ### Clamp Attribute for Vector Fields with Per-Axis Control (C#) Source: https://github.com/v0lt13/editorattributesdocs/blob/main/docs/source/Attributes/NumericalAttributes/clamp.md Illustrates the usage of the Clamp attribute for Vector2 and Vector3 fields, showing how to apply global min/max values and specific min/max values for each axis. This functionality enhances fine-grained control over vector components in the Unity editor. ```csharp using UnityEngine; using EditorAttributes; public class AttributesExample : MonoBehaviour { [SerializeField, Clamp(-10f, 10f, -5f, 5f)] private Vector2 vector2Field; [SerializeField, Clamp(-10f, 10f, -5f, 5f, -3.5f, 3.5f)] private Vector3 vector3Field; } ``` -------------------------------- ### Basic String Dropdown with EditorAttributes Source: https://github.com/v0lt13/editorattributesdocs/blob/main/docs/source/Attributes/DropdownAttributes/dropdown.md This C# code demonstrates how to use the Dropdown attribute from the EditorAttributes library to create a dropdown for a string field. It binds the dropdown options to a string array defined within the same class. ```csharp using UnityEngine; using EditorAttributes; public class AttributesExample : MonoBehaviour { [SerializeField, Dropdown(nameof(dropdownValues))] private string stringDropdown; private string[] dropdownValues = new string[] { "Value01", "Value02", "Value03" }; } ``` -------------------------------- ### Fixing Void Namespace Conflict by Removing 'using System;' (C#) Source: https://github.com/v0lt13/editorattributesdocs/blob/main/docs/source/GettingStarted/voidstruct.md Presents a solution to the Void namespace conflict by removing the 'using System;' directive. This implicitly makes EditorAttributes.Void the default when 'Void' is used, and System.Serializable is then accessed via its full namespace. ```csharp [System.Serializable] private struct ExampleStruct { public int data01; public int data02; } ``` -------------------------------- ### Dynamically Set Prefix String (C#) Source: https://github.com/v0lt13/editorattributesdocs/blob/main/docs/source/Attributes/DecorativeAttributes/prefix.md Illustrates how to dynamically set the prefix string for a field using the Prefix attribute. This involves setting the stringInputMode to Dynamic and referencing another member for the prefix string. ```csharp using UnityEngine; using EditorAttributes; public class AttributesExample : MonoBehaviour { [Prefix(nameof(stringField), stringInputMode: StringInputMode.Dynamic)] [SerializeField] private string stringField; } ``` -------------------------------- ### BINDING_FLAGS Field Source: https://github.com/v0lt13/editorattributesdocs/blob/main/docs/source/Scripting API/reflectionutility.md A preset of binding flags used by the package for reflection operations. ```APIDOC ## Field: BINDING_FLAGS ### Description A preset of binding flags used by the package. ### Type BindingFlags ### Declaration ```csharp public const BindingFlags BINDING_FLAGS; ``` ``` -------------------------------- ### Unity Editor Validation Methods Source: https://github.com/v0lt13/editorattributesdocs/blob/main/docs/source/Scripting API/editorvalidation.md Provides static methods for performing validation operations on Unity objects and assets. The Validate method checks fields marked with attributes, while IsPackageAsset checks if a given asset path belongs to a package. These methods are crucial for maintaining project integrity. ```csharp public static void Validate(Object targetObject, ref int failedValidations, ref int successfulValidations) { } public static bool IsPackageAsset(string assetPath) { return false; } ```