我有一个可编写脚本的对象Character,我们假设它有 n 个实例Character。
Character.cs
public class Character : UnityEngine.ScriptableObject
{
...
}
// Let us say that there are 100 instances of this Class
Run Code Online (Sandbox Code Playgroud)
现在我创建另一个类
CharacterList.cs
public class CharacterList
{
List<Character> characterList = new List<Character>();
FindObjectsOfType<Character>();
// I also tried to write Character[] character = FindObjectsOfType<Character>() but that did not work.
// Now How do I put all the objects found in the List?
}
Run Code Online (Sandbox Code Playgroud)
我想做的是创建一个Class不是Monobehaviour. 只是一个简单的类CharacterList,我想要一个List包含Character …
我有一个字符可编程对象,其中有多种方法。就像 GetDate、GetAge (我没有在这里展示)。我在那里创建了一个构造函数,但我不知道如何通过构造函数创建该 ScriptableObject 的实例。这就是我想做的。
我尝试在检查器中键入值,但没有运行构造函数中的方法。
角色.cs
[CreateAssetMenu]
[Serializable]
public class Character : Scriptable Object
{
// Attributes
public string firstName;
public string middleName;
public string lastName;
public string fullName;
public bool isMale;
// Constructor
public Character(string _firstName, string _middleName, string _lastName, bool _isMale)
{
firstName = _firstName;
middleName = _middleName;
lastName = _lastName;
// All The Functions
fullName = string.Format("{0} {1} {2}", firstName, middleName,
lastName);
isMale = _isMale;
// and all the other functions like date calculator.
}
} …Run Code Online (Sandbox Code Playgroud)