Exemplo n.º 1
0
        public BaseComponent NewComponent(ComponentActor actor, Type compType)
        {
            var actorType = actor.GetType();

            if (compMap.ContainsKey(actorType))
            {
                var list = compMap[actorType];
                foreach (var info in list)
                {
                    if (info.CompType == compType)
                    {
                        return(info.Instance(actor));
                    }
                }
            }
            LOGGER.Error($"{actor.GetType()}获取未注册的component:{compType}");
            return(default);
Exemplo n.º 2
0
        static bool isListenerLegal <TH>(IAgent agent) where TH : ITimerHandler
        {
            ComponentActor actor = default;

            if (agent is IComponentAgent)
            {
                var comp = (BaseComponent)agent.Owner;
                actor = comp.Actor;
            }
            else if (agent is IComponentActorAgent)
            {
                actor = (ComponentActor)agent.Owner;
            }

            var listenerType = typeof(TH);
            var agentType    = listenerType.BaseType.GetGenericArguments()[0];

            if (agentType.GetInterface(typeof(IComponentAgent).FullName) != null)
            {
                //comp
                var compType = agentType.BaseType.GenericTypeArguments[0];
                var legal    = ComponentMgr.Singleton.IsCompRegisted(actor, compType);
                if (!legal)
                {
                    LOGGER.Error($"TimerHandler类型错误,注册Timer的Actor未注册TimerHandler泛型参数类型Component,{actor.GetType()}未注册Comp:{compType}");
                }
                return(legal);
            }
            else if (agentType.GetInterface(typeof(IComponentActorAgent).FullName) != null)
            {
                //actor
                var legal = agentType == agent.GetType();
                if (!legal)
                {
                    LOGGER.Error($"TimerHandler类型错误,注册Timer的Actor与回调类型不一致{agent.GetType()} != {agentType}");
                }
                return(legal);
            }
            LOGGER.Error("TimerHandler类型错误");
            return(false);
        }