美文网首页Unity编辑器开发分享Unity教程合集
将类对象显示在Unity的Inspector面板上

将类对象显示在Unity的Inspector面板上

作者: 循环渐进123456 | 来源:发表于2017-08-21 09:04 被阅读10次

转载:http://blog.csdn.net/liqiangeastsun/article/details/42101989

Unity中默认只在Inspecotr面板上显示基本类型数据, 如 int, float, string, Rect等基本类型。
经常会用到一些类,希望显示在Inspecotr面板上.
需要在定义类前写写一行代码 [System.Serializable]
即将类对象序列化,代码如下

using UnityEngine;
using System.Collections;

[System.Serializable]
public class MyClass
{
    public int num;
    public string data;

    public MyClass()
    {
        num = 1;
        data = "ABC";
    }
}

public class Test : MonoBehaviour {

    public int nnn;
    public float mmm;

    public MyClass SelfClass;
    // Use this for initialization
    void Start () {
       
    }
    
    // Update is called once per frame
    void Update () {
    
    }
}
1TE%9P8}07%2J6BJ5_`$MRY.png

相关文章

网友评论

    本文标题:将类对象显示在Unity的Inspector面板上

    本文链接:https://www.haomeiwen.com/subject/rgxcdxtx.html