using System.Collections; using System.Collections.Generic; using UnityEngine; public class UnitManager : Singleton { public PCController pc { get; private set; } public List monsters { get; private set; } private Dictionary> m_Snapshots = new Dictionary>(); public void SetPlayerCharacter(PCController pc) { this.pc = pc; } public UnitSnapshot ClaimSnapshotSolo(UnitSnapshotInfo info) { UnitSnapshot snapshot = ClaimSnapshot(info.unit); snapshot.ApplySnapshot(info); return snapshot; } public UnitSnapshot ClaimSnapshot(UnitController unit) { List snapshots; UnitSnapshot snap = null; if (m_Snapshots.TryGetValue(unit, out snapshots)) { snap = snapshots[snapshots.Count - 1]; snapshots.RemoveAt(snapshots.Count - 1); return snap; } var obj = ResourceManager.Instance.LoadAsset(unit.unitDetail.snapshotAvatarPath); if(obj) { snap = Object.Instantiate(obj); snap.owner = unit; } return snap; } public void ReleaseSnapshot(ref UnitSnapshot snap) { List snapshots; if (!m_Snapshots.TryGetValue(snap.owner, out snapshots)) { snapshots = new List(); m_Snapshots.Add(snap.owner, snapshots); } snapshots.Add(snap); snap = null; } }