Unity 经典教程 Editor扩展之SerializeField

 时间:2026-02-15 11:19:35

1、SerializeField:Force Unity to serialize a private field.

You will almost never need this. When Unity serializes your scripts, it will only serialize public fields. If in addition to that you also want Unity to serialize one of your private fields you can add the SerializeField attribute to the field.

2、Serializable types are:- All classes inheriting from UnityEngine.Object, for example GameObject, Component, MonoBehaviour, Texture2D, AnimationClip.- All basic data types like int, string, float, bool.- Some built-in types like Vector2, Vector3, Vector4, Quaternion, Matrix4x4, Color, Rect, LayerMask.- Arrays of a serializable type- List of a serializable type)- Enums- Structs

1、打开Unity,新建一个空工程,Unity界面如下图:

Unity 经典教程 Editor扩展之SerializeField

2、在工程中新建一个脚本,脚本可以命名为“SerializeFieldTest”,具体如下图

Unity 经典教程 Editor扩展之SerializeField

3、选中新建的“SerializeFiledTest”脚本,双击脚本或者右键“Open C# Project”,打开脚本,具体如下图

Unity 经典教程 Editor扩展之SerializeField

4、在打开的“SerializeFieldTest”脚本上编辑代码,系列化一个私有参数,代码和代码说明如下图

Unity 经典教程 Editor扩展之SerializeField

5、脚本编译正确后,回到Unity界面,在场景中新建一个“GameObject”,并且把脚本“SerializeFieldTest”赋给“GameObject”,即可看到私有变量显示在“Inspector”上,具体如下图

Unity 经典教程 Editor扩展之SerializeField

6、到此,《Unity 经典教程 Editor扩展之SerializeField的使用》,谢谢

  • VMware新建虚拟机方法
  • ubuntu相对路径:[7]cd 路径
  • 在IIS服务器上发布自己的第一个应用程序
  • VI编译器保存和退出方法介绍
  • 如何使用python语言tkinter模块创建Listbox列表
  • 热门搜索
    饼的做法大全 末影人怎么驯服 天风证券怎么样 一二九运动简介 word怎么放大字体 osu怎么玩 英语手抄报内容大全 矮寨大桥简介 小孩近视怎么办 六年级周记大全