Unity3d 编辑器扩展

1. AddComponentMenu的使用:

  AddComponentMenu属性允许你在"Component"菜单中放置一个无论在哪的脚本,而不是仅仅在"Component->Scripts"菜单中。

用法:[AddComponentMenu("NGUI/Examples/cubSpin")]

Unity3d 编辑器扩展_第1张图片

2.

RequireComponent的使用:

    当你添加的一个用了RequireComponent组件的脚本,需要的组件将会自动被添加到game object(游戏物体)。这个可以有效的避免组装错误。举个例子一个脚本可能需要刚体总是被添加在相同的game object(游戏物体)上。用RequireComponent属性的话,这个过程将被自动完成,因此你可以永远不会犯组装错误。

   用法:在新建的类前面加 [RequireComponent(typeof(Rigidbody))]

如图,使用前:


使用后:

Unity3d 编辑器扩展_第2张图片

3.

MenuItem的使用:在工具栏上增加新的一列

用法:如图[MenuItem("Test/Test")]  后面必须跟一个static的方法,需要引用头文件  using UnityEditor;:

Unity编辑器扩展之RequireComponent等详解




4.

ContextMenu的使用:属性允许你去添加命令给上下文菜单

用法:

[ContextMenu("Test")]

public void Test ()

右键点击:会出现如图所示


5.

HideInInspector的使用;在Inspector面板中隐藏public变量

用法:

[HideInInspector]

public Vector3 rotationsPerSecond = new Vector3(0f,0.1f,0f);

使用前如图

Unity3d 编辑器扩展_第3张图片
添加后:

6.SerializeField 
和上面相反
[SerializeField]
    private int Num;
在Inspector下看得到Num这个值,和public 没有区别



你可能感兴趣的:(unity3d,编辑器)