UnityEngine.SerializeField & System.Serializable
【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.
【System.Serializable】
当一个成员是复合类型时,只要在这个复合类型上标注了[System.Serializable]属性,那这个成员也是一个可编辑的成员。Inspector窗口会按树的形式,依次罗列这个类型中的可编辑成员。
UnityEngine.SerializeField & System.Serializable的更多相关文章
- SerializeField和Serializable
Serialize功能 Unity3D 中提供了非常方便的功能可以帮助用户将 成员变量 在Inspector中显示,并且定义Serialize关系. 简单的说,在没有自定义Inspector的情况下所 ...
- [System.Serializable],
[System.Serializable]添加在类,枚举,结构前面,可以让该这些对象在inspector中显示 [SerializeField]是设置非public 成员对象在inspector中显示
- Unity中HideInInspector和SerializeField以及Serializable
首先,Unity会自动为Public变量做序列化,序列化的意思是说再次读取Unity时序列化的变量是有值的,不需要你再次去赋值,因为它已经被保存下来. 然后是,什么样的值会被显示在面板上? 已经被序列 ...
- PC或者手机上实现相机拉近和旋转
using System.Collections;using System.Collections.Generic;using UnityEngine;using System; //[Seriali ...
- Unity角色对话
对话类------------------------------------------------------------------------------------------------- ...
- [转]Unity: make your lists functional with ReorderableList
原文地址:http://va.lent.in/unity-make-your-lists-functional-with-reorderablelist/ This article is reprod ...
- unity UGUI实现类似NGUI切换Sprite的方式
很多都是使用NGUI的习惯,因为在NGUI中所有图片都打包在一个图集中,通过更改SpriteName就可以更改图片,so,为了方便调用UGUI的sprite,我们也同样需要为其创建一个asset文件. ...
- Unity3d项目入门之虚拟摇杆
Unity本身不提供摇杆的组件,开发者可以使用牛逼的EasyTouch插件或者应用NGUI实现相关的需求,下面本文通过Unity自身的UGUI属性,实现虚拟摇杆的功能. 主参考 <Unity:使 ...
- Unity5的关卡切换
本文章由cartzhang编写,转载请注明出处. 全部权利保留. 文章链接:http://blog.csdn.net/cartzhang/article/details/51055584 作者:car ...
随机推荐
- 字典序全排列(java实现)
import java.util.Arrays; /** *字典序全排列 *字符串的全排列 *比如单词"too" 它的全排列是"oot","oto&q ...
- 征信接口调用,解析(xml)
数据传输格式报文格式:xml public CisReportRoot queryCisReport(PyQueryBean pyQueryBean) throws Exception { CisRe ...
- tornado多路由示例
main.py代码: # encoding: utf-8 """ @version: ?? @author: andu99 @contact: andux@qq.com ...
- pixi之动画
一.循环动画 let sprite; Loader.add("images/imgs.json").load(setup); function setup() { //利用oran ...
- B树、B-树、B+树、B*树都是什么
B树.B-树.B+树.B*树都是什么 B树 即二叉搜索树: 1.所有非叶子结点至多拥有两个儿子(Left和Right): 2.所有结点存储一个关键字: 3.非叶子结点的左指针指向小于其关键字的子树,右 ...
- LOJ2319. 「NOIP2017」列队【线段树】
LINK 思路 神仙线段树 你考虑怎么样才能快速维护出答案 首先看看一条链怎么做? 首先很显然的思路是维护每个节点的是否出过队 然后对于重新入队的点 直接在后面暴力vector存一下就可以了 最核心的 ...
- java面试题9
1.选择题 public class Test01 { public static void changeStr(String str) { str = "welcome"; } ...
- swift3.0 代码创建经典界面的九宫图--优化篇
在上一篇只是简单实现了九宫图效果,本章需要形成APP界面九宫图效果 override func viewDidLoad() { super.viewDidLoad() createnine() } / ...
- ARM汇编返回指令
[ 588.756226] task: ffff000008a22f80 task.stack: ffff000008a10000 [ 588.762153] PC is at vb2_buffer_ ...
- vm虚拟机怎么访问本地硬盘
第一步:点击VMware菜单“虚拟→设置”,在配置窗口的“选项”标签页内点击“共享文件夹”,在右侧点击“添加”按钮添加要共享的文件夹. 先确认虚拟机是关闭状态(susppend时无法修改属性)再修改虚 ...