コード例 #1
0
ファイル: EventComponent.cs プロジェクト: isoundy000/Card_All
        public void Load()
        {
            this.allEvents = new Dictionary <EventIdType, List <IEventMethod> >();

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

                foreach (object attr in attrs)
                {
                    EventAttribute aEventAttribute = (EventAttribute)attr;
                    object         obj             = Activator.CreateInstance(type);
                    if (!this.allEvents.ContainsKey((EventIdType)aEventAttribute.Type))
                    {
                        this.allEvents.Add((EventIdType)aEventAttribute.Type, new List <IEventMethod>());
                    }
                    this.allEvents[(EventIdType)aEventAttribute.Type].Add(new IEventMonoMethod(obj));
                }
            }

            // hotfix dll
            Type[] hotfixTypes = DllHelper.GetHotfixTypes();
            foreach (Type type in hotfixTypes)
            {
                object[] attrs = type.GetCustomAttributes(typeof(EventAttribute), false);
                foreach (object attr in attrs)
                {
                    EventAttribute aEventAttribute = (EventAttribute)attr;
#if ILRuntime
                    IEventMethod method = new IEventILMethod(type, "Run");
#else
                    object       obj    = Activator.CreateInstance(type);
                    IEventMethod method = new IEventMonoMethod(obj);
#endif
                    if (!allEvents.ContainsKey((EventIdType)aEventAttribute.Type))
                    {
                        allEvents.Add((EventIdType)aEventAttribute.Type, new List <IEventMethod>());
                    }
                    allEvents[(EventIdType)aEventAttribute.Type].Add(method);
                }
            }
        }
コード例 #2
0
        private void Register()
        {
            Type[] types = DllHelper.GetMonoTypes();
            foreach (Type type in types)
            {
                object[] attrs = type.GetCustomAttributes(typeof(ObjectEventAttribute), false);

                if (attrs.Length == 0)
                {
                    continue;
                }

                object        obj          = Activator.CreateInstance(type);
                IObjectSystem objectSystem = obj as IObjectSystem;
                if (objectSystem == null)
                {
                    Log.Error($"组件事件没有继承IObjectEvent: {type.Name}");
                    continue;
                }
                this.disposerEvents[objectSystem.Type()] = objectSystem;
            }


            this.allEvents.Clear();
            foreach (Type type in types)
            {
                object[] attrs = type.GetCustomAttributes(typeof(EventAttribute), false);

                foreach (object attr in attrs)
                {
                    EventAttribute aEventAttribute = (EventAttribute)attr;
                    object         obj             = Activator.CreateInstance(type);
                    if (!this.allEvents.ContainsKey((EventIdType)aEventAttribute.Type))
                    {
                        this.allEvents.Add((EventIdType)aEventAttribute.Type, new List <IEventMethod>());
                    }
                    this.allEvents[(EventIdType)aEventAttribute.Type].Add(new IEventMonoMethod(obj));
                }
            }

            // hotfix dll
            Type[] hotfixTypes = DllHelper.GetHotfixTypes();
            foreach (Type type in hotfixTypes)
            {
                object[] attrs = type.GetCustomAttributes(typeof(EventAttribute), false);
                foreach (object attr in attrs)
                {
                    EventAttribute aEventAttribute = (EventAttribute)attr;
#if ILRuntime
                    IEventMethod method = new IEventILMethod(type, "Run");
#else
                    object       obj    = Activator.CreateInstance(type);
                    IEventMethod method = new IEventMonoMethod(obj);
#endif
                    if (!allEvents.ContainsKey((EventIdType)aEventAttribute.Type))
                    {
                        allEvents.Add((EventIdType)aEventAttribute.Type, new List <IEventMethod>());
                    }
                    allEvents[(EventIdType)aEventAttribute.Type].Add(method);
                }
            }
        }