Beispiel #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);
        }
Beispiel #2
0
        /// <summary>
        /// 渲染实体组件列表
        /// </summary>
        private static void DrawEntityComs(bool isShow, List <EntityComView> comViews, float width, float height)
        {
            if (isShow == false)
            {
                return;
            }
            EDLayout.CreateScrollView(ref ScrollPos, "GroupBox", width, height, () =>
            {
                for (int i = 0; i < comViews.Count; i++)
                {
                    EntityComView comView = comViews[i];
                    EditorGUILayout.Space();
                    GUI.color = Color.green;
                    //组件名
                    EditorGUILayout.LabelField("组件:", comView.ComName, GUILayout.Width(width), GUILayout.Height(20));

                    //可编辑键值
                    for (int j = 0; j < comView.EditorValueList.Count; j++)
                    {
                        GUI.color            = Color.red;
                        ComKeyValueView info = comView.EditorValueList[j];
                        object valueObj      = info.Info.GetValue(info.Com);
                        EDTypeField.CreateTypeField(info.KeyName + "= ", ref valueObj, info.Info.FieldType, width, 20);
                        LCReflect.SetTypeFieldValue(info.Com, info.KeyName, valueObj);
                    }

                    //只读值
                    for (int j = 0; j < comView.ValueList.Count; j++)
                    {
                        GUI.color            = Color.white;
                        ComKeyValueView info = comView.ValueList[j];
                        object valueObj      = info.Info.GetValue(info.Com);
                        EDTypeField.CreateLableField(info.KeyName + "= ", valueObj.ToString(), width, 20);
                    }
                }
            });
        }
Beispiel #3
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);
        }