补充derHugo给出的答案,以防万一其他人偶然发现这一点。我正在使用建议的方法,但发现为了在运行时“导入”[RuntimeInitializeOnLoadMethod]
必须设置使用的类型。可能还有其他方法,但这是我最终得到的 3 个移动文件,用于完成答案。
移动管理器.cs
public static class MoveManager
{
public static List<Move> Moves = new List<Move>();
}
移动.cs
public class Move
{
public string name;
public string description;
public Target target;
public int power;
public float accuracy;
public int cost;
public game_Type type;
public Style style;
public Move(
string name
, string description
, int power
, float accuracy
, int cost
, string typeName
, string styleName
, string targetType
)
{
this.name = name;
this.power = power;
this.accuracy = accuracy;
this.description = description;
this.type = game_Types.getByName(typeName);
this.style = MasterStyles.getByName(styleName);
this.target = new Target(targetType);
// a static class member is simply accessed via the type itself
Debug.Log("Registering " + name + " type!");
MoveManager.Moves.Add(this);
}
}
move_basic.cs
class move_basic
{
[RuntimeInitializeOnLoadMethod]
static void OnRuntimeMethodLoad()
{
// Name this move
string name = "Attack!";
// Describe this move
string description = "Strike out at the enemy with tooth, claw, weapon, or whatever else is available!";
// Choose the type of target this move is for
// self/ally/selfAlly/enemy/enemies
string target = "enemy";
// The move typing - This determines cost reduction as well as potential attack bonuses
string typeName = "physical";
game_Type type = game_Types.Types.Find(x => x.name == typeName);
// The move style - This determines additional bonuses and modifiers
string styleName = "martial";
// Style style = ??
// Power of the move, base/'normal' power is 50.
int power = 50;
// Accuracy of the move, base/normal is 90
int accuracy = 90;
// MP Cost of the move
int cost = 0;
Move mv = new Move(name, description, power, accuracy, cost, typeName, styleName, target);
}
}
下一步,现在我已经确认这项工作将是向已注册的动作添加方法,这是 IMO 真正的魔力所在。
当您需要创建一个可能需要包含可调用方法的易于扩展的对象库时,这似乎是一个非常理想的解决方案。如果不是出于这种需要,从 csv 或其他东西中导入属性可能会更好。
总的来说,我对统一和游戏设计还很陌生,所以我很高兴能编辑/更正/改进这篇文章以帮助未来的搜索者。