转载地址:http://www.cnblogs.com/nsky/p/5275106.html
1. AddComponentMenu
描述:这个属性可以在Component这个菜单栏下加自己定义的子菜单,这样可以快速添加常用的脚本。该属性要用在类上。
using UnityEngine; using System.Collections; [AddComponentMenu("MyComponent/Foo")] public class MyEditor : MonoBehaviour { // Use this for initialization void Start () { } // Update is called once per frame void Update () { } }
效果:可以看见在Component下多了一个MyComponent的子菜单,点击该子菜单下的Foo就能添加MyEditor这个组件
2. MenuItem
描述:可以添加一个菜单(而不是子菜单),与Component菜单同级。使用该属性要指定子菜单(比如下面的MyName)
using UnityEngine; using UnityEditor; using System.Collections; public class MyEditor { [MenuItem("MyMenu/MyName")] static void PrintName() { Debug.Log("Kaima"); } }
效果:可以看见多了一个MyMenu菜单,点击MyName可以看见输出中有Kaima这条输出
3. ContextMenu
描述:可以在组件的小齿轮上添加一个功能
using UnityEngine; using System.Collections; public class MyEditor { [ContextMenu("printName")] void PrintName() { Debug.Log("Kaima"); } }
4. HideInInspector
描述:可以隐藏类中的成员,使之不会再面板中显示。常用于隐藏public的。
using UnityEngine; using System.Collections; public class MyEditor { [HideInInspector] public int mValue; }
5. RequireComponent
描述:可以在添加本组件前添加需要的组件
using UnityEngine; using System.Collections; [RequireComponent(typeof(BoxCollider))] public class MyEditor { }
6. Serializable
描述:可序列化。通俗来说就是能让类成员的属性显示出来
using UnityEngine; using System.Collections; [System.Serializable] public class SubCoo{ public int mValue; public string mName; } public class MyEditor { public SubCoo mCoo; }