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 ...
随机推荐
- docker部署mysql
1. 下载 [root@localhost my.Shells]# ./dockerStart.sh start or stop start Redirecting to /bin/systemctl ...
- HBase查询优化——持续更新
Scan:setBatch,setCaching,setCacheBlocks public void setBatch(int batch) public void setCaching(int c ...
- 数据库Job定时任务
数据库Job再熟悉不过了,因为经常要数据库定时的自动执行一些脚本,或做数据库备份,或做数据的提炼,或做数据库的性能优化,包括重建索引等等的工作.但是,Oracle定时器Job时间的处理上,千变万化,今 ...
- python 用 __all__ 暴露接口
非常典型的python的用法 refer to : http://python-china.org/t/725
- python urllib2 error handling
python 2 里面的下载实现. https://stackoverflow.com/questions/666022/what-errors-exceptions-do-i-need-to-han ...
- ES6必知必会 (七)—— Generator 函数
Generator 函数 1.Generator 函数是 ES6 提供的一种异步编程解决方案,语法行为与传统函数完全不同,通常有两个特征: function关键字与函数名之间有一个星号: 函数体内部使 ...
- Java基础之一:Java开发环境配置
Java 开发环境配置 window系统安装java 下载JDK,地址:http://www.oracle.com 在下载页面中你需要选择接受许可,并根据自己的系统选择对应的版本,本文以 Window ...
- Jacoco+Jenkines小白之路
Jacoco+Jenkines小白之路 最近工作中正在推广jacoco的增量覆盖率的统计,想学习一波,纯粹采坑中,适合小白学习jacoco. 一.代码覆盖率 引入代码覆盖率 : 代码覆盖率是指对现有代 ...
- 【转】MFC消息处理(一)
原文网址:http://blog.csdn.net/hyhnoproblem/article/details/6182120 1.MFC窗口如何与AfxWndProc建立联系. 当一个新的CWnd派生 ...
- 【白银组】codevs_1160 蛇形矩阵
#include <iostream> using namespace std; #define M 100 int a[M][M]; void pt( int n ) { for ( i ...