private void SetSelComJson(string name, string value) { EntityComJson comJson = null; for (int i = 0; i < SelEntity.Coms.Count; i++) { if (SelEntity.Coms[i].ComName == SelCom.FullName) { comJson = SelEntity.Coms[i]; break; } } for (int j = 0; j < comJson.Values.Count; j++) { if (comJson.Values[j].Name == name) { comJson.Values[j].Value = value; break; } } }
private List <EntityComValueJson> UpdateSelComEditorValues() { List <EntityComValueJson> values = GetSelComEditorValues(); EntityComJson comJson = null; for (int i = 0; i < SelEntity.Coms.Count; i++) { if (SelEntity.Coms[i].ComName == SelCom.FullName) { comJson = SelEntity.Coms[i]; break; } } if (comJson == null) { return(values); } //更新 for (int i = 0; i < values.Count; i++) { for (int j = 0; j < comJson.Values.Count; j++) { if (comJson.Values[j].Name == values[i].Name) { values[i].Value = comJson.Values[j].Value; break; } } } comJson.Values = values; return(values); }
//渲染实体列表 private void DrawEntityJsonList() { //实体列表 EDLayout.CreateScrollView(ref LeftPos, "box", position.width * 0.2f, position.height, (float width, float height) => { for (int i = 0; i < MEntityJsonList.List.Count; i++) { EntityJson entity = MEntityJsonList.List[i]; EDButton.CreateBtn(entity.EntityName, width, 25, () => { SelEntityChange(entity); }); } //添加实体 EDButton.CreateBtn("新建实体", width, 30, () => { EDPopPanel.PopWindow("输入实体名>>>>>>", (x) => { if (CheckContainEntity(x)) { Debug.LogError("实体名重复>>>>>>>>>>>>" + x); return; } EntityJson json = new EntityJson(); json.EntityName = x; //默认添加Go组件 EntityComJson goComJson = new EntityComJson() { ComName = "LCECS.Core.ECS.GameObjectCom", }; json.Coms.Add(goComJson); MEntityJsonList.List.Add(json); SelEntityChange(json); }); }); }); //编辑实体 EDLayout.CreateVertical("box", position.width * 0.4f, position.height, (float width, float height) => { if (SelEntity != null) { ShowSelEntityWindow(width); } }); //实体预览 EDLayout.CreateVertical("box", position.width * 0.3f, position.height, (float width, float height) => { if (EntityEditor != null) { EntityEditor.DrawPreview(GUILayoutUtility.GetRect(300, 200)); } //实体编辑 if (SelCom != null) { ShowSelComWindow(width, position.height * 0.5f); } }); }
//实体编辑界面 private void ShowSelEntityWindow(float width) { //基础配置只读 EDTypeField.CreateLableField("实体名:", SelEntity.EntityName, width, 20); object tipobj = SelEntity.TipStr; EDTypeField.CreateTypeField("描述信息:", ref tipobj, typeof(string), width, 20); SelEntity.TipStr = tipobj.ToString(); //决策分组 SelEntity.Group = (EntityDecGroup)EditorGUILayout.EnumPopup("实体决策分组", SelEntity.Group); EditorGUILayout.Space(); //预制体路径 EditorGUILayout.LabelField("选择预制体:"); GameObject prefab = null; prefab = EditorGUILayout.ObjectField(prefab, typeof(GameObject), false) as GameObject; if (prefab != null) { SelEntity.PrefabPath = AssetDatabase.GetAssetPath(prefab); } EditorGUILayout.LabelField("预制体路径:"); EditorGUILayout.LabelField(SelEntity.PrefabPath, "", "box"); EditorGUILayout.Space(); //组件列表 EditorGUILayout.LabelField("组件列表:"); EDLayout.CreateScrollView(ref ComListPos, "box", width, 150, () => { for (int i = 0; i < SelEntity.Coms.Count; i++) { //按钮名 string btnName = SelEntity.Coms[i].ComName; Type comType = LCReflect.GetType(SelEntity.Coms[i].ComName); if (comType != null) { ComAttribute comAttribute = LCReflect.GetTypeAttr <ComAttribute>(comType); if (comAttribute != null) { btnName = comAttribute.ViewName; } } else { SelEntity.Coms.RemoveAt(i); continue; } EDButton.CreateBtn(btnName, width * 0.8f, 20, () => { int comIndex = i; EDPopMenu.CreatePopMenu(new List <string>() { "编辑组件", "删除组件" }, (int index) => { if (index == 0) { SelCom = LCReflect.GetType(SelEntity.Coms[comIndex].ComName); } else if (index == 1) { SelEntity.Coms.RemoveAt(comIndex); } }); }); EditorGUILayout.Space(); } }); //添加组件 EDButton.CreateBtn("添加组件", 200, 50, () => { List <Type> comTyps = LCReflect.GetClassByType <BaseCom>(); List <string> showList = new List <string>(); List <Type> showTyps = new List <Type>(); for (int j = 0; j < comTyps.Count; j++) { if (CheckContainCom(comTyps[j].FullName)) { continue; } showTyps.Add(comTyps[j]); ComAttribute comAttribute = LCReflect.GetTypeAttr <ComAttribute>(comTyps[j]); if (comAttribute != null) { if (comAttribute.GroupName == "") { comAttribute.GroupName = "Default"; } showList.Add(comAttribute.GroupName + "/" + comAttribute.ViewName); } else { showList.Add(comTyps[j].FullName); } } EDPopMenu.CreatePopMenu(showList, (int index) => { Type comType = showTyps[index]; if (CheckContainCom(comType.FullName)) { Debug.LogError("重复的组件>>>>>>>>" + comType.FullName); return; } EntityComJson comJson = new EntityComJson() { ComName = comType.FullName, }; SelEntity.Coms.Add(comJson); }); }); //保存配置 EDButton.CreateBtn("保存配置", 200, 50, SaveEntityJsonList); //删除实体 EDButton.CreateBtn("删除实体", 200, 30, () => { EDDialog.CreateDialog("删除", "确认删除该实体吗?", (() => { MEntityJsonList.List.Remove(SelEntity); SelEntityChange(null); })); }); }
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); }