Exemplo n.º 1
0
        static void ConnectSelectionAsInput(object p_node)
        {
            foreach (int nodeIndex in SelectionManager.selectedNodes)
            {
                NodeBase node = Graph.Nodes[nodeIndex];
                Graph.Connect((NodeBase)p_node, 0, node, 0);
            }

            DashEditorCore.SetDirty();
        }
Exemplo n.º 2
0
        void OnAddVariable(DashVariables p_variables, Type p_type)
        {
            string name = "new" + p_type.ToString().Substring(p_type.ToString().LastIndexOf(".") + 1);

            int index = 0;

            while (p_variables.HasVariable(name + index))
            {
                index++;
            }

            p_variables.AddVariableByType((Type)p_type, name + index, null);

            DashEditorCore.SetDirty();
        }
Exemplo n.º 3
0
 static void SetAsPreview(object p_node)
 {
     Graph.previewNode = (NodeBase)p_node;
     DashEditorCore.SetDirty();
 }
Exemplo n.º 4
0
        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);
            }
        }
Exemplo n.º 5
0
 static void ActivateConnection(object p_connection)
 {
     ((NodeConnection)p_connection).active = true;
     DashEditorCore.SetDirty();
 }
Exemplo n.º 6
0
 static void DeleteConnection(object p_connection)
 {
     Undo.RegisterCompleteObjectUndo(Graph, "Delete Connection");
     Graph.Disconnect((NodeConnection)p_connection);
     DashEditorCore.SetDirty();
 }
Exemplo n.º 7
0
        protected void DrawVariablesGUI(Vector2 p_position, bool p_global, Color p_color, DashVariables p_variables, ref bool p_minimized, GameObject p_boundObject)
        {
            Rect rect = new Rect(p_position.x, p_position.y, 380, p_minimized ? 32 : 200);

            DrawBoxGUI(rect, p_global ? "Global Variables" : "Graph Variables", TextAnchor.UpperCenter, p_color);

            var minStyle = new GUIStyle();

            minStyle.normal.textColor = Color.white;
            minStyle.fontStyle        = FontStyle.Bold;
            minStyle.fontSize         = 20;
            if (GUI.Button(new Rect(rect.x + rect.width - 20 + (p_minimized ? 0 : 2), rect.y + 2, 20, 20), p_minimized ? "+" : "-", minStyle))
            {
                p_minimized = !p_minimized;
                GUI.FocusControl("");
            }

            if (p_minimized)
            {
                return;
            }

            if (p_global && PrefabUtility.GetPrefabInstanceStatus(p_boundObject) != PrefabInstanceStatus.NotAPrefab)
            {
                var style = new GUIStyle();
                style.alignment        = TextAnchor.MiddleCenter;
                style.normal.textColor = Color.white;
                style.fontSize         = 20;
                style.wordWrap         = true;
                EditorGUI.TextArea(new Rect(rect.x + 5, rect.y + 30, rect.width - 10, rect.height - 30), "Global variables on prefab instances are not supported!", style);
                return;
            }

            GUILayout.BeginArea(new Rect(rect.x + 5, rect.y + 30, rect.width - 10, rect.height - 79));
            scrollPosition = GUILayout.BeginScrollView(scrollPosition, false, false);

            EditorGUI.BeginChangeCheck();

            if (p_variables != null)
            {
                int index = 0;
                foreach (var variable in p_variables)
                {
                    GUIVariableUtils.VariableField(p_variables, variable.Name, p_boundObject, rect.width - 10);
                    EditorGUILayout.Space(4);
                    index++;
                }
            }

            GUILayout.EndScrollView();
            GUILayout.EndArea();

            if (GUI.Button(new Rect(rect.x + 4, rect.y + rect.height - 48, rect.width - 8, 20), "Add Variable"))
            {
                TypesMenu.Show((type) => OnAddVariable(p_variables, type));
            }

            if (GUI.Button(new Rect(rect.x + 4, rect.y + rect.height - 24, rect.width / 2 - 6, 20), "Copy Variables"))
            {
                VariableUtils.CopyVariables(p_variables);
            }

            if (GUI.Button(new Rect(rect.x + rect.width / 2 + 2, rect.y + rect.height - 24, rect.width / 2 - 6, 20), "Paste Variables"))
            {
                VariableUtils.PasteVariables(p_variables, p_boundObject);
            }

            if (EditorGUI.EndChangeCheck())
            {
                DashEditorCore.SetDirty();
            }

            UseEvent(new Rect(rect.x, rect.y, rect.width, rect.height));
        }