private List <string> GetSystemList(bool isUpdate) { List <string> list = new List <string>(); List <Type> systemTypes = LCReflect.GetClassByType <BaseSystem>(); for (int i = 0; i < systemTypes.Count; i++) { Type sysTy = systemTypes[i]; SystemAttribute attribute = LCReflect.GetTypeAttr <SystemAttribute>(sysTy); if (isUpdate) { if (attribute == null || attribute.InFixedUpdate == false) { list.Add(sysTy.FullName); } } else { if (attribute != null && attribute.InFixedUpdate == true) { list.Add(sysTy.FullName); } } } return(list); }
//创建节点 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); }
public EntityComView(string comName, FieldInfo[] fieldInfos, BaseCom baseCom) { ComName = comName; ComAttribute comAttribute = LCReflect.GetTypeAttr <ComAttribute>(baseCom.GetType()); if (comAttribute != null) { ComName = comAttribute.ViewName; } for (int i = 0; i < fieldInfos.Length; i++) { FieldInfo info = fieldInfos[i]; ComKeyValueView keyValue = new ComKeyValueView(info.Name, info, baseCom); ComValueAttribute comValueAttribute = LCReflect.GetFieldAttr <ComValueAttribute>(info); if (comValueAttribute != null) { if (comValueAttribute.ViewEditor) { EditorValueList.Add(keyValue); } else { if (comValueAttribute.ShowView) { ValueList.Add(keyValue); } } } } }
private List <EntityComValueJson> GetSelComEditorValues() { FieldInfo[] fields = LCReflect.GetTypeFieldInfos(SelCom); List <EntityComValueJson> comValues = new List <EntityComValueJson>(); for (int i = 0; i < fields.Length; i++) { FieldInfo info = fields[i]; ComValueAttribute comValueAttribute = LCReflect.GetFieldAttr <ComValueAttribute>(info); if (comValueAttribute != null) { if (comValueAttribute.ViewEditor) { comValues.Add(new EntityComValueJson() { Name = info.Name, Type = info.FieldType.ToString(), Value = "", }); } } } return(comValues); }
private void DrawNodeWindow(int id) { //前提 if (Json.Premise == null) { EDTypeField.CreateLableField("无节点前提:", "", mRect.width, 20); } else { Type premiseType = LCReflect.GetType(Json.Premise.TypeFullName); if (premiseType == null) { Json.Premise = null; } else { EDTypeField.CreateLableField("节点前提:" + Json.Premise.Name + "...", "", mRect.width, 20); } } //信息 EDTypeField.CreateLableField("节点类型:" + Json.Type.ToString(), "", mRect.width, 20); EDTypeField.CreateLableField("节点ID:" + MId, "", mRect.width, 20); DrawEditorNodeKeyValue(); }
//注册系统 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); } }
/// <summary> /// 检测组件是否是全局单一 /// </summary> /// <param name="comType"></param> /// <returns></returns> public static bool CheckComIsGlobal(Type comType) { if (comType == null) { return(false); } ComAttribute comAttribute = LCReflect.GetTypeAttr <ComAttribute>(comType); if (comAttribute == null) { return(false); } return(comAttribute.IsGlobal); }
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); } }
private void DrawEditorNodeKeyValue() { EDLayout.CreateScrollView(ref valuePos, "", mRect.width, mRect.height, ((width, height) => { //可编辑键值 for (int j = 0; j < Json.KeyValues.Count; j++) { NodeKeyValue keyValue = Json.KeyValues[j]; object value = LCConvert.StrChangeToObject(keyValue.Value, keyValue.TypeFullName); Type ty = LCReflect.GetType(keyValue.TypeFullName); EDTypeField.CreateTypeField(keyValue.KeyName + "= ", ref value, ty, width - 10, 20); keyValue.Value = value.ToString(); } })); }
/// <summary> /// 处理实体组件 /// </summary> private static List <EntityComView> HandleEntityComs(Entity entity) { List <EntityComView> comViews = new List <EntityComView>(); //组件名 HashSet <string> entityComs = entity.GetAllComStr(); foreach (string comName in entityComs) { BaseCom com = entity.GetCom(comName); FieldInfo[] fields = LCReflect.GetTypeFieldInfos(com.GetType()); EntityComView comView = new EntityComView(comName, fields, com); comViews.Add(comView); } return(comViews); }
private void GetEditorNodeKeyValue() { Type nodeType = LCReflect.GetType(Json.TypeFullName); FieldInfo[] fields = LCReflect.GetTypeFieldInfos(nodeType); for (int i = 0; i < fields.Length; i++) { FieldInfo info = fields[i]; NodeValueAttribute nodeValueAttribute = LCReflect.GetFieldAttr <NodeValueAttribute>(info); if (nodeValueAttribute != null) { if (nodeValueAttribute.ViewEditor) { object defauleValue = LCReflect.GeTypeDefaultFieldValue(Json.TypeFullName, info.Name); UpdateNodeKeyValue(info, defauleValue); } } } }
//组件编辑界面 private void ShowSelComWindow(float width, float height) { List <EntityComValueJson> values = UpdateSelComEditorValues(); EDLayout.CreateScrollView(ref ComValuePos, "Box", width, height, () => { for (int i = 0; i < values.Count; i++) { EntityComValueJson comView = values[i]; Type resType = null; resType = LCReflect.GetType(comView.Type); if (resType == null) { resType = LCReflect.GetType(comView.Type); } object value = LCConvert.StrChangeToObject(comView.Value, resType.FullName); EDTypeField.CreateTypeField(comView.Name + "= ", ref value, resType, width, 40); SetSelComJson(comView.Name, value.ToString()); } }); }
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); } }
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); } }
/// <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); } } }); }
private void ShowCreateNodeMenu() { List <string> showStrs = new List <string>(); //控制节点 List <Type> controlTypes = LCReflect.GetClassByType <NodeControl>(); for (int i = 0; i < controlTypes.Count; i++) { NodeAttribute nodeAttribute = LCReflect.GetTypeAttr <NodeAttribute>(controlTypes[i]); if (nodeAttribute != null) { showStrs.Add("控制节点/" + nodeAttribute.ViewName); } else { showStrs.Add("控制节点/" + controlTypes[i].FullName); } } //行为节点 List <Type> actionTypes = LCReflect.GetClassByType <NodeAction>(); List <Type> actionShowTypes = new List <Type>(); for (int i = 0; i < actionTypes.Count; i++) { NodeAttribute nodeAttribute = LCReflect.GetTypeAttr <NodeAttribute>(actionTypes[i]); if (nodeAttribute == null) { showStrs.Add("基础行为节点/" + nodeAttribute.ViewName); actionShowTypes.Add(actionTypes[i]); } else { if (nodeAttribute.IsCommonAction) { showStrs.Add("基础行为/" + nodeAttribute.ViewName); actionShowTypes.Add(actionTypes[i]); } else { if (ShowDec) { if (nodeAttribute.IsBevNode == false) { showStrs.Add("扩展行为/" + nodeAttribute.ViewName); actionShowTypes.Add(actionTypes[i]); } } else { if (nodeAttribute.IsBevNode) { showStrs.Add("扩展行为/" + nodeAttribute.ViewName); actionShowTypes.Add(actionTypes[i]); } } } } } EDPopMenu.CreatePopMenu(showStrs, (int index) => { Debug.Log("创建节点》》》》》》》》》" + index + " " + controlTypes.Count + " >>" + actionShowTypes.Count); //创建控制 if (index <= controlTypes.Count - 1) { NodeDataJson node = CreateNodeJson(NodeType.Control, controlTypes[index].FullName, showStrs[index], curMousePos); //创建显示 NodeEditor nodeEditor = new NodeEditor(new Rect(new Vector2((float)node.PosX, (float)node.PosY), new Vector2(200, 100)), node, null, NodeEventCallBack); showNodeEditor.Add(nodeEditor); GUI.changed = true; } //创建行为 else { Debug.Log("创建行为节点》》》》》》》》》" + (index - controlTypes.Count)); NodeDataJson node = CreateNodeJson(NodeType.Action, actionShowTypes[index - controlTypes.Count].FullName, showStrs[index], curMousePos); //创建显示 NodeEditor nodeEditor = new NodeEditor(new Rect(new Vector2((float)node.PosX, (float)node.PosY), new Vector2(200, 100)), node, null, NodeEventCallBack); showNodeEditor.Add(nodeEditor); GUI.changed = true; } }); }
//实体编辑界面 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); })); }); }
private void DrawPopMenu() { List <string> showStrs = new List <string>() { "连接父节点", "删除节点", "删除连接", }; //前提条件 List <Type> premiseTypes = LCReflect.GetClassByType <NodePremise>(); List <Type> premiseShowTypes = new List <Type>(); for (int i = 0; i < premiseTypes.Count; i++) { if (GetPremise(premiseTypes[i].FullName, Json.Premise) != null) { continue; } NodePremiseAttribute nodeAttribute = LCReflect.GetTypeAttr <NodePremiseAttribute>(premiseTypes[i]); if (nodeAttribute == null || nodeAttribute.GroupName == "") { showStrs.Add("添加前提/默认前提/" + nodeAttribute.ViewName); premiseShowTypes.Add(premiseTypes[i]); } else { showStrs.Add("添加前提/" + nodeAttribute.GroupName + "/" + nodeAttribute.ViewName); premiseShowTypes.Add(premiseTypes[i]); } } EDPopMenu.CreatePopMenu(showStrs, (int index) => { Debug.Log("CreatePopMenu》》" + index); if (index == 2 && ParEditor == null) { Debug.Log("没有父节点》》无法删除!!"); return; } if (index == 0 && ParEditor != null) { Debug.Log("已经有父节点》》无法连接!!"); return; } if (index <= 2) { CallBack(index, this); } else { index = index - 3; NodePremiseJson nullPremise = GetNullPremise(Json.Premise); string viewName = ""; Type premiseType = premiseShowTypes[index]; NodePremiseAttribute nodeAttribute = LCReflect.GetTypeAttr <NodePremiseAttribute>(premiseType); if (nodeAttribute == null) { viewName = premiseType.FullName; } else { viewName = nodeAttribute.ViewName; } NodePremiseJson addJson = new NodePremiseJson(); addJson.Name = viewName; addJson.Type = Core.Tree.PremiseType.AND; addJson.TypeFullName = premiseType.FullName; if (nullPremise == null) { Json.Premise = addJson; } else { nullPremise.OtherPremise = addJson; } } }); }
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); }