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 <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); }
//注册系统 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 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); } }
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 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; } } }); }
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; } }); }