-
Notifications
You must be signed in to change notification settings - Fork 0
/
StateProgressDictionary.cs
36 lines (31 loc) · 1.08 KB
/
StateProgressDictionary.cs
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Sirenix.OdinInspector;
public abstract class StateProgressDictionary<T> : ProgressDictionary
{
[SerializeField]
private T defaultValue;
[ShowInInspector, SerializeField]
private SerializedDictionary<GenericProgressTracker, T> _stateDictionary = new SerializedDictionary<GenericProgressTracker, T>();
public T CurrentState
{
get
{
if (currentProgressTracker == null)
return defaultValue;
return _stateDictionary[currentProgressTracker];
}
}
public override void EnableAutoUpdate()
{
foreach (KeyValuePair<GenericProgressTracker, T> pair in _stateDictionary)
pair.Key.TrackerUpdated += UpdateCurrent;
}
public override void DisableAutoUpdate()
{
foreach (KeyValuePair<GenericProgressTracker, T> pair in _stateDictionary)
pair.Key.TrackerUpdated -= UpdateCurrent;
}
private void UpdateCurrent(GenericProgressTracker tracker) => currentProgressTracker = tracker;
}