UNITY 5.2 GameObject类
2015-10-17 02:28
411 查看
此类继承于命名空间 UnityEngine 中的Object类
变量:
public Transform transform { get; }
说明:只读属性,每个对象都具有的 变换组件
public bool activeInHierarchy { get; }
说明:只读属性,若该GameObject是活动的,则该对象和他所有的父对象的 GameObject.activeSelf 是 TRUE
public bool activeSelf { get; }
说明:只读属性,该对象是否活动
public bool isStatic { get; set; }
说明:标记对象是否 isStatic
public int layer { get; set; }
说明:对象的层级 [0...31] ,控制渲染层级和射线投射层级
public string tag { get; set; }
说明:标志类型
构造函数:
public GameObject(string name);
说明:创建一个只有名字的对象
public GameObject(string name, params Type[] components);
说明:创建一个有名字和传入组件的对象
Public函数:
添加组件函数:
public Component AddComponent(string className);
说明:传入组件类名
public T AddComponent<T>() where T : Component;
说明:通过泛型创建
public Component AddComponent(Type componentType);
说明:组件类型创建
消息传递函数:
public void BroadcastMessage(string methodName);
public void BroadcastMessage(string methodName, object parameter);
public void BroadcastMessage(string methodName, SendMessageOptions options);
public void BroadcastMessage(string methodName, object parameter, SendMessageOptions options);
说明: 该对象向自己或者子对象发送消息,在该对象或者该子对象(MonoBehaviour)中调用名字为 methodName 的方法 可以选择是否有参数
SendMessageOptions(RequireReceiver 必须有消息接受者,否则打印错误(默认) 与 DontRequireReceiver 不需要消息接受者 )
public void SendMessage(string methodName);
public void SendMessage(string methodName, object value);
public void SendMessage(string methodName, SendMessageOptions options);
public void SendMessage(string methodName, object value, SendMessageOptions options);
说明: 该对象向自己发送消息,在该对象(MonoBehaviour)中调用名字为 methodName 的方法 可以选择是否有参数
SendMessageOptions(RequireReceiver 必须有消息接受者,否则打印错误(默认) 与 DontRequireReceiver 不需要消息接受者 )
public void SendMessageUpwards(string methodName);
public void SendMessageUpwards(string methodName, object value);
public void SendMessageUpwards(string methodName, SendMessageOptions options);
public void SendMessageUpwards(string methodName, object value, SendMessageOptions options);
说明: 该对象向自己或者父对象发送消息,在该对象或者父对象(MonoBehaviour)中调用名字为 methodName 的方法 可以选择是否有参数
SendMessageOptions(RequireReceiver 必须有消息接受者,否则打印错误(默认) 与 DontRequireReceiver 不需要消息接受者 )
public T GetComponent<T>();
public Component GetComponent(string type);
public Component GetComponent(Type type);
说明:通过组件类型或者组件名称返回该对象中包含的组件,否则为null
public Component GetComponentInChildren(Type type);
public T GetComponentInChildren<T>();
说明:通过组件类型返回对象或者子对象中包含的组件对象,depth优先,只返回最先找到的那一个 否则为null
public T GetComponentInParent<T>();
public Component GetComponentInParent(Type type);
说明:通过组件类型返回父对象中包含的组件对象,depth优先,只返回最先找到的那一个 否则为null
public T[] GetComponents<T>();
public Component[] GetComponents(Type type);
说明:返回该对象中的所有该类型的组件数组
public void GetComponents<T>(List<T> results);
public void GetComponents(Type type, List<Component> results);
说明:返回该对象中的所有该类型的组件列表
public T[] GetComponentsInChildren<T>();
public T[] GetComponentsInChildren<T>(bool includeInactive);
说明:通过组件类型返回所有在该对象或者子对象中的组件数组,includeInactive是否包含不活动的对象
public Component[] GetComponentsInChildren(Type type);
public Component[] GetComponentsInChildren(Type type, bool includeInactive);
说明:通过组件类型返回所有在该对象或者子对象中的组件数组,includeInactive是否包含不活动的对象
public void GetComponentsInChildren<T>(List<T> results);
public void GetComponentsInChildren<T>(bool includeInactive, List<T> results);
说明:通过组件类型返回所有在该对象或者子对象中的组件列表,includeInactive是否包含不活动的对象
public T[] GetComponentsInParent<T>();
public T[] GetComponentsInParent<T>(bool includeInactive);
说明:通过组件类型返回所有在该对象或者父对象中的组件数组,includeInactive是否包含不活动的对象
public Component[] GetComponentsInParent(Type type);
public Component[] GetComponentsInParent(Type type, bool includeInactive);
说明:通过组件类型返回所有在该对象或者父对象中的组件数组,includeInactive是否包含不活动的对象
public void GetComponentsInParent<T>(bool includeInactive, List<T> results);
说明:通过组件类型返回所有在该对象或者父对象中的组件数组,includeInactive是否包含不活动的对象
public bool CompareTag(string tag);
说明:比较对象tag 与 tag 是否相等
public void SetActive(bool value);
说明:设置该对象是否活动
Static函数
public static GameObject CreatePrimitive(PrimitiveType type);
说明:通过 PrimitiveType 创建对象,包含碰撞盒子(Sphere、 Capsule、 Cylinder、 Cube、 Plane、 Quad)
public static GameObject Find(string name);
说明:通过 对象名称 找到该对象,若没有该名称对象或者该对象不是活动的则返回null,若名称中出现 '/' 字符,则将名字以该字符分割成层级关系。尽量不要在每一帧中使用该函数
public static GameObject FindWithTag(string tag);
说明:返回用该 tag 标记的活动的一个对象,tag在使用前必须先声明
public static GameObject[] FindGameObjectsWithTag(string tag);
说明:返回用该 tag 标记的活动的对象的数组,tag在使用前必须先声明
继承成员
变量:
hideFlags
说明:在场景编辑器中的编辑状态
name
说明:该对象的名称
Public函数:
public int GetInstanceID();
说明:返回对象的唯一ID
public string ToString();
说明:返回对象的名称
Static函数:
public static void Destroy(Object obj, float t = 0.0F);
说明:如果Object是组件,则移除该组件并销毁,若Object是对象,则移除并销毁该对象的所有子对象和组件、资源,等待时间 t 执行
public static void DestroyImmediate(Object obj, bool allowDestroyingAssets = false);
说明:立即销毁对象,allowDestroyingAssets是否销毁资源,不建议用,代码中最好使用 Destroy
public static void DontDestroyOnLoad(Object target);
说明:保证该对象在加载新场景时不会被自动回收,并保留完整的变换组件
public static Object FindObjectOfType(Type type);
说明:返回第一个该类型的活动的对象,不推荐每帧使用
public static Object[] FindObjectsOfType(Type type);
说明:返回所有该类型的对象数组
public static Object Instantiate(Object original, Vector3 position, Quaternion rotation);
public static Object Instantiate(Object original);
说明:original 期望被克隆的对象, position 新坐标, rotation 新坐标,若被克隆的是组件对象,那么附加该组件的对象也会被克隆
操作符
Object.bool
说明:该对象是否为 null
public static bool operator !=(Object x, Object y);
public static bool operator ==(Object x, Object y);
说明:判断两个对象是否相等
变量:
public Transform transform { get; }
说明:只读属性,每个对象都具有的 变换组件
public bool activeInHierarchy { get; }
说明:只读属性,若该GameObject是活动的,则该对象和他所有的父对象的 GameObject.activeSelf 是 TRUE
public bool activeSelf { get; }
说明:只读属性,该对象是否活动
public bool isStatic { get; set; }
说明:标记对象是否 isStatic
public int layer { get; set; }
说明:对象的层级 [0...31] ,控制渲染层级和射线投射层级
public string tag { get; set; }
说明:标志类型
构造函数:
public GameObject(string name);
说明:创建一个只有名字的对象
public GameObject(string name, params Type[] components);
说明:创建一个有名字和传入组件的对象
Public函数:
添加组件函数:
public Component AddComponent(string className);
说明:传入组件类名
public T AddComponent<T>() where T : Component;
说明:通过泛型创建
public Component AddComponent(Type componentType);
说明:组件类型创建
消息传递函数:
public void BroadcastMessage(string methodName);
public void BroadcastMessage(string methodName, object parameter);
public void BroadcastMessage(string methodName, SendMessageOptions options);
public void BroadcastMessage(string methodName, object parameter, SendMessageOptions options);
说明: 该对象向自己或者子对象发送消息,在该对象或者该子对象(MonoBehaviour)中调用名字为 methodName 的方法 可以选择是否有参数
SendMessageOptions(RequireReceiver 必须有消息接受者,否则打印错误(默认) 与 DontRequireReceiver 不需要消息接受者 )
public void SendMessage(string methodName);
public void SendMessage(string methodName, object value);
public void SendMessage(string methodName, SendMessageOptions options);
public void SendMessage(string methodName, object value, SendMessageOptions options);
说明: 该对象向自己发送消息,在该对象(MonoBehaviour)中调用名字为 methodName 的方法 可以选择是否有参数
SendMessageOptions(RequireReceiver 必须有消息接受者,否则打印错误(默认) 与 DontRequireReceiver 不需要消息接受者 )
public void SendMessageUpwards(string methodName);
public void SendMessageUpwards(string methodName, object value);
public void SendMessageUpwards(string methodName, SendMessageOptions options);
public void SendMessageUpwards(string methodName, object value, SendMessageOptions options);
说明: 该对象向自己或者父对象发送消息,在该对象或者父对象(MonoBehaviour)中调用名字为 methodName 的方法 可以选择是否有参数
SendMessageOptions(RequireReceiver 必须有消息接受者,否则打印错误(默认) 与 DontRequireReceiver 不需要消息接受者 )
public T GetComponent<T>();
public Component GetComponent(string type);
public Component GetComponent(Type type);
说明:通过组件类型或者组件名称返回该对象中包含的组件,否则为null
public Component GetComponentInChildren(Type type);
public T GetComponentInChildren<T>();
说明:通过组件类型返回对象或者子对象中包含的组件对象,depth优先,只返回最先找到的那一个 否则为null
public T GetComponentInParent<T>();
public Component GetComponentInParent(Type type);
说明:通过组件类型返回父对象中包含的组件对象,depth优先,只返回最先找到的那一个 否则为null
public T[] GetComponents<T>();
public Component[] GetComponents(Type type);
说明:返回该对象中的所有该类型的组件数组
public void GetComponents<T>(List<T> results);
public void GetComponents(Type type, List<Component> results);
说明:返回该对象中的所有该类型的组件列表
public T[] GetComponentsInChildren<T>();
public T[] GetComponentsInChildren<T>(bool includeInactive);
说明:通过组件类型返回所有在该对象或者子对象中的组件数组,includeInactive是否包含不活动的对象
public Component[] GetComponentsInChildren(Type type);
public Component[] GetComponentsInChildren(Type type, bool includeInactive);
说明:通过组件类型返回所有在该对象或者子对象中的组件数组,includeInactive是否包含不活动的对象
public void GetComponentsInChildren<T>(List<T> results);
public void GetComponentsInChildren<T>(bool includeInactive, List<T> results);
说明:通过组件类型返回所有在该对象或者子对象中的组件列表,includeInactive是否包含不活动的对象
public T[] GetComponentsInParent<T>();
public T[] GetComponentsInParent<T>(bool includeInactive);
说明:通过组件类型返回所有在该对象或者父对象中的组件数组,includeInactive是否包含不活动的对象
public Component[] GetComponentsInParent(Type type);
public Component[] GetComponentsInParent(Type type, bool includeInactive);
说明:通过组件类型返回所有在该对象或者父对象中的组件数组,includeInactive是否包含不活动的对象
public void GetComponentsInParent<T>(bool includeInactive, List<T> results);
说明:通过组件类型返回所有在该对象或者父对象中的组件数组,includeInactive是否包含不活动的对象
public bool CompareTag(string tag);
说明:比较对象tag 与 tag 是否相等
public void SetActive(bool value);
说明:设置该对象是否活动
Static函数
public static GameObject CreatePrimitive(PrimitiveType type);
说明:通过 PrimitiveType 创建对象,包含碰撞盒子(Sphere、 Capsule、 Cylinder、 Cube、 Plane、 Quad)
public static GameObject Find(string name);
说明:通过 对象名称 找到该对象,若没有该名称对象或者该对象不是活动的则返回null,若名称中出现 '/' 字符,则将名字以该字符分割成层级关系。尽量不要在每一帧中使用该函数
public static GameObject FindWithTag(string tag);
说明:返回用该 tag 标记的活动的一个对象,tag在使用前必须先声明
public static GameObject[] FindGameObjectsWithTag(string tag);
说明:返回用该 tag 标记的活动的对象的数组,tag在使用前必须先声明
继承成员
变量:
hideFlags
说明:在场景编辑器中的编辑状态
name
说明:该对象的名称
Public函数:
public int GetInstanceID();
说明:返回对象的唯一ID
public string ToString();
说明:返回对象的名称
Static函数:
public static void Destroy(Object obj, float t = 0.0F);
说明:如果Object是组件,则移除该组件并销毁,若Object是对象,则移除并销毁该对象的所有子对象和组件、资源,等待时间 t 执行
public static void DestroyImmediate(Object obj, bool allowDestroyingAssets = false);
说明:立即销毁对象,allowDestroyingAssets是否销毁资源,不建议用,代码中最好使用 Destroy
public static void DontDestroyOnLoad(Object target);
说明:保证该对象在加载新场景时不会被自动回收,并保留完整的变换组件
public static Object FindObjectOfType(Type type);
说明:返回第一个该类型的活动的对象,不推荐每帧使用
public static Object[] FindObjectsOfType(Type type);
说明:返回所有该类型的对象数组
public static Object Instantiate(Object original, Vector3 position, Quaternion rotation);
public static Object Instantiate(Object original);
说明:original 期望被克隆的对象, position 新坐标, rotation 新坐标,若被克隆的是组件对象,那么附加该组件的对象也会被克隆
操作符
Object.bool
说明:该对象是否为 null
public static bool operator !=(Object x, Object y);
public static bool operator ==(Object x, Object y);
说明:判断两个对象是否相等
相关文章推荐
- Android Manifest 用法
- Spark RDD API详解(一) Map和Reduce
- 一个小型js框架myJSFrame附API使用帮助
- 详细分析交换机、路由器、集线器的区别和联系
- PowerShell打开或关闭光驱
- 批处理的api WMIC学习体会有感第1/2页
- 批处理 API实现文件下载的代码第1/2页
- Lua教程(十七):C API简介
- 强制删除工具 xdelbox xdelbox1.5正式版下载
- 揪出交换机端口背后“凶手”导致网速太慢
- 电脑重启后突然检测不到硬盘的原因分析与解决办法
- C#中设计、使用Fluent API
- Google官方支持的NodeJS访问API,提供后台登录授权
- PQ分区出错! 巧用Ghost急速补救的绝妙办法
- 深入C++中API的问题详解
- 使用WindowsAPI实现播放PCM音频的方法
- 40余种刻录盘片详细对照分析介绍第1/2页
- fullCalendar中文API官方文档
- 详解ASP.NET WEB API 之属性路由
- 浅谈关于JavaScript API设计的一些建议和准则