summaryrefslogtreecommitdiff
path: root/Assets/Scripts/Managers/UnitManager.cs
blob: 6196e892ea7a45955c7816605cc39e3ae62e35a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class UnitManager : Singleton<UnitManager>
{
	public PCController pc { get; private set; }

	public List<MonsterController> monsters { get; private set; }

    private Dictionary<UnitController, List<UnitSnapshot>> m_Snapshots = new Dictionary<UnitController, List<UnitSnapshot>>();

	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<UnitSnapshot> 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<UnitSnapshot>(unit.unitDetail.snapshotAvatarPath);
        if(obj)
        {
            snap = Object.Instantiate<UnitSnapshot>(obj);
            //snap.gameObject.hideFlags = HideFlags.HideInHierarchy | HideFlags.DontSave;
            snap.Initialize(unit);
            snap.active = false;
        }
        return snap;
    } 

    public void ReleaseSnapshot(ref UnitSnapshot snap)
    {
        List<UnitSnapshot> snapshots;
        if (!m_Snapshots.TryGetValue(snap.owner, out snapshots))
        {
            snapshots = new List<UnitSnapshot>();
            m_Snapshots.Add(snap.owner, snapshots);
        }
        snapshots.Add(snap);
        snap = null;
    }

}