/
ReputationManager.cs
59 lines (50 loc) · 1.63 KB
/
ReputationManager.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnityEngine;
namespace Reputations
{
public class ReputationManager : MonoBehaviour
{
public static ReputationManager master;
private static Dictionary<string, Action> actions = new Dictionary<string, Action>();
public static Dictionary<string, Action> Actions
{
get { return actions; }
}
private static List<IReputable> reputables = new List<IReputable>();
public static List<IReputable> Reputables
{
get { return reputables; }
}
void Awake()
{
if (master == null)
{
master = this;
}
else if (master != this)
{
Destroy(gameObject);
}
}
void Start()
{
//Load All Actions from a file
actions = new Dictionary<string, Action>();
var path = Path.Combine( Directory.GetCurrentDirectory(), "\\Actions.json" );
string jsonString = File.ReadAllText( path );
ActionList actionList = JsonUtility.FromJson<ActionList>(jsonString);
foreach (Action _action in actionList.actions)
{
actions.Add(_action.name, _action);
}
// Find all the reputable objects in the scene
var foundReputables = FindObjectsOfType<MonoBehaviour>().OfType<IReputable>();
foreach (IReputable reputable in foundReputables)
{
reputables.Add( reputable );
}
}
}
}