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 ...
随机推荐
- mac下安装apache tomcat
目录 一. 默认版: 二. 自定义下载配置版: ———————————————————————正文—————————————————————————— 一. 默认版: ##一.mac 自带了apach ...
- WIN8.1 PRO RTM VOL.2013.09.18
文件名:cn_windows_8_1_pro_vl_x64_dvd_2791218.isoSHA1:61C002551763E22B64EB1BACEFFE83620114C3D6 文件名:cn_wi ...
- 5.4完成其他模块的xadmin后台注册
courses adminx.py from .models import Course, Lesson, Video, CourseResource import xadmin class Cou ...
- CS231n课程笔记翻译5:反向传播笔记
译者注:本文智能单元首发,译自斯坦福CS231n课程笔记Backprop Note,课程教师Andrej Karpathy授权翻译.本篇教程由杜客翻译完成,堃堃和巩子嘉进行校对修改.译文含公式和代码, ...
- Nginx 防盗链设置
何谓'盗链' 此内容不在自己服务器上,而通过技术手段,绕过别人放广告有利益的最终页,直接在自己的有广告有利益的页面上向最终用户提供此内容. 常常是一些名不见经传的小网站来盗取一些有实力的大网站的地址( ...
- ajax向后台请求数据,后台接收到数据并进行了处理,但前台就是调用error方法
如果你的前台页面书写正确的情况下,并且运行情况和本文题目类似,那不妨试试这个: 在ajax方法中加上:async:false,让ajax同步执行. 因为ajax默认是异步的,至于为什么会不执行succ ...
- BZOJ4025: 二分图【线段树分治】【带撤销的并查集】
Description 神犇有一个n个节点的图.因为神犇是神犇,所以在T时间内一些边会出现后消失.神犇要求出每一时间段内这个图是否是二分图.这么简单的问题神犇当然会做了,于是他想考考你. Input ...
- printk()函数学习笔记
参考: https://www.cnblogs.com/sky-heaven/p/6742062.html韦东山老师的printk讲解:https://blog.csdn.net/W110710131 ...
- 初识安卓小程序(Android短信发送器)
首先,先创建一个安卓项目(我的版本号是4.4.2的),名字为"短信发送器" 然后在res目录下找到layout目录,找到activity_main.xml或fragment_mai ...
- python把指定目录下的递归所有目录和文件名转换成小写或大写
cat convert.py #!/usr/bin/env python # -*- coding:utf-8 -*- import os, sys def convert(rootdir, opty ...