Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Unity—基于struct';存档_C#_Unity3d_Serialization_Struct - Fatal编程技术网

C# Unity—基于struct';存档

C# Unity—基于struct';存档,c#,unity3d,serialization,struct,C#,Unity3d,Serialization,Struct,我有一个自定义的可序列化结构作为列表元素存储在中。 当结构中只有一个字段是公共字段时 [System.Serializable] public struct MemoryMoment { float Importance; //Subjective Person who; Room where; string when; string what; //string why; public string Descr; publi

我有一个自定义的可序列化结构作为列表元素存储在中。 当结构中只有一个字段是公共字段时

[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;
    }
}
[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;
    }
}
然后整个结构在inspector中以该元素命名

但当struct中有多个字段是公共字段时

[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;
    }
}
[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;
    }
}
然后结构名为“Element N”

如何为我的结构提供自定义检查器名称?

也就是说,类似这样的事情:

[NameInInspector]
string n = "(" + Importance.ToString() + ") " + Descr;

这是由Unity如何序列化
memorymont
struct引起的

基本上,如果结构中有一个
字符串作为第一个声明的字段,那么Unity将使用其内容“命名”列表中的元素

因此,如果要读取
Descr
的内容而不是
Element X
,只需移动声明
公共字符串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;
    }
}

不接受屏幕截图,请将代码作为text.Edited包含。代码而不是屏幕截图。您是否尝试创建自定义检查器?尝试了PropertyDrawer,但它仅适用于类。我不知道这两次否决的原因,请立即通过发布代码而不是屏幕截图进行更正。