Unity3D的SerializeField 序列化域名
SerializeField
Inherits from Attribute
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序列化你的脚本的时候。它将紧紧序列化公有域。假设作为附加你也想要Unity去序列化你的一个私有域,你能够加入SerializeField(序列化域)属性给这个域。
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.
Unity将序列化全部你的脚本组件,重载新的集合,而且又一次创建你的脚本组件从这个序列化版本号。这个序列化不会发生通过.Net的序列化功能,而是用一个内部的Unity序列化功能。
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.
- 能够序列化非公有非静态域用[SerializeField]属性标记。
- CANNOT serialize static fields.
- 不能够序列化静态域。
- CANNOT serialize properties.
- 不能够序列化属性。
Your field will only serialize if it is of a type that Unity can serialize:
你的域将紧紧序列化假设他是Unity能够序列化的一种类型。
Serializable types are:
序列化的类型有:
- All classed inheriting from UnityEngine.Object, for example Gameobject, Commponent, 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
- 全部继承自UnityEngine.Object的类,比如GameObject,Component,MonoBehaviour,Texture2D,AnimationClip..- 全部基本类型像int,string,float,bool.- 一些内建类型像Vector2,Vector3,Vector4,Quaternion,Matrix4x4,Color,Rect,Layermask..- 一个序列化类型的Array(数组)
- List of a serializable type (new in Unity2.6)
- 一个序列化类型的列表(新的在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 Listf<> or 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.
暗示:Unity不会序列化Dictionary(字典)。然而你能够存储一个列表给键,一个列表给值。而且缝合他们在一个非序列化dictionary(字典)在Awake()。这不会解决当你想要改动dictionary(字典)和让它的"被保存"返回的问题。可是它在非常多其它的情况里是一个便利的窍门。
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
给UnityScript用户:C#中的域在UnityScript中是一个脚本变量,而且[SerializeField]变成@SerializeField。[Serializable] 在一个类上变成@script Serializable在一个UnityScript。
// Javascript example
//This field gets serialized because it is public.
//这个域被序列化由于他是公开的。
var name = "John";
//This field does not get serialized because it is private.
//这个域没有被序列化由于它是私有的。
private var age = 40;
//This field gets serialized even though it is private
//这个域被序列化虽然他是私有的。
//because it has the SerializeField attribute applied.
//由于它应用了SerializeField属性
@SerializeField
private var hasHealthPotion:boolean = true;
function Update () {
}
//C# example
using UnityEngine;
public class SomePerson : MonoBehaviour {
//This field gets serialized because it is public.
public string name = "John";
//This field does not get serialized because it is private.
private int age = 40;
//This field gets serialized even though it is private
//because it has the SerializeField attribute applied.
[SerializeField]
private bool hasHealthPotion = true;
void Update () {
}
}
Unity3D的SerializeField 序列化域名的更多相关文章
- Unity3D中的序列化测试
Unity3D中序列化字段常使用[SerializeField],序列化类常采用[System.Serializable],非序列化采用[System.NonSerialized]. 序列化类使用时发 ...
- c# 与 Unity3d 中的序列化
圣典中对于Unity3D的序列化介绍很容易和C#的序列化介绍搞混,做个笔记,方便以后查找. 很多资料算是拾人牙慧. 一.Serializable 序列化 Inherits from Attribute ...
- Unity3D学习笔记(一):Unity简介、游戏物体、组件和生命周期函数
Project(工程.项目):工程是把游戏开发当前所需要的资源归类管理用的. Console控制台:日志.报错.调试,右上角,消息过滤 Assets:资源,存储游戏中一切用到的资源 Library:临 ...
- unity3d常用属性汇总
unity常用的是C#语言.而C#语言有Attribute属性.特别强大.所以unity开发的时候.可以在变量加Attribute属性来达到开发人员想要的效果 RequireComponent:约束组 ...
- (转)Unity3d中的属性(Attributes)整理
Attributes属性属于U3D的RunTimeClass,所以加上以下的命名空间是必须的了.其它倒没什么需要注意的.本文将所有运行属性过一遍罢了. using UnityEngine; using ...
- Unity3d该物业(Attributes)整理
http://blog.sina.com.cn/s/blog_5b6cb9500101857b.html Attributes属性属于U3D的RunTimeClass,所以加上下面的命名空间是必须的了 ...
- Unity3D开发之3D按钮的声音播放
这里我们首先就简易的制作一个非常简单的3D按钮![ 图中就一个cube 加个3DText,然后我们就编写代码 [RequireComponent(typeof(CompoundButton))]//特 ...
- Unity3d中的属性(Attributes)整理
Attributes属性属于U3D的RunTimeClass,所以加上以下的命名空间是必须的了.其它倒没什么需要注意的.本文将所有运行属性过一遍罢了. using UnityEngine; using ...
- (转载)Unity3d中的属性(Attributes)整理
附加: float字段检视面板修改:[Range(1,10)] 对属性进行分组:[Header("xxx")] 工具栏中调用方法,类文件需在Editor文件夹中:[MenuIte( ...
随机推荐
- POJ 2538 WERTYU水的问题
[题目简述]:题意非常easy,没有trick. [分析]:事实上这题还是挺有趣的,在 算法竞赛入门经典中也有这一题. 详见代码: // 120K 0Ms /* 边学边做 -- */ // 字符串:W ...
- 举例说, Decorator模式(Decorator Pattern)
前言 在食品工业中的装饰图案具有比较广泛的应用,大多数的两个图案和在网上的例子饮食相关的,一旦被称为电影的手表,点咖啡要加糖要加奶昔要加这加那的时候.感觉好有派~好高大上啊~.为啥我在小卖部都是 ...
- Spark里面:获取图Spark有多少行代码
Spark1.0.0公布一个多月,有多少行代码就(Line of Code, LOC)? watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvYW56aHNvZn ...
- POJ 2217 Secretary (后缀数组)
标题效果: 计算两个公共串串最长的字符串的长度. IDEAS: 这两个组合的字符串. 然后直接确定运行后缀数组height 然后,你可以直接扫描一次height .加个是不是在一个串中的推断就能够了. ...
- 2014百度之星预赛(第二场)——Best Financing
2014百度之星预赛(第二场)--Best Financing Problem Description 小A想通过合理投资银行理財产品达到收益最大化.已知小A在未来一段时间中的收入情况,描写叙述为两个 ...
- 11gRAC CHM 管理
Cluster Health Monitor(缩写CHM)是Oracle提供的工具,自己主动的资源来收集操作系统(CPU.内存.SWAP.过程.I/O与网络)用法. CHM数据被收集每秒一次,11.2 ...
- url参数中出现+、空格、=、%、&、#等字符的解决办法
url出现了有+,空格,/,?,%,#,&,=等特殊符号的时候,可能在服务器端无法获得正确的参数值,如何是好?解决办法将这些字符转化成服务器可以识别的字符,对应关系如下:URL字符转义 用其它 ...
- Python学习笔记23:Django构建一个简单的博客网站(一个)
在说如何下载和安装Django,本节将重点讨论如何使用Django站点. 一 新建project 命令:django-admin startproject mysite # 有的须要输入:django ...
- SDUT 2498-AOE网上的关键路径(spfa+字典序路径)
AOE网上的关键路径 Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描写叙述 一个无环的有向图称为无环图(Directed Acycl ...
- MEF初体验之十一:查询组合容器
查询组合容器 组合容器暴露了几个get exports的重载方法和导出对象和对象集合.你需要注意下面的行为: 当请求单个对象实例时,如果未发现导出,一个异常将被抛出 当请求单个对象实例时,如果发现超过 ...