| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- using System;
- using System.Collections.Generic;
- namespace Model
- {
- [ObjectSystem]
- public class NumericWatcherComponentSystem : ObjectSystem<NumericWatcherComponent>, IAwake, ILoad
- {
- public void Awake()
- {
- this.Get().Awake();
- }
- public void Load()
- {
- this.Get().Load();
- }
- }
-
- /// <summary>
- /// 监视数值变化组件,分发监听
- /// </summary>
- public class NumericWatcherComponent : Component
- {
- private Dictionary<NumericType, List<INumericWatcher>> allWatchers;
- public void Awake()
- {
- this.Load();
- }
- public void Load()
- {
- this.allWatchers = new Dictionary<NumericType, List<INumericWatcher>>();
- Type[] types = DllHelper.GetMonoTypes();
- 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, int value)
- {
- List<INumericWatcher> list;
- if (!this.allWatchers.TryGetValue(numericType, out list))
- {
- return;
- }
- foreach (INumericWatcher numericWatcher in list)
- {
- numericWatcher.Run(id, value);
- }
- }
- }
- }
|