forked from egametang/ET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNumericWatcherComponent.cs
More file actions
74 lines (63 loc) · 1.81 KB
/
Copy pathNumericWatcherComponent.cs
File metadata and controls
74 lines (63 loc) · 1.81 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System;
using System.Collections.Generic;
namespace ET
{
public class NumericWatcherComponentAwakeSystem : AwakeSystem<NumericWatcherComponent>
{
public override void Awake(NumericWatcherComponent self)
{
NumericWatcherComponent.Instance = self;
self.Awake();
}
}
public class NumericWatcherComponentLoadSystem : LoadSystem<NumericWatcherComponent>
{
public override void Load(NumericWatcherComponent self)
{
self.Load();
}
}
/// <summary>
/// 监视数值变化组件,分发监听
/// </summary>
public class NumericWatcherComponent : Entity
{
public static NumericWatcherComponent Instance { get; set; }
private Dictionary<NumericType, List<INumericWatcher>> allWatchers;
public void Awake()
{
this.Load();
}
public void Load()
{
this.allWatchers = new Dictionary<NumericType, List<INumericWatcher>>();
HashSet<Type> types = Game.EventSystem.GetTypes(typeof(NumericWatcherAttribute));
foreach (Type type in types)
{
object[] attrs = type.GetCustomAttributes(typeof(NumericWatcherAttribute), false);
foreach (object attr in attrs)
{
NumericWatcherAttribute numericWatcherAttribute = (NumericWatcherAttribute)attr;
INumericWatcher obj = (INumericWatcher)Activator.CreateInstance(type);
if (!this.allWatchers.ContainsKey(numericWatcherAttribute.NumericType))
{
this.allWatchers.Add(numericWatcherAttribute.NumericType, new List<INumericWatcher>());
}
this.allWatchers[numericWatcherAttribute.NumericType].Add(obj);
}
}
}
public void Run(NumericType numericType, long id, long value)
{
List<INumericWatcher> list;
if (!this.allWatchers.TryGetValue(numericType, out list))
{
return;
}
foreach (INumericWatcher numericWatcher in list)
{
numericWatcher.Run(id, value);
}
}
}
}