public void SetCanvas(NodeCanvas canvas) { nodeCanvas = canvas; editorState = NodeEditorSaveManager.ExtractEditorState(nodeCanvas, MainEditorStateIdentifier); NodeEditor.RepaintClients(); }
public virtual void OnSaveEditorState(NodeEditorState editorState) { }
public static Vector2 ScreenToCanvasSpace(NodeEditorState editorState, Vector2 screenPos) { return((screenPos - editorState.canvasRect.position - editorState.zoomPos) * editorState.zoom - editorState.panOffset); }
public virtual void OnLoadEditorState(NodeEditorState editorState) { }
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; }