Documentation Use the SelectionBaseAttribute to mark a GameObject as a selection base object, allowing it to be selected directly in the Scene View when clicking on it.
using UnityEngine;
[SelectionBase]
public class ExampleSelectionBase : MonoBehaviour
{
// This GameObject will be treated as a selection base in the Scene View
}
Documentation Enables you to create new ScriptableObjects from the Unity Editor menu.
[CreateAssetMenu(fileName = "NewItem", menuName = "Inventory/Item")]
public class Item : ScriptableObject
{
public string itemName;
public int itemID;
}
Documentation Adds a method to the context menu for easy access from the Unity Inspector.
public class ExampleContextMenuUsage : MonoBehaviour
{
[ContextMenu("Print Message")]
void PrintMessage()
{
Debug.Log("This is a message from the context menu!");
}
}
Documentation Executes a static constructor when the editor is loaded, useful for setup.
[InitializeOnLoad]
public static class ExampleInitializedOnLoad
{
static ExampleInitializedOnLoad()
{
Debug.Log("This runs when the editor loads.");
}
}
Documentation Provides a link to documentation related to the script for easier access.
[HelpURL("https://docs.unity3d.com/ScriptReference/HelpURLAttribute.html")]
public class ExampleHelpUrl : MonoBehaviour
{
// This script has a help URL associated with it.
}
Documentation
*Allows a script to run even when the game is not playing
, useful for editor tools.*
[ExecuteInEditMode]
public class ExampleExecuteInEditMode : MonoBehaviour
{
void Update()
{
// This code runs in editor mode as well.
Debug.Log("This is running in edit mode.");
}
}
Board: https://github.com/users/EloiStree/projects/17/views/1
🤖
Unity Attributes and Examples
1. RuntimeInitialize
Documentation
Used to specify methods that should be called when the game starts.
2. ContextMenuItem
Documentation
Allows you to add custom options to the right-click context menu in the Unity Editor.
3. SelectionBaseAttribute
Documentation
Use the
SelectionBaseAttribute
to mark a GameObject as a selection base object, allowing it to be selected directly in the Scene View when clicking on it.4. MenuItem
Documentation
Creates a menu item in the Unity Editor, allowing quick access to custom functions.
5. Serializable
Documentation
Marks a class as serializable, allowing its instances to be saved and loaded.
6. CreateAssetMenu
Documentation
Enables you to create new ScriptableObjects from the Unity Editor menu.
7. RequireComponent
Documentation
Ensures that a GameObject has a specific component attached before this script can work.
8. Header
Documentation
Adds a header label above a field in the Inspector for better organization.
9. ContextMenu
Documentation
Adds a method to the context menu for easy access from the Unity Inspector.
10. ToolTip
Documentation
Displays a tooltip with information about a field when hovering in the Inspector.
11. TextArea
Documentation
Creates a multi-line text area in the Inspector for easier text input.
12. Range
Documentation
Restricts a numeric field to a specified range in the Inspector.
13. InitializedOnLoad
Documentation
Executes a static constructor when the editor is loaded, useful for setup.
14. RuntimeInitializeddonLoad
Documentation
Specifies methods that should be called when the game is initialized at runtime.
15. HelpUrl
Documentation
Provides a link to documentation related to the script for easier access.
16. SerializedField
Documentation
Allows private fields to be serialized and visible in the Inspector.
17. Multiline
Documentation
Creates a multi-line text input for a string field in the Inspector.
18. Space
Documentation
Adds space between fields in the Inspector for better organization.
19. CustomEditor
Documentation
Creates a custom Inspector for a specified class, allowing for personalized layouts and buttons.
20. ExecuteInEditorMode
Documentation
*Allows a script to run even when the game is not playing
, useful for editor tools.*