您的位置:首页 > 移动开发 > Unity3D

Unity中的Attribute

2015-08-21 20:48 615 查看
1.AddComponentMenu 添加组件菜单

这函数只是起方便用,原本的脚本(组建)都会在“Component/Script”菜单下,在类之前声明一下这个,它便可以出现在"Componet"菜单下的任何位置。说明指的是要重启U3D才能显示,不过测试貌似直接可以显示。

[AddComponentMenu("MyPhysic/PhysicType")]

public class PhysicType: MonoBehaviour

{

}

2、

2.ContextMenu 上下文菜单

这个译名我觉得很不自然,其实上下文算是啥东西……这个函数是在Inspector的脚本中加一个触发事件,可以作为调试或者测试之用

public class Attributes : MonoBehaviour {

[ContextMenu("Hello World!")]

void HelloWorld()

{

Debug.Log("Hello World!");

}

}

3、HideInInspector 在检视面板中隐藏

public class HideInspectorTest : MonoBehaviour

{

[HideInInspector]

public Transform m_Target;

void Start()

{

m_Target = GameObject.Find("test").transform;

}

}

4、
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: