public IfJudgeData Clone() { IfJudgeData ifJudgeData = new IfJudgeData(); ifJudgeData.nodeId = nodeId; ifJudgeData.ifJudegType = ifJudegType; ifJudgeData.ifResult = ifResult; return(ifJudgeData); }
private IfJudgeData GetData(int nodeId) { for (int i = 0; i < _ifJudgeDataList.Count; ++i) { IfJudgeData data = _ifJudgeDataList[i]; if (data.nodeId == nodeId) { return(data); } } return(null); }
private List <IfJudgeData> GetIfJudgeDataList(JsonData jsonData) { List <IfJudgeData> ifJudgeDataList = new List <IfJudgeData>(); foreach (JsonData item in jsonData) { IfJudgeData judgeData = new IfJudgeData(); judgeData.nodeId = int.Parse(item["nodeId"].ToString()); judgeData.ifJudegType = int.Parse(item["ifJudegType"].ToString()); judgeData.ifResult = int.Parse(item["ifResult"].ToString()); ifJudgeDataList.Add(judgeData); } return(ifJudgeDataList); }
private NodeBase GetBaseNode(ResultType resultType) { for (int i = 0; i < nodeChildList.Count; ++i) { NodeBase node = nodeChildList[i]; IfJudgeData judgeData = GetData(node.NodeId); if (judgeData.ifJudegType == (int)NodeIfJudgeEnum.IF) { continue; } if (judgeData.ifResult == (int)resultType) { return(node); } } return(null); }
private void JudgeNodeChangeChildCondition(NodeValue nodeValue, int childId, ResultType resultType) { for (int i = 0; i < nodeValue.ifJudgeDataList.Count; ++i) { IfJudgeData judgeData = nodeValue.ifJudgeDataList[i]; if (judgeData.ifJudegType == (int)NodeIfJudgeEnum.IF) { continue; } if (judgeData.nodeId == childId) { judgeData.ifResult = (int)resultType; } else { int result = (int)resultType - (int)ResultType.Success; judgeData.ifResult = Mathf.Abs(result); } } }
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); }); }