评论

收藏

[C++] Unity常用API笔记

编程语言 编程语言 发布于:2021-08-03 10:33 | 阅读数:863 | 评论:0

一.概述
Unity使用反射即时获取和加载脚本信息。Unity所有脚本继承自Monobehaviour类,这个类的内容如下:
namespace UnityEngine
{
  //
  // 摘要:
  //   MonoBehaviour is the base class from which every Unity script derives.
  [ExtensionOfNativeClass]
  [NativeHeader("Runtime/Mono/MonoBehaviour.h")]
  [NativeHeader("Runtime/Scripting/DelayedCallUtility.h")]
  [RequiredByNativeCode]
  public class MonoBehaviour : Behaviour
  {
    public MonoBehaviour();
    //
    // 摘要:
    //   Disabling this lets you skip the GUI layout phase.
    public bool useGUILayout { get; set; }
    //
    // 摘要:
    //   Allow a specific instance of a MonoBehaviour to run in edit mode (only available
    //   in the editor).
    public bool runInEditMode { get; set; }
    //
    // 摘要:
    //   Logs message to the Unity Console (identical to Debug.Log).
    //
    // 参数:
    //   message:
    public static void print(object message);
    //
    // 摘要:
    //   Cancels all Invoke calls with name methodName on this behaviour.
    //
    // 参数:
    //   methodName:
    public void CancelInvoke(string methodName);
    //
    // 摘要:
    //   Cancels all Invoke calls on this MonoBehaviour.
    public void CancelInvoke();
    //
    // 摘要:
    //   Invokes the method methodName in time seconds.
    //
    // 参数:
    //   methodName:
    //
    //   time:
    public void Invoke(string methodName, float time);
    //
    // 摘要:
    //   Invokes the method methodName in time seconds, then repeatedly every repeatRate
    //   seconds.
    //
    // 参数:
    //   methodName:
    //
    //   time:
    //
    //   repeatRate:
    public void InvokeRepeating(string methodName, float time, float repeatRate);
    //
    // 摘要:
    //   Is any invoke on methodName pending?
    //
    // 参数:
    //   methodName:
    public bool IsInvoking(string methodName);
    //
    // 摘要:
    //   Is any invoke pending on this MonoBehaviour?
    public bool IsInvoking();
    //
    // 摘要:
    //   Starts a coroutine named methodName.
    //
    // 参数:
    //   methodName:
    //
    //   value:
    [ExcludeFromDocs]
    public Coroutine StartCoroutine(string methodName);
    //
    // 摘要:
    //   Starts a Coroutine.
    //
    // 参数:
    //   routine:
    public Coroutine StartCoroutine(IEnumerator routine);
    //
    // 摘要:
    //   Starts a coroutine named methodName.
    //
    // 参数:
    //   methodName:
    //
    //   value:
    public Coroutine StartCoroutine(string methodName, [DefaultValue("null")] object value);
    [Obsolete("StartCoroutine_Auto has been deprecated. Use StartCoroutine instead (UnityUpgradable) -> StartCoroutine([mscorlib] System.Collections.IEnumerator)", false)]
    public Coroutine StartCoroutine_Auto(IEnumerator routine);
    //
    // 摘要:
    //   Stops all coroutines running on this behaviour.
    public void StopAllCoroutines();
    //
    // 摘要:
    //   Stops the first coroutine named methodName, or the coroutine stored in routine
    //   running on this behaviour.
    //
    // 参数:
    //   methodName:
    //   Name of coroutine.
    //
    //   routine:
    //   Name of the function in code, including coroutines.
    public void StopCoroutine(IEnumerator routine);
    //
    // 摘要:
    //   Stops the first coroutine named methodName, or the coroutine stored in routine
    //   running on this behaviour.
    //
    // 参数:
    //   methodName:
    //   Name of coroutine.
    //
    //   routine:
    //   Name of the function in code, including coroutines.
    public void StopCoroutine(Coroutine routine);
    //
    // 摘要:
    //   Stops the first coroutine named methodName, or the coroutine stored in routine
    //   running on this behaviour.
    //
    // 参数:
    //   methodName:
    //   Name of coroutine.
    //
    //   routine:
    //   Name of the function in code, including coroutines.
    public void StopCoroutine(string methodName);
  }
}
可以看到,脚本的生命周期函数,如常用的Awake、OnEnable、Start、FixedUpdate、OnTriggerXXX、OnCollisionXXX、Update、LateUpdate、OnGUI、OnDisable、OnDestroy等并不在里面,因为这些函数不是从父类继承然后重写的(也没有override关键字),是Unity通过反射自动获取我们在脚本中定义了哪些生命周期函数,然后按照Unity定义好的执行顺序自动执行这些函数。游戏可以理解为就是一个死循环,在循环中进行了游戏逻辑运算、画面绘制等,每循环一次就是一帧,而Unity就是帮助我们定义好了这个死循环框架,并提供好了生命周期函数,我们只需要将需要执行的逻辑和绘制的画面等在相应的生命周期函数中定义好即可。打个比方,Unity的游戏场景就是一个舞台,而游戏物体就是舞台上的演员,游戏物体的具体形状、物理特性等都是通过脚本定义的,这些脚本就相当于是演员的剧本,而脚本的生命周期函数就是剧本的书写模式,如准备上台时需要做的动作就在Awake等函数中定义,台上不断执行的动作在Update等函数中定义。
常用的生命周期函数:Awake:脚本创建时执行;OnEnable:脚本激活时执行;Start:游戏的第一帧更新之前执行;FixedUpdate:定时更新,游戏中循环执行,每秒执行的次数固定,可以在Unity中设置这个函数每秒执行的次数,一般用于物理逻辑更新;Update:游戏逻辑更新,循环执行,每秒执行的次数不能自定义,和函数的计算量和计算机性能有关;LateUpdate:后更新,循环执行,一般用于处理摄像机的相关行为;OnGUI:游戏的渲染,循环执行;OnDisable:脚本失活时执行;OnDestroy:脚本被销毁前执行。此外还有OntriggerXXX、OnMouseXXX、OnCollisionXXX等常用函数。一般地,首先执行的时Awake、OnEnable、Start等脚本创建时执行的函数,Awake只执行一次,OnEnable、Start一般也只执行一次,但是如果脚本多次失活激活,也可能执行多次;这部分函数执行完成后进入循环更新的函数,如FixedUpdate、Update、LateUpdate等,这其中物理逻辑先执行,如FixedUpdate,而OnTriggerXXX、OnCollisionXXX等物理碰撞有关的函数在特定情况下执行(有碰撞时),接下来是输入获取,然后是游戏的逻辑更新,其中在进行物理更新和游戏的逻辑更新时都会进行动画更新,最后在游戏逻辑更新后进行各种画面的渲染如OnGUI函数(GUI渲染),之后重复更新物理情况,进入下一个循环;在脚本需要被销毁时,就会跳出循环,执行相应的函数如OnDisable、OnDistroy等函数。下图是官方文档中的脚本生命周期函数的执行顺序:
DSC0000.png

在Unity中,并不是所有的效果都需要我们自己写脚本实现,Unity已经为我们提供了一些写好的脚本,这些脚本称之为组件,下图是Unity中常用类的类图:
DSC0001.png

下图是简化版的类继承关系:
DSC0002.png

从类关系中可以看到,Unity提供的组件都不是继承自MonoBehaviour的,但是我们自定义的挂载在游戏物体上的脚本一定是继承自这个类或者他的子类的。
PS:Unity中,继承自MonoBehaviour的类是不能new的,这是Unity根据自身调用这些脚本的方式定义好的规则,所以也不需要构造函数,如果要在Unity中使用脚本,就必须要首先通过一些方式获取脚本后文会进行介绍。
二.GameObject类、Object类和Component类中的常用方法
首先要说一说Component类,下面是Component类:
namespace UnityEngine
{
  //
  // 摘要:
  //   Base class for everything attached to GameObjects.
  [NativeClass("Unity::Component")]
  [NativeHeader("Runtime/Export/Scripting/Component.bindings.h")]
  [RequiredByNativeCode]
  public class Component : Object
  {
    public Component();
    //
    // 摘要:
    //   The ParticleSystem attached to this GameObject. (Null if there is none attached).
    [EditorBrowsable(EditorBrowsableState.Never)]
    [Obsolete("Property particleSystem has been deprecated. Use GetComponent<ParticleSystem>() instead. (UnityUpgradable)", true)]
    public Component particleSystem { get; }
    //
    // 摘要:
    //   The Transform attached to this GameObject.
    public Transform transform { get; }
    //
    // 摘要:
    //   The game object this component is attached to. A component is always attached
    //   to a game object.
    public GameObject gameObject { get; }
    //
    // 摘要:
    //   The tag of this game object.
    public string tag { get; set; }
    //
    // 摘要:
    //   The Rigidbody attached to this GameObject. (Null if there is none attached).
    [EditorBrowsable(EditorBrowsableState.Never)]
    [Obsolete("Property rigidbody has been deprecated. Use GetComponent<Rigidbody>() instead. (UnityUpgradable)", true)]
    public Component rigidbody { get; }
    //
    // 摘要:
    //   The HingeJoint attached to this GameObject. (Null if there is none attached).
    [EditorBrowsable(EditorBrowsableState.Never)]
    [Obsolete("Property hingeJoint has been deprecated. Use GetComponent<HingeJoint>() instead. (UnityUpgradable)", true)]
    public Component hingeJoint { get; }
    //
    // 摘要:
    //   The Camera attached to this GameObject. (Null if there is none attached).
    [EditorBrowsable(EditorBrowsableState.Never)]
    [Obsolete("Property camera has been deprecated. Use GetComponent<Camera>() instead. (UnityUpgradable)", true)]
    public Component camera { get; }
    //
    // 摘要:
    //   The Rigidbody2D that is attached to the Component's GameObject.
    [EditorBrowsable(EditorBrowsableState.Never)]
    [Obsolete("Property rigidbody2D has been deprecated. Use GetComponent<Rigidbody2D>() instead. (UnityUpgradable)", true)]
    public Component rigidbody2D { get; }
    //
    // 摘要:
    //   The Animation attached to this GameObject. (Null if there is none attached).
    [EditorBrowsable(EditorBrowsableState.Never)]
    [Obsolete("Property animation has been deprecated. Use GetComponent<Animation>() instead. (UnityUpgradable)", true)]
    public Component animation { get; }
    //
    // 摘要:
    //   The ConstantForce attached to this GameObject. (Null if there is none attached).
    [EditorBrowsable(EditorBrowsableState.Never)]
    [Obsolete("Property constantForce has been deprecated. Use GetComponent<ConstantForce>() instead. (UnityUpgradable)", true)]
    public Component constantForce { get; }
    //
    // 摘要:
    //   The Renderer attached to this GameObject. (Null if there is none attached).
    [EditorBrowsable(EditorBrowsableState.Never)]
    [Obsolete("Property renderer has been deprecated. Use GetComponent<Renderer>() instead. (UnityUpgradable)", true)]
    public Component renderer { get; }
    //
    // 摘要:
    //   The AudioSource attached to this GameObject. (Null if there is none attached).
    [EditorBrowsable(EditorBrowsableState.Never)]
    [Obsolete("Property audio has been deprecated. Use GetComponent<AudioSource>() instead. (UnityUpgradable)", true)]
    public Component audio { get; }
    //
    // 摘要:
    //   The NetworkView attached to this GameObject (Read Only). (null if there is none
    //   attached).
    [EditorBrowsable(EditorBrowsableState.Never)]
    [Obsolete("Property networkView has been deprecated. Use GetComponent<NetworkView>() instead. (UnityUpgradable)", true)]
    public Component networkView { get; }
    //
    // 摘要:
    //   The Collider attached to this GameObject. (Null if there is none attached).
    [EditorBrowsable(EditorBrowsableState.Never)]
    [Obsolete("Property collider has been deprecated. Use GetComponent<Collider>() instead. (UnityUpgradable)", true)]
    public Component collider { get; }
    //
    // 摘要:
    //   The Collider2D component attached to the object.
    [EditorBrowsable(EditorBrowsableState.Never)]
    [Obsolete("Property collider2D has been deprecated. Use GetComponent<Collider2D>() instead. (UnityUpgradable)", true)]
    public Component collider2D { get; }
    //
    // 摘要:
    //   The Light attached to this GameObject. (Null if there is none attached).
    [EditorBrowsable(EditorBrowsableState.Never)]
    [Obsolete("Property light has been deprecated. Use GetComponent<Light>() instead. (UnityUpgradable)", true)]
    public Component light { get; }
    //
    // 摘要:
    //   Calls the method named methodName on every MonoBehaviour in this game object
    //   or any of its children.
    //
    // 参数:
    //   methodName:
    //   Name of the method to call.
    //
    //   parameter:
    //   Optional parameter to pass to the method (can be any value).
    //
    //   options:
    //   Should an error be raised if the method does not exist for a given target object?
    public void BroadcastMessage(string methodName, SendMessageOptions options);
    //
    // 摘要:
    //   Calls the method named methodName on every MonoBehaviour in this game object
    //   or any of its children.
    //
    // 参数:
    //   methodName:
    //   Name of the method to call.
    //
    //   parameter:
    //   Optional parameter to pass to the method (can be any value).
    //
    //   options:
    //   Should an error be raised if the method does not exist for a given target object?
    [ExcludeFromDocs]
    public void BroadcastMessage(string methodName);
    //
    // 摘要:
    //   Calls the method named methodName on every MonoBehaviour in this game object
    //   or any of its children.
    //
    // 参数:
    //   methodName:
    //   Name of the method to call.
    //
    //   parameter:
    //   Optional parameter to pass to the method (can be any value).
    //
    //   options:
    //   Should an error be raised if the method does not exist for a given target object?
    [ExcludeFromDocs]
    public void BroadcastMessage(string methodName, object parameter);
    //
    // 摘要:
    //   Calls the method named methodName on every MonoBehaviour in this game object
    //   or any of its children.
    //
    // 参数:
    //   methodName:
    //   Name of the method to call.
    //
    //   parameter:
    //   Optional parameter to pass to the method (can be any value).
    //
    //   options:
    //   Should an error be raised if the method does not exist for a given target object?
    [FreeFunction("BroadcastMessage", HasExplicitThis = true)]
    public void BroadcastMessage(string methodName, [Internal.DefaultValue("null")] object parameter, [Internal.DefaultValue("SendMessageOptions.RequireReceiver")] SendMessageOptions options);
    //
    // 摘要:
    //   Is this game object tagged with tag ?
    //
    // 参数:
    //   tag:
    //   The tag to compare.
    public bool CompareTag(string tag);
    //
    // 摘要:
    //   Returns the component of Type type if the game object has one attached, null
    //   if it doesn't.
    //
    // 参数:
    //   type:
    //   The type of Component to retrieve.
    [TypeInferenceRule(TypeInferenceRules.TypeReferencedByFirstArgument)]
    public Component GetComponent(Type type);
    [SecuritySafeCritical]
    public T GetComponent<T>();
    //
    // 摘要:
    //   Returns the component with name type if the game object has one attached, null
    //   if it doesn't.
    //
    // 参数:
    //   type:
    [FreeFunction(HasExplicitThis = true)]
    public Component GetComponent(string type);
    [TypeInferenceRule(TypeInferenceRules.TypeReferencedByFirstArgument)]
    public Component GetComponentInChildren(Type t, bool includeInactive);
    //
    // 摘要:
    //   Returns the component of Type type in the GameObject or any of its children using
    //   depth first search.
    //
    // 参数:
    //   t:
    //   The type of Component to retrieve.
    //
    // 返回结果:
    //   A component of the matching type, if found.
    [TypeInferenceRule(TypeInferenceRules.TypeReferencedByFirstArgument)]
    public Component GetComponentInChildren(Type t);
    public T GetComponentInChildren<T>([Internal.DefaultValue("false")] bool includeInactive);
    [ExcludeFromDocs]
    public T GetComponentInChildren<T>();
    //
    // 摘要:
    //   Returns the component of Type type in the GameObject or any of its parents.
    //
    // 参数:
    //   t:
    //   The type of Component to retrieve.
    //
    // 返回结果:
    //   A component of the matching type, if found.
    [TypeInferenceRule(TypeInferenceRules.TypeReferencedByFirstArgument)]
    public Component GetComponentInParent(Type t);
    public T GetComponentInParent<T>();
    //
    // 摘要:
    //   Returns all components of Type type in the GameObject.
    //
    // 参数:
    //   type:
    //   The type of Component to retrieve.
    public Component[] GetComponents(Type type);
    public void GetComponents(Type type, List<Component> results);
    public void GetComponents<T>(List<T> results);
    public T[] GetComponents<T>();
    [ExcludeFromDocs]
    public Component[] GetComponentsInChildren(Type t);
    public void GetComponentsInChildren<T>(List<T> results);
    public T[] GetComponentsInChildren<T>();
    public void GetComponentsInChildren<T>(bool includeInactive, List<T> result);
    public T[] GetComponentsInChildren<T>(bool includeInactive);
    //
    // 摘要:
    //   Returns all components of Type type in the GameObject or any of its children.
    //
    // 参数:
    //   t:
    //   The type of Component to retrieve.
    //
    //   includeInactive:
    //   Should Components on inactive GameObjects be included in the found set? includeInactive
    //   decides which children of the GameObject will be searched. The GameObject that
    //   you call GetComponentsInChildren on is always searched regardless.
    public Component[] GetComponentsInChildren(Type t, bool includeInactive);
    public T[] GetComponentsInParent<T>(bool includeInactive);
    [ExcludeFromDocs]
    public Component[] GetComponentsInParent(Type t);
    //
    // 摘要:
    //   Returns all components of Type type in the GameObject or any of its parents.
    //
    // 参数:
    //   t:
    //   The type of Component to retrieve.
    //
    //   includeInactive:
    //   Should inactive Components be included in the found set?
    public Component[] GetComponentsInParent(Type t, [Internal.DefaultValue("false")] bool includeInactive);
    public T[] GetComponentsInParent<T>();
    public void GetComponentsInParent<T>(bool includeInactive, List<T> results);
    //
    // 摘要:
    //   Calls the method named methodName on every MonoBehaviour in this game object.
    //
    // 参数:
    //   methodName:
    //   Name of the method to call.
    //
    //   value:
    //   Optional parameter for the method.
    //
    //   options:
    //   Should an error be raised if the target object doesn't implement the method for
    //   the message?
    [FreeFunction("SendMessage", HasExplicitThis = true)]
    public void SendMessage(string methodName, object value, SendMessageOptions options);
    //
    // 摘要:
    //   Calls the method named methodName on every MonoBehaviour in this game object.
    //
    // 参数:
    //   methodName:
    //   Name of the method to call.
    //
    //   value:
    //   Optional parameter for the method.
    //
    //   options:
    //   Should an error be raised if the target object doesn't implement the method for
    //   the message?
    public void SendMessage(string methodName);
    //
    // 摘要:
    //   Calls the method named methodName on every MonoBehaviour in this game object.
    //
    // 参数:
    //   methodName:
    //   Name of the method to call.
    //
    //   value:
    //   Optional parameter for the method.
    //
    //   options:
    //   Should an error be raised if the target object doesn't implement the method for
    //   the message?
    public void SendMessage(string methodName, object value);
    //
    // 摘要:
    //   Calls the method named methodName on every MonoBehaviour in this game object.
    //
    // 参数:
    //   methodName:
    //   Name of the method to call.
    //
    //   value:
    //   Optional parameter for the method.
    //
    //   options:
    //   Should an error be raised if the target object doesn't implement the method for
    //   the message?
    public void SendMessage(string methodName, SendMessageOptions options);
    //
    // 摘要:
    //   Calls the method named methodName on every MonoBehaviour in this game object
    //   and on every ancestor of the behaviour.
    //
    // 参数:
    //   methodName:
    //   Name of method to call.
    //
    //   value:
    //   Optional parameter value for the method.
    //
    //   options:
    //   Should an error be raised if the method does not exist on the target object?
    [ExcludeFromDocs]
    public void SendMessageUpwards(string methodName, object value);
    //
    // 摘要:
    //   Calls the method named methodName on every MonoBehaviour in this game object
    //   and on every ancestor of the behaviour.
    //
    // 参数:
    //   methodName:
    //   Name of method to call.
    //
    //   value:
    //   Optional parameter value for the method.
    //
    //   options:
    //   Should an error be raised if the method does not exist on the target object?
    public void SendMessageUpwards(string methodName, SendMessageOptions options);
    //
    // 摘要:
    //   Calls the method named methodName on every MonoBehaviour in this game object
    //   and on every ancestor of the behaviour.
    //
    // 参数:
    //   methodName:
    //   Name of method to call.
    //
    //   value:
    //   Optional parameter value for the method.
    //
    //   options:
    //   Should an error be raised if the method does not exist on the target object?
    [ExcludeFromDocs]
    public void SendMessageUpwards(string methodName);
    //
    // 摘要:
    //   Calls the method named methodName on every MonoBehaviour in this game object
    //   and on every ancestor of the behaviour.
    //
    // 参数:
    //   methodName:
    //   Name of method to call.
    //
    //   value:
    //   Optional parameter value for the method.
    //
    //   options:
    //   Should an error be raised if the method does not exist on the target object?
    [FreeFunction(HasExplicitThis = true)]
    public void SendMessageUpwards(string methodName, [Internal.DefaultValue("null")] object value, [Internal.DefaultValue("SendMessageOptions.RequireReceiver")] SendMessageOptions options);
    [SecuritySafeCritical]
    public bool TryGetComponent<T>(out T component);
    [TypeInferenceRule(TypeInferenceRules.TypeReferencedByFirstArgument)]
    public bool TryGetComponent(Type type, out Component component);
  }
}
在这个类中,可以发现有很多属性,像gameObject、transform、rigidbody等,这些属性都对应着组件所在游戏物体身上的其他组件,但是可以看到除了transform、gameObject和tag这3个属性外,其他属性都标注了Obsolute特性,表示弃用的,调用时如下图:
DSC0003.png

这些已弃用的组件现在都需要使用GetComponent函数去获取。没有弃用的3个属性使用还是非常普遍的,其中transform是Transform组件对象,是当前物体的位置信息(位置坐标、旋转、缩放等信息)对象,tag是当前物体的标签对象,gameObject对象是当前的游戏物体类GameObject的对象,GameObject类继承自Object类,是Component的“兄弟类”(见上面的简版类图),这个类是游戏物体的模板类。下面是GameObject类:
namespace UnityEngine
{
  //
  // 摘要:
  //   Base class for all entities in Unity Scenes.
  [ExcludeFromPreset]
  [NativeHeader("Runtime/Export/Scripting/GameObject.bindings.h")]
  [UsedByNativeCode]
  public sealed class GameObject : Object
  {
    //
    // 摘要:
    //   Creates a new game object, named name.
    //
    // 参数:
    //   name:
    //   The name that the GameObject is created with.
    //
    //   components:
    //   A list of Components to add to the GameObject on creation.
    public GameObject();
    //
    // 摘要:
    //   Creates a new game object, named name.
    //
    // 参数:
    //   name:
    //   The name that the GameObject is created with.
    //
    //   components:
    //   A list of Components to add to the GameObject on creation.
    public GameObject(string name);
    //
    // 摘要:
    //   Creates a new game object, named name.
    //
    // 参数:
    //   name:
    //   The name that the GameObject is created with.
    //
    //   components:
    //   A list of Components to add to the GameObject on creation.
    public GameObject(string name, params Type[] components);
    //
    // 摘要:
    //   The ParticleSystem attached to this GameObject (Read Only). (Null if there is
    //   none attached).
    [EditorBrowsable(EditorBrowsableState.Never)]
    [Obsolete("Property particleSystem has been deprecated. Use GetComponent<ParticleSystem>() instead. (UnityUpgradable)", true)]
    public Component particleSystem { get; }
    //
    // 摘要:
    //   The Transform attached to this GameObject.
    public Transform transform { get; }
    //
    // 摘要:
    //   The layer the game object is in.
    public int layer { get; set; }
    [Obsolete("GameObject.active is obsolete. Use GameObject.SetActive(), GameObject.activeSelf or GameObject.activeInHierarchy.")]
    public bool active { get; set; }
    //
    // 摘要:
    //   The local active state of this GameObject. (Read Only)
    public bool activeSelf { get; }
    //
    // 摘要:
    //   Defines whether the GameObject is active in the Scene.
    public bool activeInHierarchy { get; }
    //
    // 摘要:
    //   Gets and sets the GameObject's StaticEditorFlags.
    public bool isStatic { get; set; }
    //
    // 摘要:
    //   The tag of this game object.
    public string tag { get; set; }
    //
    // 摘要:
    //   Scene that the GameObject is part of.
    public Scene scene { get; }
    //
    // 摘要:
    //   Scene culling mask Unity uses to determine which scene to render the GameObject
    //   in.
    public ulong sceneCullingMask { get; }
    public GameObject gameObject { get; }
    //
    // 摘要:
    //   The Rigidbody2D component attached to this GameObject. (Read Only)
    [EditorBrowsable(EditorBrowsableState.Never)]
    [Obsolete("Property rigidbody2D has been deprecated. Use GetComponent<Rigidbody2D>() instead. (UnityUpgradable)", true)]
    public Component rigidbody2D { get; }
    //
    // 摘要:
    //   The Camera attached to this GameObject (Read Only). (Null if there is none attached).
    [EditorBrowsable(EditorBrowsableState.Never)]
    [Obsolete("Property camera has been deprecated. Use GetComponent<Camera>() instead. (UnityUpgradable)", true)]
    public Component camera { get; }
    //
    // 摘要:
    //   The Light attached to this GameObject (Read Only). (Null if there is none attached).
    [EditorBrowsable(EditorBrowsableState.Never)]
    [Obsolete("Property light has been deprecated. Use GetComponent<Light>() instead. (UnityUpgradable)", true)]
    public Component light { get; }
    //
    // 摘要:
    //   The Animation attached to this GameObject (Read Only). (Null if there is none
    //   attached).
    [EditorBrowsable(EditorBrowsableState.Never)]
    [Obsolete("Property animation has been deprecated. Use GetComponent<Animation>() instead. (UnityUpgradable)", true)]
    public Component animation { get; }
    //
    // 摘要:
    //   The ConstantForce attached to this GameObject (Read Only). (Null if there is
    //   none attached).
    [EditorBrowsable(EditorBrowsableState.Never)]
    [Obsolete("Property constantForce has been deprecated. Use GetComponent<ConstantForce>() instead. (UnityUpgradable)", true)]
    public Component constantForce { get; }
    //
    // 摘要:
    //   The Renderer attached to this GameObject (Read Only). (Null if there is none
    //   attached).
    [EditorBrowsable(EditorBrowsableState.Never)]
    [Obsolete("Property renderer has been deprecated. Use GetComponent<Renderer>() instead. (UnityUpgradable)", true)]
    public Component renderer { get; }
    //
    // 摘要:
    //   The AudioSource attached to this GameObject (Read Only). (Null if there is none
    //   attached).
    [EditorBrowsable(EditorBrowsableState.Never)]
    [Obsolete("Property audio has been deprecated. Use GetComponent<AudioSource>() instead. (UnityUpgradable)", true)]
    public Component audio { get; }
    //
    // 摘要:
    //   The NetworkView attached to this GameObject (Read Only). (Null if there is none
    //   attached).
    [EditorBrowsable(EditorBrowsableState.Never)]
    [Obsolete("Property networkView has been deprecated. Use GetComponent<NetworkView>() instead. (UnityUpgradable)", true)]
    public Component networkView { get; }
    //
    // 摘要:
    //   The Collider attached to this GameObject (Read Only). (Null if there is none
    //   attached).
    [EditorBrowsable(EditorBrowsableState.Never)]
    [Obsolete("Property collider has been deprecated. Use GetComponent<Collider>() instead. (UnityUpgradable)", true)]
    public Component collider { get; }
    //
    // 摘要:
    //   The Collider2D component attached to this object.
    [EditorBrowsable(EditorBrowsableState.Never)]
    [Obsolete("Property collider2D has been deprecated. Use GetComponent<Collider2D>() instead. (UnityUpgradable)", true)]
    public Component collider2D { get; }
    //
    // 摘要:
    //   The Rigidbody attached to this GameObject (Read Only). (Null if there is none
    //   attached).
    [EditorBrowsable(EditorBrowsableState.Never)]
    [Obsolete("Property rigidbody has been deprecated. Use GetComponent<Rigidbody>() instead. (UnityUpgradable)", true)]
    public Component rigidbody { get; }
    //
    // 摘要:
    //   The HingeJoint attached to this GameObject (Read Only). (Null if there is none
    //   attached).
    [EditorBrowsable(EditorBrowsableState.Never)]
    [Obsolete("Property hingeJoint has been deprecated. Use GetComponent<HingeJoint>() instead. (UnityUpgradable)", true)]
    public Component hingeJoint { get; }
    //
    // 摘要:
    //   Creates a game object with a primitive mesh renderer and appropriate collider.
    //
    // 参数:
    //   type:
    //   The type of primitive object to create.
    [FreeFunction("GameObjectBindings::CreatePrimitive")]
    public static GameObject CreatePrimitive(PrimitiveType type);
    //
    // 摘要:
    //   Finds a GameObject by name and returns it.
    //
    // 参数:
    //   name:
    [FreeFunction(Name = "GameObjectBindings::Find")]
    public static GameObject Find(string name);
    //
    // 摘要:
    //   Returns an array of active GameObjects tagged tag. Returns empty array if no
    //   GameObject was found.
    //
    // 参数:
    //   tag:
    //   The name of the tag to search GameObjects for.
    [FreeFunction(Name = "GameObjectBindings::FindGameObjectsWithTag", ThrowsException = true)]
    public static GameObject[] FindGameObjectsWithTag(string tag);
    [FreeFunction(Name = "GameObjectBindings::FindGameObjectWithTag", ThrowsException = true)]
    public static GameObject FindGameObjectWithTag(string tag);
    //
    // 摘要:
    //   Returns one active GameObject tagged tag. Returns null if no GameObject was found.
    //
    // 参数:
    //   tag:
    //   The tag to search for.
    public static GameObject FindWithTag(string tag);
    public T AddComponent<T>() where T : Component;
    //
    // 摘要:
    //   Adds a component class named className to the game object.
    //
    // 参数:
    //   className:
    [EditorBrowsable(EditorBrowsableState.Never)]
    [Obsolete("GameObject.AddComponent with string argument has been deprecated. Use GameObject.AddComponent<T>() instead. (UnityUpgradable).", true)]
    public Component AddComponent(string className);
    //
    // 摘要:
    //   Adds a component class of type componentType to the game object. C# Users can
    //   use a generic version.
    //
    // 参数:
    //   componentType:
    [TypeInferenceRule(TypeInferenceRules.TypeReferencedByFirstArgument)]
    public Component AddComponent(Type componentType);
    //
    // 参数:
    //   methodName:
    //
    //   options:
    public void BroadcastMessage(string methodName, SendMessageOptions options);
    //
    // 摘要:
    //   Calls the method named methodName on every MonoBehaviour in this game object
    //   or any of its children.
    //
    // 参数:
    //   methodName:
    //
    //   parameter:
    //
    //   options:
    [FreeFunction(Name = "Scripting::BroadcastScriptingMessage", HasExplicitThis = true)]
    public void BroadcastMessage(string methodName, [Internal.DefaultValue("null")] object parameter, [Internal.DefaultValue("SendMessageOptions.RequireReceiver")] SendMessageOptions options);
    //
    // 摘要:
    //   Calls the method named methodName on every MonoBehaviour in this game object
    //   or any of its children.
    //
    // 参数:
    //   methodName:
    //
    //   parameter:
    //
    //   options:
    [ExcludeFromDocs]
    public void BroadcastMessage(string methodName, object parameter);
    //
    // 摘要:
    //   Calls the method named methodName on every MonoBehaviour in this game object
    //   or any of its children.
    //
    // 参数:
    //   methodName:
    //
    //   parameter:
    //
    //   options:
    [ExcludeFromDocs]
    public void BroadcastMessage(string methodName);
    //
    // 摘要:
    //   Is this game object tagged with tag ?
    //
    // 参数:
    //   tag:
    //   The tag to compare.
    [FreeFunction(Name = "GameObjectBindings::CompareTag", HasExplicitThis = true)]
    public bool CompareTag(string tag);
    [SecuritySafeCritical]
    public T GetComponent<T>();
    //
    // 摘要:
    //   Returns the component of Type type if the game object has one attached, null
    //   if it doesn't.
    //
    // 参数:
    //   type:
    //   The type of Component to retrieve.
    [FreeFunction(Name = "GameObjectBindings::GetComponentFromType", HasExplicitThis = true, ThrowsException = true)]
    [TypeInferenceRule(TypeInferenceRules.TypeReferencedByFirstArgument)]
    public Component GetComponent(Type type);
    //
    // 摘要:
    //   Returns the component with name type if the game object has one attached, null
    //   if it doesn't.
    //
    // 参数:
    //   type:
    //   The type of Component to retrieve.
    public Component GetComponent(string type);
    //
    // 摘要:
    //   Returns the component of Type type in the GameObject or any of its children using
    //   depth first search.
    //
    // 参数:
    //   type:
    //   The type of Component to retrieve.
    //
    //   includeInactive:
    //
    // 返回结果:
    //   A component of the matching type, if found.
    [TypeInferenceRule(TypeInferenceRules.TypeReferencedByFirstArgument)]
    public Component GetComponentInChildren(Type type);
    //
    // 摘要:
    //   Returns the component of Type type in the GameObject or any of its children using
    //   depth first search.
    //
    // 参数:
    //   type:
    //   The type of Component to retrieve.
    //
    //   includeInactive:
    //
    // 返回结果:
    //   A component of the matching type, if found.
    [FreeFunction(Name = "GameObjectBindings::GetComponentInChildren", HasExplicitThis = true, ThrowsException = true)]
    [TypeInferenceRule(TypeInferenceRules.TypeReferencedByFirstArgument)]
    public Component GetComponentInChildren(Type type, bool includeInactive);
    public T GetComponentInChildren<T>([Internal.DefaultValue("false")] bool includeInactive);
    [ExcludeFromDocs]
    public T GetComponentInChildren<T>();
    public T GetComponentInParent<T>();
    //
    // 摘要:
    //   Returns the component of Type type in the GameObject or any of its parents.
    //
    // 参数:
    //   type:
    //   Type of component to find.
    [FreeFunction(Name = "GameObjectBindings::GetComponentInParent", HasExplicitThis = true, ThrowsException = true)]
    [TypeInferenceRule(TypeInferenceRules.TypeReferencedByFirstArgument)]
    public Component GetComponentInParent(Type type);
    //
    // 摘要:
    //   Returns all components of Type type in the GameObject.
    //
    // 参数:
    //   type:
    //   The type of component to retrieve.
    public Component[] GetComponents(Type type);
    public T[] GetComponents<T>();
    public void GetComponents(Type type, List<Component> results);
    public void GetComponents<T>(List<T> results);
    public T[] GetComponentsInChildren<T>();
    //
    // 摘要:
    //   Returns all components of Type type in the GameObject or any of its children.
    //
    // 参数:
    //   type:
    //   The type of Component to retrieve.
    //
    //   includeInactive:
    //   Should Components on inactive GameObjects be included in the found set?
    [ExcludeFromDocs]
    public Component[] GetComponentsInChildren(Type type);
    //
    // 摘要:
    //   Returns all components of Type type in the GameObject or any of its children.
    //
    // 参数:
    //   type:
    //   The type of Component to retrieve.
    //
    //   includeInactive:
    //   Should Components on inactive GameObjects be included in the found set?
    public Component[] GetComponentsInChildren(Type type, [Internal.DefaultValue("false")] bool includeInactive);
    public T[] GetComponentsInChildren<T>(bool includeInactive);
    public void GetComponentsInChildren<T>(bool includeInactive, List<T> results);
    public void GetComponentsInChildren<T>(List<T> results);
    public T[] GetComponentsInParent<T>(bool includeInactive);
    [ExcludeFromDocs]
    public Component[] GetComponentsInParent(Type type);
    public void GetComponentsInParent<T>(bool includeInactive, List<T> results);
    public T[] GetComponentsInParent<T>();
    //
    // 摘要:
    //   Returns all components of Type type in the GameObject or any of its parents.
    //
    // 参数:
    //   type:
    //   The type of Component to retrieve.
    //
    //   includeInactive:
    //   Should inactive Components be included in the found set?
    public Component[] GetComponentsInParent(Type type, [Internal.DefaultValue("false")] bool includeInactive);
    [EditorBrowsable(EditorBrowsableState.Never)]
    [Obsolete("gameObject.PlayAnimation is not supported anymore. Use animation.Play()", true)]
    public void PlayAnimation(Object animation);
    [EditorBrowsable(EditorBrowsableState.Never)]
    [Obsolete("GameObject.SampleAnimation(AnimationClip, float) has been deprecated. Use AnimationClip.SampleAnimation(GameObject, float) instead (UnityUpgradable).", true)]
    public void SampleAnimation(Object clip, float time);
    //
    // 参数:
    //   methodName:
    //
    //   options:
    public void SendMessage(string methodName, SendMessageOptions options);
    //
    // 摘要:
    //   Calls the method named methodName on every MonoBehaviour in this game object.
    //
    // 参数:
    //   methodName:
    //   The name of the method to call.
    //
    //   value:
    //   An optional parameter value to pass to the called method.
    //
    //   options:
    //   Should an error be raised if the method doesn't exist on the target object?
    [FreeFunction(Name = "Scripting::SendScriptingMessage", HasExplicitThis = true)]
    public void SendMessage(string methodName, [Internal.DefaultValue("null")] object value, [Internal.DefaultValue("SendMessageOptions.RequireReceiver")] SendMessageOptions options);
    //
    // 摘要:
    //   Calls the method named methodName on every MonoBehaviour in this game object.
    //
    // 参数:
    //   methodName:
    //   The name of the method to call.
    //
    //   value:
    //   An optional parameter value to pass to the called method.
    //
    //   options:
    //   Should an error be raised if the method doesn't exist on the target object?
    [ExcludeFromDocs]
    public void SendMessage(string methodName, object value);
    //
    // 摘要:
    //   Calls the method named methodName on every MonoBehaviour in this game object.
    //
    // 参数:
    //   methodName:
    //   The name of the method to call.
    //
    //   value:
    //   An optional parameter value to pass to the called method.
    //
    //   options:
    //   Should an error be raised if the method doesn't exist on the target object?
    [ExcludeFromDocs]
    public void SendMessage(string methodName);
    //
    // 摘要:
    //   Calls the method named methodName on every MonoBehaviour in this game object
    //   and on every ancestor of the behaviour.
    //
    // 参数:
    //   methodName:
    //   The name of the method to call.
    //
    //   value:
    //   An optional parameter value to pass to the called method.
    //
    //   options:
    //   Should an error be raised if the method doesn't exist on the target object?
    [FreeFunction(Name = "Scripting::SendScriptingMessageUpwards", HasExplicitThis = true)]
    public void SendMessageUpwards(string methodName, [Internal.DefaultValue("null")] object value, [Internal.DefaultValue("SendMessageOptions.RequireReceiver")] SendMessageOptions options);
    //
    // 参数:
    //   methodName:
    //
    //   options:
    public void SendMessageUpwards(string methodName, SendMessageOptions options);
    //
    // 摘要:
    //   Calls the method named methodName on every MonoBehaviour in this game object
    //   and on every ancestor of the behaviour.
    //
    // 参数:
    //   methodName:
    //   The name of the method to call.
    //
    //   value:
    //   An optional parameter value to pass to the called method.
    //
    //   options:
    //   Should an error be raised if the method doesn't exist on the target object?
    [ExcludeFromDocs]
    public void SendMessageUpwards(string methodName);
    //
    // 摘要:
    //   Calls the method named methodName on every MonoBehaviour in this game object
    //   and on every ancestor of the behaviour.
    //
    // 参数:
    //   methodName:
    //   The name of the method to call.
    //
    //   value:
    //   An optional parameter value to pass to the called method.
    //
    //   options:
    //   Should an error be raised if the method doesn't exist on the target object?
    [ExcludeFromDocs]
    public void SendMessageUpwards(string methodName, object value);
    //
    // 摘要:
    //   ActivatesDeactivates the GameObject, depending on the given true or false/ value.
    //
    // 参数:
    //   value:
    //   Activate or deactivate the object, where true activates the GameObject and false
    //   deactivates the GameObject.
    [NativeMethod(Name = "SetSelfActive")]
    public void SetActive(bool value);
    [NativeMethod(Name = "SetActiveRecursivelyDeprecated")]
    [Obsolete("gameObject.SetActiveRecursively() is obsolete. Use GameObject.SetActive(), which is now inherited by children.")]
    public void SetActiveRecursively(bool state);
    [EditorBrowsable(EditorBrowsableState.Never)]
    [Obsolete("gameObject.StopAnimation is not supported anymore. Use animation.Stop()", true)]
    public void StopAnimation();
    public bool TryGetComponent(Type type, out Component component);
    [SecuritySafeCritical]
    public bool TryGetComponent<T>(out T component);
  }
}
下面是Object类:
namespace UnityEngine
{
  //
  // 摘要:
  //   Base class for all objects Unity can reference.
  [NativeHeader("Runtime/GameCode/CloneObject.h")]
  [NativeHeader("Runtime/Export/Scripting/UnityEngineObject.bindings.h")]
  [NativeHeader("Runtime/SceneManager/SceneManager.h")]
  [RequiredByNativeCode(GenerateProxy = true)]
  public class Object
  {
    public Object();
    //
    // 摘要:
    //   Should the object be hidden, saved with the Scene or modifiable by the user?
    public HideFlags hideFlags { get; set; }
    //
    // 摘要:
    //   The name of the object.
    public string name { get; set; }
    //
    // 摘要:
    //   Removes a GameObject, component or asset.
    //
    // 参数:
    //   obj:
    //   The object to destroy.
    //
    //   t:
    //   The optional amount of time to delay before destroying the object.
    [ExcludeFromDocs]
    public static void Destroy(Object obj);
    //
    // 摘要:
    //   Removes a GameObject, component or asset.
    //
    // 参数:
    //   obj:
    //   The object to destroy.
    //
    //   t:
    //   The optional amount of time to delay before destroying the object.
    [NativeMethod(Name = "Scripting::DestroyObjectFromScripting", IsFreeFunction = true, ThrowsException = true)]
    public static void Destroy(Object obj, [DefaultValue("0.0F")] float t);
    //
    // 摘要:
    //   Destroys the object obj immediately. You are strongly recommended to use Destroy
    //   instead.
    //
    // 参数:
    //   obj:
    //   Object to be destroyed.
    //
    //   allowDestroyingAssets:
    //   Set to true to allow assets to be destroyed.
    [ExcludeFromDocs]
    public static void DestroyImmediate(Object obj);
    //
    // 摘要:
    //   Destroys the object obj immediately. You are strongly recommended to use Destroy
    //   instead.
    //
    // 参数:
    //   obj:
    //   Object to be destroyed.
    //
    //   allowDestroyingAssets:
    //   Set to true to allow assets to be destroyed.
    [NativeMethod(Name = "Scripting::DestroyObjectFromScriptingImmediate", IsFreeFunction = true, ThrowsException = true)]
    public static void DestroyImmediate(Object obj, [DefaultValue("false")] bool allowDestroyingAssets);
    [Obsolete("use Object.Destroy instead.")]
    public static void DestroyObject(Object obj, [DefaultValue("0.0F")] float t);
    [ExcludeFromDocs]
    [Obsolete("use Object.Destroy instead.")]
    public static void DestroyObject(Object obj);
    //
    // 摘要:
    //   Do not destroy the target Object when loading a new Scene.
    //
    // 参数:
    //   target:
    //   An Object not destroyed on Scene change.
    [FreeFunction("GetSceneManager().DontDestroyOnLoad")]
    public static void DontDestroyOnLoad(Object target);
    //
    // 摘要:
    //   Returns the first active loaded object of Type type.
    //
    // 参数:
    //   type:
    //   The type of object to find.
    //
    // 返回结果:
    //   This returns the Object that matches the specified type. It returns null if no
    //   Object matches the type.
    [TypeInferenceRule(TypeInferenceRules.TypeReferencedByFirstArgument)]
    public static Object FindObjectOfType(Type type);
    public static T FindObjectOfType<T>() where T : Object;
    public static T[] FindObjectsOfType<T>() where T : Object;
    //
    // 摘要:
    //   Returns a list of all active loaded objects of Type type.
    //
    // 参数:
    //   type:
    //   The type of object to find.
    //
    //   includeInactive:
    //   If true, components attached to inactive GameObjects are also included.
    //
    // 返回结果:
    //   The array of objects found matching the type specified.
    [FreeFunction("UnityEngineObjectBindings::FindObjectsOfType")]
    [TypeInferenceRule(TypeInferenceRules.ArrayOfTypeReferencedByFirstArgument)]
    public static Object[] FindObjectsOfType(Type type);
    //
    // 摘要:
    //   Returns a list of all active and inactive loaded objects of Type type.
    //
    // 参数:
    //   type:
    //   The type of object to find.
    //
    // 返回结果:
    //   The array of objects found matching the type specified.
    [Obsolete("Please use Resources.FindObjectsOfTypeAll instead")]
    public static Object[] FindObjectsOfTypeAll(Type type);
    //
    // 摘要:
    //   Returns a list of all active and inactive loaded objects of Type type, including
    //   assets.
    //
    // 参数:
    //   type:
    //   The type of object or asset to find.
    //
    // 返回结果:
    //   The array of objects and assets found matching the type specified.
    [FreeFunction("UnityEngineObjectBindings::FindObjectsOfTypeIncludingAssets")]
    [Obsolete("use Resources.FindObjectsOfTypeAll instead.")]
    public static Object[] FindObjectsOfTypeIncludingAssets(Type type);
    [FreeFunction("UnityEngineObjectBindings::FindObjectsOfType")]
    [Obsolete("warning use Object.FindObjectsOfType instead.")]
    public static Object[] FindSceneObjectsOfType(Type type);
    //
    // 摘要:
    //   Clones the object original and returns the clone.
    //
    // 参数:
    //   original:
    //   An existing object that you want to make a copy of.
    //
    //   position:
    //   Position for the new object.
    //
    //   rotation:
    //   Orientation of the new object.
    //
    //   parent:
    //   Parent that will be assigned to the new object.
    //
    //   instantiateInWorldSpace:
    //   When you assign a parent Object, pass true to position the new object directly
    //   in world space. Pass false to set the Object’s position relative to its new parent..
    //
    // 返回结果:
    //   The instantiated clone.
    [TypeInferenceRule(TypeInferenceRules.TypeOfFirstArgument)]
    public static Object Instantiate(Object original);
    //
    // 摘要:
    //   Clones the object original and returns the clone.
    //
    // 参数:
    //   original:
    //   An existing object that you want to make a copy of.
    //
    //   position:
    //   Position for the new object.
    //
    //   rotation:
    //   Orientation of the new object.
    //
    //   parent:
    //   Parent that will be assigned to the new object.
    //
    //   instantiateInWorldSpace:
    //   When you assign a parent Object, pass true to position the new object directly
    //   in world space. Pass false to set the Object’s position relative to its new parent..
    //
    // 返回结果:
    //   The instantiated clone.
    [TypeInferenceRule(TypeInferenceRules.TypeOfFirstArgument)]
    public static Object Instantiate(Object original, Transform parent);
    //
    // 摘要:
    //   Clones the object original and returns the clone.
    //
    // 参数:
    //   original:
    //   An existing object that you want to make a copy of.
    //
    //   position:
    //   Position for the new object.
    //
    //   rotation:
    //   Orientation of the new object.
    //
    //   parent:
    //   Parent that will be assigned to the new object.
    //
    //   instantiateInWorldSpace:
    //   When you assign a parent Object, pass true to position the new object directly
    //   in world space. Pass false to set the Object’s position relative to its new parent..
    //
    // 返回结果:
    //   The instantiated clone.
    [TypeInferenceRule(TypeInferenceRules.TypeOfFirstArgument)]
    public static Object Instantiate(Object original, Vector3 position, Quaternion rotation);
    //
    // 摘要:
    //   Clones the object original and returns the clone.
    //
    // 参数:
    //   original:
    //   An existing object that you want to make a copy of.
    //
    //   position:
    //   Position for the new object.
    //
    //   rotation:
    //   Orientation of the new object.
    //
    //   parent:
    //   Parent that will be assigned to the new object.
    //
    //   instantiateInWorldSpace:
    //   When you assign a parent Object, pass true to position the new object directly
    //   in world space. Pass false to set the Object’s position relative to its new parent..
    //
    // 返回结果:
    //   The instantiated clone.
    [TypeInferenceRule(TypeInferenceRules.TypeOfFirstArgument)]
    public static Object Instantiate(Object original, Vector3 position, Quaternion rotation, Transform parent);
    public static T Instantiate<T>(T original, Transform parent, bool worldPositionStays) where T : Object;
    public static T Instantiate<T>(T original, Transform parent) where T : Object;
    public static T Instantiate<T>(T original, Vector3 position, Quaternion rotation, Transform parent) where T : Object;
    public static T Instantiate<T>(T original, Vector3 position, Quaternion rotation) where T : Object;
    public static T Instantiate<T>(T original) where T : Object;
    //
    // 摘要:
    //   Clones the object original and returns the clone.
    //
    // 参数:
    //   original:
    //   An existing object that you want to make a copy of.
    //
    //   position:
    //   Position for the new object.
    //
    //   rotation:
    //   Orientation of the new object.
    //
    //   parent:
    //   Parent that will be assigned to the new object.
    //
    //   instantiateInWorldSpace:
    //   When you assign a parent Object, pass true to position the new object directly
    //   in world space. Pass false to set the Object’s position relative to its new parent..
    //
    // 返回结果:
    //   The instantiated clone.
    [TypeInferenceRule(TypeInferenceRules.TypeOfFirstArgument)]
    public static Object Instantiate(Object original, Transform parent, bool instantiateInWorldSpace);
    public override bool Equals(object other);
    public override int GetHashCode();
    //
    // 摘要:
    //   Returns the instance id of the object.
    [SecuritySafeCritical]
    public int GetInstanceID();
    //
    // 摘要:
    //   Returns the name of the object.
    //
    // 返回结果:
    //   The name returned by ToString.
    public override string ToString();
    public static bool operator ==(Object x, Object y);
    public static bool operator !=(Object x, Object y);
    public static implicit operator bool(Object exists);
  }
}
1.GameObject中的成员变量
DSC0004.png

name:游戏物体名称;activeSelf:是否激活;isStatic:是否静态对象;layer:层级;tag:标签;transform:位置信息对象(和物体上组件中继承自Component类的transform对象是同一个对象)
void Start()
  {
    print(transform.GetHashCode());
    print(gameObject.transform.GetHashCode());
  }
DSC0005.png

2.静态方法
GameObject中的静态方法:
DSC0006.png

Object中的静态方法:
DSC0007.png

Object类中大多数方法都是静态方法,Component类中没有提供静态方法,但是根据继承关系,从Object类中继承了这些静态方法。下面是这些静态方法的分类说明:
1)使用CreatePrimitive方法根据系统自带的游戏物体模板创建游戏物体,这个方法由GameObject类提供。
DSC0008.png
void Start()
  {
    //静态方法创建系统自带的几何体,传入的参数是枚举类型
    GameObject go = GameObject.CreatePrimitive(PrimitiveType.Cube);
    //可以修改物体的名称等变量
    go.name = "MyCube";
    go.tag = "MyCube";
  }
2)查找游戏物体的Find系列方法
GameObject类提供的方法:
DSC0009.png

通过名称查找:Find方法;通过标签查找:其他Find方法。
Object类(这个Object和万物之父Object只是同名,所在命名空间并不相同,Unity中的Object继承自System中的万物之父Object)提供的方法:
DSC00010.png

Object类中的Find方法基本都是根据类型查找,GameObject类中的Find方法是根据名称和标签查找。使用时一般使用泛型查找方法。
说明:在GameObject类中的Find系列方法啊,会遍历场景中所有对象,查找效率比较低下;Object类中的Find方法是通过类型查找,这个类型一般是脚本类型,因此不仅遍历对象,还会遍历对象身上的脚本,效率更低。这两个类中的Find方法在实际使用中都不推荐。
3)克隆对象(实例化对象)的方法
DSC00011.png

Instantiate方法是Object类提供的方法,一般也使用泛型方法,一般用于使用预制体克隆(实例化)对象。
4)删除对象的方法
DSC00012.png

删除对象的方法也是Object基类提供的方法。一般上图中第一个方法和第五个方法用得比较多,第五个方法是延迟删除方法。Destroy方法会在下一帧移除游戏物体或者脚本(参数是Object类对象,代表继承自Object的类对象都可以移除),不会马上移除对象,如果要马上移除,可以使用上面的第三个和第四个方法(DestroyImmediate方法)。
5)过场景不移除
DSC00013.png

这个方法也是由Object类提供,在切换场景时会自动移除上一个场景中的游戏物体,使用这个方法指定的target在切换场景时不会被移除。
PS:因为MonoBehaviour继承自Behaviour,Behaviour继承自Component,Component继承自Object,Component和GameObject是“兄弟类”,所以继承自Object的静态方法(如根据类型的Find系列方法、Instantiate系列方法、Destroy系列方法、DontDestroyOnLoad方法等)在继承自MonoBehaviour的脚本中也存在,直接写方法名就可以调用,而GameObject类提供的静态方法(如根据名字的Find方法、根据标签的Find系列方法等)在继承了MonoBehaviour的脚本中则需要使用GameObject类名点出方法名来调用。
3.成员方法
1)创建一个物体
DSC00014.png

GameObject类中提供了三种构造方法,因此可以使用new关键字创建空物体,在创建物体时还可以指定物体的名称和挂载的组件。
void Start()
  {
    GameObject go = new GameObject("NewCamera", typeof(Camera), typeof(Rigidbody));
  }
DSC00015.png

2)添加脚本
DSC00016.png

使用AddComponent方法添加脚本,一般使用泛型,这个方法是GameObject类提供的成员方法,一般使用gameObject对象调用。
3)获取脚本
DSC00017.png

获取脚本的方法是由Component类提供,GameObject类也提供了这些方法,但是Object类中没有,一般直接由脚本或游戏物体对象调用。
同时还有TryGetComponent方法,返回值为bool类型,代表是否成功获取组件,使用out参数接收获取的组件。
DSC00018.png

4)标签比较
DSC00019.png

可以使用CompareTag方法比较两个游戏物体的标签,也可以通过gameObject对象中的tag变量获得标签,tag变量是字符串类型,使用字符串的比较方法(==运算符或者重载Equals方法)比较标签是否相等。GameObject类和Component类都提供了这个方法。
5)设置游戏中对象失活或者激活
DSC00020.png

这个方法由GameObject类提供,通过GameObject类对象调用,设置游戏对象是否失活。
void Start()
  {
    GameObject obj = GameObject.CreatePrimitive(PrimitiveType.Capsule);
    obj.SetActive(false);
  }
DSC00021.png

6)不建议使用的成员方法(了解即可,效率低)
DSC00022.png

SendMessage系列方法由GameObject类提供,Component类也提供了这类方法,可以广播方法让其他脚本执行这个方法,但是这个方法会遍历所有脚本,还涉及到装箱拆箱等(传入了object类型参数),效率低。
DSC00023.png

BroadCastMessage系列方法也是GameObject类提供的方法,同样Component类中也有这一系列方法,和SendMessage类似,效率低,不建议使用。
三.Time类(时间相关类)
下面是Time类:
namespace UnityEngine
{
  //
  // 摘要:
  //   The interface to get time information from Unity.
  [NativeHeader("Runtime/Input/TimeManager.h")]
  [StaticAccessor("GetTimeManager()", StaticAccessorType.Dot)]
  public class Time
  {
    public Time();
    //
    // 摘要:
    //   Slows game playback time to allow screenshots to be saved between frames.
    public static float captureDeltaTime { get; set; }
    //
    // 摘要:
    //   The real time in seconds since the game started (Read Only).
    [NativeProperty("Realtime")]
    public static float realtimeSinceStartup { get; }
    [NativeProperty("RenderFrameCount")]
    public static int renderedFrameCount { get; }
    //
    // 摘要:
    //   The total number of frames that have passed (Read Only).
    public static int frameCount { get; }
    //
    // 摘要:
    //   The scale at which time passes. This can be used for slow motion effects.
    public static float timeScale { get; set; }
    //
    // 摘要:
    //   The maximum time a frame can spend on particle updates. If the frame takes longer
    //   than this, then updates are split into multiple smaller updates.
    public static float maximumParticleDeltaTime { get; set; }
    //
    // 摘要:
    //   A smoothed out Time.deltaTime (Read Only).
    public static float smoothDeltaTime { get; }
    //
    // 摘要:
    //   The maximum time a frame can take. Physics and other fixed frame rate updates
    //   (like MonoBehaviour's MonoBehaviour.FixedUpdate) will be performed only for this
    //   duration of time per frame.
    public static float maximumDeltaTime { get; set; }
    //
    // 摘要:
    //   The interval in seconds at which physics and other fixed frame rate updates (like
    //   MonoBehaviour's MonoBehaviour.FixedUpdate) are performed.
    public static float fixedDeltaTime { get; set; }
    //
    // 摘要:
    //   The timeScale-independent interval in seconds from the last fixed frame to the
    //   current one (Read Only).
    public static float fixedUnscaledDeltaTime { get; }
    //
    // 摘要:
    //   The timeScale-independent interval in seconds from the last frame to the current
    //   one (Read Only).
    public static float unscaledDeltaTime { get; }
    //
    // 摘要:
    //   The TimeScale-independant time the latest MonoBehaviour.FixedUpdate has started
    //   (Read Only). This is the time in seconds since the start of the game.
    public static float fixedUnscaledTime { get; }
    //
    // 摘要:
    //   The timeScale-independant time for this frame (Read Only). This is the time in
    //   seconds since the start of the game.
    public static float unscaledTime { get; }
    //
    // 摘要:
    //   The time the latest MonoBehaviour.FixedUpdate has started (Read Only). This is
    //   the time in seconds since the start of the game.
    public static float fixedTime { get; }
    //
    // 摘要:
    //   The completion time in seconds since the last frame (Read Only).
    public static float deltaTime { get; }
    //
    // 摘要:
    //   The time this frame has started (Read Only). This is the time in seconds since
    //   the last level has been loaded.
    [NativeProperty("TimeSinceSceneLoad")]
    public static float timeSinceLevelLoad { get; }
    //
    // 摘要:
    //   The time at the beginning of this frame (Read Only). This is the time in seconds
    //   since the start of the game.
    [NativeProperty("CurTime")]
    public static float time { get; }
    //
    // 摘要:
    //   The reciprocal of Time.captureDeltaTime.
    public static int captureFramerate { get; set; }
    //
    // 摘要:
    //   Returns true if called inside a fixed time step callback (like MonoBehaviour's
    //   MonoBehaviour.FixedUpdate), otherwise returns false.
    public static bool inFixedTimeStep { get; }
  }
}
可以看到,Time类中的内容都是一些静态属性,接下来我们分类说明这些属性:
1.时间缩放比例
DSC00024.png

这个属性用于控制游戏内时间速度,这个值为0时游戏暂停,为1时游戏内时间流速和真实事件相同,为0~1之间时游戏内时间比真实时间流动速度慢,大于1时游戏内时间流速快于真实时间。可以简单理解为几倍速播放。
2.帧时间
DSC00025.png

执行当前代码的最近一帧的时间,单位秒。一般用于计算位移。在Update中使用。
DSC00026.png

不受scale影响的帧时间,和deltaTime相比,这个时间和timeScale无关,一般不受游戏暂停影响的游戏物体位移使用这个属性。
3.游戏开始时间
DSC00027.png

从游戏开始到现在的时间。
DSC00028.png

不受scale影响的游戏时间。
4.物理帧时间
DSC00029.png

在FixedUpdate中使用的物理帧时间。这个时间可以设置,游戏运行时不会变化。
DSC00030.png

不受scale影响的物理帧时间。
5.游戏开始后总共多少帧
DSC00031.png

计算游戏开始后总共跑了多少次循环(总帧数)。一般在帧同步时使用。
四.Vector3结构体
namespace UnityEngine
{
  //
  // 摘要:
  //   Representation of 3D vectors and points.
  [DefaultMember("Item")]
  [NativeClass("Vector3f")]
  [NativeHeader("Runtime/Math/Vector3.h")]
  [NativeHeader("Runtime/Math/MathScripting.h")]
  [NativeType(Header = "Runtime/Math/Vector3.h")]
  [RequiredByNativeCode(Optional = true, GenerateProxy = true)]
  public struct Vector3 : IEquatable<Vector3>
  {
    public const float kEpsilon = 1E-05F;
    public const float kEpsilonNormalSqrt = 1E-15F;
    //
    // 摘要:
    //   X component of the vector.
    public float x;
    //
    // 摘要:
    //   Y component of the vector.
    public float y;
    //
    // 摘要:
    //   Z component of the vector.
    public float z;
    //
    // 摘要:
    //   Creates a new vector with given x, y components and sets z to zero.
    //
    // 参数:
    //   x:
    //
    //   y:
    public Vector3(float x, float y);
    //
    // 摘要:
    //   Creates a new vector with given x, y, z components.
    //
    // 参数:
    //   x:
    //
    //   y:
    //
    //   z:
    public Vector3(float x, float y, float z);
    public float this[int index] { get; set; }
    //
    // 摘要:
    //   Shorthand for writing Vector3(1, 0, 0).
    public static Vector3 right { get; }
    //
    // 摘要:
    //   Shorthand for writing Vector3(-1, 0, 0).
    public static Vector3 left { get; }
    //
    // 摘要:
    //   Shorthand for writing Vector3(0, 1, 0).
    public static Vector3 up { get; }
    //
    // 摘要:
    //   Shorthand for writing Vector3(0, 0, -1).
    public static Vector3 back { get; }
    //
    // 摘要:
    //   Shorthand for writing Vector3(0, 0, 1).
    public static Vector3 forward { get; }
    //
    // 摘要:
    //   Shorthand for writing Vector3(1, 1, 1).
    public static Vector3 one { get; }
    //
    // 摘要:
    //   Shorthand for writing Vector3(0, 0, 0).
    public static Vector3 zero { get; }
    //
    // 摘要:
    //   Shorthand for writing Vector3(float.NegativeInfinity, float.NegativeInfinity,
    //   float.NegativeInfinity).
    public static Vector3 negativeInfinity { get; }
    //
    // 摘要:
    //   Shorthand for writing Vector3(float.PositiveInfinity, float.PositiveInfinity,
    //   float.PositiveInfinity).
    public static Vector3 positiveInfinity { get; }
    //
    // 摘要:
    //   Shorthand for writing Vector3(0, -1, 0).
    public static Vector3 down { get; }
    [Obsolete("Use Vector3.forward instead.")]
    public static Vector3 fwd { get; }
    //
    // 摘要:
    //   Returns the squared length of this vector (Read Only).
    public float sqrMagnitude { get; }
    //
    // 摘要:
    //   Returns this vector with a magnitude of 1 (Read Only).
    public Vector3 normalized { get; }
    //
    // 摘要:
    //   Returns the length of this vector (Read Only).
    public float magnitude { get; }
    //
    // 摘要:
    //   Returns the angle in degrees between from and to.
    //
    // 参数:
    //   from:
    //   The vector from which the angular difference is measured.
    //
    //   to:
    //   The vector to which the angular difference is measured.
    //
    // 返回结果:
    //   The angle in degrees between the two vectors.
    public static float Angle(Vector3 from, Vector3 to);
    [Obsolete("Use Vector3.Angle instead. AngleBetween uses radians instead of degrees and was deprecated for this reason")]
    public static float AngleBetween(Vector3 from, Vector3 to);
    //
    // 摘要:
    //   Returns a copy of vector with its magnitude clamped to maxLength.
    //
    // 参数:
    //   vector:
    //
    //   maxLength:
    public static Vector3 ClampMagnitude(Vector3 vector, float maxLength);
    //
    // 摘要:
    //   Cross Product of two vectors.
    //
    // 参数:
    //   lhs:
    //
    //   rhs:
    public static Vector3 Cross(Vector3 lhs, Vector3 rhs);
    //
    // 摘要:
    //   Returns the distance between a and b.
    //
    // 参数:
    //   a:
    //
    //   b:
    public static float Distance(Vector3 a, Vector3 b);
    //
    // 摘要:
    //   Dot Product of two vectors.
    //
    // 参数:
    //   lhs:
    //
    //   rhs:
    public static float Dot(Vector3 lhs, Vector3 rhs);
    [Obsolete("Use Vector3.ProjectOnPlane instead.")]
    public static Vector3 Exclude(Vector3 excludeThis, Vector3 fromThat);
    //
    // 摘要:
    //   Linearly interpolates between two points.
    //
    // 参数:
    //   a:
    //
    //   b:
    //
    //   t:
    public static Vector3 Lerp(Vector3 a, Vector3 b, float t);
    //
    // 摘要:
    //   Linearly interpolates between two vectors.
    //
    // 参数:
    //   a:
    //
    //   b:
    //
    //   t:
    public static Vector3 LerpUnclamped(Vector3 a, Vector3 b, float t);
    public static float Magnitude(Vector3 vector);
    //
    // 摘要:
    //   Returns a vector that is made from the largest components of two vectors.
    //
    // 参数:
    //   lhs:
    //
    //   rhs:
    public static Vector3 Max(Vector3 lhs, Vector3 rhs);
    //
    // 摘要:
    //   Returns a vector that is made from the smallest components of two vectors.
    //
    // 参数:
    //   lhs:
    //
    //   rhs:
    public static Vector3 Min(Vector3 lhs, Vector3 rhs);
    //
    // 摘要:
    //   Calculate a position between the points specified by current and target, moving
    //   no farther than the distance specified by maxDistanceDelta.
    //
    // 参数:
    //   current:
    //   The position to move from.
    //
    //   target:
    //   The position to move towards.
    //
    //   maxDistanceDelta:
    //   Distance to move current per call.
    //
    // 返回结果:
    //   The new position.
    public static Vector3 MoveTowards(Vector3 current, Vector3 target, float maxDistanceDelta);
    //
    // 摘要:
    //   Makes this vector have a magnitude of 1.
    //
    // 参数:
    //   value:
    public static Vector3 Normalize(Vector3 value);
    public static void OrthoNormalize(ref Vector3 normal, ref Vector3 tangent, ref Vector3 binormal);
    public static void OrthoNormalize(ref Vector3 normal, ref Vector3 tangent);
    //
    // 摘要:
    //   Projects a vector onto another vector.
    //
    // 参数:
    //   vector:
    //
    //   onNormal:
    public static Vector3 Project(Vector3 vector, Vector3 onNormal);
    //
    // 摘要:
    //   Projects a vector onto a plane defined by a normal orthogonal to the plane.
    //
    // 参数:
    //   planeNormal:
    //   The direction from the vector towards the plane.
    //
    //   vector:
    //   The location of the vector above the plane.
    //
    // 返回结果:
    //   The location of the vector on the plane.
    public static Vector3 ProjectOnPlane(Vector3 vector, Vector3 planeNormal);
    //
    // 摘要:
    //   Reflects a vector off the plane defined by a normal.
    //
    // 参数:
    //   inDirection:
    //
    //   inNormal:
    public static Vector3 Reflect(Vector3 inDirection, Vector3 inNormal);
    //
    // 摘要:
    //   Rotates a vector current towards target.
    //
    // 参数:
    //   current:
    //   The vector being managed.
    //
    //   target:
    //   The vector.
    //
    //   maxRadiansDelta:
    //   The maximum angle in radians allowed for this rotation.
    //
    //   maxMagnitudeDelta:
    //   The maximum allowed change in vector magnitude for this rotation.
    //
    // 返回结果:
    //   The location that RotateTowards generates.
    [FreeFunction(IsThreadSafe = true)]
    public static Vector3 RotateTowards(Vector3 current, Vector3 target, float maxRadiansDelta, float maxMagnitudeDelta);
    //
    // 摘要:
    //   Multiplies two vectors component-wise.
    //
    // 参数:
    //   a:
    //
    //   b:
    public static Vector3 Scale(Vector3 a, Vector3 b);
    //
    // 摘要:
    //   Returns the signed angle in degrees between from and to.
    //
    // 参数:
    //   from:
    //   The vector from which the angular difference is measured.
    //
    //   to:
    //   The vector to which the angular difference is measured.
    //
    //   axis:
    //   A vector around which the other vectors are rotated.
    public static float SignedAngle(Vector3 from, Vector3 to, Vector3 axis);
    //
    // 摘要:
    //   Spherically interpolates between two vectors.
    //
    // 参数:
    //   a:
    //
    //   b:
    //
    //   t:
    [FreeFunction("VectorScripting::Slerp", IsThreadSafe = true)]
    public static Vector3 Slerp(Vector3 a, Vector3 b, float t);
    //
    // 摘要:
    //   Spherically interpolates between two vectors.
    //
    // 参数:
    //   a:
    //
    //   b:
    //
    //   t:
    [FreeFunction("VectorScripting::SlerpUnclamped", IsThreadSafe = true)]
    public static Vector3 SlerpUnclamped(Vector3 a, Vector3 b, float t);
    public static Vector3 SmoothDamp(Vector3 current, Vector3 target, ref Vector3 currentVelocity, float smoothTime, [DefaultValue("Mathf.Infinity")] float maxSpeed, [DefaultValue("Time.deltaTime")] float deltaTime);
    [ExcludeFromDocs]
    public static Vector3 SmoothDamp(Vector3 current, Vector3 target, ref Vector3 currentVelocity, float smoothTime, float maxSpeed);
    [ExcludeFromDocs]
    public static Vector3 SmoothDamp(Vector3 current, Vector3 target, ref Vector3 currentVelocity, float smoothTime);
    public static float SqrMagnitude(Vector3 vector);
    public bool Equals(Vector3 other);
    //
    // 摘要:
    //   Returns true if the given vector is exactly equal to this vector.
    //
    // 参数:
    //   other:
    public override bool Equals(object other);
    public override int GetHashCode();
    public void Normalize();
    //
    // 摘要:
    //   Multiplies every component of this vector by the same component of scale.
    //
    // 参数:
    //   scale:
    public void Scale(Vector3 scale);
    //
    // 摘要:
    //   Set x, y and z components of an existing Vector3.
    //
    // 参数:
    //   newX:
    //
    //   newY:
    //
    //   newZ:
    public void Set(float newX, float newY, float newZ);
    //
    // 摘要:
    //   Returns a nicely formatted string for this vector.
    //
    // 参数:
    //   format:
    public string ToString(string format);
    //
    // 摘要:
    //   Returns a nicely formatted string for this vector.
    //
    // 参数:
    //   format:
    public override string ToString();
    public static Vector3 operator +(Vector3 a, Vector3 b);
    public static Vector3 operator -(Vector3 a);
    public static Vector3 operator -(Vector3 a, Vector3 b);
    public static Vector3 operator *(Vector3 a, float d);
    public static Vector3 operator *(float d, Vector3 a);
    public static Vector3 operator /(Vector3 a, float d);
    public static bool operator ==(Vector3 lhs, Vector3 rhs);
    public static bool operator !=(Vector3 lhs, Vector3 rhs);
  }
}
这个结构体是用于表示三维向量的结构体。
1.初始化
可以使用结构体提供的无参构造,同时也提供了两个构造函数重载:
DSC00032.png

提供了x和y的构造函数默认z是0,一般用于表示二维向量(当然Unity也提供了Vector2结构体)。
2.有3个变量,代表向量或位置坐标的三个坐标
DSC00033.png

3.提供了索引器访问坐标和各种静态属性
DSC00034.png

4.提供向量的运算符重载
DSC00035.png

5.提供计算模长平方、向量单位化和取模长的方法
DSC00036.png

6.提供了各种其他数学向量运算方法
DSC00037.png

五.Transform类
namespace UnityEngine
{
  //
  // 摘要:
  //   Position, rotation and scale of an object.
  [NativeHeader("Runtime/Transform/Transform.h")]
  [NativeHeader("Runtime/Transform/ScriptBindings/TransformScriptBindings.h")]
  [NativeHeader("Configuration/UnityConfigure.h")]
  [RequiredByNativeCode]
  public class Transform : Component, IEnumerable
  {
    protected Transform();
    //
    // 摘要:
    //   Position of the transform relative to the parent transform.
    public Vector3 localPosition { get; set; }
    //
    // 摘要:
    //   The rotation as Euler angles in degrees.
    public Vector3 eulerAngles { get; set; }
    //
    // 摘要:
    //   The rotation as Euler angles in degrees relative to the parent transform's rotation.
    public Vector3 localEulerAngles { get; set; }
    //
    // 摘要:
    //   The red axis of the transform in world space.
    public Vector3 right { get; set; }
    //
    // 摘要:
    //   The green axis of the transform in world space.
    public Vector3 up { get; set; }
    //
    // 摘要:
    //   Returns a normalized vector representing the blue axis of the transform in world
    //   space.
    public Vector3 forward { get; set; }
    //
    // 摘要:
    //   A Quaternion that stores the rotation of the Transform in world space.
    public Quaternion rotation { get; set; }
    //
    // 摘要:
    //   The world space position of the Transform.
    public Vector3 position { get; set; }
    //
    // 摘要:
    //   The rotation of the transform relative to the transform rotation of the parent.
    public Quaternion localRotation { get; set; }
    //
    // 摘要:
    //   The parent of the transform.
    public Transform parent { get; set; }
    //
    // 摘要:
    //   Matrix that transforms a point from world space into local space (Read Only).
    public Matrix4x4 worldToLocalMatrix { get; }
    //
    // 摘要:
    //   Matrix that transforms a point from local space into world space (Read Only).
    public Matrix4x4 localToWorldMatrix { get; }
    //
    // 摘要:
    //   Returns the topmost transform in the hierarchy.
    public Transform root { get; }
    //
    // 摘要:
    //   The number of children the parent Transform has.
    public int childCount { get; }
    //
    // 摘要:
    //   The global scale of the object (Read Only).
    public Vector3 lossyScale { get; }
    //
    // 摘要:
    //   Has the transform changed since the last time the flag was set to 'false'?
    [NativeProperty("HasChangedDeprecated")]
    public bool hasChanged { get; set; }
    //
    // 摘要:
    //   The scale of the transform relative to the GameObjects parent.
    public Vector3 localScale { get; set; }
    //
    // 摘要:
    //   The transform capacity of the transform's hierarchy data structure.
    public int hierarchyCapacity { get; set; }
    //
    // 摘要:
    //   The number of transforms in the transform's hierarchy data structure.
    public int hierarchyCount { get; }
    //
    // 摘要:
    //   Unparents all children.
    [FreeFunction("DetachChildren", HasExplicitThis = true)]
    public void DetachChildren();
    //
    // 摘要:
    //   Finds a child by n and returns it.
    //
    // 参数:
    //   n:
    //   Name of child to be found.
    //
    // 返回结果:
    //   The returned child transform or null if no child is found.
    public Transform Find(string n);
    [Obsolete("FindChild has been deprecated. Use Find instead (UnityUpgradable) -> Find([mscorlib] System.String)", false)]
    public Transform FindChild(string n);
    //
    // 摘要:
    //   Returns a transform child by index.
    //
    // 参数:
    //   index:
    //   Index of the child transform to return. Must be smaller than Transform.childCount.
    //
    // 返回结果:
    //   Transform child by index.
    [FreeFunction("GetChild", HasExplicitThis = true)]
    [NativeThrows]
    public Transform GetChild(int index);
    [NativeMethod("GetChildrenCount")]
    [Obsolete("warning use Transform.childCount instead (UnityUpgradable) -> Transform.childCount", false)]
    public int GetChildCount();
    public IEnumerator GetEnumerator();
    //
    // 摘要:
    //   Gets the sibling index.
    public int GetSiblingIndex();
    //
    // 摘要:
    //   Transforms a direction from world space to local space. The opposite of Transform.TransformDirection.
    //
    // 参数:
    //   direction:
    public Vector3 InverseTransformDirection(Vector3 direction);
    //
    // 摘要:
    //   Transforms the direction x, y, z from world space to local space. The opposite
    //   of Transform.TransformDirection.
    //
    // 参数:
    //   x:
    //
    //   y:
    //
    //   z:
    public Vector3 InverseTransformDirection(float x, float y, float z);
    //
    // 摘要:
    //   Transforms the position x, y, z from world space to local space. The opposite
    //   of Transform.TransformPoint.
    //
    // 参数:
    //   x:
    //
    //   y:
    //
    //   z:
    public Vector3 InverseTransformPoint(float x, float y, float z);
    //
    // 摘要:
    //   Transforms position from world space to local space.
    //
    // 参数:
    //   position:
    public Vector3 InverseTransformPoint(Vector3 position);
    //
    // 摘要:
    //   Transforms a vector from world space to local space. The opposite of Transform.TransformVector.
    //
    // 参数:
    //   vector:
    public Vector3 InverseTransformVector(Vector3 vector);
    //
    // 摘要:
    //   Transforms the vector x, y, z from world space to local space. The opposite of
    //   Transform.TransformVector.
    //
    // 参数:
    //   x:
    //
    //   y:
    //
    //   z:
    public Vector3 InverseTransformVector(float x, float y, float z);
    //
    // 摘要:
    //   Is this transform a child of parent?
    //
    // 参数:
    //   parent:
    [FreeFunction("Internal_IsChildOrSameTransform", HasExplicitThis = true)]
    public bool IsChildOf([NotNull] Transform parent);
    //
    // 摘要:
    //   Rotates the transform so the forward vector points at target's current position.
    //
    // 参数:
    //   target:
    //   Object to point towards.
    //
    //   worldUp:
    //   Vector specifying the upward direction.
    public void LookAt(Transform target, [DefaultValue("Vector3.up")] Vector3 worldUp);
    //
    // 摘要:
    //   Rotates the transform so the forward vector points at worldPosition.
    //
    // 参数:
    //   worldPosition:
    //   Point to look at.
    //
    //   worldUp:
    //   Vector specifying the upward direction.
    public void LookAt(Vector3 worldPosition, [DefaultValue("Vector3.up")] Vector3 worldUp);
    //
    // 摘要:
    //   Rotates the transform so the forward vector points at worldPosition.
    //
    // 参数:
    //   worldPosition:
    //   Point to look at.
    //
    //   worldUp:
    //   Vector specifying the upward direction.
    public void LookAt(Vector3 worldPosition);
    //
    // 摘要:
    //   Rotates the transform so the forward vector points at target's current position.
    //
    // 参数:
    //   target:
    //   Object to point towards.
    //
    //   worldUp:
    //   Vector specifying the upward direction.
    public void LookAt(Transform target);
    public void Rotate(float xAngle, float yAngle, float zAngle);
    //
    // 摘要:
    //   Applies a rotation of eulerAngles.z degrees around the z-axis, eulerAngles.x
    //   degrees around the x-axis, and eulerAngles.y degrees around the y-axis (in that
    //   order).
    //
    // 参数:
    //   eulers:
    //   The rotation to apply.
    //
    //   relativeTo:
    //   Determines whether to rotate the GameObject either locally to the GameObject
    //   or relative to the Scene in world space.
    public void Rotate(Vector3 eulers, [DefaultValue("Space.Self")] Space relativeTo);
    public void Rotate(Vector3 eulers);
    //
    // 摘要:
    //   The implementation of this method applies a rotation of zAngle degrees around
    //   the z axis, xAngle degrees around the x axis, and yAngle degrees around the y
    //   axis (in that order).
    //
    // 参数:
    //   relativeTo:
    //   Determines whether to rotate the GameObject either locally to the GameObject
    //   or relative to the Scene in world space.
    //
    //   xAngle:
    //   Degrees to rotate the GameObject around the X axis.
    //
    //   yAngle:
    //   Degrees to rotate the GameObject around the Y axis.
    //
    //   zAngle:
    //   Degrees to rotate the GameObject around the Z axis.
    public void Rotate(float xAngle, float yAngle, float zAngle, [DefaultValue("Space.Self")] Space relativeTo);
    //
    // 摘要:
    //   Rotates the object around the given axis by the number of degrees defined by
    //   the given angle.
    //
    // 参数:
    //   angle:
    //   The degrees of rotation to apply.
    //
    //   axis:
    //   The axis to apply rotation to.
    //
    //   relativeTo:
    //   Determines whether to rotate the GameObject either locally to the GameObject
    //   or relative to the Scene in world space.
    public void Rotate(Vector3 axis, float angle, [DefaultValue("Space.Self")] Space relativeTo);
    public void Rotate(Vector3 axis, float angle);
    //
    // 摘要:
    //   Rotates the transform about axis passing through point in world coordinates by
    //   angle degrees.
    //
    // 参数:
    //   point:
    //
    //   axis:
    //
    //   angle:
    public void RotateAround(Vector3 point, Vector3 axis, float angle);
    //
    // 参数:
    //   axis:
    //
    //   angle:
    [Obsolete("warning use Transform.Rotate instead.")]
    public void RotateAround(Vector3 axis, float angle);
    [Obsolete("warning use Transform.Rotate instead.")]
    public void RotateAroundLocal(Vector3 axis, float angle);
    //
    // 摘要:
    //   Move the transform to the start of the local transform list.
    public void SetAsFirstSibling();
    //
    // 摘要:
    //   Move the transform to the end of the local transform list.
    public void SetAsLastSibling();
    //
    // 摘要:
    //   Set the parent of the transform.
    //
    // 参数:
    //   parent:
    //   The parent Transform to use.
    //
    //   worldPositionStays:
    //   If true, the parent-relative position, scale and rotation are modified such that
    //   the object keeps the same world space position, rotation and scale as before.
    //
    //   p:
    public void SetParent(Transform p);
    //
    // 摘要:
    //   Set the parent of the transform.
    //
    // 参数:
    //   parent:
    //   The parent Transform to use.
    //
    //   worldPositionStays:
    //   If true, the parent-relative position, scale and rotation are modified such that
    //   the object keeps the same world space position, rotation and scale as before.
    //
    //   p:
    [FreeFunction("SetParent", HasExplicitThis = true)]
    public void SetParent(Transform parent, bool worldPositionStays);
    //
    // 摘要:
    //   Sets the world space position and rotation of the Transform component.
    //
    // 参数:
    //   position:
    //
    //   rotation:
    public void SetPositionAndRotation(Vector3 position, Quaternion rotation);
    //
    // 摘要:
    //   Sets the sibling index.
    //
    // 参数:
    //   index:
    //   Index to set.
    public void SetSiblingIndex(int index);
    //
    // 摘要:
    //   Transforms direction x, y, z from local space to world space.
    //
    // 参数:
    //   x:
    //
    //   y:
    //
    //   z:
    public Vector3 TransformDirection(float x, float y, float z);
    //
    // 摘要:
    //   Transforms direction from local space to world space.
    //
    // 参数:
    //   direction:
    public Vector3 TransformDirection(Vector3 direction);
    //
    // 摘要:
    //   Transforms the position x, y, z from local space to world space.
    //
    // 参数:
    //   x:
    //
    //   y:
    //
    //   z:
    public Vector3 TransformPoint(float x, float y, float z);
    //
    // 摘要:
    //   Transforms position from local space to world space.
    //
    // 参数:
    //   position:
    public Vector3 TransformPoint(Vector3 position);
    //
    // 摘要:
    //   Transforms vector x, y, z from local space to world space.
    //
    // 参数:
    //   x:
    //
    //   y:
    //
    //   z:
    public Vector3 TransformVector(float x, float y, float z);
    //
    // 摘要:
    //   Transforms vector from local space to world space.
    //
    // 参数:
    //   vector:
    public Vector3 TransformVector(Vector3 vector);
    //
    // 摘要:
    //   Moves the transform by x along the x axis, y along the y axis, and z along the
    //   z axis.
    //
    // 参数:
    //   x:
    //
    //   y:
    //
    //   z:
    //
    //   relativeTo:
    public void Translate(float x, float y, float z);
    //
    // 摘要:
    //   Moves the transform by x along the x axis, y along the y axis, and z along the
    //   z axis.
    //
    // 参数:
    //   x:
    //
    //   y:
    //
    //   z:
    //
    //   relativeTo:
    public void Translate(float x, float y, float z, [DefaultValue("Space.Self")] Space relativeTo);
    //
    // 摘要:
    //   Moves the transform in the direction and distance of translation.
    //
    // 参数:
    //   translation:
    //
    //   relativeTo:
    public void Translate(Vector3 translation);
    //
    // 摘要:
    //   Moves the transform in the direction and distance of translation.
    //
    // 参数:
    //   translation:
    //
    //   relativeTo:
    public void Translate(Vector3 translation, [DefaultValue("Space.Self")] Space relativeTo);
    //
    // 摘要:
    //   Moves the transform by x along the x axis, y along the y axis, and z along the
    //   z axis.
    //
    // 参数:
    //   x:
    //
    //   y:
    //
    //   z:
    //
    //   relativeTo:
    public void Translate(float x, float y, float z, Transform relativeTo);
    //
    // 摘要:
    //   Moves the transform in the direction and distance of translation.
    //
    // 参数:
    //   translation:
    //
    //   relativeTo:
    public void Translate(Vector3 translation, Transform relativeTo);
  }
}
下面是常用的一些方法和属性:
DSC00038.png

世界坐标系中的位置。position只能使用Vector3向量赋值,不能使用某个数字赋值某个坐标(如transform.position.x = 1;是不被允许的)
DSC00039.png

本地坐标系的位置(相对于父对象的位置,没有父对象,就以世界坐标原点作为本地坐标原点。)。同样只能使用Vector3向量赋值。
DSC00040.png

使用Translate函数进行位移计算。中间两个Translate函数运用较多。默认是局部坐标系运算,可以使用第二个参数指定世界坐标系运算位移。
DSC00041.png

DSC00042.png

表示物体朝向(从标准朝向(朝向z轴)旋转到当前朝向的旋转)使用的是四元数结构体Quaternion,不是Vector3结构体,一般对物体朝向赋值都不是给rotation赋值(四元数计算太麻烦)。
DSC00043.png

可以使用欧拉角赋值物体的朝向。和position相同,只能使用Vector3对象给欧拉角赋值,不能单独改变其中某一个坐标的值。欧拉角的值虽然在inspector面板中显示有负数,但是通过代码获取的角度只能是0~360的范围。
DSC00044.png

使用Rotate函数进行旋转计算。
DSC00045.png

使用RotateAround函数围绕点旋转。后两个方法已经弃用。Rotate可以理解为自传函数,RotateAround可以理解为公转函数。
DSC00046.png

DSC00047.png

相对于世界坐标的缩放大小和本地坐标缩放大小属性。注意:lossyScale属性只提供了get方法,没有set方法。修改时同样只能使用Vector3赋值,不能为某个单独的坐标赋值。Unity没有提供缩放的方法,只能通过赋值使缩放变化.
DSC00048.png

LookAt函数能够使物体的前方一直朝向某个点或对象。
DSC00049.png

parent属性对应了当前Transform所在物体的父物体的transform对象,提供了get和set方法,可以设置父物体。
DSC00050.png

也可以通过SetParent方法设置父物体,bool参数代表是否保留世界坐标位置、角度、缩放等信息。
DSC00051.png

使用DetachChildren方法抛弃所有子物体。
DSC00052.png

通过名称查找子对象的transform组件,其中FindChild方法已弃用。只能找一层子对象,不能找孙子辈的子对象。
DSC00053.png

得到所有子对象的数量,失活的子对象也会被计算在内,但是孙子辈的子对象不计算在内。
DSC00054.png

通过索引值得到相应的子对象,配合子对象的数量GetChildCount函数可以遍历所有子对象。
DSC00055.png

判断是否是子对象的方法。
DSC00056.png

得到作为子对象的索引。
DSC00057.png

设定自己作为子对象的索引值为第一个或最后一个。
DSC00058.png

设置作为子对象的编号,如果给定的编号溢出,始终会被设置为最后一个(不管正溢出还是负溢出)。
DSC00059.png

坐标转换相关的函数,这六个方法都是世界坐标系转本地坐标系,分别是两个转换方向的重载、两个转换点坐标的重载、两个转换方向的重载(不受缩放影响)。
DSC00060.png

同样的,这六个方法是本地坐标下转世界坐标系。
六.Input类
Input类没有继承任何类,是一个用于检测鼠标输入的类,这个类中除了一个无参构造以外其他方法和属性都是静态的。下面是这个类的元数据:
namespace UnityEngine
{
  //
  // 摘要:
  //   Interface into the Input system.
  [NativeHeader("Runtime/Input/InputBindings.h")]
  public class Input
  {
    public Input();
    //
    // 摘要:
    //   Returns the keyboard input entered this frame. (Read Only)
    [NativeThrows]
    public static string inputString { get; }
    //
    // 摘要:
    //   Controls enabling and disabling of IME input composition.
    public static IMECompositionMode imeCompositionMode { get; set; }
    //
    // 摘要:
    //   The current IME composition string being typed by the user.
    public static string compositionString { get; }
    //
    // 摘要:
    //   Does the user have an IME keyboard input source selected?
    public static bool imeIsSelected { get; }
    //
    // 摘要:
    //   The current text input position used by IMEs to open windows.
    public static Vector2 compositionCursorPos { get; set; }
    //
    // 摘要:
    //   Property indicating whether keypresses are eaten by a textinput if it has focus
    //   (default true).
    [Obsolete("eatKeyPressOnTextFieldFocus property is deprecated, and only provided to support legacy behavior.")]
    public static bool eatKeyPressOnTextFieldFocus { get; set; }
    //
    // 摘要:
    //   Indicates if a mouse device is detected.
    public static bool mousePresent { get; }
    //
    // 摘要:
    //   Number of touches. Guaranteed not to change throughout the frame. (Read Only)
    public static int touchCount { get; }
    //
    // 摘要:
    //   Bool value which let's users check if touch pressure is supported.
    public static bool touchPressureSupported { get; }
    //
    // 摘要:
    //   Returns true when Stylus Touch is supported by a device or platform.
    public static bool stylusTouchSupported { get; }
    //
    // 摘要:
    //   Returns whether the device on which application is currently running supports
    //   touch input.
    public static bool touchSupported { get; }
    //
    // 摘要:
    //   Property indicating whether the system handles multiple touches.
    public static bool multiTouchEnabled { get; set; }
    [Obsolete("isGyroAvailable property is deprecated. Please use SystemInfo.supportsGyroscope instead.")]
    public static bool isGyroAvailable { get; }
    //
    // 摘要:
    //   Device physical orientation as reported by OS. (Read Only)
    public static DeviceOrientation deviceOrientation { get; }
    //
    // 摘要:
    //   Last measured linear acceleration of a device in three-dimensional space. (Read
    //   Only)
    public static Vector3 acceleration { get; }
    //
    // 摘要:
    //   This property controls if input sensors should be compensated for screen orientation.
    public static bool compensateSensors { get; set; }
    //
    // 摘要:
    //   Number of acceleration measurements which occurred during last frame.
    public static int accelerationEventCount { get; }
    //
    // 摘要:
    //   Should Back button quit the application? Only usable on Android, Windows Phone
    //   or Windows Tablets.
    public static bool backButtonLeavesApp { get; set; }
    //
    // 摘要:
    //   Property for accessing device location (handheld devices only). (Read Only)
    public static LocationService location { get; }
    //
    // 摘要:
    //   Property for accessing compass (handheld devices only). (Read Only)
    public static Compass compass { get; }
    //
    // 摘要:
    //   Returns default gyroscope.
    public static Gyroscope gyro { get; }
    //
    // 摘要:
    //   The current mouse scroll delta. (Read Only)
    [NativeThrows]
    public static Vector2 mouseScrollDelta { get; }
    //
    // 摘要:
    //   The current mouse position in pixel coordinates. (Read Only)
    [NativeThrows]
    public static Vector3 mousePosition { get; }
    //
    // 摘要:
    //   Returns list of acceleration measurements which occurred during the last frame.
    //   (Read Only) (Allocates temporary variables).
    public static AccelerationEvent[] accelerationEvents { get; }
    //
    // 摘要:
    //   Returns true the first frame the user hits any key or mouse button. (Read Only)
    [NativeThrows]
    public static bool anyKeyDown { get; }
    //
    // 摘要:
    //   Is any key or mouse button currently held down? (Read Only)
    [NativeThrows]
    public static bool anyKey { get; }
    //
    // 摘要:
    //   Enables/Disables mouse simulation with touches. By default this option is enabled.
    public static bool simulateMouseWithTouches { get; set; }
    //
    // 摘要:
    //   Returns list of objects representing status of all touches during last frame.
    //   (Read Only) (Allocates temporary variables).
    public static Touch[] touches { get; }
    //
    // 摘要:
    //   Returns specific acceleration measurement which occurred during last frame. (Does
    //   not allocate temporary variables).
    //
    // 参数:
    //   index:
    [NativeThrows]
    public static AccelerationEvent GetAccelerationEvent(int index);
    //
    // 摘要:
    //   Returns the value of the virtual axis identified by axisName.
    //
    // 参数:
    //   axisName:
    [NativeThrows]
    public static float GetAxis(string axisName);
    //
    // 摘要:
    //   Returns the value of the virtual axis identified by axisName with no smoothing
    //   filtering applied.
    //
    // 参数:
    //   axisName:
    [NativeThrows]
    public static float GetAxisRaw(string axisName);
    //
    // 摘要:
    //   Returns true while the virtual button identified by buttonName is held down.
    //
    // 参数:
    //   buttonName:
    //   The name of the button such as Jump.
    //
    // 返回结果:
    //   True when an axis has been pressed and not released.
    [NativeThrows]
    public static bool GetButton(string buttonName);
    //
    // 摘要:
    //   Returns true during the frame the user pressed down the virtual button identified
    //   by buttonName.
    //
    // 参数:
    //   buttonName:
    [NativeThrows]
    public static bool GetButtonDown(string buttonName);
    //
    // 摘要:
    //   Returns true the first frame the user releases the virtual button identified
    //   by buttonName.
    //
    // 参数:
    //   buttonName:
    [NativeThrows]
    public static bool GetButtonUp(string buttonName);
    //
    // 摘要:
    //   Returns an array of strings describing the connected joysticks.
    [NativeThrows]
    public static string[] GetJoystickNames();
    //
    // 摘要:
    //   Returns true while the user holds down the key identified by name.
    //
    // 参数:
    //   name:
    public static bool GetKey(string name);
    //
    // 摘要:
    //   Returns true while the user holds down the key identified by the key KeyCode
    //   enum parameter.
    //
    // 参数:
    //   key:
    public static bool GetKey(KeyCode key);
    //
    // 摘要:
    //   Returns true during the frame the user starts pressing down the key identified
    //   by the key KeyCode enum parameter.
    //
    // 参数:
    //   key:
    public static bool GetKeyDown(KeyCode key);
    //
    // 摘要:
    //   Returns true during the frame the user starts pressing down the key identified
    //   by name.
    //
    // 参数:
    //   name:
    public static bool GetKeyDown(string name);
    //
    // 摘要:
    //   Returns true during the frame the user releases the key identified by the key
    //   KeyCode enum parameter.
    //
    // 参数:
    //   key:
    public static bool GetKeyUp(KeyCode key);
    //
    // 摘要:
    //   Returns true during the frame the user releases the key identified by name.
    //
    // 参数:
    //   name:
    public static bool GetKeyUp(string name);
    //
    // 摘要:
    //   Returns whether the given mouse button is held down.
    //
    // 参数:
    //   button:
    [NativeThrows]
    public static bool GetMouseButton(int button);
    //
    // 摘要:
    //   Returns true during the frame the user pressed the given mouse button.
    //
    // 参数:
    //   button:
    [NativeThrows]
    public static bool GetMouseButtonDown(int button);
    //
    // 摘要:
    //   Returns true during the frame the user releases the given mouse button.
    //
    // 参数:
    //   button:
    [NativeThrows]
    public static bool GetMouseButtonUp(int button);
    //
    // 摘要:
    //   Call Input.GetTouch to obtain a Touch struct.
    //
    // 参数:
    //   index:
    //   The touch input on the device screen.
    //
    // 返回结果:
    //   Touch details in the struct.
    [NativeThrows]
    public static Touch GetTouch(int index);
    //
    // 摘要:
    //   Determine whether a particular joystick model has been preconfigured by Unity.
    //   (Linux-only).
    //
    // 参数:
    //   joystickName:
    //   The name of the joystick to check (returned by Input.GetJoystickNames).
    //
    // 返回结果:
    //   True if the joystick layout has been preconfigured; false otherwise.
    public static bool IsJoystickPreconfigured(string joystickName);
    //
    // 摘要:
    //   Resets all input. After ResetInputAxes all axes return to 0 and all buttons return
    //   to 0 for one frame.
    [FreeFunction("ResetInput")]
    public static void ResetInputAxes();
  }
}
同样,我们分类来总结这个类中的属性和方法。
1.鼠标相关
DSC00061.png

鼠标位置mousePosition属性。
DSC00062.png

每帧鼠标中键滚动量,是一个二维向量值,鼠标滚动时其中的y值会发生变化,y=-1代表向下滚、y=0代表没有滚动、y=1代表向上滚。
DSC00063.png

检测鼠标输入,分别代表鼠标按住时触发、鼠标刚按下时触发、鼠标抬起时触发,其中参数0代表鼠标左键,1代表鼠标右键,2代表鼠标中键。
2.键盘输入。
DSC00064.png

和鼠标状态相似,分别代表键盘按住、键盘刚按下、键盘抬起时触发的函数。注意:传入参数为键的名称时传入的一定是小写字符串,一般不传入名称,而是使用KeyCode参数的重载,KeyCode是一个所有键盘上键的枚举类型。
3.默认轴输入
DSC00065.png

Unity提供了轴输入,其中GetAxis的返回值是-1到1之间,按住相应的键不动轴的值会逐渐向-1或者1变化,值是渐变的。GetAxisRaw也是获得轴的返回值,但是这个返回的轴的值只能是-1,0和1三个值,没有中间值,返回值直接变化。
轴的名称和对应的键可以在Unity中设置:
DSC00066.png

添加或者删除轴只需要直接更改轴的数量即可。
4.其他输入
1)任意键或鼠标
DSC00067.png

是否有任意键按下和按住的属性。在设置游戏的改建功能时可以使用。
2)手柄输入
DSC00068.png

获取所有手柄的键的名称。
DSC00069.png

获取手柄的键是否按住、按下和抬起操作。
3)触摸输入
DSC00070.png

当前触摸点个数。
DSC00071.png

所有触摸点。一般和触摸点个数配合使用,先判断是否有触摸,再获取触摸点。
DSC00072.png

多点触控是否开启。
4)陀螺仪(重力感应)
DSC00073.png

获取陀螺仪类对象,在其中开启陀螺仪和获取陀螺仪的值。
七.屏幕相关Screen类
Screen类是一个sealed关键字修饰的类,这个类不能被继承。这个类中的属性和方法也都是静态的,这个类用于记录当前屏幕的信息。
namespace UnityEngine
{
  //
  // 摘要:
  //   Access to display information.
  public sealed class Screen
  {
    public Screen();
    //
    // 摘要:
    //   Set this property to one of the values in FullScreenMode to change the display
    //   mode of your application.
    public static FullScreenMode fullScreenMode { get; set; }
    [EditorBrowsable(EditorBrowsableState.Never)]
    [Obsolete("Property GetResolution has been deprecated. Use resolutions instead (UnityUpgradable) -> resolutions", true)]
    public static Resolution[] GetResolution { get; }
    //
    // 摘要:
    //   The current brightness of the screen.
    public static float brightness { get; set; }
    //
    // 摘要:
    //   A power saving setting, allowing the screen to dim some time after the last active
    //   user interaction.
    public static int sleepTimeout { get; set; }
    //
    // 摘要:
    //   Specifies logical orientation of the screen.
    public static ScreenOrientation orientation { get; set; }
    //
    // 摘要:
    //   Allow auto-rotation to landscape right?
    public static bool autorotateToLandscapeRight { get; set; }
    //
    // 摘要:
    //   Allow auto-rotation to landscape left?
    public static bool autorotateToLandscapeLeft { get; set; }
    //
    // 摘要:
    //   Allow auto-rotation to portrait, upside down?
    public static bool autorotateToPortraitUpsideDown { get; set; }
    //
    // 摘要:
    //   Allow auto-rotation to portrait?
    public static bool autorotateToPortrait { get; set; }
    //
    // 摘要:
    //   Returns a list of screen areas that are not functional for displaying content
    //   (Read Only).
    public static Rect[] cutouts { get; }
    //
    // 摘要:
    //   Returns the safe area of the screen in pixels (Read Only).
    public static Rect safeArea { get; }
    //
    // 摘要:
    //   Should the cursor be locked?
    [EditorBrowsable(EditorBrowsableState.Never)]
    [Obsolete("Use Cursor.lockState and Cursor.visible instead.", false)]
    public static bool lockCursor { get; set; }
    //
    // 摘要:
    //   Is the game running full-screen?
    public static bool fullScreen { get; set; }
    //
    // 摘要:
    //   All full-screen resolutions supported by the monitor (Read Only).
    public static Resolution[] resolutions { get; }
    //
    // 摘要:
    //   The current screen resolution (Read Only).
    public static Resolution currentResolution { get; }
    //
    // 摘要:
    //   The current DPI of the screen / device (Read Only).
    public static float dpi { get; }
    //
    // 摘要:
    //   The current height of the screen window in pixels (Read Only).
    public static int height { get; }
    //
    // 摘要:
    //   The current width of the screen window in pixels (Read Only).
    public static int width { get; }
    //
    // 摘要:
    //   Should the cursor be visible?
    [EditorBrowsable(EditorBrowsableState.Never)]
    [Obsolete("Property showCursor has been deprecated. Use Cursor.visible instead (UnityUpgradable) -> UnityEngine.Cursor.visible", true)]
    public static bool showCursor { get; set; }
    //
    // 摘要:
    //   Switches the screen resolution.
    //
    // 参数:
    //   width:
    //
    //   height:
    //
    //   fullscreen:
    //
    //   preferredRefreshRate:
    //
    //   fullscreenMode:
    public static void SetResolution(int width, int height, bool fullscreen);
    //
    // 摘要:
    //   Switches the screen resolution.
    //
    // 参数:
    //   width:
    //
    //   height:
    //
    //   fullscreen:
    //
    //   preferredRefreshRate:
    //
    //   fullscreenMode:
    public static void SetResolution(int width, int height, bool fullscreen, [Internal.DefaultValue("0")] int preferredRefreshRate);
    public static void SetResolution(int width, int height, FullScreenMode fullscreenMode);
    //
    // 摘要:
    //   Switches the screen resolution.
    //
    // 参数:
    //   width:
    //
    //   height:
    //
    //   fullscreen:
    //
    //   preferredRefreshRate:
    //
    //   fullscreenMode:
    public static void SetResolution(int width, int height, FullScreenMode fullscreenMode, [Internal.DefaultValue("0")] int preferredRefreshRate);
  }
}
下面同样分类整理其中常用的属性和方法:
1.当前屏幕分辨率
DSC00074.png

currentResolution是游戏当前所在的屏幕的信息,如在Unity中制作游戏时就是显示Unity软件的屏幕的宽高,和Unity中Game窗口设置的宽高无关。Resolution是一个屏幕信息结构体,记录了当前屏幕的基本信息(宽、高、刷新率)。
DSC00075.png

2.游戏屏幕宽高
DSC00076.png

游戏实际占用的宽高信息直接由Screen类中的height和width属性记录,如Unity制作游戏时height和width得到的就是Game窗口的宽高。一般作计算时使用这个宽高信息。
3.息屏设置
DSC00077.png

可以设置息屏时间,如果想设置不息屏,可以将值设置为SleepTimeout类中的NeverSleep常量。
4.其他
1)是否全屏
DSC00078.png

2)窗口模式
DSC00079.png

设置窗口的模式,FullScreenMode是一个枚举,有四个值:
DSC00080.png

0:独占全屏;1:全屏窗口化;2:最大化窗口;3:窗口模式
一般屏幕信息在发布时设置,不在代码中设置。
3)屏幕旋转
DSC00081.png

分别代表左横向、右横向、竖屏倒置、竖屏正放,设置为true代表允许屏幕设置为此模式。同样地,一般在发布时设置这类信息,在制作游戏内内容时不用设置这类信息。
DSC00082.png

指定屏幕显示方向。ScreenOrientation是一个枚举类型:
DSC00083.png

4)设置分辨率

使用SetResolution静态方法设置分辨率,但是移动设备一般不会使用此方法。


关注下面的标签,发现更多相似文章