unity源码解析Component
2016-04-06 11:32
896 查看
Component 这个没有声明好说的,因为他的方法实现基本都在GameObject中,就是上一篇中的额内容,就单单贴出源码好了
具体可以参考上一篇博客中Gameobject的实现
using System; using System.Collections.Generic; using System.Runtime.CompilerServices; using UnityEngine.Internal; using UnityEngineInternal; namespace UnityEngine { public class Component : Object { public Transform transform { get { return this.InternalGetTransform(); } } public extern Rigidbody rigidbody { [WrapperlessIcall] [MethodImpl(MethodImplOptions.InternalCall)] get; } public extern Rigidbody2D rigidbody2D { [WrapperlessIcall] [MethodImpl(MethodImplOptions.InternalCall)] get; } public extern Camera camera { [WrapperlessIcall] [MethodImpl(MethodImplOptions.InternalCall)] get; } public extern Light light { [WrapperlessIcall] [MethodImpl(MethodImplOptions.InternalCall)] get; } public extern Animation animation { [WrapperlessIcall] [MethodImpl(MethodImplOptions.InternalCall)] get; } public extern ConstantForce constantForce { [WrapperlessIcall] [MethodImpl(MethodImplOptions.InternalCall)] get; } public extern Renderer renderer { [WrapperlessIcall] [MethodImpl(MethodImplOptions.InternalCall)] get; } public extern AudioSource audio { [WrapperlessIcall] [MethodImpl(MethodImplOptions.InternalCall)] get; } public extern GUIText guiText { [WrapperlessIcall] [MethodImpl(MethodImplOptions.InternalCall)] get; } public extern NetworkView networkView { [WrapperlessIcall] [MethodImpl(MethodImplOptions.InternalCall)] get; } [Obsolete("Please use guiTexture instead")] public extern GUIElement guiElement { [WrapperlessIcall] [MethodImpl(MethodImplOptions.InternalCall)] get; } public extern GUITexture guiTexture { [WrapperlessIcall] [MethodImpl(MethodImplOptions.InternalCall)] get; } public extern Collider collider { [WrapperlessIcall] [MethodImpl(MethodImplOptions.InternalCall)] get; } public extern Collider2D collider2D { [WrapperlessIcall] [MethodImpl(MethodImplOptions.InternalCall)] get; } public extern HingeJoint hingeJoint { [WrapperlessIcall] [MethodImpl(MethodImplOptions.InternalCall)] get; } public extern ParticleEmitter particleEmitter { [WrapperlessIcall] [MethodImpl(MethodImplOptions.InternalCall)] get; } public extern ParticleSystem particleSystem { [WrapperlessIcall] [MethodImpl(MethodImplOptions.InternalCall)] get; } public GameObject gameObject { get { return this.InternalGetGameObject(); } } [Obsolete("the active property is deprecated on components. Please use gameObject.active instead. If you meant to enable / disable a single component use enabled instead.")] public extern bool active { [WrapperlessIcall] [MethodImpl(MethodImplOptions.InternalCall)] get; [WrapperlessIcall] [MethodImpl(MethodImplOptions.InternalCall)] set; } public extern string tag { [WrapperlessIcall] [MethodImpl(MethodImplOptions.InternalCall)] get; [WrapperlessIcall] [MethodImpl(MethodImplOptions.InternalCall)] set; } [WrapperlessIcall] [MethodImpl(MethodImplOptions.InternalCall)] internal extern Transform InternalGetTransform(); [WrapperlessIcall] [MethodImpl(MethodImplOptions.InternalCall)] internal extern GameObject InternalGetGameObject(); [WrapperlessIcall, TypeInferenceRule(TypeInferenceRules.TypeReferencedByFirstArgument)] [MethodImpl(MethodImplOptions.InternalCall)] public extern Component GetComponent(Type type); public T GetComponent<T>() where T : Component { return this.GetComponent(typeof(T)) as T; } public Component GetComponent(string type) { return this.gameObject.GetComponent(type); } [TypeInferenceRule(TypeInferenceRules.TypeReferencedByFirstArgument)] public Component GetComponentInChildren(Type t) { return this.gameObject.GetComponentInChildren(t); } public T GetComponentInChildren<T>() where T : Component { return (T)((object)this.GetComponentInChildren(typeof(T))); } [ExcludeFromDocs] public Component[] GetComponentsInChildren(Type t) { bool includeInactive = false; return this.GetComponentsInChildren(t, includeInactive); } public Component[] GetComponentsInChildren(Type t, [DefaultValue("false")] bool includeInactive) { return this.gameObject.GetComponentsInChildren(t, includeInactive); } public T[] GetComponentsInChildren<T>(bool includeInactive) where T : Component { return this.gameObject.GetComponentsInChildren<T>(includeInactive); } public void GetComponentsInChildren<T>(bool includeInactive, List<T> result) where T : Component { this.gameObject.GetComponentsInChildren<T>(includeInactive, result); } public T[] GetComponentsInChildren<T>() where T : Component { return this.GetComponentsInChildren<T>(false); } public void GetComponentsInChildren<T>(List<T> results) where T : Component { this.GetComponentsInChildren<T>(false, results); } [TypeInferenceRule(TypeInferenceRules.TypeReferencedByFirstArgument)] public Component GetComponentInParent(Type t) { return this.gameObject.GetComponentInParent(t); } public T GetComponentInParent<T>() where T : Component { return (T)((object)this.GetComponentInParent(typeof(T))); } [ExcludeFromDocs] public Component[] GetComponentsInParent(Type t) { bool includeInactive = false; return this.GetComponentsInParent(t, includeInactive); } public Component[] GetComponentsInParent(Type t, [DefaultValue("false")] bool includeInactive) { return this.gameObject.GetComponentsInParent(t, includeInactive); } public T[] GetComponentsInParent<T>(bool includeInactive) where T : Component { return this.gameObject.GetComponentsInParent<T>(includeInactive); } public T[] GetComponentsInParent<T>() where T : Component { return this.GetComponentsInParent<T>(false); } [WrapperlessIcall] [MethodImpl(MethodImplOptions.InternalCall)] public extern Component[] GetComponents(Type type); [WrapperlessIcall] [MethodImpl(MethodImplOptions.InternalCall)] private extern Component[] GetComponentsWithCorrectReturnType(Type type); [WrapperlessIcall] [MethodImpl(MethodImplOptions.InternalCall)] private extern void GetComponentsForListInternal(Type searchType, Type listElementType, bool recursive, bool includeInactive, object resultList); public T[] GetComponents<T>() where T : Component { return (T[])this.GetComponentsWithCorrectReturnType(typeof(T)); } public void GetComponents(Type type, List<Component> results) { this.GetComponentsForListInternal(type, typeof(Component), false, true, results); } public void GetComponents<T>(List<T> results) where T : Component { this.GetComponentsForListInternal(typeof(T), typeof(T), false, true, results); } [WrapperlessIcall] [MethodImpl(MethodImplOptions.InternalCall)] public extern bool CompareTag(string tag); [WrapperlessIcall] [MethodImpl(MethodImplOptions.InternalCall)] public extern void SendMessageUpwards(string methodName, [DefaultValue("null")] object value, [DefaultValue("SendMessageOptions.RequireReceiver")] SendMessageOptions options); [ExcludeFromDocs] public void SendMessageUpwards(string methodName, object value) { SendMessageOptions options = SendMessageOptions.RequireReceiver; this.SendMessageUpwards(methodName, value, options); } [ExcludeFromDocs] public void SendMessageUpwards(string methodName) { SendMessageOptions options = SendMessageOptions.RequireReceiver; object value = null; this.SendMessageUpwards(methodName, value, options); } public void SendMessageUpwards(string methodName, SendMessageOptions options) { this.SendMessageUpwards(methodName, null, options); } [WrapperlessIcall] [MethodImpl(MethodImplOptions.InternalCall)] public extern void SendMessage(string methodName, [DefaultValue("null")] object value, [DefaultValue("SendMessageOptions.RequireReceiver")] SendMessageOptions options); [ExcludeFromDocs] public void SendMessage(string methodName, object value) { SendMessageOptions options = SendMessageOptions.RequireReceiver; this.SendMessage(methodName, value, options); } [ExcludeFromDocs] public void SendMessage(string methodName) { SendMessageOptions options = SendMessageOptions.RequireReceiver; object value = null; this.SendMessage(methodName, value, options); } public void SendMessage(string methodName, SendMessageOptions options) { this.SendMessage(methodName, null, options); } [WrapperlessIcall] [MethodImpl(MethodImplOptions.InternalCall)] public extern void BroadcastMessage(string methodName, [DefaultValue("null")] object parameter, [DefaultValue("SendMessageOptions.RequireReceiver")] SendMessageOptions options); [ExcludeFromDocs] public void BroadcastMessage(string methodName, object parameter) { SendMessageOptions options = SendMessageOptions.RequireReceiver; this.BroadcastMessage(methodName, parameter, options); } [ExcludeFromDocs] public void BroadcastMessage(string methodName) { SendMessageOptions options = SendMessageOptions.RequireReceiver; object parameter = null; this.BroadcastMessage(methodName, parameter, options); } public void BroadcastMessage(string methodName, SendMessageOptions options) { this.BroadcastMessage(methodName, null, options); } } }
具体可以参考上一篇博客中Gameobject的实现
相关文章推荐
- unity 第四期
- unity 第三期
- unity源码解析GameObject
- unity 第二期
- Unity 第一期
- 3dsMax与Unity3D坐标系同步
- 查看unity打包的texture文件
- 【Unity】4.2 提升开发效率的捷径--导入 Unity 5.3.4 自带的资源包
- iTween基础之iTweenPath(自定义路径移动)
- 【Unity&C#】运行在主线程的Socket
- Unity中的Path对应各平台中的Path
- Unity+百度推送+IOS版
- Unity 加载 失败 解决办法
- Unity3D研究院之手游开发中所有特殊的文件夹(assetbundle与Application.persistentDataPath)
- unity, 使导入的材质名与3dmax中一致
- Unity+Xcode7.x 提示Undefined symbols for architecture arm64:
- Unity渲染路径比较
- ubuntu12.04开启虚拟机的unity模式
- 构建ASP.NET MVC5+EF6+EasyUI 1.4.3+Unity4.x注入的后台管理系统(1)-前言与目录(持续更新中...)
- 构建ASP.NET MVC5+EF6+EasyUI 1.4.3+Unity4.x注入的后台管理系统(52)-美化EasyUI皮肤和图标