| | |
| | | private Queue<RecordAction> recordActionQueue = new Queue<RecordAction>(); |
| | | protected RecordAction currentRecordAction; |
| | | |
| | | protected List<RecordAction> immediatelyActionList = new List<RecordAction>(); |
| | | |
| | | private bool isWaitingNextAction = false; |
| | | private float waitTimer = 0f; |
| | | private const float waitInterval = 0.2f; |
| | |
| | | |
| | | public bool IsPlaying() |
| | | { |
| | | return currentRecordAction != null || recordActionQueue.Count > 0; |
| | | return currentRecordAction != null || recordActionQueue.Count > 0 || immediatelyActionList.Count > 0; |
| | | } |
| | | |
| | | public void PlayRecord(RecordAction recordAction) |
| | |
| | | } |
| | | } |
| | | |
| | | public void InsertRecord(RecordAction recordAction) |
| | | { |
| | | BattleDebug.LogError("Insert record action " + recordAction.GetType()); |
| | | if (currentRecordAction != null) |
| | | { |
| | | Queue<RecordAction> tempQueue = new Queue<RecordAction>(); |
| | | tempQueue.Enqueue(recordAction); |
| | | while (recordActionQueue.Count > 0) |
| | | { |
| | | tempQueue.Enqueue(recordActionQueue.Dequeue()); |
| | | } |
| | | recordActionQueue = tempQueue; |
| | | } |
| | | else |
| | | { |
| | | recordActionQueue.Enqueue(recordAction); |
| | | } |
| | | } |
| | | |
| | | public void ImmediatelyPlay(RecordAction recordAction) |
| | | { |
| | | 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--) |
| | | { |
| | | var action = immediatelyActionList[i]; |
| | | if (action.IsFinished()) |
| | | { |
| | | removeIndexList.Add(i); |
| | | } |
| | | else |
| | | { |
| | | action.Run(); |
| | | } |
| | | } |
| | | |
| | | for (int i = removeIndexList.Count - 1; i >= 0; i--) |
| | | { |
| | | immediatelyActionList.RemoveAt(removeIndexList[i]); |
| | | } |
| | | } |
| | | } |
| | | |
| | | public virtual void Run() |
| | | { |
| | | ImmediatelyPlayRun(); |
| | | |
| | | // 等待下一个action |
| | | if (isWaitingNextAction) |
| | | { |