我有一个自定义的可序列化结构存储在列表元素中。 只有结构的一个字段是公共的
[System.Serializable]
public struct MemoryMoment {
float Importance; //Subjective
Person who;
Room where;
string when;
string what;
//string why;
public string Descr;
public MemoryMoment (float importance, Person who, Room where, string when, string what) {
this.Importance = importance;
this.who = who;
this.where = where;
this.when = when;
this.what = what;
//this.why = "UNUSED";
this.Descr = where.Type.ToString () + " " + when + ", " + who.Name + " " + what;
}
}
然后整个结构在该元素http://fotovideotec.de/adobe_rgb/
之后的检查器中命名但是当struct中的多个字段是公共
时[System.Serializable]
public struct MemoryMoment {
public float Importance; //Subjective
Person who;
Room where;
string when;
string what;
//string why;
public string Descr;
public MemoryMoment (float importance, Person who, Room where, string when, string what) {
this.Importance = importance;
this.who = who;
this.where = where;
this.when = when;
this.what = what;
//this.why = "UNUSED";
this.Descr = where.Type.ToString () + " " + when + ", " + who.Name + " " + what;
}
}
如何为我的结构提供自定义检查器名称?
即。像这样的东西:
[NameInInspector]
string n = "(" + Importance.ToString() + ") " + Descr;
答案 0 :(得分:6)
这是由Unity如何序列化MemoryMoment
结构。
基本上,如果结构中第一个声明的字段有string
,那么Unity将使用其内容“命名”列表的元素。
因此,如果您想要阅读Descr
而不是Element X
的内容,您只需要在所有声明之上移动声明public string Descr;
:
[System.Serializable]
public struct MemoryMoment {
public string Descr;
public float Importance; //Subjective
Person who;
Room where;
string when;
string what;
//string why;
public MemoryMoment (float importance, Person who, Room where, string when, string what) {
this.Importance = importance;
this.who = who;
this.where = where;
this.when = when;
this.what = what;
//this.why = "UNUSED";
this.Descr = where.Type.ToString () + " " + when + ", " + who.Name + " " + what;
}
}