我正在C#的Unity中研究基于回合的战斗序列,目前我有回合切换工作,输入和AI。但是我还不太清楚如何将其与动画和其他内容一起排队,以便在 ExecuteTurnActions();
中一个接一个地发生所以我的问题基本上是,我该如何构造 ExecuteTurnActions()?
我需要它遍历所有实体并根据发生的情况播放其动画,例如:
// PlayAnimation is simply Animator.SetTrigger(string)
Entities[0].PlayAnimation("Attack") or Entities[0].PlayAnimation("ReceiveDamage")
我需要确保当一个实体攻击时,恰好在发生攻击时,另一个实体在此时受到损害并播放其动画。我知道有动画事件,但是我不确定如何使它从一个地方流出来,并确保每个实体都知道下一个触发动画的实体(例如,在受到攻击时)。有什么建议吗?
我的结构在伪代码中是这样的:
ENTITIES_TO_CREATE = MatchMaker.GetNumberOfPlayersAndEnemies();
void Start() {
InitializeAllThatsNeeded();
Entities[] = new Entity[ENTITIES_TO_CREATE];
// In a for loop, load up stuff and populate Entities
Entities[0].Name = MatchMaker.GetName(0);
Entities[0].Strength = MatchMaker.GetStrength(0); // etc etc etc
}
void Update() {
bool HaveAllEntitiesSelectedTurnAction = new bool[Entities.Length];
// Check every frame if all Entities have selected a turn action
for (int i = 0; i <= Entities.Length - 1; i++) {
HaveAllEntitiesSelectedTurnAction[i] = Entities[i].isTurnActionSelected;
}
// If the Entity that goes first has its action selected, then let the rest select theirs
if(Entities[EntityHasFirstTurn].TurnActionSelected) {
//All logic happens here, if Entity happens to be player then the player
//is allowed input, if enity is NPC then generate hit value etc.
// isTurnActionSelected set in this part
// Now if all have selected their action, execute them in order
if(HaveAllEntitiesSelectedTurnAction.All(x => x) {
ExecuteTurnActions();
}
}
}
答案 0 :(得分:0)
要确定事件的优先级,我建议使用priority queue数据结构。
对于Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Me.Columns("D:F")) Is Nothing Then
MsgBox "Your selection includes hidden column(s). BAD!", vbCritical
Me.Range("A1").Select
End If
End Sub
,它应该仅设置Animator Component的适当标志(最有可能基于队列)。您可能希望每个实体都有自己的事件队列,该事件队列与自己的Animator交互。
首先需要为所有动画构建状态机。设置某些状态将允许Unity处理所有转换。要了解有关Animator以及如何处理其状态的更多信息,请查看here。