编写脚本
public class Serializable : MonoBehaviour
{
public Test test;
// Update is called once per frame
void Update()
{
Debug.Log(test.id +" "+ test.name+" "+ test.vector3);
}
}
[System.Serializable]
public class Test:System.Object
{
public int id = 100;
public string name = "xpw";
public Vector3 vector3;
}
脚本应用于Object上,可以在Inspector里看到相应设置

本文介绍了一个Unity脚本示例,展示了如何使用C#实现对象的序列化,并在Inspector面板中显示设置。通过public class Serializable继承MonoBehaviour,定义了Update方法用于实时输出对象属性。
6992





