コード例 #1
0
        public static NodeEditorState ExtractEditorState(NodeCanvas canvas, string stateName)
        {
            NodeEditorState state = null;

            if (canvas.editorStates.Length > 0)
            {
                state = canvas.editorStates.First((NodeEditorState s) => s.name == stateName);
                if (state == null)
                {
                    state = canvas.editorStates[0];
                }
            }
            if (state == null)
            {
                state               = ScriptableObject.CreateInstance <NodeEditorState>();
                state.canvas        = canvas;
                canvas.editorStates = new NodeEditorState[] { state };
#if UNITY_EDITOR
                UnityEditor.EditorUtility.SetDirty(canvas);
#endif
            }
            state.name = stateName;
            return(state);
        }
コード例 #2
0
 private static NodeEditorState[] CreateWorkingCopy(NodeEditorState[] editorStates, NodeCanvas associatedNodeCanvas)
 {
     if (editorStates == null)
     {
         return(new NodeEditorState[0]);
     }
     editorStates = (NodeEditorState[])editorStates.Clone();
     for (int stateCnt = 0; stateCnt < editorStates.Length; stateCnt++)
     {
         if (editorStates[stateCnt] == null)
         {
             continue;
         }
         NodeEditorState state = editorStates[stateCnt] = Clone(editorStates[stateCnt]);
         if (state == null)
         {
             Debug.LogError("Failed to create a working copy for an NodeEditorState during the loading process of " + associatedNodeCanvas.name + "!");
             continue;
         }
         state.canvas = associatedNodeCanvas;
     }
     associatedNodeCanvas.editorStates = editorStates;
     return(editorStates);
 }
コード例 #3
0
 public NodeEditorUserCache(string CachePath, NodeCanvas loadedCanvas)
 {
     useCache  = true;
     cachePath = CachePath;
     SetCanvas(loadedCanvas);
 }
コード例 #4
0
        public static NodeCanvas CreateWorkingCopy(NodeCanvas nodeCanvas, bool editorStates)
        {
            nodeCanvas.Validate();
            nodeCanvas = Clone(nodeCanvas);


            List <ScriptableObject> allSOs    = new List <ScriptableObject>();
            List <ScriptableObject> clonedSOs = new List <ScriptableObject>();

            for (int nodeCnt = 0; nodeCnt < nodeCanvas.nodes.Count; nodeCnt++)
            {
                Node node = nodeCanvas.nodes[nodeCnt];
                node.CheckNodeKnobMigration();


                Node clonedNode = AddClonedSO(allSOs, clonedSOs, node);
                AddClonedSOs(allSOs, clonedSOs, clonedNode.GetScriptableObjects());

                foreach (NodeKnob knob in clonedNode.nodeKnobs)
                {
                    AddClonedSO(allSOs, clonedSOs, knob);
                    AddClonedSOs(allSOs, clonedSOs, knob.GetScriptableObjects());
                }
            }


            for (int nodeCnt = 0; nodeCnt < nodeCanvas.nodes.Count; nodeCnt++)
            {
                Node node = nodeCanvas.nodes[nodeCnt];

                Node clonedNode = nodeCanvas.nodes[nodeCnt] = ReplaceSO(allSOs, clonedSOs, node);
                clonedNode.CopyScriptableObjects((ScriptableObject so) => ReplaceSO(allSOs, clonedSOs, so));


                clonedNode.Inputs  = new List <NodeInput>();
                clonedNode.Outputs = new List <NodeOutput>();
                for (int knobCnt = 0; knobCnt < clonedNode.nodeKnobs.Count; knobCnt++)
                {
                    NodeKnob knob = clonedNode.nodeKnobs[knobCnt] = ReplaceSO(allSOs, clonedSOs, clonedNode.nodeKnobs[knobCnt]);
                    knob.body = clonedNode;

                    knob.CopyScriptableObjects((ScriptableObject so) => ReplaceSO(allSOs, clonedSOs, so));

                    if (knob is NodeInput)
                    {
                        clonedNode.Inputs.Add(knob as NodeInput);
                    }
                    else if (knob is NodeOutput)
                    {
                        clonedNode.Outputs.Add(knob as NodeOutput);
                    }
                }
            }

            if (editorStates)
            {
                nodeCanvas.editorStates = CreateWorkingCopy(nodeCanvas.editorStates, nodeCanvas);
                foreach (NodeEditorState state in nodeCanvas.editorStates)
                {
                    state.selectedNode = ReplaceSO(allSOs, clonedSOs, state.selectedNode);
                }
            }
            else
            {
                foreach (NodeEditorState state in nodeCanvas.editorStates)
                {
                    state.selectedNode = null;
                }
            }

            return(nodeCanvas);
        }
コード例 #5
0
 public NodeEditorUserCache(NodeCanvas loadedCanvas)
 {
     useCache = false;
     SetCanvas(loadedCanvas);
 }
コード例 #6
0
 public void SetCanvas(NodeCanvas canvas)
 {
     nodeCanvas  = canvas;
     editorState = NodeEditorSaveManager.ExtractEditorState(nodeCanvas, MainEditorStateIdentifier);
     NodeEditor.RepaintClients();
 }
 public virtual void OnSaveCanvas(NodeCanvas canvas)
 {
 }
 public virtual void OnLoadCanvas(NodeCanvas canvas)
 {
 }
コード例 #9
0
ファイル: NodeEditor.cs プロジェクト: mdlandis/voidheart
        private static void DrawSubCanvas(NodeCanvas nodeCanvas, NodeEditorState editorState)
        {
            if (!editorState.drawing)
            {
                return;
            }

            NodeCanvas      prevNodeCanvas  = curNodeCanvas;
            NodeEditorState prevEditorState = curEditorState;

            curNodeCanvas  = nodeCanvas;
            curEditorState = editorState;

            if (Event.current.type == EventType.Repaint)
            {
                float   width      = curEditorState.zoom / NodeEditorGUI.Background.width;
                float   height     = curEditorState.zoom / NodeEditorGUI.Background.height;
                Vector2 offset     = curEditorState.zoomPos + curEditorState.panOffset / curEditorState.zoom;
                Rect    uvDrawRect = new Rect(-offset.x * width,
                                              (offset.y - curEditorState.canvasRect.height) * height,
                                              curEditorState.canvasRect.width * width,
                                              curEditorState.canvasRect.height * height);
                GUI.DrawTextureWithTexCoords(curEditorState.canvasRect, NodeEditorGUI.Background, uvDrawRect);
            }

            NodeEditorInputSystem.HandleInputEvents(curEditorState);
            if (Event.current.type != EventType.Layout)
            {
                curEditorState.ignoreInput = new List <Rect>();
            }

            Rect canvasRect = curEditorState.canvasRect;

            curEditorState.zoomPanAdjust = GUIScaleUtility.BeginScale(ref canvasRect, curEditorState.zoomPos, curEditorState.zoom, false);
            if (curEditorState.navigate)
            {
                Vector2 startPos = (curEditorState.selectedNode != null ? curEditorState.selectedNode.rect.center : curEditorState.panOffset) + curEditorState.zoomPanAdjust;
                Vector2 endPos   = Event.current.mousePosition;
                RTEditorGUI.DrawLine(startPos, endPos, Color.green, null, 3);
                RepaintClients();
            }

            if (curEditorState.connectOutput != null)
            {
                NodeOutput output   = curEditorState.connectOutput;
                Vector2    startPos = output.GetGUIKnob().center;
                Vector2    startDir = output.GetDirection();
                Vector2    endPos   = Event.current.mousePosition;
                Vector2    endDir   = NodeEditorGUI.GetSecondConnectionVector(startPos, endPos, startDir);
                NodeEditorGUI.DrawConnection(startPos, startDir, endPos, endDir, output.typeData.Color);
                RepaintClients();
            }

            if (Event.current.type == EventType.Layout && curEditorState.selectedNode != null)
            {
                curNodeCanvas.nodes.Remove(curEditorState.selectedNode);
                curNodeCanvas.nodes.Add(curEditorState.selectedNode);
            }

            for (int nodeCnt = 0; nodeCnt < curNodeCanvas.nodes.Count; nodeCnt++)
            {
                curNodeCanvas.nodes[nodeCnt].DrawConnections();
            }

            for (int nodeCnt = 0; nodeCnt < curNodeCanvas.nodes.Count; nodeCnt++)
            {
                Node node = curNodeCanvas.nodes[nodeCnt];
                node.DrawNode();
                if (Event.current.type == EventType.Repaint)
                {
                    node.DrawKnobs();
                }
            }

            GUIScaleUtility.EndScale();

            GUI.DrawTexture(new Rect(12, 12, NodeEditorGUI.GuiShadero.width / 2, NodeEditorGUI.GuiShadero.height / 2), NodeEditorGUI.GuiShadero);
            GUIStyle g = new GUIStyle();

            g.fontSize         = 26;
            g.normal.textColor = Color.white;
            if (Node.ShaderNameX == "")
            {
                Node.ShaderNameX = "Default";
            }
            g          = new GUIStyle();
            g.fontSize = 22;

            if (FlagIsLoadedMaterial)
            {
                FlagIsLoadedMaterial = false;
            }
            if (FlagIsSavedMaterial)
            {
                FlagIsSavedMaterial = false;
            }

            g                  = new GUIStyle();
            g.fontSize         = 18;
            g.normal.textColor = Color.white;

            Texture2D preview = ResourceManager.LoadTexture("Textures/previews/shadero_firstscreen.jpg");

            g           = new GUIStyle();
            g.fontSize  = 18;
            g.fontStyle = FontStyle.Italic;
            Color yellow = new Color(0, 1, 1, UpdatePreview);

            UpdatePreview -= Time.deltaTime * 0.2f;
            if (UpdatePreview < 0)
            {
                UpdatePreview = 0;
            }
            g.normal.textColor = yellow;

            Rect position = _ShaderoShaderEditorFramework.Standard.NodeEditorWindow.editor.position;

            GUI.Label(new Rect(position.width - 320, position.height - 50, 150, 50), "*Updated*", g);

            Node.ShaderNameX = NodeEditor.curEditorState.ShaderName;

            if (curNodeCanvas.nodes.Count == 0)
            {
                preview = ResourceManager.LoadTexture("Textures/previews/shadero_firstscreen.jpg");
                Vector2 scr  = new Vector2(position.width / 2 - 120, position.height / 2);
                Vector2 size = new Vector2(1365 / 2, 781 / 2);
                GUI.DrawTexture(new Rect(scr.x - size.x / 2, scr.y - size.y / 2, size.x, size.y), preview);
            }

            NodeEditorInputSystem.HandleLateInputEvents(curEditorState);
            curNodeCanvas  = prevNodeCanvas;
            curEditorState = prevEditorState;
        }