Пример #1
0
        //创建节点
        public static Node CreateNodeInstance(NodeDataJson node)
        {
            if (string.IsNullOrEmpty(node.TypeFullName))
            {
                return(null);
            }

            Node rootNode = LCReflect.CreateInstanceByType <Node>(node.TypeFullName);

            rootNode.Init(node.NodeId, node.Type, node.ChildMaxCnt);
            if (node.Premise != null)
            {
                NodePremise premise = LCReflect.CreateInstanceByType <NodePremise>(node.Premise.TypeFullName);
                premise.Init(rootNode.GetHashCode(), node.Premise.Type, node.Premise.TrueValue);

                if (node.Premise.OtherPremise != null)
                {
                    CreateNodePremise(rootNode.GetHashCode(), premise, node.Premise.OtherPremise);
                }

                rootNode.SetPremise(premise);
            }

            //属性设置
            for (int i = 0; i < node.KeyValues.Count; i++)
            {
                NodeKeyValue keyValue = node.KeyValues[i];
                object       value    = LCConvert.StrChangeToObject(keyValue.Value, keyValue.TypeFullName);
                LCReflect.SetTypeFieldValue(rootNode, keyValue.KeyName, value);
            }
            return(rootNode);
        }
Пример #2
0
        //注册系统
        private void RegSystems()
        {
            List <Type> systemTypes        = LCReflect.GetClassByType <BaseSystem>();
            List <Type> updateSystems      = new List <Type>();
            List <Type> fixedUpdateSystems = new List <Type>();

            //分组
            for (int i = 0; i < systemTypes.Count; i++)
            {
                Type            type = systemTypes[i];
                SystemAttribute attr = LCReflect.GetTypeAttr <SystemAttribute>(type);
                if (attr == null)
                {
                    //ECSLocate.ECSLog.Log("该系统没有设置系统特性>>>>>>", type.Name);
                    updateSystems.Add(type);
                }
                else
                {
                    if (attr.InFixedUpdate)
                    {
                        fixedUpdateSystems.Add(type);
                    }
                    else
                    {
                        updateSystems.Add(type);
                    }
                }
            }

            //排序
            updateSystems.Sort(SystemSortFunc);
            fixedUpdateSystems.Sort(SystemSortFunc);

            //注册
            for (int i = 0; i < updateSystems.Count; i++)
            {
                Type       type   = updateSystems[i];
                BaseSystem system = LCReflect.CreateInstanceByType <BaseSystem>(type.FullName);
                system.Init();

                ECSLocate.ECS.RegUpdateSystem(system);
            }
            for (int i = 0; i < fixedUpdateSystems.Count; i++)
            {
                Type       type   = fixedUpdateSystems[i];
                BaseSystem system = LCReflect.CreateInstanceByType <BaseSystem>(type.FullName);
                system.Init();

                ECSLocate.ECS.RegFixedUpdateSystem(system);
            }
        }
Пример #3
0
        private static void CreateNodePremise(int nodeId, NodePremise premise, NodePremiseJson premiseJson)
        {
            if (premiseJson == null)
            {
                return;
            }
            NodePremise otherPremise = LCReflect.CreateInstanceByType <NodePremise>(premiseJson.TypeFullName);

            otherPremise.Init(nodeId, premiseJson.Type);
            premise.AddOtherPrecondition(otherPremise);

            if (premiseJson.OtherPremise != null)
            {
                CreateNodePremise(nodeId, otherPremise, premiseJson.OtherPremise);
            }
        }
Пример #4
0
        private void RegAllSensor()
        {
            List <Type> worldSensorTypes  = LCReflect.GetInterfaceByType <IWorldSensor>();
            List <Type> entitySensorTypes = LCReflect.GetInterfaceByType <IEntitySensor>();

            if (worldSensorTypes == null && entitySensorTypes == null)
            {
                return;
            }

            //世界信息
            foreach (Type type in worldSensorTypes)
            {
                WorldSensorAttribute attr = LCReflect.GetTypeAttr <WorldSensorAttribute>(type);
                if (attr == null)
                {
                    ECSLocate.ECSLog.LogR("有世界信息没有加入特性 >>>>>>", type.Name);
                    return;
                }

                IWorldSensor sensor = LCReflect.CreateInstanceByType <IWorldSensor>(type.FullName);
                WorldSensorDict.Add((int)attr.InfoKey, sensor);
            }

            //实体信息
            foreach (Type type in entitySensorTypes)
            {
                EntitySensorAttribute attr = LCReflect.GetTypeAttr <EntitySensorAttribute>(type);
                if (attr == null)
                {
                    ECSLocate.ECSLog.LogR("有实体信息没有加入特性 >>>>>>", type.Name);
                    return;
                }

                IEntitySensor sensor = LCReflect.CreateInstanceByType <IEntitySensor>(type.FullName);
                EntitySensorDict.Add((int)attr.InfoKey, sensor);
            }
        }
Пример #5
0
        private void RegAllRequest()
        {
            List <Type> worldRequestTypes  = LCReflect.GetInterfaceByType <IWorldRequest>();
            List <Type> entityRequestTypes = LCReflect.GetInterfaceByType <IEntityRequest>();

            if (worldRequestTypes == null && entityRequestTypes == null)
            {
                return;
            }

            //世界请求
            foreach (Type type in worldRequestTypes)
            {
                WorldRequestAttribute attr = LCReflect.GetTypeAttr <WorldRequestAttribute>(type);
                if (attr == null)
                {
                    ECSLocate.ECSLog.Log("有请求没有加特性 走权重 >>>>>>", type.Name);
                    return;
                }

                IWorldRequest request = LCReflect.CreateInstanceByType <IWorldRequest>(type.FullName);
                WorldRequestDict.Add((int)attr.ReqId, request);
            }

            //实体请求
            foreach (Type type in entityRequestTypes)
            {
                EntityRequestAttribute attr = LCReflect.GetTypeAttr <EntityRequestAttribute>(type);
                if (attr == null)
                {
                    ECSLocate.ECSLog.Log("有请求没有加特性 走权重 >>>>>>", type.Name);
                    return;
                }

                IEntityRequest request = LCReflect.CreateInstanceByType <IEntityRequest>(type.FullName);
                EntityRequestDict.Add((int)attr.ReqId, request);
            }
        }
Пример #6
0
        public Entity CreateProduct(Action <object[]> func, params object[] data)
        {
            //解析参数
            int        entityId   = int.Parse(data[0].ToString());
            string     entityName = data[1].ToString();
            GameObject entityGo   = data.Length > 2?data[2] as GameObject:null;

            //配置数据
            EntityJson entityData = ECSLayerLocate.Info.GetEntityConf(entityName);

            if (entityData == null)
            {
                ECSLocate.ECSLog.LogError("实体配置数据不存在>>>>>>>", entityName);
                return(null);
            }

            //创建实体节点
            if (entityGo == null)
            {
                entityGo = (GameObject)ECSLocate.Factory.GetProduct <Object>(FactoryType.Asset, null, entityData.PrefabPath);
                entityGo = Object.Instantiate(entityGo);
            }
            if (entityGo == null)
            {
                ECSLocate.ECSLog.LogR("有一个实体没有节点>>>>>>>>", entityId, entityName);
            }
            else
            {
#if UNITY_EDITOR
                EntityEditorViewHelp sceneHelp = entityGo.AddComponent <EntityEditorViewHelp>();
                sceneHelp.EntityId = entityId;
#endif
            }

            //创建实体
            Entity entity = new Entity();

            //添加组件
            for (int i = 0; i < entityData.Coms.Count; i++)
            {
                EntityComJson comJson = entityData.Coms[i];
                BaseCom       com     = LCReflect.CreateInstanceByType <BaseCom>(comJson.ComName);

                //赋值
                for (int j = 0; j < comJson.Values.Count; j++)
                {
                    EntityComValueJson valueJson = comJson.Values[j];

                    object value = LCConvert.StrChangeToObject(valueJson.Value, valueJson.Type);
                    LCReflect.SetTypeFieldValue(com, valueJson.Name, value);
                }

                com.Init(entityId, entityGo);
                entity.AddCom(com);
            }

            func?.Invoke(new object[] { entityGo });

            ECSLocate.ECSLog.LogR("创建实体成功>>>>>>>>", entityName);
            return(entity);
        }