我目前正在处理一些有效的代码。真的归结为我是否应该让所有这些?盲目的?演员表。
我有一堂课:
public abstract class Trigger
{
// no logic, just three automatic properties
}
继承自:
// there are several classes like this that store different things like strings,
// int,floats, enums, etc,etc.
public class ActivateOnTimeDelay : Trigger
{
// More automatic properties and possibly fields.
}
然后我将这些类放入List<Trigger>
并在另一个类中以反向 for 循环遍历列表
if (currentMission.ActiveTriggers.Count > 0)
{
for (int i = currentMission.ActiveTriggers.Count - 1; i >= 0; i--)
{
ActivateOnDeathDelay activateOnDeathD = currentMission.ActiveTriggers[i] as ActivateOnDeathDelay;
ActivateOnDeathImmediate activateOnDeathI = currentMission.ActiveTriggers[i] as ActivateOnDeathImmediate;
ActivateOnFinishDelay activateOnFinishD = currentMission.ActiveTriggers[i] as ActivateOnFinishDelay;
ActivateOnFinishImmediate activateOnFinishI = currentMission.ActiveTriggers[i] as ActivateOnFinishImmediate;
ActivateOnFinishMass activateOnFinishM = currentMission.ActiveTriggers[i] as ActivateOnFinishMass;
ActivateOnTimeDelay activateOnTimeD = currentMission.ActiveTriggers[i] as ActivateOnTimeDelay;
ActivateOnTimeImmediate activateOnTimeI = currentMission.ActiveTriggers[i] as ActivateOnTimeImmediate;
DisplayDialog displayDialog = currentMission.ActiveTriggers[i] as DisplayDialog;
SpawnEnemy spawnEnemy = currentMission.ActiveTriggers[i] as SpawnEnemy;
if (activateOnDeathD != null)
{
// do logic
}
// more null checks for each possible item that may be created this loop pass.
当一个触发器被使用时,它会从列表中移除,并且它的 ID 被放置到一个HashSet<string>
UsedTriggers 中,一些触发器会监视它。