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 ClickNode(SkillHsmConfigNodeData nodeValue) { if (null == nodeValue) { return; } int nodeId = (null != nodeValue) ? nodeValue.Id : -1; if (HSMManager.hSMChangeSelectId != null) { HSMManager.hSMChangeSelectId(nodeId); } if (nodeValue.NodeType == (int)NODE_TYPE.SUB_STATE_MACHINE) { int currentTime = (int)(Time.realtimeSinceStartup * 1000); if (currentTime - lastClickNodeTime <= 200) { if (null != HSMManager.hsmOpenSubMachine) { HSMManager.hsmOpenSubMachine(nodeId); } } lastClickNodeTime = (int)(Time.realtimeSinceStartup * 1000); } }