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

unity源码解析Component

2016-04-06 11:32 896 查看
Component 这个没有声明好说的,因为他的方法实现基本都在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的实现
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: