예제 #1
0
        /// <summary>
        /// 检测是否能够创建鼠标关联的线
        /// </summary>
        private void MakeTransitionToMouse()
        {
            bool inWindowArea = false;

            foreach (var pair in nodeWindows)
            {
                var nodeWindow = pair.Value;
                var pos        = currentLocalMousePosition;
                pos.x -= nodeWindow.WindowArea.x;
                pos.y -= nodeWindow.WindowArea.y;
                for (var i = 0; i < nodeWindow.OutputAreas.Count; ++i)
                {
                    if (nodeWindow.OutputAreas[i].Contains(pos) &&
                        nodeWindow.CanStartTransition(i))
                    {
                        inWindowArea        = true;
                        mouseTransitionLine = new MouseTransitionLine(nodeWindow, i);
                        break;
                    }
                }
            }

            if (inWindowArea)
            {
                Event.current.Use();
            }
        }
예제 #2
0
        /// <summary>
        /// 处理事件
        /// </summary>
        private void HandleEvents()
        {
            //检测是否保存
            var e = Event.current;

            //记录鼠标位置
            currentMousePosition      = e.mousePosition;
            currentLocalMousePosition = ConvertFromWorldToLocal(currentMousePosition, true);

            //检测鼠标按键
            switch (e.type)
            {
            case EventType.MouseUp:
                if (mouseTransitionLine != null)
                {    //检测是否点击到某个NodeWindow的输入区域
                    MakeTransitionToNode();
                    mouseTransitionLine = null;
                }
                else
                {
                    var clickwindow = GetClickedNodeWindow();
                    if (clickwindow != null)
                    {
                        propertyID = clickwindow.ID;
                    }
                }
                break;

            case EventType.MouseDown:
                if (e.button == 0 && mouseTransitionLine == null)
                {    //检测是否点击到某个NodeWindow的输出区域
                    MakeTransitionToMouse();
                }
                else if (e.button == 1)
                {
                    CreateGenericMenu();
                    e.Use();
                }
                break;

            case EventType.MouseDrag:
                if (e.control)
                {    //移动ScrollView
                    translateValue += e.delta;
                    e.Use();
                }
                break;

            case EventType.ScrollWheel:
                Zoom();
                e.Use();
                break;

            case EventType.KeyDown:
                if (e.control && e.keyCode == KeyCode.S)
                {    //保存配置
                    Save();
                    e.Use();
                }
                else if (e.control && e.keyCode == KeyCode.R)
                {    //刷新函数
                    BehaviorTreeManager.Instance.RefreshAIFunctions();
                    ShowNotification(new GUIContent("刷新成功"));
                    e.Use();
                }
                else if (e.control && e.keyCode == KeyCode.H)
                {    //显示/隐藏工具面板
                    toolVisible = !toolVisible;
                    e.Use();
                }
                break;
            }
        }