using System; using System.Collections.Generic; using System.Configuration; using UnityEngine; namespace Game { public class RoleSnapshotClass { public float time; public Sprite mSprite; public Vector3 BridgeDir; public Vector3 Pos; public void Reset() { time = 0; mSprite = null; BridgeDir = Vector3.zero; Pos = Vector3.zero; } } //主控玩家角色操作数据 public class SnapshotData { /// /// 释放出来的行为历史 /// List KeyHistory = new List(); static Queue tempHistoryQueue = new Queue(); const int HistoryLimit = 10; public SnapshotData() { Init(); } void Init() { ClearHistory(); } RoleSnapshotClass EnqueueOneMotionHistory() { if (tempHistoryQueue.Count > 0) return tempHistoryQueue.Dequeue(); return new RoleSnapshotClass(); } public void AddSnap(Sprite sprite,Vector3 bridgeDir,Vector3 pos) { while (KeyHistory.Count > HistoryLimit) { KeyHistory[0].Reset(); tempHistoryQueue.Enqueue(KeyHistory[0]); KeyHistory.RemoveAt(0); } RoleSnapshotClass snap = EnqueueOneMotionHistory(); snap.time = Time.time; snap.mSprite = sprite; snap.BridgeDir = bridgeDir; snap.Pos = pos; KeyHistory.Add(snap); } public void ClearHistory() { for (int i = 0; i < KeyHistory.Count; i++) { KeyHistory[i].Reset(); tempHistoryQueue.Enqueue(KeyHistory[i]); } KeyHistory.Clear(); } /// /// 获得后记得深度拷贝 避免引用类型问题 /// /// public RoleSnapshotClass[] GetHistoryArray() { return KeyHistory.ToArray(); } } }