在unity里,自定义数据类型无法显示在inspectior面板里,需要对定义数据类型的类或者结构体使用[System.Serializable]。效果如图:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Test : MonoBehaviour {
public A[] AList;
public B[] BList;
public A a;
public B b;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}
[System.Serializable]
public struct A
{
public int a;
public GameObject b;
public Vector3 c;
}
public struct B
{
public int a;
public GameObject b;
public Vector3 c;
}
可以看到,结构体B的数据无法再面板内显示,而A的则可以显示。
本文介绍了如何在Unity中使自定义数据类型能在Inspector面板上显示。通过使用[System.Serializable]特性,可以实现在Inspector面板中展示自定义结构体的内容。
2176

被折叠的 条评论
为什么被折叠?



