美文网首页
Unity Text源码分析

Unity Text源码分析

作者: 忻恆 | 来源:发表于2020-02-26 10:29 被阅读0次

    命名空间为UnityEngine.UI

    使用 [AddComponentMenu("UI/Text", 10)] 

    The AddComponentMenu attribute allows you to place a script anywhere in the "Component" menu, instead of just the "Component->Scripts" menu.You need to restart.

    10:componentOrder,The order of the component in the component menu (lower is higher to the top).

    继承于 MaskableGraphic, ILayoutElement。

    [SerializeField] Force Unity to serialize a private field.

    When Unity serializes your scripts, it only serializes public fields. If you also want Unity to serialize your private fields you can add the SerializeField attribute to those fields.

    Unity serializes all your script components, reloads the new assemblies, and recreates your script components from the serialized versions. This serialization is done with an internal Unity serialization system; not with .NET's serialization functionality.

    Unity can serialize fields of the following types:

    - All classes inheriting from UnityEngine.Object

    - All basic data types

    - Some built-in types,

    - Arrays of a serializable type

    - Lists of a serializable type

    - Enums

    - Structs

    序列化对于Unity而言是非常核心的功能。可用于存储脚本数据:

    1.Inspector窗口并不是用C#的API来得知它检视数据的属性,而是要求物体进行序列化,然后展示序列化信息。

    2.一个Prefab就是一个游戏物体或者组件的序列化信息流。一个实例就是一系列对于序列化信息的更改。Prefab这个改变只存在编辑器里。当Unity执行构建的时候,Prefab的更改将序列化到版本中,然后在初始化的时候,这些信息会被反序列化出来,这样,初始化出来的物体就会和编辑器中的预制件一样了。

    3.当调用Instantiate()的时候,我们对物体进行序列化,然后创建一个新的物体,然后把数据反序列化到新的物体里面去。

    每个UnityEngine.Object都被作为一个整体进行序列化,包含了对其他UnityEngine.Objects的引用。

    以后再补充

    相关文章

      网友评论

          本文标题:Unity Text源码分析

          本文链接:https://www.haomeiwen.com/subject/zikxchtx.html