yyl
2026-01-09 ed9bf64c03bf5fee5e115645de5a975baaa9041d
Main/System/Battle/RecordPlayer/RecordPlayer.cs
@@ -43,7 +43,7 @@
    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();
@@ -69,7 +69,7 @@
            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>();
@@ -97,13 +97,39 @@
        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)
@@ -111,6 +137,38 @@
                    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();
@@ -120,6 +178,7 @@
                removeIndexList.Add(i);
            }
            //  从后往前删除,确保索引不会因为删除而错位
            for (int i = removeIndexList.Count - 1; i >= 0; i--)
            {
                int index = removeIndexList[i];
@@ -166,7 +225,7 @@
        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;
@@ -179,7 +238,7 @@
            if (recordActionQueue.Count > 0)
            {
                currentRecordAction = recordActionQueue.Dequeue();
                BattleDebug.LogError("play record action " + currentRecordAction.GetType());
                // BattleDebug.LogError("play record action " + currentRecordAction.GetType());
            }
        }
    }