一般设定游戏对象参数是用public多还是serializefield c多

当前位置: >
Unity3D的SerializeField 序列化域
时间: 09:57 来源:Unity之家 作者:unity.jb51.net 浏览:
SerializeField 序列化域Inherits from AttributeForce 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&=&
function&Update&()&{
}//C#&exampleusing&UnityE
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&=&
void&Update&()&{
(责任编辑:脚印)
免责声明:Unity之家部分内容来源于互联网,如有侵权,请联系我们,本站将立即进行处理。
猜你也喜欢看这些 ??????
其他类型的开发经验 ??????推荐这篇日记的豆列
······
&(2人关注)QQ群: --->>战斗卡牌视频教程发布(网游)
:使用了该属性的变量不显示在inspector 但是被序列化。即不会显示,也不会被外部类调用。
:将不会被序列化的非公共变量可以序列化,这么在下次读取时,就是上次赋值的值。
[ExecuteInEditMode()]:这个函数可以使代码在编辑模式下运行,不需要运行游戏;
[ExecuteInEditMode]: 编辑环境中该功能(类)生效,简单讲就是。不运行游戏。就可你让你的功能起作用,比如:NGUI中的Slider
[MenuItem(“”)]:导航条中加入自定义菜单。可参考:
[CustomEditor(typeof(EButton))]:绑定使用该类。必须依赖EButton类。参考:
[RequireComponent (typeof (ClassName))]:添加该类时。自动会加入ClassName类。
[ContextMenu (“XXX”)]:加入Inspector面板右键菜单。点击执行该功能。
[AddComponentMenu(“XXX/XX/XXX”)]:菜单中出现定义的该类。
[HideInInspector]用法:
正常情况下我们这样定义变量。如下:
public int index;
这样。我们在Inspector是能看到index变量的。
如果我们要他不再Inspector显示。
[HideInInspector]
[HideInInspector]public int index;
这样就不能在Inspector中看到。不能手动赋值了。
[SerializeField]用法:
正常情况下我们定义的私有变量在Inspector中我们是不能看到并且手动赋值了。 如果要就可以用[SerializeField]了。如下
[SerializeField]
[SerializeField]private int index;
这样即使是私有变量。我们也能在编辑时。在Inspector中赋值了。
转载请注明: &
or分享 (0)
本站所有内容如未标明转载的内容,均为原创内容。转载请注明来源!
发表我的评论java期末复习题(解答)_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
java期末复习题(解答)
上传于||暂无简介
阅读已结束,如果下载本文需要使用0下载券
想免费下载更多文档?
定制HR最喜欢的简历
下载文档到电脑,查找使用更方便
还剩10页未读,继续阅读
定制HR最喜欢的简历
你可能喜欢

我要回帖

更多关于 easyui field 对象 的文章

 

随机推荐