示例#1
0
        public static async ETTask Run(this CommandWatcherComponent self, string command, GalGameEngineComponent engine, GalGameEnginePara para)
        {
            List <ICommandWatcher> list;

            if (!self.allWatchers.TryGetValue(command, out list))
            {
                return;
            }

            for (int i = 0; i < list.Count; i++)
            {
                ICommandWatcher watcher = list[i];
                await watcher.Run(engine, para);
            }
        }
示例#2
0
        private static void Init(this CommandWatcherComponent self)
        {
            self.allWatchers = new Dictionary <string, List <ICommandWatcher> >();

            List <Type> types = Game.EventSystem.GetTypes(typeof(CommandWatcherAttribute));

            foreach (Type type in types)
            {
                object[] attrs = type.GetCustomAttributes(typeof(CommandWatcherAttribute), false);

                for (int i = 0; i < attrs.Length; i++)
                {
                    CommandWatcherAttribute numericWatcherAttribute = (CommandWatcherAttribute)attrs[i];
                    ICommandWatcher         obj = (ICommandWatcher)Activator.CreateInstance(type);
                    if (!self.allWatchers.ContainsKey(numericWatcherAttribute.Command))
                    {
                        self.allWatchers.Add(numericWatcherAttribute.Command, new List <ICommandWatcher>());
                    }
                    self.allWatchers[numericWatcherAttribute.Command].Add(obj);
                }
            }
        }