예제 #1
0
        private static void FillContextMenu(NodeEditorInputInfo inputInfo, GenericMenu contextMenu, ContextType contextType)
        {
            foreach (KeyValuePair <ContextEntryAttribute, PopupMenu.MenuFunctionData> contextEntry in contextEntries)
            {
                if (inputInfo.editorState.focusedNode)
                {
                    if (inputInfo.editorState.focusedNode.name == "Build Shader" && contextEntry.Key.contextPath == "Duplicate Node" && NodeEditor.NoBuildShaderContext)
                    {
                        continue;
                    }
                    if (inputInfo.editorState.focusedNode.name == "Lighting Support" && contextEntry.Key.contextPath == "Duplicate Node" && NodeEditor.NoBuildShaderContext)
                    {
                        continue;
                    }
                }
                if (contextEntry.Key.contextType == contextType)
                {
                    contextMenu.AddItem(new GUIContent(contextEntry.Key.contextPath), false, contextEntry.Value, inputInfo);
                }
            }

            object[] fillerParams = new object[] { inputInfo, contextMenu };
            foreach (KeyValuePair <ContextFillerAttribute, Delegate> contextFiller in contextFillers)
            {
                if (contextFiller.Key.contextType == contextType)
                {
                    contextFiller.Value.DynamicInvoke(fillerParams);
                }
            }
        }
예제 #2
0
        private static void KB_MoveNode(NodeEditorInputInfo inputInfo)
        {
            NodeEditorState state = inputInfo.editorState;

            if (state.selectedNode != null)
            {
                Vector2 pos         = state.selectedNode.rect.position;
                int     shiftAmount = inputInfo.inputEvent.shift? 50 : 10;

                if (inputInfo.inputEvent.keyCode == KeyCode.RightArrow)
                {
                    pos = new Vector2(pos.x + shiftAmount, pos.y);
                }
                else if (inputInfo.inputEvent.keyCode == KeyCode.LeftArrow)
                {
                    pos = new Vector2(pos.x - shiftAmount, pos.y);
                }
                else if (inputInfo.inputEvent.keyCode == KeyCode.DownArrow)
                {
                    pos = new Vector2(pos.x, pos.y + shiftAmount);
                }
                else if (inputInfo.inputEvent.keyCode == KeyCode.UpArrow)
                {
                    pos = new Vector2(pos.x, pos.y - shiftAmount);
                }

                state.selectedNode.rect.position = pos;
                inputInfo.inputEvent.Use();
            }
            NodeEditor.RepaintClients();
        }
예제 #3
0
 private static void DeleteNode(NodeEditorInputInfo inputInfo)
 {
     inputInfo.SetAsCurrentEnvironment();
     if (inputInfo.editorState.focusedNode != null)
     {
         inputInfo.editorState.focusedNode.Delete();
         inputInfo.inputEvent.Use();
     }
 }
예제 #4
0
        public static void HandleLateInputEvents(NodeEditorState state)
        {
            if (shouldIgnoreInput(state))
            {
                return;
            }
            NodeEditorInputInfo inputInfo = new NodeEditorInputInfo(state);

            CallEventHandlers(inputInfo, true);
        }
예제 #5
0
        private static void HandleApplyConnection(NodeEditorInputInfo inputInfo)
        {
            NodeEditorState state = inputInfo.editorState;

            if (inputInfo.inputEvent.button == 0 && state.connectOutput != null && state.focusedNode != null && state.focusedNodeKnob != null && state.focusedNodeKnob is NodeInput)
            {
                NodeInput clickedInput = state.focusedNodeKnob as NodeInput;
                clickedInput.TryApplyConnection(state.connectOutput);
                inputInfo.inputEvent.Use();
            }
            state.connectOutput = null;
        }
예제 #6
0
        public static void HandleInputEvents(NodeEditorState state)
        {
            if (shouldIgnoreInput(state))
            {
                return;
            }

            NodeEditorInputInfo inputInfo = new NodeEditorInputInfo(state);

            CallEventHandlers(inputInfo, false);
            CallHotkeys(inputInfo, Event.current.keyCode, Event.current.modifiers);
        }
예제 #7
0
        private static void HandleNodeSnap(NodeEditorInputInfo inputInfo)
        {
            NodeEditorState state = inputInfo.editorState;

            if (state.selectedNode != null)
            {
                Vector2 pos = state.selectedNode.rect.position;
                pos = new Vector2(Mathf.RoundToInt(pos.x / 10) * 10, Mathf.RoundToInt(pos.y / 10) * 10);
                state.selectedNode.rect.position = pos;
                inputInfo.inputEvent.Use();
            }
            NodeEditor.RepaintClients();
        }
예제 #8
0
        private static void CreateNodeCallback(object infoObj)
        {
            NodeEditorInputInfo callback = infoObj as NodeEditorInputInfo;

            if (callback == null)
            {
                throw new UnityException("Callback Object passed by context is not of type NodeEditorInputInfo!");
            }
            callback.SetAsCurrentEnvironment();
            Node.Create(callback.message, NodeEditor.ScreenToCanvasSpace(callback.inputPos), callback.editorState.connectOutput);
            callback.editorState.connectOutput = null;
            NodeEditor.RepaintClients();
        }
예제 #9
0
        private static void DuplicateNode(NodeEditorInputInfo inputInfo)
        {
            inputInfo.SetAsCurrentEnvironment();
            NodeEditorState state = inputInfo.editorState;

            if (state.focusedNode != null)
            {
                Node duplicatedNode = Node.Create(state.focusedNode.GetID, NodeEditor.ScreenToCanvasSpace(inputInfo.inputPos), state.connectOutput);
                state.selectedNode  = state.focusedNode = duplicatedNode;
                state.connectOutput = null;
                inputInfo.inputEvent.Use();
            }
        }
예제 #10
0
        private static void HandleFocussing(NodeEditorInputInfo inputInfo)
        {
            NodeEditorState state = inputInfo.editorState;

            state.focusedNode = NodeEditor.NodeAtPosition(NodeEditor.ScreenToCanvasSpace(inputInfo.inputPos), out state.focusedNodeKnob);

            if (unfocusControlsForState == state && Event.current.type == EventType.Repaint)
            {
                GUIUtility.hotControl      = 0;
                GUIUtility.keyboardControl = 0;
                unfocusControlsForState    = null;
            }
        }
예제 #11
0
        private static void HandleWindowPanning(NodeEditorInputInfo inputInfo)
        {
            NodeEditorState state = inputInfo.editorState;

            if (state.panWindow)
            {
                Vector2 panOffsetChange = state.dragOffset;
                state.dragOffset = inputInfo.inputPos - state.dragStart;
                panOffsetChange  = (state.dragOffset - panOffsetChange) * state.zoom;
                state.panOffset += panOffsetChange;
                NodeEditor.RepaintClients();
            }
        }
예제 #12
0
        private static void HandleWindowPanningStart(NodeEditorInputInfo inputInfo)
        {
            if (GUIUtility.hotControl > 0)
            {
                return;
            }

            NodeEditorState state = inputInfo.editorState;

            if ((inputInfo.inputEvent.button == 0 || inputInfo.inputEvent.button == 2) && state.focusedNode == null)
            {
                state.panWindow  = true;
                state.dragStart  = inputInfo.inputPos;
                state.dragOffset = Vector2.zero;
            }
        }
예제 #13
0
 private static void CallEventHandlers(NodeEditorInputInfo inputInfo, bool late)
 {
     object[] parameter = new object[] { inputInfo };
     foreach (KeyValuePair <EventHandlerAttribute, Delegate> eventHandler in eventHandlers)
     {
         if ((eventHandler.Key.handledEvent == null || eventHandler.Key.handledEvent == inputInfo.inputEvent.type) &&
             (late? eventHandler.Key.priority >= 100 : eventHandler.Key.priority < 100))
         {
             eventHandler.Value.DynamicInvoke(parameter);
             if (inputInfo.inputEvent.type == EventType.Used)
             {
                 return;
             }
         }
     }
 }
예제 #14
0
 private static void HandleContextClicks(NodeEditorInputInfo inputInfo)
 {
     if (Event.current.button == 1)
     {
         GenericMenu contextMenu = new GenericMenu();
         if (inputInfo.editorState.focusedNode != null) // Node Context Click
         {
             FillContextMenu(inputInfo, contextMenu, ContextType.Node);
         }
         else
         {
             FillContextMenu(inputInfo, contextMenu, ContextType.Canvas);
         }
         contextMenu.Show(inputInfo.inputPos);
         Event.current.Use();
     }
 }
예제 #15
0
        private static void HandleSelecting(NodeEditorInputInfo inputInfo)
        {
            NodeEditorState state = inputInfo.editorState;

            if (inputInfo.inputEvent.button == 0 && state.focusedNode != state.selectedNode)
            {
                unfocusControlsForState = state;
                state.selectedNode      = state.focusedNode;
                NodeEditor.RepaintClients();
                        #if UNITY_EDITOR
                if (state.selectedNode != null)
                {
                    UnityEditor.Selection.activeObject = state.selectedNode;
                }
                        #endif
            }
        }
예제 #16
0
        private static void FillAddNodes(NodeEditorInputInfo inputInfo, GenericMenu canvasContextMenu)
        {
            NodeEditorState state          = inputInfo.editorState;
            List <Node>     displayedNodes = state.connectOutput != null?NodeTypes.getCompatibleNodes(state.connectOutput) : NodeTypes.nodes.Keys.ToList();

            foreach (Node compatibleNode in displayedNodes)
            {
                if (compatibleNode.GetType().Name == "BuildShader" && NodeEditor.NoBuildShaderContext)
                {
                    continue;
                }
                if (NodeCanvasManager.CheckCanvasCompability(compatibleNode, inputInfo.editorState.canvas.GetType()))
                {
                    canvasContextMenu.AddItem(new GUIContent("" + NodeTypes.nodes[compatibleNode].adress), false, CreateNodeCallback, new NodeEditorInputInfo(compatibleNode.GetID, state));
                }
            }
        }
예제 #17
0
 private static void CallHotkeys(NodeEditorInputInfo inputInfo, KeyCode keyCode, EventModifiers mods)
 {
     object[] parameter = new object[] { inputInfo };
     foreach (KeyValuePair <HotkeyAttribute, Delegate> hotKey in hotkeyHandlers)
     {
         if (hotKey.Key.handledHotKey == keyCode &&
             (hotKey.Key.modifiers == null || hotKey.Key.modifiers == mods) &&
             (hotKey.Key.limitingEventType == null || hotKey.Key.limitingEventType == inputInfo.inputEvent.type))
         {
             hotKey.Value.DynamicInvoke(parameter);
             if (inputInfo.inputEvent.type == EventType.Used)
             {
                 return;
             }
         }
     }
 }
예제 #18
0
        private static void HandleNodeDraggingStart(NodeEditorInputInfo inputInfo)
        {
            if (GUIUtility.hotControl > 0)
            {
                return;
            }

            NodeEditorState state = inputInfo.editorState;

            if (inputInfo.inputEvent.button == 0 && state.focusedNode != null && state.focusedNode == state.selectedNode && state.focusedNodeKnob == null)
            {
                state.dragNode             = true;
                state.dragStart            = inputInfo.inputPos;
                state.dragPos              = state.focusedNode.rect.position;
                state.dragOffset           = Vector2.zero;
                inputInfo.inputEvent.delta = Vector2.zero;
            }
        }
예제 #19
0
        private static void HandleNodeDragging(NodeEditorInputInfo inputInfo)
        {
            NodeEditorState state = inputInfo.editorState;

            if (state.dragNode)
            {
                if (state.selectedNode != null && GUIUtility.hotControl == 0)
                {
                    state.dragOffset = inputInfo.inputPos - state.dragStart;
                    state.selectedNode.rect.position = state.dragPos + state.dragOffset * state.zoom;
                    NodeEditorCallbacks.IssueOnMoveNode(state.selectedNode);
                    NodeEditor.RepaintClients();
                }
                else
                {
                    state.dragNode = false;
                }
            }
        }
예제 #20
0
        private static void HandleConnectionDrawing(NodeEditorInputInfo inputInfo)
        {
            NodeEditorState state = inputInfo.editorState;

            if (inputInfo.inputEvent.button == 0 && state.focusedNodeKnob != null)
            {
                if (state.focusedNodeKnob is NodeOutput)
                {
                    state.connectOutput = (NodeOutput)state.focusedNodeKnob;
                    inputInfo.inputEvent.Use();
                }
                else if (state.focusedNodeKnob is NodeInput)
                {
                    NodeInput clickedInput = (NodeInput)state.focusedNodeKnob;
                    if (clickedInput.connection != null)
                    {
                        state.connectOutput = clickedInput.connection;
                        clickedInput.RemoveConnection();
                        inputInfo.inputEvent.Use();
                    }
                }
            }
        }
예제 #21
0
 private static void HandleNodeDraggingEnd(NodeEditorInputInfo inputInfo)
 {
     inputInfo.editorState.dragNode = false;
 }
예제 #22
0
 private static void HandleEndNavigating(NodeEditorInputInfo inputInfo)
 {
     inputInfo.editorState.navigate = false;
 }
예제 #23
0
 private static void HandleStartNavigating(NodeEditorInputInfo inputInfo)
 {
     inputInfo.editorState.navigate = true;
 }
예제 #24
0
 private static void HandleZooming(NodeEditorInputInfo inputInfo)
 {
     inputInfo.editorState.zoom = (float)Math.Round(Math.Min(6.0, Math.Max(0.6, inputInfo.editorState.zoom + inputInfo.inputEvent.delta.y / 15)), 2);
     NodeEditor.RepaintClients();
 }
예제 #25
0
 private static void HandleWindowPanningEnd(NodeEditorInputInfo inputInfo)
 {
     inputInfo.editorState.panWindow = false;
 }