unity3d 4.5
RequireComponent的使用: 当你添加的一个用了RequireComponent组件的脚本,需要的组件将会自动被添加到game object(游戏物体)。这个可以有效的避免组装错误。举个例子一个脚本可能需要刚体总是被添加在相同的game object(游戏物体)上。用RequireComponent属性的话,这个过程将被自动完成,因此你可以永远不会犯组装错误。 用法:在新建的类前面加 [RequireComponent(typeof(Rigidbody))]如图:使用前
使用后,而且新加的Rigidbody是不可以被删除的
AddComponentMenu的使用: AddComponentMenu属性允许你在'Component'菜单中放置一个无论在哪的脚本,而不是仅仅在'Component->Scripts'菜单中。用法:[AddComponentMenu('NGUI/Examples/cubSpin')]
MenuItem的使用:在工具栏上增加新的一列用法:如图[MenuItem('Test/Test')] 后面必须跟一个static的方法,需要引用头文件 using UnityEditor;:
ContextMenu的使用:属性允许你去添加命令给上下文菜单用法:[ContextMenu('Test')] public void Test ()右键点击:会出现如图所示
HideInInspector的使用;在Inspector面板中隐藏public变量用法:[HideInInspector] public Vector3 rotationsPerSecond = new Vector3(0f,0.1f,0f);使用前如图
使用后;如图所示
如果此经验对你有帮助,请投上你的一票吧