UnityEngine.SerializeField

  Force Unity to serialize a private field.

  强制Unity序列化一个私有变量。

  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.

  Unity will serialize all your script components, reload the new assemblies, and recreate your script components from the serialized verions. This serialization does not happen with .NET's serialization functionality, but with an internal Unity one.

  The serialization system used can do the following:

  - CAN serialize public nonstatic fields (of serializable types)
  - CAN serialize nonpublic nonstatic fields marked with the [SerializeField] attribute.
  - CANNOT serialize static fields.
  - CANNOT serialize properties.

  Your field will only serialize if it is of a type that Unity can serialize:

  

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 (new in Unity2.6)
- Enums

Headsup note: if you put one element in a list (or array) twice, when the list gets serialized, you'll get two copies of that element, instead of one copy being in the new list twice.

Hint: Unity won't serialize Dictionary, however you could store a List<> for keys and a List<> for values, and sew them up in a non serialized dictionary on Awake(). This doesn't solve the problem of when you want to modify the dictionary and have it "saved" back, but it is a handy trick in a lot of other cases.

For UnityScript users: Fields in c# is a script variable in UnityScript, and [SerializeField] becomes @SerializeField. [Serializable] on a class becomes @script Serializable in a UnityScript.

参考:file://localhost/Applications/Unity/Unity.app/Contents/Documentation/html/en/ScriptReference/SerializeField.html  

System.Serializable

  当一个成员是复合类型时,只要在这个复合类型上标注了[System.Serializable]属性,那这个成员也是一个可编辑的成员。Inspector窗口会按树的形式,依次罗列这个类型中的可编辑成员。

UnityEngine.SerializeField & System.Serializable的更多相关文章

  1. SerializeField和Serializable

    Serialize功能 Unity3D 中提供了非常方便的功能可以帮助用户将 成员变量 在Inspector中显示,并且定义Serialize关系. 简单的说,在没有自定义Inspector的情况下所 ...

  2. [System.Serializable],

    [System.Serializable]添加在类,枚举,结构前面,可以让该这些对象在inspector中显示 [SerializeField]是设置非public 成员对象在inspector中显示

  3. Unity中HideInInspector和SerializeField以及Serializable

    首先,Unity会自动为Public变量做序列化,序列化的意思是说再次读取Unity时序列化的变量是有值的,不需要你再次去赋值,因为它已经被保存下来. 然后是,什么样的值会被显示在面板上? 已经被序列 ...

  4. PC或者手机上实现相机拉近和旋转

    using System.Collections;using System.Collections.Generic;using UnityEngine;using System; //[Seriali ...

  5. Unity角色对话

    对话类------------------------------------------------------------------------------------------------- ...

  6. [转]Unity: make your lists functional with ReorderableList

    原文地址:http://va.lent.in/unity-make-your-lists-functional-with-reorderablelist/ This article is reprod ...

  7. unity UGUI实现类似NGUI切换Sprite的方式

    很多都是使用NGUI的习惯,因为在NGUI中所有图片都打包在一个图集中,通过更改SpriteName就可以更改图片,so,为了方便调用UGUI的sprite,我们也同样需要为其创建一个asset文件. ...

  8. Unity3d项目入门之虚拟摇杆

    Unity本身不提供摇杆的组件,开发者可以使用牛逼的EasyTouch插件或者应用NGUI实现相关的需求,下面本文通过Unity自身的UGUI属性,实现虚拟摇杆的功能. 主参考 <Unity:使 ...

  9. Unity5的关卡切换

    本文章由cartzhang编写,转载请注明出处. 全部权利保留. 文章链接:http://blog.csdn.net/cartzhang/article/details/51055584 作者:car ...

随机推荐

  1. Linux jdk环境配置模板

    export JAVA_HOME=/opt/JAVA/jdk1.8.0_191export JRE_HOME=${JAVA_HOME}/jreexport CLASSPATH=.:${JAVA_HOM ...

  2. 20181009-7 选题 Scrum立会报告+燃尽图 06

    Scrum立会报告+燃尽图(06)选题 此作业要求参见:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2196 一.小组介绍 组长:刘莹莹 ...

  3. PCB 中过孔和通孔焊盘的区别

    在PCB设计中,过孔VIA和焊盘PAD都可以实现相似的功能.它们都能插入元件管脚,特别是对于直插DIP)封装的的器件来说,几乎是一样的. 但是!在PCB制造中,它们的处理方法是不一样的. 1.VIA的 ...

  4. Hosts 文件的作用

    问题来源: 我修改了hosts文件访问公司的内网  但是出现错误找不到服务器或DNS错误  一个下午了都上不了公司的系统. Hosts是什么?Hosts是Window系统目录里的一个文件,它的作用可大 ...

  5. BZOJ4033: [HAOI2015]树上染色(树形DP)

    4033: [HAOI2015]树上染色 Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 3461  Solved: 1473[Submit][Stat ...

  6. 洛谷九月月赛II

    题解:模拟 一旦不匹配就要break #include<iostream> #include<cstdio> #include<cstring> #include& ...

  7. Java常用基础代码

    1.加载properties文件 Properties properties = new Properties();  properties.load(Properties.class.getReso ...

  8. Jenkins在windows环境下安装无法安装插件

    在windos平台下安装jenkins要是无法安装插件,tomcat控制台报以下错误: 解决方法: 进入到jenkins里头,Jenkins -- 管理插件 -- 高级 -- 升级站点,如图所示: 将 ...

  9. Apache 多网站配置

    直接看实例就清楚了 Listen 80<VirtualHost *:80> DocumentRoot D:/Server/www ServerAdmin webmaster@lifashi ...

  10. hdu 4336 Card Collector——最值反演

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=4336 点集中最早出现的元素的期望是 min ,最晚出现的元素的期望是 max :全部出现的期望就是最晚出现 ...