| | |
| | | public void PlayRecord(RecordAction recordAction) |
| | | { |
| | | if (recordAction == null) return; |
| | | BattleDebug.LogError("Enqueue record action " + recordAction.GetType()); |
| | | // Debug.LogError("Enqueue record action " + recordAction.GetType() + " to queue"); |
| | | if (isForceFinish || stepForcefinish) |
| | | { |
| | | recordAction.ForceFinish(); |
| | |
| | | return; |
| | | } |
| | | |
| | | BattleDebug.LogError("Insert record action " + recordAction.GetType()); |
| | | // Debug.LogError("Insert record action " + recordAction.GetType() + " at front of queue"); |
| | | if (currentRecordAction != null) |
| | | { |
| | | Queue<RecordAction> tempQueue = new Queue<RecordAction>(); |
| | |
| | | immediatelyActionList.Add(recordAction); |
| | | } |
| | | |
| | | // 增强版本:支持父子关系和WaitingPlay标记 |
| | | public void ImmediatelyPlay(RecordAction recordAction, RecordAction parentAction, bool isWaitingPlay) |
| | | { |
| | | if (recordAction == null) return; |
| | | if (isForceFinish || stepForcefinish) |
| | | { |
| | | recordAction.ForceFinish(); |
| | | return; |
| | | } |
| | | |
| | | // Debug.LogError("insert recordAction ImmediatelyPlay: " + recordAction.GetType().Name + " parentAction: " + (parentAction != null ? parentAction.GetType().Name : "null") + " isWaitingPlay: " + isWaitingPlay); |
| | | |
| | | // 设置父子关系 |
| | | if (parentAction != null) |
| | | { |
| | | recordAction.SetParentAction(parentAction); |
| | | parentAction.AddChildAction(recordAction); |
| | | } |
| | | |
| | | // 设置WaitingPlay标记 |
| | | recordAction.SetWaitingPlay(isWaitingPlay); |
| | | |
| | | immediatelyActionList.Add(recordAction); |
| | | } |
| | | |
| | | protected void ImmediatelyPlayRun() |
| | | { |
| | | if (immediatelyActionList.Count > 0) |
| | | { |
| | | List<int> removeIndexList = new List<int>(); |
| | | |
| | | for (int i = immediatelyActionList.Count - 1; i >= 0; i--) |
| | | // 关键修复:从前往后遍历,确保按加入顺序执行 |
| | | for (int i = 0; i < immediatelyActionList.Count; i++) |
| | | { |
| | | var action = immediatelyActionList[i]; |
| | | if (action == null) |
| | |
| | | removeIndexList.Add(i); |
| | | continue; |
| | | } |
| | | |
| | | // 检查是否可以开始执行(WaitingPlay条件检查) |
| | | if (!action.CanStartExecution()) |
| | | { |
| | | continue; |
| | | } |
| | | |
| | | // 检查同级的前置兄弟节点:如果有相同父节点且索引更小的节点还在执行,则等待 |
| | | bool shouldWaitForSibling = false; |
| | | if (action.isWaitingPlay && action.parentAction != null) |
| | | { |
| | | for (int j = 0; j < i; j++) |
| | | { |
| | | var prevAction = immediatelyActionList[j]; |
| | | if (prevAction != null && prevAction.parentAction == action.parentAction) |
| | | { |
| | | // 找到同级前置节点,如果它还在执行中,则当前节点需要等待 |
| | | if (!prevAction.IsFinished()) |
| | | { |
| | | shouldWaitForSibling = true; |
| | | // BattleDebug.LogError($"RecordPlayer: {action.GetType().Name} 等待同级前置节点 {prevAction.GetType().Name} 完成"); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (shouldWaitForSibling) |
| | | { |
| | | continue; |
| | | } |
| | | |
| | | if (!action.IsFinished()) |
| | | { |
| | | action.Run(); |
| | |
| | | removeIndexList.Add(i); |
| | | } |
| | | |
| | | // 从后往前删除,确保索引不会因为删除而错位 |
| | | for (int i = removeIndexList.Count - 1; i >= 0; i--) |
| | | { |
| | | int index = removeIndexList[i]; |
| | |
| | | if (currentRecordAction != null && currentRecordAction.IsFinished()) |
| | | { |
| | | var guid = currentRecordAction.GetBattleFieldGuid(); |
| | | BattleDebug.LogError("record action " + currentRecordAction.GetType() + " play finished"); |
| | | // BattleDebug.LogError("record action " + currentRecordAction.GetType() + " play finished"); |
| | | currentRecordAction = null; |
| | | isWaitingNextAction = true; |
| | | waitTimer = 0f; |
| | |
| | | if (recordActionQueue.Count > 0) |
| | | { |
| | | currentRecordAction = recordActionQueue.Dequeue(); |
| | | BattleDebug.LogError("play record action " + currentRecordAction.GetType()); |
| | | // BattleDebug.LogError("play record action " + currentRecordAction.GetType()); |
| | | } |
| | | } |
| | | } |