示例#1
0
文件: GraphView.cs 项目: pshtif/Dash
        void ProcessDragging(Event p_event, Rect p_rect)
        {
            // Left drag
            if (p_event.button == 0 && p_event.alt && p_event.type == EventType.MouseDrag && dragging == DraggingType.NONE)
            {
                if (Graph != null)
                {
                    Graph.viewOffset += p_event.delta * Zoom;

                    DashEditorWindow.SetDirty(true);
                }
            }

            // Right drag start
            if (p_event.button == 1 && p_event.type == EventType.MouseDown)
            {
                _rightDragStart = p_event.mousePosition;
            }

            // Right drag
            if (p_event.button == 1 && p_event.type == EventType.MouseDrag)
            {
                if (_rightDrag)
                {
                    Graph.viewOffset += p_event.delta * Zoom;
                }
                else if ((p_event.mousePosition - _rightDragStart).magnitude > 5)
                {
                    _rightDrag        = true;
                    Graph.viewOffset += (p_event.mousePosition - _rightDragStart) * Zoom;
                }

                DashEditorWindow.SetDirty(true);
            }
        }
示例#2
0
文件: GraphView.cs 项目: pshtif/Dash
        void ProcessZoom(Event p_event, Rect p_rect)
        {
            if (!p_event.isScrollWheel)
            {
                return;
            }

            float zoom = DashEditorCore.EditorConfig.zoom;

            float previousZoom = zoom;

            zoom += p_event.delta.y / 12;
            if (zoom < 1)
            {
                zoom = 1;
            }
            if (zoom > 4)
            {
                zoom = 4;
            }
            if (previousZoom != zoom && Graph != null)
            {
                Graph.viewOffset.x += (zoom - previousZoom) * p_rect.width / 2 + (p_event.mousePosition.x - p_rect.x - p_rect.width / 2) * (zoom - previousZoom);
                Graph.viewOffset.y += (zoom - previousZoom) * p_rect.height / 2 + (p_event.mousePosition.y - p_rect.y - p_rect.height / 2) * (zoom - previousZoom);
            }

            DashEditorCore.EditorConfig.zoom = zoom;
            DashEditorWindow.SetDirty(true);
        }
示例#3
0
 public override void OnInspectorGUI()
 {
     GUI.color = new Color(1, 0.75f, 0.5f);
     if (GUILayout.Button("Open Editor", GUILayout.Height(40)))
     {
         DashEditorWindow.InitEditorWindow(null);
         DashEditorCore.EditGraph((DashGraph)target);
     }
 }
示例#4
0
        public static DashEditorWindow InitEditorWindow(DashController p_dashController)
        {
            DashEditorCore.EditController(p_dashController);

            Instance = GetWindow <DashEditorWindow>();
            Instance.titleContent = new GUIContent("Dash Editor");
            Instance.minSize      = new Vector2(800, 400);

            return(Instance);
        }
示例#5
0
文件: GraphView.cs 项目: pshtif/Dash
        void ProcessRightClick(Event p_event, Rect p_rect)
        {
            if (p_event.button != 1)
            {
                return;
            }

            if (p_event.type == EventType.MouseUp)
            {
                if (!_rightDrag)
                {
                    NodeBase hitNode = Graph.HitsNode(p_event.mousePosition * Zoom - new Vector2(p_rect.x, p_rect.y));
                    if (hitNode != null)
                    {
                        NodeContextMenu.Show(hitNode);
                    }
                    else
                    {
                        NodeConnection hitConnection = Graph.HitsConnection(
                            p_event.mousePosition * Zoom - new Vector2(p_rect.x, p_rect.y),
                            12);

                        if (hitConnection != null)
                        {
                            ConnectionContextMenu.Show(hitConnection);
                        }
                        else
                        {
                            GraphBox hitRegion =
                                Graph.HitsBoxDrag(p_event.mousePosition * Zoom - new Vector2(p_rect.x, p_rect.y));

                            if (hitRegion != null)
                            {
                                BoxContextMenu.Show(hitRegion);
                            }
                            else
                            {
                                CreateNodeContextMenu.ShowAsPopup();
                            }
                        }
                    }
                }
                else
                {
                    _rightDrag = false;
                }

                p_event.Use();

                DashEditorWindow.SetDirty(true);
            }
        }
示例#6
0
        public static bool OpenDashGraphEditor(int p_instanceID, int p_line)
        {
            Object asset = EditorUtility.InstanceIDToObject(p_instanceID);

            if (asset.GetType() == typeof(DashGraph))
            {
                string path = AssetDatabase.GetAssetPath(asset);
                DashEditorWindow.InitEditorWindow(null);
                DashEditorCore.EditGraph((DashGraph)AssetDatabase.LoadAssetAtPath <DashGraph>(path));

                return(true);
            }

            return(false);
        }
示例#7
0
文件: GraphView.cs 项目: pshtif/Dash
        public override void ProcessEvent(Event p_event, Rect p_rect)
        {
            if (Graph == null || !p_rect.Contains(p_event.mousePosition))
            {
                return;
            }

            ProcessZoom(p_event, p_rect);

            if (!Application.isPlaying && !DashEditorCore.Previewer.IsPreviewing && Graph != null)
            {
                ProcessLeftClick(p_event, p_rect);

                ProcessRightClick(p_event, p_rect);
            }

            ProcessDragging(p_event, p_rect);

            if (Graph.connectingNode != null)
            {
                DashEditorWindow.SetDirty(true);
            }
        }
示例#8
0
        private void OnGUI()
        {
            DashEditorCore.EditorConfig.editorPosition = position;

            if (Event.current.type == EventType.MouseDown)
            {
                DashEditorCore.editingBoxComment = null;
            }

            // Skin/Resources are null during project building and can crash build process if editor is open
            if (DashEditorCore.Skin == null)
            {
                return;
            }

            // Instance lost issue in 2020?
            if (Instance == null)
            {
                Instance = this;
            }

            if (_views == null)
            {
                CreateViews();
                return;
            }

            var rect = new Rect(0, 0, position.width, position.height);

            // Ugly hack to avoid error drawing on Repaint event before firing Layout event which happens after script compilation
            if (Event.current.type == EventType.Layout)
            {
                _previousLayoutDone = true;
            }
            if ((Event.current.type == EventType.Repaint || Event.current.isMouse) && !_previousLayoutDone)
            {
                return;
            }

//            if (CheckVersionPopup.IsCurrentVersion())
            {
                ShortcutsHandler.Handle();

                // Draw view GUIs
                _views.ForEach(v => v.DrawGUI(Event.current, rect));

                // Process events after views update so overlaying views had chance to block mouse
                _views.ForEach(v => v.ProcessEvent(Event.current, rect));

                // Local dirty is no longer used but I will left it here as it will back come to use after optimization refactor
                if (IsDirty)
                {
                    SetDirty(false);
                    Repaint();
                }
            }
            //        else
            //        {
            //            CheckVersionPopup.ShowVersionMigrate(position);
            //        }
        }
示例#9
0
文件: GraphView.cs 项目: pshtif/Dash
        void ProcessLeftClick(Event p_event, Rect p_rect)
        {
            if (p_event.button != 0)
            {
                return;
            }

            if (p_event.type == EventType.MouseDown)
            {
                GUI.FocusControl("");
            }

            // Select
            if (p_event.type == EventType.MouseDown && !p_event.alt && Graph != null && !p_event.control)
            {
                DashEditorWindow.SetDirty(true);

                NodeBase hitNode      = Graph.HitsNode(p_event.mousePosition * Zoom - new Vector2(p_rect.x, p_rect.y));
                int      hitNodeIndex = Graph.Nodes.IndexOf(hitNode);

                if (!SelectionManager.IsSelected(hitNodeIndex) && (!p_event.shift || hitNodeIndex == 0))
                {
                    SelectionManager.ClearSelection();
                }

                if (hitNodeIndex >= 0)
                {
                    AddSelectedNode(hitNodeIndex);

                    dragging = DraggingType.NODE_DRAG;
                }
                else
                {
                    GraphBox box = Graph.HitsBoxDrag(p_event.mousePosition * Zoom - new Vector2(p_rect.x, p_rect.y));

                    if (box != null)
                    {
                        DashEditorCore.selectedBox = box;
                        DashEditorCore.selectedBox.StartDrag();
                        dragging = DraggingType.BOX_DRAG;
                    }
                    else
                    {
                        box = Graph.HitsBoxResize(p_event.mousePosition * Zoom - new Vector2(p_rect.x, p_rect.y));

                        if (box != null)
                        {
                            DashEditorCore.selectedBox = box;
                            DashEditorCore.selectedBox.StartResize();
                            dragging = DraggingType.BOX_RESIZE;
                        }
                        else
                        {
                            dragging = DraggingType.SELECTION;
                            DashEditorCore.selectedBox = null;
                            Graph.connectingNode       = null;
                            selectedRegion             = new Rect(p_event.mousePosition.x, p_event.mousePosition.y, 0, 0);
                        }
                    }
                }
            }

            // Dragging
            if (p_event.type == EventType.MouseDrag)
            {
                switch (dragging)
                {
                case DraggingType.NODE_DRAG:
                    Vector2 delta = p_event.alt ? Snapping.Snap(p_event.delta, new Vector2(10, 10)): p_event.delta;
                    SelectionManager.DragSelectedNodes(delta, Graph);
                    break;

                case DraggingType.BOX_DRAG:
                    DashEditorCore.selectedBox.Drag(new Vector2(p_event.delta.x * Zoom, p_event.delta.y * Zoom));
                    break;

                case DraggingType.BOX_RESIZE:
                    DashEditorCore.selectedBox.Resize(new Vector2(p_event.delta.x * Zoom, p_event.delta.y * Zoom));
                    break;

                case DraggingType.SELECTION:
                    selectedRegion.width  += p_event.delta.x;
                    selectedRegion.height += p_event.delta.y;
                    Rect fixedRect = FixRect(selectedRegion);
                    SelectionManager.SelectingNodes(Graph.Nodes.FindAll(n => n.IsInsideRect(fixedRect)).Select(n => n.Index).ToList());
                    break;
                }

                DashEditorWindow.SetDirty(true);
            }

            if (p_event.type == EventType.MouseUp)
            {
                if (dragging == DraggingType.SELECTION)
                {
                    SelectionManager.SelectingToSelected();
                }

                if (dragging == DraggingType.NODE_DRAG || dragging == DraggingType.BOX_DRAG || dragging == DraggingType.BOX_RESIZE)
                {
                    DashEditorCore.SetDirty();
                }

                dragging       = DraggingType.NONE;
                selectedRegion = Rect.zero;
                DashEditorWindow.SetDirty(true);
            }
        }
示例#10
0
 private void OpenEditor()
 {
     DashEditorWindow.InitEditorWindow(Controller);
 }