AddComponentMenu
可以在
UnityEditor的Component的Menu中增加自定义的项目。菜单可以设置多级,使用斜线/分隔即可。
例如:using UnityEngine; [AddComponentMenu("TestMenu/Component")] public class TestMenu : MonoBehaviour { }
AssemblyIsEditorAssembly
汇编级属性,任何类在组装这个属性将被认为是编辑器类。
ContextMenu
可以在
Inspector的ContextMenu中增加选项。
必须是非静态的函数。
例如:using UnityEngine; public class ContextTesting : MonoBehaviour { /// Add a context menu named "Do Something" in the inspector /// of the attached script. [ContextMenu ("Do Something")] void DoSomething () { Debug.Log ("Perform operation"); } }
ContextMenuItemAttribute
可以在
Inspector上面对变量追加一个右键菜单,并执行指定的函数。
例如:public class Sample : MonoBehaviour { [ContextMenuItem("Reset", "ResetName")] public string name = "Default"; void ResetName() { name = "Default"; } }
DisallowMultipleComponent
不允许在同一个
Gameo

本文详细介绍了Unity中的一系列内置属性,如AddComponentMenu用于自定义组件菜单,ExecuteInEditMode使得脚本在编辑模式下运行,SerializeField实现变量在Inspector中可编辑,RequireComponent自动附加依赖组件等。这些属性极大地丰富了Unity开发的灵活性和便捷性。
最低0.47元/天 解锁文章
1720

被折叠的 条评论
为什么被折叠?



