protected override void Common1() { nodeValue.subTreeValue = EditorGUILayout.LongField("SubTreeValue:", nodeValue.subTreeValue); string[] nameArr = EnumNames.GetEnumNames <SUB_TREE_TYPE>(); int index = EnumNames.GetEnumIndex <SUB_TREE_TYPE>((SUB_TREE_TYPE)nodeValue.subTreeType); int result = EditorGUILayout.Popup(new GUIContent("子树类型"), index, nameArr); nodeValue.subTreeType = (int)(EnumNames.GetEnum <SUB_TREE_TYPE>(result)); nodeValue.subTreeConfig = EditorGUILayout.TextField(new GUIContent("配置文件"), nodeValue.subTreeConfig); GUILayout.Space(5); if (nodeValue.subTreeType == (int)SUB_TREE_TYPE.CONFIG) { DataHandler dataHandler = new DataHandler(); dataHandler.DeleteSubTreeChild(nodeValue.id); if (GUILayout.Button("选择子树配置文件")) { ConfigFileSelect configFileSelect = new ConfigFileSelect(); nodeValue.subTreeConfig = configFileSelect.Select(); } } else { if (GUILayout.Button("将子树存储为配置文件")) { ConfigFileSaveSubTree configFileSaveSubTree = new ConfigFileSaveSubTree(); configFileSaveSubTree.SaveSubTree(nodeValue.subTreeConfig, nodeValue.id); } } }
public static string GetTitle(NODE_TYPE nodeType) { int index = EnumNames.GetEnumIndex <NODE_TYPE>(nodeType); string title = EnumNames.GetEnumName <NODE_TYPE>(index); return(title); }
private string GetNodeName(NodeValue nodeValue) { int nodeIndex = EnumNames.GetEnumIndex <NODE_TYPE>((NODE_TYPE)nodeValue.NodeType); string name = EnumNames.GetEnumName <NODE_TYPE>(nodeIndex); return(string.Format("{0}_{1}", name, nodeValue.id)); }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (string.IsNullOrEmpty(EnumType) || string.IsNullOrEmpty(EnumNames) || this.Items.Count > 0) { return; } Type type = Type.GetType(EnumType, true); Array values = Enum.GetValues(type); string[] names = EnumNames.Split(','); for (int i = 0; i < names.Length; i++) { if (names[i] != "!") { Items.Add(new ListItem(names[i], ((int)values.GetValue(i)).ToString())); } if (values.GetValue(i).ToString() == SelectedEnum) { Items[Items.Count - 1].Selected = true; } } }
protected override void NodeName() { int index = EnumNames.GetEnumIndex <NODE_TYPE>((NODE_TYPE)nodeValue.NodeType); string name = EnumNames.GetEnumName <NODE_TYPE>(index); name = string.Format("{0}_{1}", name, nodeValue.id); EditorGUILayout.LabelField(name); base.NodeName(); }
private void CompositeNode(NodeValue nodeValue) { if (nodeValue.NodeType == (int)NODE_TYPE.CONDITION || nodeValue.NodeType == (int)NODE_TYPE.ACTION) { return; } EditorGUILayout.BeginHorizontal(/*"box"*/); { string[] nameArr = EnumNames.GetEnumNames <NODE_TYPE>(); List <string> nameList = new List <string>(nameArr); NODE_TYPE[] removeTypeArr = new NODE_TYPE[2] { NODE_TYPE.ACTION, NODE_TYPE.CONDITION }; for (int i = nameList.Count - 1; i >= 0; --i) { for (int j = 0; j < removeTypeArr.Length; ++j) { NODE_TYPE type = removeTypeArr[j]; int value = EnumNames.GetEnumIndex <NODE_TYPE>(type); string name = EnumNames.GetEnumName <NODE_TYPE>(value); if (name.CompareTo(nameList[i]) == 0) { nameList.RemoveAt(i); break; } } } nameArr = nameList.ToArray(); int index = EnumNames.GetEnumIndex <NODE_TYPE>((NODE_TYPE)nodeValue.NodeType); if (index > nameArr.Length) { index -= 2;//把 条件节点、行为节点,两个节点减掉 } if ((NODE_TYPE)nodeValue.NodeType != NODE_TYPE.SUB_TREE) { int result = EditorGUILayout.Popup(new GUIContent("改变节点类型"), index, nameArr); if (result != index) { nodeValue.NodeType = (int)(EnumNames.GetEnum <NODE_TYPE>(result)); nodeValue.nodeName = EnumNames.GetEnumName <NODE_TYPE>(result); nodeValue.function = NodeDescript.GetFunction((NODE_TYPE)nodeValue.NodeType);; Debug.LogError(nodeValue.nodeName); } } } EditorGUILayout.EndHorizontal(); }
public void Draw(NodeValue nodeValue) { if (null == nodeValue) { EditorGUILayout.LabelField("未选择节点"); return; } EditorGUILayout.BeginVertical("box"); { if (nodeValue.NodeType == (int)NODE_TYPE.CONDITION || nodeValue.NodeType == (int)NODE_TYPE.ACTION) { int index = EnumNames.GetEnumIndex <NODE_TYPE>((NODE_TYPE)nodeValue.NodeType); string name = EnumNames.GetEnumName <NODE_TYPE>(index); EditorGUILayout.LabelField(name); GUILayout.Space(5); } string nodeName = nodeValue.nodeName; EditorGUILayout.LabelField(nodeName); string nodeId = string.Format("节点_{0}", nodeValue.id); EditorGUILayout.LabelField(nodeId); GUI.enabled = false; nodeValue.isRootNode = EditorGUILayout.Toggle(new GUIContent("根节点"), nodeValue.isRootNode, GUILayout.Width(50)); GUI.enabled = true; if (nodeValue.parentNodeID >= 0) { string parentName = string.Format("父节点_{0}", nodeValue.parentNodeID); EditorGUILayout.LabelField(parentName); } if (nodeValue.identification > 0) { string identificationName = string.Format("类标识_{0}", nodeValue.identification); EditorGUILayout.LabelField(identificationName); CustomIdentification customIdentification = CustomNode.Instance.GetIdentification(nodeValue.identification); string className = customIdentification.ClassType.Name; EditorGUILayout.LabelField(className); } nodeValue.descript = EditorGUILayout.TextArea(nodeValue.descript, GUILayout.Height(50)); } EditorGUILayout.EndVertical(); DrawNode(nodeValue, "参数"); }
protected void TrySetValue() { try { if (SelectedIndex >= 0 && SelectedIndex < Options.Count) { Configuration.Value = EnumNames.FirstOrDefault(x => x.Value == Options[SelectedIndex]).Key; } } catch (Exception e) { AncoraLogger.Instance.LogException("Error parsing MultipleChoiceSetting's enum value.", e); } }
public void Draw(SkillHsmConfigNodeData nodeValue) { if (null == nodeValue) { EditorGUILayout.LabelField("未选择节点"); return; } EditorGUILayout.BeginVertical("box"); { //string nodeId = string.Format("节点 ID:{0}", nodeValue.Id); //EditorGUILayout.LabelField(nodeId); int index = EnumNames.GetEnumIndex <NODE_TYPE>((NODE_TYPE)nodeValue.NodeType); string name = EnumNames.GetEnumName <NODE_TYPE>(index); name = string.Format("节点类型:{0}", name); EditorGUILayout.LabelField(name); if (nodeValue.Identification > 0) { CustomIdentification customIdentification = CustomNode.Instance.GetIdentification((IDENTIFICATION)nodeValue.Identification); string typeName = string.Format("类 型:{0}", customIdentification.Name); EditorGUILayout.LabelField(typeName); string className = string.Format("类 名:{0}", customIdentification.Type.Name); EditorGUILayout.LabelField(className); //string identificationName = string.Format("类标识 :{0}", nodeValue.Identification); //EditorGUILayout.LabelField(identificationName); } GUILayout.Space(5); EditorGUILayout.BeginHorizontal(); { EditorGUILayout.LabelField("节点名:", GUILayout.Width(50)); nodeValue.NodeName = EditorGUILayout.TextField(nodeValue.NodeName, GUILayout.ExpandWidth(true)); } EditorGUILayout.EndHorizontal(); EditorGUILayout.LabelField("节点描述:"); nodeValue.Descript = EditorGUILayout.TextArea(nodeValue.Descript, GUILayout.Height(30)); GUILayout.Space(5); } EditorGUILayout.EndVertical(); DrawNode(nodeValue); }
public void Reset(BehaviorTreeData behaviorTreeData) { behaviorTreeData.nodeDic.Clear(); for (int i = 0; i < behaviorTreeData.nodeList.Count; ++i) { NodeValue nodeValue = behaviorTreeData.nodeList[i]; int index = EnumNames.GetEnumIndex <NODE_TYPE>((NODE_TYPE)nodeValue.NodeType); nodeValue.nodeName = EnumNames.GetEnumName <NODE_TYPE>(index); behaviorTreeData.nodeDic.Add(nodeValue.id, nodeValue); } BehaviorAnalysis.GetInstance().SetLoadConfigEvent(LoadConfig); _behaviorTreeEntity = new BehaviorTreeEntity(long.MaxValue, behaviorTreeData); BehaviorTreeEntity.CurrentDebugEntityId = _behaviorTreeEntity.EntityId; SetRunTimeDrawNode(_behaviorTreeEntity); NodeNotify.Clear(); }
// 绘制节点 private void DrawNodeWindows() { Action CallBack = () => { for (int i = 0; i < _nodeList.Count; i++) { SkillHsmConfigNodeData nodeValue = _nodeList[i]; int index = EnumNames.GetEnumIndex <NODE_TYPE>((NODE_TYPE)nodeValue.NodeType); string name = EnumNames.GetEnumName <NODE_TYPE>(index); name = string.Format("{0}_{1}", name, nodeValue.Id); Rect rect = GUI.Window(i, RectTExtension.RectTToRect(nodeValue.Position), DrawNodeWindow, name); nodeValue.Position = RectTExtension.RectToRectT(rect); DrawToChildCurve(nodeValue); } }; _treeNodeWindow.DrawWindow(CallBack); }
private static void CheckNode(List <NodeValue> nodeValueList) { int rootNodeCount = 0; NodeValue invalidNodeValue = null; // 开始绘制节点 // 注意:必须在 BeginWindows(); 和 EndWindows(); 之间 调用 GUI.Window 才能显示 for (int i = 0; i < nodeValueList.Count; i++) { NodeValue nodeValue = nodeValueList[i]; if (nodeValue.isRootNode) { ++rootNodeCount; } if (((NODE_TYPE)nodeValue.NodeType >= NODE_TYPE.CONDITION) && nodeValue.childNodeList.Count > 0) { invalidNodeValue = nodeValue; // 叶节点 不能有子节点 } } string meg = string.Empty; if (rootNodeCount > 1) { meg = "只能有一个根节点"; } else if (rootNodeCount == 0) { meg = "必须有一个根节点"; } if (null != invalidNodeValue) { int index = EnumNames.GetEnumIndex <NODE_TYPE>((NODE_TYPE)invalidNodeValue.NodeType); string name = EnumNames.GetEnumName <NODE_TYPE>(index); meg = string.Format("节点:{0} {1} 不能有子节点", invalidNodeValue.id, name); } if (TreeNodeWindow.window != null && !string.IsNullOrEmpty(meg)) { TreeNodeWindow.window.ShowNotification(meg); } }
private void SubTreeNode(NodeValue nodeValue) { nodeValue.subTreeValue = EditorGUILayout.LongField("SubTreeValue:", nodeValue.subTreeValue); string[] nameArr = EnumNames.GetEnumNames <SUB_TREE_TYPE>(); int index = EnumNames.GetEnumIndex <SUB_TREE_TYPE>((SUB_TREE_TYPE)nodeValue.subTreeType); int result = EditorGUILayout.Popup(new GUIContent("子树类型"), index, nameArr); nodeValue.subTreeType = (int)(EnumNames.GetEnum <SUB_TREE_TYPE>(result)); GUILayout.Space(8); nodeValue.subTreeConfig = EditorGUILayout.TextField(new GUIContent("配置文件"), nodeValue.subTreeConfig); GUILayout.Space(5); if (nodeValue.subTreeType == (int)SUB_TREE_TYPE.CONFIG) { if (null != BehaviorManager.behaviorDeleteSubTreeChild) { BehaviorManager.behaviorDeleteSubTreeChild(nodeValue.id); } if (GUILayout.Button("选择子树配置文件")) { if (null != BehaviorManager.behaviorSelectFile) { nodeValue.subTreeConfig = BehaviorManager.behaviorSelectFile(); } } } else { if (GUILayout.Button("将子树存储为配置文件")) { if (null != BehaviorManager.behaviorSaveSubTree) { BehaviorManager.behaviorSaveSubTree(nodeValue.subTreeConfig, nodeValue.id); } } } }
/// <summary> /// Sets the value. /// </summary> /// <param name="sField">The field.</param> /// <param name="indexValue">The index value.</param> /// <param name="data">The data.</param> /// <param name="dataOffset">The data offset.</param> /// <param name="dataSize">The data size.</param> /// <param name="reqType">The req type.</param> /// <param name="value">The value.</param> /// <exception cref="HfaPointerInsertNotSupportedException">Attempting to insert a pointer is not supported.</exception> /// <exception cref="HfaEnumerationNotFoundException">Occurs if the specified value is not a valid member of the enumeration for this field.</exception> public void SetInstValue(string sField, int indexValue, byte[] data, long dataOffset, int dataSize, char reqType, object value) { // If this field contains a pointer, then we wil adjust the data offset relative to it. // This updates the offset info, but doesn't change the first four bytes. if (Pointer != '\0') { int nCount; if (NumBytes > -1) { nCount = ItemCount; } else if (reqType == 's' && (ItemType == 'c' || ItemType == 'C')) { // Either a string or a character array nCount = 0; IEnumerable <char> strVal = value as IEnumerable <char>; if (strVal != null) { nCount = strVal.Count() + 1; } } else { nCount = indexValue + 1; } uint nOffset = (uint)nCount; Array.Copy(Hfa.LittleEndian(nOffset), 0, data, dataOffset + 4, 4); dataOffset += 8; dataSize -= 8; } // Pointers to char or uchar arrays requested as strings are handled as a special case if ((ItemType == 'c' || ItemType == 'C') && reqType == 's') { int nBytesToCopy = NumBytes; var strVal = (value as IEnumerable <char>)?.ToArray(); if (strVal != null) { nBytesToCopy = strVal.Length; } if (NumBytes == -1 && strVal != null) { nBytesToCopy = strVal.Length; } // Force a blank erase to remove previous characters byte[] blank = new byte[nBytesToCopy]; Array.Copy(blank, 0, data, dataOffset, nBytesToCopy); if (strVal != null) { ASCIIEncoding ascii = new ASCIIEncoding(); string str = new string(strVal); byte[] charData = ascii.GetBytes(str); Array.Copy(charData, 0, data, dataOffset, charData.Length); } return; } // Translate the passed type into different representations int nIntValue; double dfDoubleValue; if (reqType == 's') { nIntValue = int.Parse((string)value); dfDoubleValue = double.Parse((string)value); } else if (reqType == 'd') { dfDoubleValue = (double)value; nIntValue = Convert.ToInt32((double)value); } else if (reqType == 'i') { dfDoubleValue = Convert.ToDouble((int)value); nIntValue = (int)value; } else if (reqType == 'p') { throw new HfaPointerInsertNotSupportedException(); } else { return; } // Handle by type switch (ItemType) { case 'c': // Char64 case 'C': // Char128 if (reqType == 's') { // handled earlier as special case, } else { data[dataOffset + nIntValue] = (byte)nIntValue; } break; case 'e': // enums are stored as ushort case 's': // little s = ushort type if (ItemType == 'e' && reqType == 's') { nIntValue = EnumNames.IndexOf((string)value); if (nIntValue == -1) { throw new HfaEnumerationNotFoundException((string)value); } } // Each enumeration is stored as a 2-bit unsigned short entry. ushort num = (ushort)nIntValue; Array.Copy(Hfa.LittleEndian(num), 0, data, dataOffset + (2 * indexValue), 2); break; case 'S': // signed short Array.Copy(Hfa.LittleEndian((short)nIntValue), 0, data, dataOffset + (indexValue * 2), 2); break; case 't': case 'l': Array.Copy(Hfa.LittleEndian((uint)nIntValue), 0, data, dataOffset + (indexValue * 4), 4); break; case 'L': // Int32 Array.Copy(Hfa.LittleEndian(nIntValue), 0, data, dataOffset + (indexValue * 4), 4); break; case 'f': // Float (32 bit) float dfNumber = Convert.ToSingle(dfDoubleValue); Array.Copy(Hfa.LittleEndian(dfNumber), 0, data, dataOffset + (indexValue * 4), 4); break; case 'd': // Double (float 64) Array.Copy(Hfa.LittleEndian(dfDoubleValue), 0, data, dataOffset + (8 * indexValue), 8); break; case 'o': // object if (ItemObjectType == null) { break; } int nExtraOffset = 0; if (ItemObjectType.NumBytes > 0) { nExtraOffset = ItemObjectType.NumBytes * indexValue; } else { for (int iIndexCounter = 0; iIndexCounter < indexValue; iIndexCounter++) { nExtraOffset += ItemObjectType.GetInstBytes(data, dataOffset + nExtraOffset); } } if (!string.IsNullOrEmpty(sField)) { ItemObjectType.SetInstValue(sField, data, dataOffset + nExtraOffset, dataSize - nExtraOffset, reqType, value); } break; default: throw new ArgumentException(); } }
/// <summary> /// Parses the input string into a valid HfaField, or returns null /// if one could not be created. /// </summary> /// <param name="input">The input string.</param> /// <returns>The parsed string, or null if the field could not be created.</returns> public string Initialize(string input) { int length = input.Length; int start = 0; // Read the number if (!input.Contains(":")) { return(null); } ItemCount = short.Parse(input.ExtractTo(ref start, ":")); // is this a pointer? if (input[start] == 'p' || input[start] == '*') { start += 1; Pointer = input[start]; } // Get the general type start += 1; if (start == length) { return(null); } ItemType = input[start]; if (!"124cCesStlLfdmMbox".Contains(ItemType.ToString())) { throw new HfaFieldTypeException(ItemType); } // If this is an object, we extract the type of the object if (ItemType == 'o') { ItemObjectTypeString = input.ExtractTo(ref start, ","); } // If this is an inline object, we need to skip past the // definition, and then extract the object class name. // we ignore the actual definition, so if the object type isn't // already defined, things will not work properly. See the // file lceugr250)00)pct.aus for an example of inline defs. if (ItemType == 'x' && input[start] == '{') { int braceDepth = 1; start += 1; // Skip past the definition in braces while (braceDepth > 0 && start < input.Length) { if (input[start] == '{') { braceDepth++; } if (input[start] == '}') { braceDepth--; } start++; } ItemType = 'o'; ItemObjectTypeString = input.ExtractTo(ref start, ","); } // If this is an enumeration, we have to extract all the values. if (ItemType == 'e') { if (!input.Contains(":")) { return(null); } int enumCount = int.Parse(input.ExtractTo(ref start, ":")); if (EnumNames == null) { EnumNames = new List <string>(); } for (int ienum = 0; ienum < enumCount; ienum++) { EnumNames.Add(input.ExtractTo(ref start, ",")); } } // Extract the field name FieldName = input.ExtractTo(ref start, ","); // Return whatever is left in the string, which should be a new field. return(input.Substring(start, input.Length - start)); }
public static void CheckNode(List <NodeValue> nodeValueList) { int rootNodeCount = 0; NodeValue invalidNodeValue = null; rootNodeArr = new int[nodeValueList.Count]; bool rootNodeHasParent = false; // 开始绘制节点 // 注意:必须在 BeginWindows(); 和 EndWindows(); 之间 调用 GUI.Window 才能显示 for (int i = 0; i < nodeValueList.Count; i++) { NodeValue nodeValue = nodeValueList[i]; if (nodeValue.isRootNode) { rootNodeArr[rootNodeCount] = nodeValue.id; ++rootNodeCount; if (nodeValue.parentNodeID >= 0) { rootNodeHasParent = true; } } if (((NODE_TYPE)nodeValue.NodeType == NODE_TYPE.CONDITION || (NODE_TYPE)nodeValue.NodeType == NODE_TYPE.ACTION) && nodeValue.childNodeList.Count > 0) { invalidNodeValue = nodeValue; // 叶节点 不能有子节点 } } string meg = string.Empty; if (rootNodeCount > 1) { meg = string.Format("有多个根节点:"); for (int i = 0; i < rootNodeCount; ++i) { meg += string.Format("_{0} ", rootNodeArr[i]); } } else if (rootNodeCount == 0) { meg = "必须有一个根节点"; } else if (rootNodeHasParent) { meg = string.Format("跟节点_{0} 不能有父节点", rootNodeArr[0]); } if (null != invalidNodeValue) { int index = EnumNames.GetEnumIndex <NODE_TYPE>((NODE_TYPE)invalidNodeValue.NodeType); string name = EnumNames.GetEnumName <NODE_TYPE>(index); meg = string.Format("节点:{0} {1} 不能有子节点", invalidNodeValue.id, name); } if (TreeNodeWindow.window != null && !string.IsNullOrEmpty(meg)) { TreeNodeWindow.window.ShowNotification(meg); } }
public void GetTypeName() { int index = EnumNames.GetEnumIndex <NODE_TYPE>(_nodeType); _nodeName = EnumNames.GetEnumName <NODE_TYPE>(index); }
protected override void Common1() { HashSet <int> childHash = new HashSet <int>(); if (nodeValue.childNodeList.Count > 3) { if (null != TreeNodeWindow.window) { string msg = string.Format("判断节点 {0} 最多只能有三个节点", nodeValue.id); TreeNodeWindow.window.ShowNotification(msg); } while (nodeValue.childNodeList.Count > 3) { nodeValue.childNodeList.RemoveAt(nodeValue.childNodeList.Count - 1); } while (nodeValue.ifJudgeDataList.Count > 3) { nodeValue.ifJudgeDataList.RemoveAt(nodeValue.ifJudgeDataList.Count - 1); } } EditorGUILayout.BeginVertical("box"); { for (int i = 0; i < nodeValue.childNodeList.Count; ++i) { int childId = nodeValue.childNodeList[i]; childHash.Add(childId); IfJudgeData judgeData = nodeValue.ifJudgeDataList.Find((a) => { return(a.nodeId == childId); }); if (null == judgeData) { judgeData = new IfJudgeData(); judgeData.nodeId = childId; nodeValue.ifJudgeDataList.Add(judgeData); } judgeData.ifJudegType = ((i == 0) ? (int)NodeIfJudgeEnum.IF : (int)NodeIfJudgeEnum.ACTION); EditorGUILayout.BeginVertical("box"); { GUI.enabled = false; EditorGUILayout.IntField("nodeId:", judgeData.nodeId); { string[] nameArr = EnumNames.GetEnumNames <NodeIfJudgeEnum>(); int index = EnumNames.GetEnumIndex <NodeIfJudgeEnum>((NodeIfJudgeEnum)judgeData.ifJudegType); int result = EditorGUILayout.Popup(new GUIContent("节点类型"), index, nameArr); judgeData.ifJudegType = (int)(EnumNames.GetEnum <NodeIfJudgeEnum>(result)); } GUI.enabled = true; if (judgeData.ifJudegType == (int)NodeIfJudgeEnum.ACTION) { string[] nameArr = new string[] { "Fail", "Success" }; int oldValue = judgeData.ifResult; int result = EditorGUILayout.Popup(new GUIContent("执行条件"), judgeData.ifResult, nameArr); if (oldValue != result) { JudgeNodeChangeChildCondition(nodeValue, judgeData.nodeId, (ResultType)result); } } } EditorGUILayout.EndVertical(); } EditorGUILayout.BeginVertical("box"); { EditorGUILayout.LabelField("没有 if判断节点 返回结果对应类型的 执行节点"); string[] nameArr = new string[] { "Fail", "Success", "Running" }; nodeValue.defaultResult = EditorGUILayout.Popup(new GUIContent("默认返回结果"), nodeValue.defaultResult, nameArr); } EditorGUILayout.EndVertical(); } EditorGUILayout.EndVertical(); for (int i = nodeValue.ifJudgeDataList.Count - 1; i >= 0; --i) { IfJudgeData data = nodeValue.ifJudgeDataList[i]; if (!childHash.Contains(data.nodeId)) { nodeValue.ifJudgeDataList.RemoveAt(i); } } nodeValue.ifJudgeDataList.Sort((a, b) => { return(a.ifJudegType - b.ifJudegType); }); }
public static NodeParameter Draw(NodeParameter behaviorParameter, DrawParameterType drawParameterType, Action DelCallBack) { if (null == behaviorParameter) { return(behaviorParameter); } EditorGUILayout.BeginHorizontal(); { string[] parameterNameArr = EnumNames.GetEnumNames <ParameterType>(); int index = EnumNames.GetEnumIndex <ParameterType>((ParameterType)(behaviorParameter.parameterType)); ParameterType behaviorParameterType = EnumNames.GetEnum <ParameterType>(index); GUI.enabled = false; if (drawParameterType == DrawParameterType.NODE_PARAMETER) { EditorGUILayout.BeginHorizontal(); { behaviorParameter.index = EditorGUILayout.IntField(behaviorParameter.index, GUILayout.Width(30)); } EditorGUILayout.EndHorizontal(); } bool enableChangeType = (drawParameterType == DrawParameterType.BEHAVIOR_PARAMETER_ADD); GUI.enabled = enableChangeType && !BehaviorDataController.Instance.CurrentOpenConfigSubTree(); { index = EditorGUILayout.Popup(index, parameterNameArr); behaviorParameter.parameterType = (int)EnumNames.GetEnum <ParameterType>(index); GUILayout.Space(5); } GUI.enabled = true; if (drawParameterType == DrawParameterType.NODE_PARAMETER) { GUI.enabled = false; EditorGUILayout.BeginHorizontal(); { behaviorParameter.parameterName = EditorGUILayout.TextField(behaviorParameter.parameterName); } EditorGUILayout.EndHorizontal(); GUI.enabled = true; } if (drawParameterType == DrawParameterType.NODE_PARAMETER || drawParameterType == DrawParameterType.BEHAVIOR_PARAMETER) { GUI.enabled = !BehaviorDataController.Instance.CurrentOpenConfigSubTree(); if (GUILayout.Button("Del")) { if (null != DelCallBack) { DelCallBack(); } } GUI.enabled = true; } } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { if (drawParameterType == DrawParameterType.NODE_PARAMETER) { List <NodeParameter> parameterList = BehaviorDataController.Instance.BehaviorTreeData.parameterList; string[] parameterArr = new string[parameterList.Count]; int index = -1; for (int i = 0; i < parameterList.Count; ++i) { NodeParameter p = parameterList[i]; parameterArr[i] = p.CNName; if (behaviorParameter.parameterName.CompareTo(p.parameterName) == 0) { index = i; } } GUI.enabled = !BehaviorDataController.Instance.CurrentOpenConfigSubTree(); int result = EditorGUILayout.Popup(index, parameterArr, GUILayout.ExpandWidth(true)); GUI.enabled = true; if (result != index) { behaviorParameter.parameterName = parameterList[result].parameterName; } } else if (drawParameterType == DrawParameterType.BEHAVIOR_PARAMETER || drawParameterType == DrawParameterType.RUNTIME_PARAMETER) { GUI.enabled = false; behaviorParameter.parameterName = EditorGUILayout.TextField(behaviorParameter.parameterName); GUI.enabled = true; string cnName = EditorGUILayout.TextField(behaviorParameter.CNName); if (cnName.CompareTo(behaviorParameter.CNName) != 0) { TreeNodeWindow.window.ShowNotification("此处字段名只支持查看,不能修改"); } } else if (drawParameterType == DrawParameterType.BEHAVIOR_PARAMETER_ADD) { EditorGUILayout.BeginVertical(); { string oldName = behaviorParameter.parameterName; behaviorParameter.parameterName = EditorGUILayout.TextField("英文:", behaviorParameter.parameterName); if (oldName.CompareTo(behaviorParameter.parameterName) != 0) { bool isNumOrAlp = IsNumOrAlp(behaviorParameter.parameterName); if (!isNumOrAlp) { string msg = string.Format("参数名只能包含:数字、字母、下划线,且数字不能放在第一个字符位置"); TreeNodeWindow.window.ShowNotification(msg); behaviorParameter.parameterName = oldName; } } behaviorParameter.CNName = EditorGUILayout.TextField("中文", behaviorParameter.CNName); } EditorGUILayout.EndVertical(); } ParameterCompare[] compareEnumArr = new ParameterCompare[] { }; if (behaviorParameter.parameterType == (int)ParameterType.Int) { compareEnumArr = new ParameterCompare[] { ParameterCompare.GREATER, ParameterCompare.GREATER_EQUALS, ParameterCompare.LESS_EQUAL, ParameterCompare.LESS, ParameterCompare.EQUALS, ParameterCompare.NOT_EQUAL }; } if (behaviorParameter.parameterType == (int)ParameterType.Long) { compareEnumArr = new ParameterCompare[] { ParameterCompare.GREATER, ParameterCompare.GREATER_EQUALS, ParameterCompare.LESS_EQUAL, ParameterCompare.LESS, ParameterCompare.EQUALS, ParameterCompare.NOT_EQUAL }; } if (behaviorParameter.parameterType == (int)ParameterType.Float) { compareEnumArr = new ParameterCompare[] { ParameterCompare.GREATER, ParameterCompare.LESS }; } if (behaviorParameter.parameterType == (int)ParameterType.Bool) { compareEnumArr = new ParameterCompare[] { ParameterCompare.EQUALS, ParameterCompare.NOT_EQUAL }; } if (behaviorParameter.parameterType == (int)ParameterType.String) { compareEnumArr = new ParameterCompare[] { ParameterCompare.EQUALS, ParameterCompare.NOT_EQUAL }; } string[] compareArr = new string[compareEnumArr.Length]; int compare = behaviorParameter.compare; bool found = false; for (int i = 0; i < compareEnumArr.Length; ++i) { string name = System.Enum.GetName(typeof(ParameterCompare), compareEnumArr[i]); compareArr[i] = name; if ((ParameterCompare)behaviorParameter.compare == compareEnumArr[i]) { compare = i; found = true; } } if (!found) { compare = 0; } GUI.enabled = (drawParameterType != DrawParameterType.BEHAVIOR_PARAMETER) && (drawParameterType != DrawParameterType.RUNTIME_PARAMETER) && !BehaviorDataController.Instance.CurrentOpenConfigSubTree();; bool value = (drawParameterType != DrawParameterType.BEHAVIOR_PARAMETER) && (drawParameterType != DrawParameterType.RUNTIME_PARAMETER) && (drawParameterType != DrawParameterType.BEHAVIOR_PARAMETER_ADD); bool boolType = (behaviorParameter.parameterType == (int)ParameterType.Bool); if (value && !boolType) { compare = EditorGUILayout.Popup(compare, compareArr, GUILayout.Width(65)); behaviorParameter.compare = (int)(compareEnumArr[compare]); } GUI.enabled = true; if (boolType) { behaviorParameter.compare = (int)ParameterCompare.EQUALS; } GUI.enabled = true && !BehaviorDataController.Instance.CurrentOpenConfigSubTree(); { if (behaviorParameter.parameterType == (int)ParameterType.Int) { behaviorParameter.intValue = EditorGUILayout.IntField(behaviorParameter.intValue, GUILayout.Width(60)); } if (behaviorParameter.parameterType == (int)ParameterType.Long) { behaviorParameter.longValue = EditorGUILayout.LongField(behaviorParameter.longValue, GUILayout.Width(60)); } if (behaviorParameter.parameterType == (int)ParameterType.Float) { behaviorParameter.floatValue = EditorGUILayout.FloatField(behaviorParameter.floatValue, GUILayout.Width(60)); } if (behaviorParameter.parameterType == (int)ParameterType.Bool) { behaviorParameter.boolValue = EditorGUILayout.Toggle(behaviorParameter.boolValue, GUILayout.Width(60)); } if (behaviorParameter.parameterType == (int)ParameterType.String) { behaviorParameter.stringValue = EditorGUILayout.TextField(behaviorParameter.stringValue, GUILayout.Width(60)); } } GUI.enabled = true; } EditorGUILayout.EndHorizontal(); GUILayout.Space(5); return(behaviorParameter); }
public static BehaviorParameter Draw(BehaviorParameter behaviorParameter, DrawParameterType drawParameterType, Action DelCallBack) { if (null == behaviorParameter) { return(behaviorParameter); } { string[] parameterNameArr = EnumNames.GetEnumNames <BehaviorParameterType>(); int index = EnumNames.GetEnumIndex <BehaviorParameterType>((BehaviorParameterType)(behaviorParameter.parameterType)); BehaviorParameterType behaviorParameterType = EnumNames.GetEnum <BehaviorParameterType>(index); bool enableChangeType = (drawParameterType == DrawParameterType.GLOBAL_PARAMETER_ADD); GUI.enabled = enableChangeType; { index = EditorGUILayout.Popup(index, parameterNameArr); behaviorParameter.parameterType = (int)EnumNames.GetEnum <BehaviorParameterType>(index); GUILayout.Space(5); } GUI.enabled = true; } EditorGUILayout.BeginHorizontal(); { if (drawParameterType == DrawParameterType.NODE_PARAMETER) { List <BehaviorParameter> parameterList = BehaviorManager.Instance.GlobalParameter.parameterList; string[] parameterArr = new string[parameterList.Count]; int index = -1; for (int i = 0; i < parameterList.Count; ++i) { BehaviorParameter p = parameterList[i]; parameterArr[i] = p.parameterName; if (behaviorParameter.parameterName.CompareTo(p.parameterName) == 0) { index = i; } } int result = EditorGUILayout.Popup(index, parameterArr, GUILayout.ExpandWidth(true)); if (result != index) { behaviorParameter.parameterName = parameterArr[result]; } } else if (drawParameterType == DrawParameterType.GLOBAL_PARAMETER || (drawParameterType == DrawParameterType.GLOBAL_PARAMETER_ADD) || drawParameterType == DrawParameterType.RUNTIME_PARAMETER) { GUI.enabled = (drawParameterType == DrawParameterType.GLOBAL_PARAMETER_ADD); behaviorParameter.parameterName = EditorGUILayout.TextField(behaviorParameter.parameterName); GUI.enabled = true; } BehaviorCompare[] compareEnumArr = new BehaviorCompare[] { }; if (behaviorParameter.parameterType == (int)BehaviorParameterType.Int) { compareEnumArr = new BehaviorCompare[] { BehaviorCompare.GREATER, BehaviorCompare.GREATER_EQUALS, BehaviorCompare.LESS_EQUAL, BehaviorCompare.LESS, BehaviorCompare.EQUALS, BehaviorCompare.NOT_EQUAL }; } if (behaviorParameter.parameterType == (int)BehaviorParameterType.Float) { compareEnumArr = new BehaviorCompare[] { BehaviorCompare.GREATER, BehaviorCompare.LESS }; } if (behaviorParameter.parameterType == (int)BehaviorParameterType.Bool) { compareEnumArr = new BehaviorCompare[] { BehaviorCompare.EQUALS, BehaviorCompare.NOT_EQUAL }; } string[] compareArr = new string[compareEnumArr.Length]; int compare = behaviorParameter.compare; bool found = false; for (int i = 0; i < compareEnumArr.Length; ++i) { string name = System.Enum.GetName(typeof(BehaviorCompare), compareEnumArr[i]); compareArr[i] = name; if ((BehaviorCompare)behaviorParameter.compare == compareEnumArr[i]) { compare = i; found = true; } } if (!found) { compare = 0; } GUI.enabled = (drawParameterType != DrawParameterType.GLOBAL_PARAMETER) && (drawParameterType != DrawParameterType.RUNTIME_PARAMETER); { compare = EditorGUILayout.Popup(compare, compareArr, GUILayout.Width(65)); behaviorParameter.compare = (int)(compareEnumArr[compare]); } GUI.enabled = true; } EditorGUILayout.EndHorizontal(); GUILayout.Space(5); EditorGUILayout.BeginHorizontal(); { GUI.enabled = (drawParameterType != DrawParameterType.GLOBAL_PARAMETER); { if (behaviorParameter.parameterType == (int)BehaviorParameterType.Int) { behaviorParameter.intValue = EditorGUILayout.IntField("DefaultIntValue", behaviorParameter.intValue); } if (behaviorParameter.parameterType == (int)BehaviorParameterType.Float) { behaviorParameter.floatValue = EditorGUILayout.FloatField("DefaultFloatValue", behaviorParameter.floatValue); } if (behaviorParameter.parameterType == (int)BehaviorParameterType.Bool) { behaviorParameter.boolValue = EditorGUILayout.Toggle("DefaultBoolValue", behaviorParameter.boolValue); } } GUI.enabled = true; if (drawParameterType == DrawParameterType.NODE_PARAMETER || drawParameterType == DrawParameterType.GLOBAL_PARAMETER) { if (GUILayout.Button("Del")) { if (null != DelCallBack) { DelCallBack(); } } } } EditorGUILayout.EndHorizontal(); return(behaviorParameter); }
public void Draw(NodeValue nodeValue) { if (null == nodeValue) { EditorGUILayout.LabelField("未选择节点"); return; } GUI.enabled = !BehaviorManager.Instance.CurrentOpenConfigSubTree(); EditorGUILayout.BeginVertical("box"); { if (nodeValue.NodeType == (int)NODE_TYPE.CONDITION || nodeValue.NodeType == (int)NODE_TYPE.ACTION) { int index = EnumNames.GetEnumIndex <NODE_TYPE>((NODE_TYPE)nodeValue.NodeType); string name = EnumNames.GetEnumName <NODE_TYPE>(index); name = string.Format("{0}_{1}", name, nodeValue.id); EditorGUILayout.LabelField(name); GUILayout.Space(5); } string nodeName = nodeValue.nodeName; string msg = string.Format("{0}_{1}", nodeName, nodeValue.id); EditorGUILayout.LabelField(msg); if (nodeValue.NodeType == (int)NODE_TYPE.SUB_TREE) { SubTreeNode(nodeValue); } if (nodeValue.NodeType != (int)NODE_TYPE.CONDITION && nodeValue.NodeType != (int)NODE_TYPE.ACTION) { CompositeNode(nodeValue); } EntryNode(nodeValue); if (nodeValue.NodeType == (int)NODE_TYPE.DECORATOR_REPEAT) { nodeValue.repeatTimes = EditorGUILayout.IntField("重复执行次数", nodeValue.repeatTimes); } if (nodeValue.NodeType == (int)NODE_TYPE.IF_JUDEG) { IfJudge(nodeValue); } if (nodeValue.childNodeList.Count > 0) { if (nodeValue.NodeType != (int)NODE_TYPE.SUB_TREE) { nodeValue.moveWithChild = EditorGUILayout.Toggle(new GUIContent("同步移动子节点"), nodeValue.moveWithChild); } else { nodeValue.moveWithChild = false; } } if (nodeValue.parentNodeID >= 0) { string parentName = string.Format("父节点_{0}", nodeValue.parentNodeID); EditorGUILayout.LabelField(parentName); } if (nodeValue.childNodeList.Count > 0 && nodeValue.NodeType == (int)NODE_TYPE.RANDOM_PRIORITY) { EditorGUILayout.BeginVertical("box"); { for (int i = 0; i < nodeValue.childNodeList.Count; ++i) { NodeValue childNode = BehaviorManager.Instance.GetNode(nodeValue.childNodeList[i]); string nodeMsg = string.Format("子节点:{0} 权值:", childNode.id); childNode.priority = EditorGUILayout.IntField(nodeMsg, childNode.priority); childNode.priority = Mathf.Max(1, childNode.priority); } } EditorGUILayout.EndVertical(); } if (!string.IsNullOrEmpty(nodeValue.identificationName)) { string identificationName = string.Format("类标识_{0}", nodeValue.identificationName); EditorGUILayout.LabelField(identificationName); ICustomIdentification <NodeLeaf> customIdentification = CustomNode.Instance.GetIdentification(nodeValue.identificationName); string className = customIdentification.IdentificationName; EditorGUILayout.LabelField(className); } EditorGUILayout.LabelField("备注"); nodeValue.descript = EditorGUILayout.TextArea(nodeValue.descript, GUILayout.Width(250)); if ((nodeValue.NodeType != (int)NODE_TYPE.CONDITION && nodeValue.NodeType != (int)NODE_TYPE.ACTION)) { GUILayout.Space(20); EditorGUILayout.LabelField("组合节点功能描述"); nodeValue.function = EditorGUILayout.TextArea(nodeValue.function, GUILayout.Height(150), GUILayout.Width(300)); } } EditorGUILayout.EndVertical(); GUI.enabled = true; DrawNode(nodeValue, "参数"); GUI.enabled = true; ParentInfo(); }
public void CalculateMapData(string savePath, NamespaceReferenceInfo namespaceReferenceInfo, string serviceName) { ProjectInfoBase project = LanguageMapBase.GetCurrent.GetActiveProject(); List <MapDataClassInfo> MapDataClassInfoes = new List <MapDataClassInfo>(); List <string> usingsOfClass = new List <string>(); string fileName = ""; foreach (ProjectItemInfoBase projectItem in LanguageMapBase.GetCurrent.GetAllProjectItemsWithoutServices(project.ProjectItemsInfoBase)) { if (projectItem.GetFileCount() == 0) { continue; } fileName = projectItem.GetFileName(0); if (Path.GetExtension(fileName).ToLower() == ".java") { string dir = Path.GetDirectoryName(fileName); if (File.Exists(Path.Combine(dir, "setting.signalgo")) || !File.Exists(fileName)) { continue; } string fileText = File.ReadAllText(fileName, Encoding.UTF8); if (fileText.Contains("ModelMappAttribute(") || fileText.Contains("ModelMapp(")) { using (StringReader streamReader = new StringReader(fileText)) { string line = ""; bool lineReadClassStarted = false; bool findStartBlock = false; bool canSetBody = false; int findEndBlock = int.MaxValue; MapDataClassInfo mapDataClassInfo = new MapDataClassInfo(); StringBuilder builder = new StringBuilder(); while ((line = streamReader.ReadLine()) != null) { string lineResult = line; //if (lineResult.Trim().StartsWith("using ") && lineResult.Trim().EndsWith(";") && !lineResult.Contains("(")) //{ // var uses = GetListOfUsing(lineResult); // mapDataClassInfo.Usings.AddRange(uses); // usingsOfClass.AddRange(uses); //} if (findStartBlock && (line.Contains("{") || line.Contains("}"))) { int countPlus = line.Count(x => x == '{') - line.Count(x => x == '}'); if (findEndBlock == int.MaxValue) { findEndBlock = countPlus; } else { findEndBlock += countPlus; } if (findEndBlock <= 0) { mapDataClassInfo.Body = builder.ToString(); builder.Clear(); MapDataClassInfo find = MapDataClassInfoes.FirstOrDefault(x => x.Name == mapDataClassInfo.Name && (usingsOfClass.Contains(serviceName) || x.ServiceName == serviceName)); if (find != null) { find.Body += Environment.NewLine + mapDataClassInfo.Body; } else { MapDataClassInfoes.Add(mapDataClassInfo); } lineReadClassStarted = false; findStartBlock = false; canSetBody = false; findEndBlock = int.MaxValue; mapDataClassInfo = new MapDataClassInfo(); } else { if (canSetBody) { builder.AppendLine(lineResult); } canSetBody = true; } } else if (lineReadClassStarted && line.Contains(" class ")) { string[] splitInheritance = line.Split(':', ','); //multiple inheritance if (splitInheritance.Length > 1) { foreach (string item in splitInheritance.Skip(1)) { Tuple <string, string> nameSpaceAndName = GetNameSpaceAndName(item); if (!string.IsNullOrEmpty(nameSpaceAndName.Item1)) { usingsOfClass.Add(nameSpaceAndName.Item1); } mapDataClassInfo.Inheritances.Add(nameSpaceAndName.Item2); } } findStartBlock = true; } else if (!lineResult.TrimStart().StartsWith("//") && (lineResult.Contains("ModelMappAttribute(") || lineResult.Contains("ModelMapp("))) { int length = "ModelMappAttribute(".Length; int index = lineResult.IndexOf("ModelMappAttribute("); if (index == -1) { index = lineResult.IndexOf("ModelMapp("); length = "ModelMapp(".Length; } string[] split = SplitWithIgnoreQuotes(lineResult.Substring(index + length), ","); foreach (string item in split) { if (item.ToLower().Contains("maptotype") || item.Contains("typeof")) { Tuple <string, string> nameSpaceAndName = GetNameSpaceAndName(item.Split('=').LastOrDefault()); if (!string.IsNullOrEmpty(nameSpaceAndName.Item1)) { usingsOfClass.Add(nameSpaceAndName.Item1); mapDataClassInfo.ServiceName = nameSpaceAndName.Item1; } mapDataClassInfo.Name = nameSpaceAndName.Item2.Replace("typeof", "").Replace("(", "").Replace(")", "") .Replace("[", "").Replace("]", "").Trim(); } else if (item.Contains("IsEnabledNotifyPropertyChangedBaseClass")) { if (item.Contains("false")) { mapDataClassInfo.IsEnabledNotifyPropertyChangedBaseClass = false; } } else if (item.Contains("IsIncludeInheritances")) { if (item.Contains("false")) { mapDataClassInfo.IsIncludeInheritances = false; } } else if (item.Contains("IgnoreProperties")) { Tuple <string, string> nameSpaceAndName = GetNameSpaceAndName(item.Split('=').LastOrDefault()); Regex reg = new Regex("\".*?\""); MatchCollection matches = reg.Matches(nameSpaceAndName.Item2); foreach (object str in matches) { mapDataClassInfo.IgnoreProperties.Add(str.ToString().Replace("\"", "")); } } } lineReadClassStarted = true; } else if (canSetBody) { builder.AppendLine(lineResult); } } } } } } string folder = ""; EnumNames.Clear(); EnumNames.AddRange(namespaceReferenceInfo.Enums); foreach (IGrouping <string, ClassReferenceInfo> groupInfo in namespaceReferenceInfo.Classes.Where(x => x.Type == ClassReferenceType.ModelLevel || x.Type == ClassReferenceType.InterfaceLevel).GroupBy(x => x.NameSpace)) { folder = Path.Combine(savePath, groupInfo.Key); foreach (ClassReferenceInfo modelInfo in groupInfo) { //key is full name and value 1 is name space and value 2 is name Dictionary <string, Dictionary <string, string> > namespaces = new Dictionary <string, Dictionary <string, string> >(); StringBuilder builderResult = new StringBuilder(); builderResult.AppendLine(LanguageMapBase.GetCurrent.GetAutoGeneratedText()); builderResult.AppendLine($"package {serviceName}.{modelInfo.NameSpace};"); builderResult.AppendLine("*$-SignalGoNameSpaces-!*"); fileName = Path.Combine(FixDirectoryName(folder), GetFileNameFromClassName(modelInfo.NormalizedName)); GenerateModelClass(modelInfo, " ", builderResult, MapDataClassInfoes.Where(x => x.Name == modelInfo.NormalizedName).FirstOrDefault(), serviceName, namespaces); StringBuilder nameSpacesResult = new StringBuilder(); List <string> added = new List <string>(); foreach (KeyValuePair <string, Dictionary <string, string> > item in namespaces) { foreach (KeyValuePair <string, string> keyValue in item.Value) { string fullName = keyValue.Key; if (fullName.Contains("DontAddOnSignalGoAddreference")) { continue; } if (fullName != "java.util.Date" && fullName != "java.util.List" && fullName != "java.util.Dictionary") { fullName = serviceName + "." + keyValue.Key + ".*"; } if (added.Contains(fullName)) { continue; } else { added.Add(fullName); } if (keyValue.Key != modelInfo.NameSpace && keyValue.Key != "System") { nameSpacesResult.AppendLine($"import {fullName};"); } } } builderResult.Replace("*$-SignalGoNameSpaces-!*", nameSpacesResult.ToString()); File.WriteAllText(fileName, builderResult.ToString(), Encoding.ASCII); } } //foreach (ClassReferenceInfo httpClassInfo in namespaceReferenceInfo.Classes.Where(x => x.Type == ClassReferenceType.HttpServiceLevel)) //{ // //key is full name and value 1 is name space and value 2 is name // Dictionary<string, Dictionary<string, string>> namespaces = new Dictionary<string, Dictionary<string, string>>(); // StringBuilder builder = new StringBuilder(); // builder.AppendLine(LanguageMapBase.GetCurrent.GetAutoGeneratedText()); // builder.AppendLine("*$-SignalGoNameSpaces-!*"); // //builder.AppendLine("import { List } from 'src/app/SharedComponents/linqts';"); // GenerateHttpServiceClass(httpClassInfo, " ", builder, serviceName, namespaces); // StringBuilder nameSpacesResult = new StringBuilder(); // foreach (KeyValuePair<string, Dictionary<string, string>> item in namespaces) // { // foreach (KeyValuePair<string, string> keyValue in item.Value) // { // nameSpacesResult.AppendLine($"import {{{ keyValue.Value }}} from \"./{keyValue.Key}/{keyValue.Value}\""); // } // } // //string result = builder.ToString(); // //foreach (string space in namespaces) // //{ // // if (result.Contains(serviceName + "." + space)) // // continue; // // result = result.Replace(space, serviceName + "." + space); // //} // builder.Replace("*$-SignalGoNameSpaces-!*", nameSpacesResult.ToString()); // File.WriteAllText(Path.Combine(savePath, httpClassInfo.ServiceName.Replace("/", "").Replace("\\", "") + "Service.ts"), builder.ToString(), Encoding.UTF8); //} foreach (IGrouping <string, EnumReferenceInfo> groupInfo in namespaceReferenceInfo.Enums.GroupBy(x => x.NameSpace)) { folder = Path.Combine(savePath, groupInfo.Key); foreach (EnumReferenceInfo enumInfo in groupInfo) { StringBuilder builderResult = new StringBuilder(); builderResult.AppendLine(LanguageMapBase.GetCurrent.GetAutoGeneratedText()); fileName = Path.Combine(FixDirectoryName(folder), GetFileNameFromClassName(enumInfo.Name)); GenerateModelEnum(serviceName, enumInfo, " ", builderResult); File.WriteAllText(fileName, builderResult.ToString(), Encoding.ASCII); } } //return builderResult.ToString(); }
public static SkillHsmConfigHSMParameter Draw(SkillHsmConfigHSMParameter hSMParameter, HSMDrawParameterType drawParameterType, Action DelCallBack) { if (null == hSMParameter) { return(hSMParameter); } EditorGUILayout.BeginHorizontal(); { string[] parameterNameArr = EnumNames.GetEnumNames <HSMParameterType>(); int index = EnumNames.GetEnumIndex <HSMParameterType>((HSMParameterType)(hSMParameter.ParameterType)); HSMParameterType HSMParameterType = EnumNames.GetEnum <HSMParameterType>(index); bool enableChangeType = (drawParameterType == HSMDrawParameterType.HSM_PARAMETER_ADD); GUI.enabled = enableChangeType; { GUI.enabled = false; if (drawParameterType == HSMDrawParameterType.NODE_PARAMETER) { EditorGUILayout.BeginHorizontal(); { hSMParameter.Index = EditorGUILayout.IntField(hSMParameter.Index, GUILayout.Width(30)); } EditorGUILayout.EndHorizontal(); } GUI.enabled = enableChangeType; index = EditorGUILayout.Popup(index, parameterNameArr, GUILayout.ExpandWidth(true)); hSMParameter.ParameterType = (int)EnumNames.GetEnum <HSMParameterType>(index); GUILayout.Space(5); } GUI.enabled = true; if (drawParameterType == HSMDrawParameterType.NODE_PARAMETER || drawParameterType == HSMDrawParameterType.HSM_PARAMETER) { if (GUILayout.Button("删除", GUILayout.Width(45))) { if (null != DelCallBack) { DelCallBack(); } } } } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { if (drawParameterType == HSMDrawParameterType.NODE_PARAMETER) { List <SkillHsmConfigHSMParameter> parameterList = HSMManager.Instance.HSMTreeData.ParameterList; string[] parameterArr = new string[parameterList.Count]; int index = -1; for (int i = 0; i < parameterList.Count; ++i) { SkillHsmConfigHSMParameter p = parameterList[i]; parameterArr[i] = p.CNName; //p.ParameterName; if (hSMParameter.ParameterName.CompareTo(p.ParameterName) == 0) { index = i; } } int result = EditorGUILayout.Popup(index, parameterArr, GUILayout.ExpandWidth(true)); if (result != index) { hSMParameter.ParameterName = parameterList[result].ParameterName; //parameterArr[result]; } } else if (drawParameterType == HSMDrawParameterType.HSM_PARAMETER || drawParameterType == HSMDrawParameterType.RUNTIME_PARAMETER) { GUI.enabled = (drawParameterType == HSMDrawParameterType.HSM_PARAMETER_ADD); hSMParameter.ParameterName = EditorGUILayout.TextField(hSMParameter.ParameterName); hSMParameter.CNName = EditorGUILayout.TextField(hSMParameter.CNName); GUI.enabled = true; } else if (drawParameterType == HSMDrawParameterType.HSM_PARAMETER_ADD) { EditorGUILayout.BeginVertical(); { string oldName = hSMParameter.ParameterName; hSMParameter.ParameterName = EditorGUILayout.TextField("英文:", hSMParameter.ParameterName); if (oldName.CompareTo(hSMParameter.ParameterName) != 0) { bool isNumOrAlp = IsNumOrAlp(hSMParameter.ParameterName); if (!isNumOrAlp) { string msg = string.Format("参数名只能包含:数字、字母、下划线,且数字不能放在第一个字符位置"); HSMNodeWindow.window.ShowNotification(msg); hSMParameter.ParameterName = oldName; } } hSMParameter.CNName = EditorGUILayout.TextField("中文", hSMParameter.CNName); } EditorGUILayout.EndVertical(); } HSMCompare[] compareEnumArr = new HSMCompare[] { }; if (hSMParameter.ParameterType == (int)HSMParameterType.Int) { compareEnumArr = new HSMCompare[] { HSMCompare.GREATER, HSMCompare.GREATER_EQUALS, HSMCompare.LESS_EQUAL, HSMCompare.LESS, HSMCompare.EQUALS, HSMCompare.NOT_EQUAL }; } if (hSMParameter.ParameterType == (int)HSMParameterType.Float) { compareEnumArr = new HSMCompare[] { HSMCompare.GREATER, HSMCompare.LESS }; } if (hSMParameter.ParameterType == (int)HSMParameterType.Bool) { compareEnumArr = new HSMCompare[] { HSMCompare.EQUALS, HSMCompare.NOT_EQUAL }; } string[] compareArr = new string[compareEnumArr.Length]; int compare = hSMParameter.Compare; bool found = false; for (int i = 0; i < compareEnumArr.Length; ++i) { int index = EnumNames.GetEnumIndex <HSMCompare>(compareEnumArr[i]); string typeName = EnumNames.GetEnumName <HSMCompare>(index); compareArr[i] = typeName; if ((HSMCompare)hSMParameter.Compare == compareEnumArr[i]) { compare = i; found = true; } } if (!found) { compare = 0; } bool value = (drawParameterType != HSMDrawParameterType.HSM_PARAMETER) && (drawParameterType != HSMDrawParameterType.RUNTIME_PARAMETER) && (drawParameterType != HSMDrawParameterType.HSM_PARAMETER_ADD); bool boolType = (hSMParameter.ParameterType == (int)HSMParameterType.Bool); if (boolType) { hSMParameter.Compare = (int)HSMCompare.EQUALS; } else if (value) { compare = EditorGUILayout.Popup(compare, compareArr, GUILayout.Width(65)); hSMParameter.Compare = (int)(compareEnumArr[compare]); } { if (hSMParameter.ParameterType == (int)HSMParameterType.Int) { hSMParameter.IntValue = EditorGUILayout.IntField(hSMParameter.IntValue, GUILayout.Width(50)); } if (hSMParameter.ParameterType == (int)HSMParameterType.Float) { hSMParameter.FloatValue = EditorGUILayout.FloatField(hSMParameter.FloatValue, GUILayout.Width(50)); } if (hSMParameter.ParameterType == (int)HSMParameterType.Bool) { hSMParameter.BoolValue = EditorGUILayout.Toggle(hSMParameter.BoolValue, GUILayout.Width(50)); } } } EditorGUILayout.EndHorizontal(); return(hSMParameter); }