【发布时间】:2018-02-11 16:56:19
【问题描述】:
当在编辑模式下从 Unity 检查器创建新的 List 元素时,我在从其构造函数初始化字符串时遇到了一些问题。
它所做的只是将“调用测试”写入控制台,而不是将其名称和描述初始化为占位符文本。
public class StatsManager : MonoBehaviour {
[System.Serializable]
public class StatValue {
public string name;
public string description;
public int currentValue;
public StatValue(){
this.name = "Times hit";
this.description = "This is how much you have been hit since the start of the game.";
Debug.Log("Call test");
}
}
[SerializeField]
public List<StatsManager.StatValue> stats;
}
【问题讨论】:
-
我看不到对该构造函数的任何调用...
-
当我在控制台中收到 debug.log 消息时,构造函数被调用。它会在实例化时自动调用。
-
不确定我是否理解。所以有一些隐藏代码,其中 stats = new List
() 和 stats.Add(new StatsManager.StatValue()),对吧? -
@McMidas:您向我们展示了一些代码。您没有向我们展示您使用上述代码的地方,那么我们应该如何帮助您调试正在发生的事情?
-
哦忘了说我在unity的inspector中编辑了列表
标签: c# list class unity3d initialization