码迷,mamicode.com
首页 > 编程语言 > 详细

论unity中[System.Serializable]的作用

时间:2015-12-08 18:07:54      阅读:4016      评论:0      收藏:0      [点我收藏+]

标签:

首先解释[System.Serializable]什么意思,就是把一个对象序列化(网上就是这么解释的),在unity中有什么作用呢请看一下代码便一目了然。

这是一个属性类,里面声明了4个字段:

 1 using UnityEngine;
 2 using System.Collections;
 3 
 4 [System.Serializable]
 5 public class Property {
 6 
 7     public string name = "aa";
 8     public int age = 0;
 9     public bool sex = true;
10     public float height = 183.0f;
11 }

以下代码是声明了Show类,类中引用了Property类:

 1 using UnityEngine;
 2 using System.Collections;
 3 
 4 public class Show : MonoBehaviour {
 5 
 6     public Property[] propertys;
 7     string strSex;
 8 
 9     void OnGUI()
10     {
11         for (int i = 0; i < propertys.Length; i++)
12         {
13             strSex = propertys[i].sex == true ? "" : "";
14             GUI.Button(new Rect(10, 10 + i * 35, 250, 30), "名字:" + propertys[i].name + " 年龄:" + propertys[i].age + " 性别:" + strSex  + " 身高:" + propertys[i].height);
15         }
16           
17           
18        
19     }
20 }


效果图:

技术分享

 

论unity中[System.Serializable]的作用

标签:

原文地址:http://www.cnblogs.com/qingrenlei/p/5029463.html

(1)
(1)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!