Table of Contents

MonoBehaviour

只知道是一个类,其余的概念很模糊,待补充…

[有道理吗?]MonoBehaviour上面可以选择脚本就说明了MonoBehaviour和脚本的关系,MonoBehaviour是脚本的容器,而不是脚本本身


不是MonoBehaviour也能作为Component

以下是PlayableDirector的定义,它并不继承自MonoBehaviour(而是Behaviour),但依然可以作为Component被附加在GameObject上

//
// Summary:
//     Instantiates a PlayableAsset and controls playback of Playable objects.
[NativeHeader("Runtime/Mono/MonoBehaviour.h")]
[NativeHeader("Modules/Director/PlayableDirector.h")]
[RequiredByNativeCode]
public class PlayableDirector : Behaviour, IExposedPropertyTable

如何理解?

Playable Director, like other Unity behaviours and components are C# wrappers around a native implementation. All serialization is done through native code. Monobehaviours are special behaviours that allow for serialization of C# defined data, so all components written in script are assumed to (and need to) derive from monobehaviour.
Even if the UI allowed your derived class, any data you added to your class would not get serialized.

来源:https://forum.unity.com/threads/cant-add-a-custom-playabledirector-to-an-object-in-scene.518412/

那么,什么是Wrappers?只是大概对Wrappers有一个概念,但具体应该如何理解?

In general, a wrapper class is any class which “wraps” or “encapsulates” the functionality of another class or component. These are useful by providing a level of abstraction from the implementation of the underlying class or component; for example, wrapper classes that wrap COM components can manage the process of invoking the COM component without bothering the calling code with it. They can also simplify the use of the underlying object by reducing the number interface points involved; frequently, this makes for more secure use of underlying components.

来源:https://stackoverflow.com/questions/889160/what-is-a-wrapper-class

生命周期相关

一个MonoBehaviour的生命周期是Awake > Start > (Update) > OnDestroy,这个OnDestroy的命名也是有点迷惑(为什么不是Destroy?因为Destroy是动词?),可能是历史遗留问题吧

协程

MonoBehaviour.StartCoroutine就是启动一个协程,[为什么]要设计成MonoBehaviour的成员函数?[学习一下]IEnumerator