《Unity_API解析》 第三章 GameObject类
来源:互联网 发布:中国移动积分兑换软件 编辑:程序博客网 时间:2024/06/11 02:20
GameObject类实例属性
activeSelf属性:GameObject的Active标识
public bool activeSelf{ get; }
功能说明 此属性用来返回GameObject对象的Active标识状态,即物体的活跃状态。
注意:此属性与activeInHierarchy的区别。activeInHierarchy属性的功能是返回GameObject实例在程序运行时的激活状态,只有当GameObject实例的状态被激活时才会返回true。而且它会受其父物体对象激活状态的影响,如果其父类至最顶层的对象中有一个对象未被激活,activeInHierarchy就会返回false。
GameObject类构造方法
1.public GameObject();
2.public GameObject(string name);
参数为构造GameObject对象的名字
3.public GameObject(string name,params Type[] components);
参数那么为GameObject对象的名字,components为构造对象要添加的组件类型集合,多个组件之间用逗号隔开。
功能说明 此构造方法用来创建一个GameObject对象。
GameObject类实例方法
GetComponent方法:获取组件
1.public T GetComponent<T> where T : Component;
2.public Component GetComponent(string type);
其中参数type为组件名。
3.public Component GetComponent(Type type);
其中参数type为组件类型。
功能说明 此方法用于获取GameObject中第一个符合Type类型的Component。
注意:与此方法功能相似的方法有GetComponentInChildren,GetComponents和GetComponentsInChildren。
1.在使用GetComponents(type:Type)方法时
Component[] cjs = GetComponents(typeof(configurableJoint)) as Component[];,这样写是不可以的:
ConfigurableJoint[] cjs = GetComponents(typeof(ConfigurableJoint)) as Configurable Joint[];
因为ConfigurableJoint不是Component,而是其子类,建议使用其泛型方式。
2.在使用GetComponentsInChidren(type:Type,includeInactive:boolean = false)方法时,不可以这样写。
Component[] cjs = GetComponentsInChildren(typeof(ConfigurableJoint),false) as Component[];
ConfigurableJoint[] cjs = GetComponentsInChidren(typeof(ConfigurableJoint), false) as ConfigurableJoint[];
因为ConfigurableJoint不是Component,而是其子类,建议使用其泛型方式。
SendMessage方法:发送消息
1.public void SendMessage(string methodName);
2.public void SendMessage(string methodName, object value);
3.public void SendMessage(string methodName, SendMessageOptions options);
4.public void SendMessage(string methodName, object value, SendMessageOptions options);
参数methodName为接收消息的方法名字,value为信息的内容,options为信息的接收方式,默认为SendMessageOptions.RequireReceiver。
功能说明 此方法的功能是向GameObject自身发送消息,对其作用范围说明如下:
1.和接受消息对象同级的物体不会收到消息。
2.SendMessageOptions有两个可选方式:SendMessageOptions.RequireReceiver和SendMessageOptions.DontRequireReceiver。前者要求信息的接收方必须有接受信息的方法,否则程序会报错,后者无要求。
提示:与此方法功能相似的方法有BroadcastMessage和SendMessageUpwards,对其功能说明如下:
1.BroadcastMessage方法的功能是向对象自身及其所有子类发送消息。和对象同级的物体不会收到消息。
2.SendMessageUpwards方法的功能是向对象自身及其所有父类发送消息。和自身同级的物体不会收到消息。
GameObject类静态方法
Createprimitive方法 : 创建GameObject对象
public static GameObject CreatePrimitive(PrimitiveType type);
参数为枚举PrimitiveType的类型值。
功能说明:此方法的功能是创建一个系统自带的GameObject对象。
0 0
- 《Unity_API解析》 第三章 GameObject类
- 【Unity】《Unity_API解析》 第四章 HideFlags类
- Unity学习第三章 GameObject
- Unity API 解析—— GameObject 类
- gameObject类
- GameObject类
- unity源码解析GameObject
- UNITY 5.2 GameObject类
- Unity 入门 Gameobject类
- 02-GameObject类
- Unity3D-GameObject类
- Unity_API之monoBehaviour
- GameObject类一些常用的方法属性
- unity3d(3)GameObject-游戏对象类
- Unity扩展GameObject等类中的方法
- 第三章Python解析list,dictionary,set
- 《Python核心编程》第三章练习解析
- 算法导论课后习题解析 第三章
- 如何在使用moveRowAtIndexPath:方法时替换默认图片
- java下载文件名乱码
- Android 自定义软键盘
- Java—内部类(三)—内部类的继承
- Python 的 yield 在 C++ 上的一种实现
- 《Unity_API解析》 第三章 GameObject类
- android应用版本升级时签名冲突问题的原因及解决办法
- 数据结构学习笔记(前言)
- PhalApi框架浅谈之融云扩展类库(PhalApi——RongYun)
- CRAN 的任务视图(View Task)
- linux常见命令
- Linux下NFS的配置
- Android 6.0 sensor 框架详解(前言)
- curl指令