private void SelectTransition() { Event _event = Event.current; Vector3 mousePos = _event.mousePosition; if (_event.type != EventType.MouseDown || (_event.button != 0)) // 鼠标左键 { return; } for (int i = 0; i < _nodeList.Count; i++) { SkillHsmConfigNodeData nodeValue = _nodeList[i]; for (int j = 0; j < nodeValue.TransitionList.Count; ++j) { SkillHsmConfigTransition transition = nodeValue.TransitionList[j]; int toId = transition.ToStateId; SkillHsmConfigNodeData toNode = HSMManager.Instance.GetNode(toId); if (null == toNode) { continue; } int transitionId = nodeValue.Id * 1000 + transition.TransitionId; Vector3 startPos = Vector3.zero; Vector3 endPos = Vector3.zero; CalculateTranstion(nodeValue.Position, toNode.Position, ref startPos, ref endPos); Vector3 AB = endPos - startPos; Vector3 AP = mousePos - startPos; Vector3 BP = mousePos - endPos; float dotAP_AB = Vector3.Dot(AP, AB.normalized); float dotBP_BA = Vector3.Dot(BP, (AB * -1).normalized); if (dotAP_AB < 0 || dotBP_BA < 0) { continue; } float distance = Vector3.Cross(AB, AP).magnitude / AB.magnitude; bool value = (distance < 10) && (Mathf.Abs(dotAP_AB) < AB.magnitude); if (value) { if (null != HSMManager.hSMChangeSelectTransitionId) { int id = nodeValue.Id * 1000 + transition.TransitionId; HSMManager.hSMChangeSelectTransitionId(id); } if (null != HSMManager.hSMChangeSelectId) { HSMManager.hSMChangeSelectId(nodeValue.Id); } } //float distance = Vector3.Cross(AB, AP).magnitude / AB.magnitude; //return distance <= (sRadius + cRadius); } } }
private void DrawNode(SkillHsmConfigNodeData nodeData) { string selectTitle = string.Empty; int selectTransitionId = -1; bool selectTransition = SelectTransition(nodeData, ref selectTransitionId); selectNodeParameter = !selectTransition; GUI.backgroundColor = selectNodeParameter ? new Color(0, 1, 0, 1) : Color.white;// EditorGUILayout.BeginVertical("box"); { bool oldValue = selectNodeParameter; selectNodeParameter = EditorGUILayout.Toggle(new GUIContent("节点参数"), selectNodeParameter); if ((!oldValue && selectNodeParameter) && HSMManager.Instance.CurrentTransitionId >= 0 && null != HSMManager.hSMChangeSelectTransitionId) { HSMManager.hSMChangeSelectTransitionId(-1); } } EditorGUILayout.EndVertical(); GUI.backgroundColor = Color.white; SkillHsmConfigTransition transition = null; EditorGUILayout.BeginVertical("box"); { EditorGUILayout.LabelField("选择转换连线查看/添加/删除参数"); for (int i = 0; i < nodeData.TransitionList.Count; ++i) { SkillHsmConfigTransition temp = nodeData.TransitionList[i]; string name = string.Format("转换条件参数:连线ID_{0}", temp.ToStateId); bool lastValue = (selectTransitionId == temp.TransitionId); if (lastValue) { transition = temp; selectTitle = name;//string.Format("{0} 参数", name); } GUI.backgroundColor = lastValue ? new Color(0, 1, 0, 1) : Color.white;// EditorGUILayout.BeginHorizontal("box"); { GUIStyle guiStyle = new GUIStyle(); guiStyle.normal.textColor = lastValue ? Color.green : Color.black; bool value = EditorGUILayout.Toggle(new GUIContent(name), lastValue); if (value && !lastValue) { if (null != HSMManager.hSMChangeSelectTransitionId) { int id = nodeData.Id * 1000 + temp.TransitionId; HSMManager.hSMChangeSelectTransitionId(id); } } if (GUILayout.Button("复制")) { HSMManager.copyTransition = temp.Clone(); } if (GUILayout.Button("粘贴")) { if (null != HSMManager.copyTransition) { HSMManager.copyTransition.TransitionId = temp.TransitionId; HSMManager.copyTransition.ToStateId = temp.ToStateId; temp = HSMManager.copyTransition.Clone(); nodeData.TransitionList[i] = temp; HSMManager.copyTransition = null; } } if (GUILayout.Button("删除")) { if (null != HSMManager.hSMNodeChangeTransition) { HSMManager.hSMNodeChangeTransition(nodeData.Id, temp.ToStateId, false); } } } EditorGUILayout.EndHorizontal(); GUI.backgroundColor = Color.white; } } EditorGUILayout.EndVertical(); if (null != transition) { DrawTransitionParameter(nodeData, transition, selectTitle); } if (selectNodeParameter) { DrawNodeParameter(nodeData, selectTitle); } }