c# - Is there a way to use a class as an array? (Unity C#)
问题描述
So i have a class with a bunch of variables:
class DialogueBase
{
[SerializeField] private string input;
[SerializeField] private Color textColor;
[SerializeField] private float delay;
}
And I want to have another script with an array of this class so that I can add a bunch of dialogues and edit each one in the editor. So for example, I need to have 3 dialogues in a single dialogue, so I make the lenght of the array to 3 and edit each value in the editor.
Is it possible to do this? Or am I being dumb?
解决方案
As hijinxbassist said, you need to declare your class serializable.
[System.Serializable]
class DialogueBase
{
[SerializeField] private string input;
[SerializeField] private Color textColor;
[SerializeField] private float delay;
}
Then
public DialoguBase[] dialoges;
For inspector editing
And one extra thing. You don't need to use private
keyword to make your fields private. According to C# docs, a field is private by default. So private int A
is literally the same as int A
.
推荐阅读
- laravel - 如何将所有json文件数据插入数据库?
- java - java - 如何将sql查询附加到java中的现有文件?
- webpack - Wepback 和前端 monorepo
- python-3.x - 如何在 python 中拆分“21-13,20-21”-> [[21,13],[20,21]]?
- java - Swagger 引用一个 Spring 对象的响应,使用 Swagger 进行分页
- python - 如何在 python 函数 save_single_frameset 中使用 Realsense
- c# - 当自己的 ErrorHandler 事件发生时如何添加一些事情?
- r - 在 `...` 中为 R 函数设置名称
- python - Pycharm 仍在为排除的文件夹编制索引,这需要很长时间
- sql - 从 Django 传递可选列表参数以在原始 SQL 中过滤