Unity Editor knowledge point sorting (feature Class)

[Serializable]

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;


public class InspectorClass : MonoBehaviour
{
    
    
    public SerializeableClass SClass;
}

[Serializable] //序列化一个类,作为一个子属性显示在监视面板
public class SerializeableClass
{
    
    
    public int Int;
    public bool boolean;
    public string String;
}

Mount the script on the object to obtain the following effect, this method is also applicable to the enumeration delegate of the class structure
insert image description here

RequireComponent

[RequireComponent(typeof(Rigidbody))]
public class InspectorClass : MonoBehaviour
{
    
    
    public SerializeableClass SClass;
}

[Serializable] //序列化一个类,作为一个子属性显示在监视面板
public class SerializeableClass
{
    
    
    public int Int;
    public bool boolean;
    public string String;
}

RequireComponent will automatically add the required components, and the component cannot be removed
Mount the script on the object to get the following effect, automatically adding the RigidBody component
insert image description here

DisallowMultipleComponent
prevents a MonoBehaviour of the same type (or subtype) from being added multiple times to a GameObject.

[RequireComponent(typeof(Rigidbody)),DisallowMultipleComponent]
public class InspectorClass : MonoBehaviour
{
    
    
    public SerializeableClass SClass;
}

[Serializable] //序列化一个类,作为一个子属性显示在监视面板
public class SerializeableClass
{
    
    
    public int Int;
    public bool boolean;
    public string String;
}

When trying to mount the script on the same object for the second time, the following error will occur
insert image description here

[ExecuteInEditMode]
Makes all instances of a script execute in Edit Mode.
Let all instances of this class run in Edit Mode.
Note that Update does not usually run, only when the attribute value changes, the update will run

[ExecuteInEditMode]// Makes all instances of a script execute in Edit Mode.
public class InspectorClass : MonoBehaviour
{
    
    
    public SerializeableClass SClass;

    private void Start()
    {
    
    
        Debug.Log("hhh");
    }
}

After mounting the script on the object, you will find that hhh is printed without clicking to run

[CanEditMultipleObjects]
Allows to modify values ​​uniformly when multiple objects with this script attached to it are
selected. After multiple objects are selected, editors without this property will display the "Multi-object editing not supported" message

insert image description here

AddComponentMenu
Use the AddComponentMenu property to place scripts anywhere in the Component menu, not just the Component > Scripts menu.
Use this property to better organize the Component menu, improving workflow when adding scripts


[AddComponentMenu("Transform/AddComponentMenuTest")]
public class AddComponentMenuTest : MonoBehaviour
{
    
    
    
}

Once the script is mounted, the custom script will be found under Transform.
insert image description here
Add this property to the script class to mark its GameObject as the selection base object selected by Scene View.

[SelectionBase]
In Unity Scene View, when you click to select an object, Unity will try to find the best object to select for you. If you click on an object that is part of a prefab, the root of that prefab is selected because the prefab root is considered the selection base. You can also make other objects be considered selection bases.
You need to create a script class with a SelectionBase property, then you need to add the script to the GameObject.
Add this attribute to a script class to mark its GameObject as a selection base object for Scene View picking.

Reference
https://blog.csdn.net/qq_35361471/article/details/84715294
https://docs.unity.cn/cn/current/ScriptReference/AddComponentMenu.html

Guess you like

Origin blog.csdn.net/qq_43388137/article/details/122192300