public void SaveCanvas()
        {
            string path = canvasCache.nodeCanvas.savePath;

            if (!string.IsNullOrEmpty(path))
            {
                canvasCache.SaveNodeCanvas(path);
                ShowNotification(new GUIContent("Canvas Saved!"));
                Debug.Log($"{path}已保存成功");
            }
            else
            {
                Debug.LogError($"{path}保存失败,请先确保要覆盖的文件已存在!(尝试使用Save As创建目标文件)");
                ShowNotification(new GUIContent("No save location found. Use 'Save As'!"));
            }
        }
Пример #2
0
        private void SaveCanvas()
        {
            string path = canvasCache.nodeCanvas.savePath;

            if (!string.IsNullOrEmpty(path))
            {
                if (path.StartsWith("SCENE/"))
                {
                    canvasCache.SaveSceneNodeCanvas(path.Substring(6));
                }
                else
                {
                    canvasCache.SaveNodeCanvas(path);
                }
            }
            else
            {
                ShowNotification(new GUIContent("No save location found. Use 'Save As'!"));
            }
        }
Пример #3
0
        public void SaveCanvas()
        {
            string path = canvasCache.nodeCanvas.savePath;

            if (!string.IsNullOrEmpty(path))
            {
                if (path.StartsWith("SCENE/"))
                {
                    canvasCache.SaveSceneNodeCanvas(path.Substring(6));
                }
                else
                {
                    canvasCache.SaveNodeCanvas(path);
                }
                ShowNotification(new GUIContent("Canvas Saved!"));
            }
            else
            {
                SaveCanvasAs();
            }
        }
Пример #4
0
        public void DrawSideWindow()
        {
            GUILayout.Label(new GUIContent("TextureWang ", "Opened Canvas path: " + openedCanvasPath), NodeEditorGUI.nodeLabelBold);

            if (GUILayout.Button(new GUIContent("Save Canvas", "Saves the Canvas to a Canvas Save File in the Assets Folder")))
            {
                string path = EditorUtility.SaveFilePanelInProject("Save Node Canvas", "Node Canvas", "asset", "", NodeEditor.editorPath + "Resources/Saves/");
                if (!string.IsNullOrEmpty(path))
                {
                    canvasCache.SaveNodeCanvas(path);
                }

/*
 *              string path = EditorUtility.SaveFilePanelInProject ("Save Node Canvas", m_LastLoadedName, "asset", "", NodeEditor.editorPath + "Resources/Saves/");
 *                          if (!string.IsNullOrEmpty(path))
 *                          {
 *                              SaveNodeCanvas(path);
 *
 *              }
 */
                if (m_NodeSelectionWindow != null)
                {
                    m_NodeSelectionWindow.ReInit();
                }
            }

            /*
             *          if (GUILayout.Button(new GUIContent("New Canvas",
             *                  "Create a copy")))
             *          {
             *              CreateEditorCopy();
             *          }
             */

            if (GUILayout.Button(new GUIContent("Load Canvas", "Loads the Canvas from a Canvas Save File in the Assets Folder")))
            {
                string path = EditorUtility.OpenFilePanel("Load Node Canvas", NodeEditor.editorPath + "Resources/Saves/", "asset");
                if (!path.Contains(Application.dataPath))
                {
                    if (!string.IsNullOrEmpty(path))
                    {
                        ShowNotification(new GUIContent("You should select an asset inside your project folder!"));
                    }
                }
                else
                {
                    NodeEditor.curEditorState = null;
                    canvasCache.LoadNodeCanvas(path);
                    canvasCache.NewEditorState();
                }
            }

            if (GUILayout.Button(new GUIContent("New TextureWang", "Create a new TextureWang Canvas")))
            {
                NewTextureWangPopup.Init(this);
            }


            if (GUILayout.Button(new GUIContent("Recalculate All",
                                                "Initiates complete recalculate. Usually does not need to be triggered manually.")))
            {
                NodeEditor.RecalculateAll(canvasCache.nodeCanvas);
                GUI.changed = false;
            }

            if (GUILayout.Button("Force Re-Init"))
            {
                NodeEditor.ReInit(true);
            }

            NodeEditorGUI.knobSize       = EditorGUILayout.IntSlider(new GUIContent("Handle Size", "The size of the Node Input/Output handles"), NodeEditorGUI.knobSize, 12, 20);
            canvasCache.editorState.zoom = EditorGUILayout.Slider(new GUIContent("Zoom", "Use the Mousewheel. Seriously."), canvasCache.editorState.zoom, 0.6f, 2);

            //miked            mainNodeCanvas.scaleMode = (ScaleMode)EditorGUILayout.EnumPopup(new GUIContent("ScaleMode", ""), mainNodeCanvas.scaleMode, GUILayout.MaxWidth(200));



            //        m_OpType = (TexOP)UnityEditor.EditorGUILayout.EnumPopup(new GUIContent("Type", "The type of calculation performed on Input 1"), m_OpType, GUILayout.MaxWidth(200));
            //            if (mainNodeCanvas != null)
            {
                //                EditorGUILayout.LabelField("width: " + mainNodeCanvas.m_TexWidth);
                //                EditorGUILayout.LabelField("height: " + mainNodeCanvas.m_TexHeight);
            }

/*
 *          if (NodeEditor.curEditorState == null)
 *          {
 *              Debug.Log("TWWindow has no editor state " + NodeEditor.curEditorState);
 *          }
 *          else if (NodeEditor.curEditorState.selectedNode == null)
 *          {
 *              Debug.Log("TWWindow has no Selected Node " + NodeEditor.curEditorState);
 *          }
 *          else
 *          {
 *              Debug.Log(" Selected Node " + NodeEditor.curEditorState.selectedNode);
 *          }
 */
            if (canvasCache.editorState != null && canvasCache.editorState.selectedNode != null)
            // if (Event.current.type != EventType.Ignore)
            {
                RTEditorGUI.Seperator();
                GUILayout.Label(canvasCache.editorState.selectedNode.name);
                RTEditorGUI.Seperator();
                canvasCache.editorState.selectedNode.DrawNodePropertyEditor();
                if (GUI.changed)
                {
                    NodeEditor.RecalculateFrom(PriorLoop(canvasCache.editorState.selectedNode));
                }
            }


            //            var assets = UnityEditor.AssetDatabase.FindAssets("NodeCanvas");
            //            foreach(var x in assets)
            //                GUILayout.Label(new GUIContent("Node Editor (" + x + ")", "Opened Canvas path: " ), NodeEditorGUI.nodeLabelBold);

            /*
             *          if (m_All == null)
             *              m_All = GetAtPath<NodeCanvas>("Node_Editor-master/Node_Editor/Resources/Saves");//Resources.LoadAll<NodeCanvas>(NodeEditor.editorPath + "Resources/Saves/");
             *
             *          scrollPos =EditorGUILayout.BeginScrollView(scrollPos, GUILayout.Width(300), GUILayout.Height(600));
             *          guiStyle.fontSize = 20;
             *          guiStyle.fixedHeight = 20;
             *          foreach (var x in m_All)
             *               EditorGUILayout.SelectableLabel("(" + x.name + ")", guiStyle);
             *          EditorGUILayout.EndScrollView();
             */
        }
Пример #5
0
        private void DrawSideWindow()
        {
            GUILayout.Label(new GUIContent("Node Editor (" + canvasCache.nodeCanvas.name + ")", "Opened Canvas path: " + canvasCache.openedCanvasPath), NodeEditorGUI.nodeLabelBold);

            EditorGUILayout.ObjectField("Loaded Canvas", canvasCache.nodeCanvas, typeof(NodeCanvas), false);
            EditorGUILayout.ObjectField("Loaded State", canvasCache.editorState, typeof(NodeEditorState), false);

/*
 *                      if (GUILayout.Button(new GUIContent("New Canvas", "Loads an Specified Empty CanvasType")))
 *                      {
 *                              NodeEditorFramework.Utilities.GenericMenu menu = new NodeEditorFramework.Utilities.GenericMenu();
 *                              NodeCanvasManager.FillCanvasTypeMenu(ref menu, canvasCache.NewNodeCanvas);
 *                              menu.Show(createCanvasUIPos.position, createCanvasUIPos.width);
 *                      }
 */
            if (Event.current.type == EventType.Repaint)
            {
                Rect popupPos = GUILayoutUtility.GetLastRect();
                createCanvasUIPos = new Rect(popupPos.x + 2, popupPos.yMax + 2, popupPos.width - 4, 0);
            }

            GUILayout.Space(6);

            if (GUILayout.Button(new GUIContent("Save Canvas", "Saves the Canvas to a Canvas Save File in the Assets Folder")))
            {
                string path = EditorUtility.SaveFilePanelInProject("Save Node Canvas", "Node Canvas", "asset", "", NodeEditor.editorPath + "Resources/Saves/");
                if (!string.IsNullOrEmpty(path))
                {
                    canvasCache.SaveNodeCanvas(path);
                }
            }

            if (GUILayout.Button(new GUIContent("Load Canvas", "Loads the Canvas from a Canvas Save File in the Assets Folder")))
            {
                string path = EditorUtility.OpenFilePanel("Load Node Canvas", NodeEditor.editorPath + "Resources/Saves/", "asset");
                if (!path.Contains(Application.dataPath))
                {
                    if (!string.IsNullOrEmpty(path))
                    {
                        ShowNotification(new GUIContent("You should select an asset inside your project folder!"));
                    }
                }
                else
                {
                    canvasCache.LoadNodeCanvas(path);
                }
            }

            GUILayout.Space(6);

            GUILayout.BeginHorizontal();
            sceneCanvasName = GUILayout.TextField(sceneCanvasName, GUILayout.ExpandWidth(true));
            if (GUILayout.Button(new GUIContent("Save to Scene", "Saves the Canvas to the Scene"), GUILayout.ExpandWidth(false)))
            {
                canvasCache.SaveSceneNodeCanvas(sceneCanvasName);
            }
            GUILayout.EndHorizontal();

            if (GUILayout.Button(new GUIContent("Load from Scene", "Loads the Canvas from the Scene")))
            {
                NodeEditorFramework.Utilities.GenericMenu menu = new NodeEditorFramework.Utilities.GenericMenu();
                foreach (string sceneSave in NodeEditorSaveManager.GetSceneSaves())
                {
                    menu.AddItem(new GUIContent(sceneSave), false, LoadSceneCanvasCallback, (object)sceneSave);
                }
                menu.Show(loadSceneUIPos.position, loadSceneUIPos.width);
            }
            if (Event.current.type == EventType.Repaint)
            {
                Rect popupPos = GUILayoutUtility.GetLastRect();
                loadSceneUIPos = new Rect(popupPos.x + 2, popupPos.yMax + 2, popupPos.width - 4, 0);
            }

            GUILayout.Space(6);

            if (GUILayout.Button(new GUIContent("Recalculate All", "Initiates complete recalculate. Usually does not need to be triggered manually.")))
            {
                NodeEditor.RecalculateAll(canvasCache.nodeCanvas);
            }

            if (GUILayout.Button("Force Re-Init"))
            {
                NodeEditor.ReInit(true);
            }

            NodeEditorGUI.knobSize       = EditorGUILayout.IntSlider(new GUIContent("Handle Size", "The size of the Node Input/Output handles"), NodeEditorGUI.knobSize, 12, 20);
            canvasCache.editorState.zoom = EditorGUILayout.Slider(new GUIContent("Zoom", "Use the Mousewheel. Seriously."), canvasCache.editorState.zoom, 0.6f, 2);

            if (canvasCache.editorState.selectedNode != null && Event.current.type != EventType.Ignore)
            {
                canvasCache.editorState.selectedNode.DrawNodePropertyEditor();
            }
        }
        public void DrawSideWindow()
        {
            string canvasName = "Node Canvas";

            if (canvasCache != null && !string.IsNullOrEmpty(canvasCache.openedCanvasPath))
            {
                canvasName = canvasCache.openedCanvasPath.Substring(canvasCache.openedCanvasPath.LastIndexOf(@"/") + 1);
                canvasName = canvasName.Replace(".asset", "");
            }

            GUILayout.Label(new GUIContent(canvasName));

            if (GUILayout.Button(new GUIContent("Save Canvas", "Saves the Canvas to a Canvas Save File in the Assets Folder")))
            {
                string lastpath = NodeEditor.editorPathLoadSave + "Saves/";
                lastpath = GetLastUsedPath(lastpath);
                string path = EditorUtility.SaveFilePanelInProject("Save Node Canvas", canvasName, "asset", "", lastpath);
                if (!string.IsNullOrEmpty(path))
                {
                    canvasCache.SaveNodeCanvas(path);
                }

/*
 *              string path = EditorUtility.SaveFilePanelInProject ("Save Node Canvas", m_LastLoadedName, "asset", "", NodeEditor.editorPath + "Resources/Saves/");
 *                          if (!string.IsNullOrEmpty(path))
 *                          {
 *                              SaveNodeCanvas(path);
 *
 *              }
 */
                if (m_NodeSelectionWindow != null)
                {
                    m_NodeSelectionWindow.ReInit();
                }
            }

            /*
             *          if (GUILayout.Button(new GUIContent("New Canvas",
             *                  "Create a copy")))
             *          {
             *              CreateEditorCopy();
             *          }
             */

            if (GUILayout.Button(new GUIContent("Load Canvas", "Loads the Canvas from a Canvas Save File in the Assets Folder")))
            {
                string lastpath = NodeEditor.editorPathLoadSave + "Saves/";
                lastpath = GetLastUsedPath(lastpath);
                Debug.Log(" last path for load canvas" + lastpath);
                string path = EditorUtility.OpenFilePanel("Load Node Canvas", lastpath, "asset");

                if (!path.Contains(Application.dataPath))
                {
                    if (!string.IsNullOrEmpty(path))
                    {
                        ShowNotification(new GUIContent("You should select an asset inside your project folder!"));
                    }
                }
                else
                {
                    NodeEditor.curEditorState = null;
                    canvasCache.LoadNodeCanvas(path);
                    canvasCache.NewEditorState();
                }
                NodeEditor.RecalculateAll(canvasCache.nodeCanvas);
            }

            if (GUILayout.Button(new GUIContent("New TextureWang", "Create a new TextureWang Canvas")))
            {
                NewTextureWangPopup.Init(this);
            }


            if (GUILayout.Button(new GUIContent("Recalculate All", "Initiates complete recalculate. Usually does not need to be triggered manually.")))
            {
                NodeEditor.RecalculateAll(canvasCache.nodeCanvas);
                GUI.changed = false;
            }
            if (GUILayout.Button(new GUIContent("Recalculate All Export PNG'S", "Initiates complete recalculate. Usually does not need to be triggered manually.")))
            {
                UnityTextureOutput.ms_ExportPNG = true;
                NodeEditor.RecalculateAll(canvasCache.nodeCanvas);
                GUI.changed = false;
                UnityTextureOutput.ms_ExportPNG = false;
            }
            canvasCache.nodeCanvas.m_PreviewAnimation     = GUILayout.Toggle(canvasCache.nodeCanvas.m_PreviewAnimation, "Preview Animation");
            canvasCache.nodeCanvas.m_ExportToExternalPath = GUILayout.Toggle(canvasCache.nodeCanvas.m_ExportToExternalPath, "Export To External Path");
            if (GUILayout.Button(new GUIContent("Browse External path", "Sets External export path outside asset folder ")))
            {
                canvasCache.nodeCanvas.m_ExternalPath = EditorUtility.SaveFolderPanel("Set External Export Path", canvasCache.nodeCanvas.m_ExternalPath, "");
            }
            canvasCache.nodeCanvas.m_ExternalPath    = GUILayout.TextField(canvasCache.nodeCanvas.m_ExternalPath);
            UnityTextureOutput.ms_ExportExternal     = canvasCache.nodeCanvas.m_ExportToExternalPath;
            UnityTextureOutput.ms_ExportExternalPath = canvasCache.nodeCanvas.m_ExternalPath;


            if (GUILayout.Button(new GUIContent("Recalculate All Animated Export PNG'S", "Initiates complete recalculate. ")))
            {
                UnityTextureOutput.ms_ExportPNG = true;
                int   count = 0;
                float step  = 1.0f / canvasCache.nodeCanvas.m_FrameCount;
                UnityTextureOutput.ms_ExportPNGFrameCount = canvasCache.nodeCanvas.m_FrameCount;
                for (float f = 0; f <= 1.001f; f += step)
                {
                    UnityTextureOutput.ms_ExportPNGAnimated = true;
                    UnityTextureOutput.ms_ExportPNGFrame    = count++;
                    foreach (var x in canvasCache.nodeCanvas.nodes)
                    {
                        if (x is InputNodeAnimated)
                        {
                            var ina = x as InputNodeAnimated;
                            ina.m_Value.Set(f);
                        }
                        if (x is UnityTextureOutput || x is UnityTextureOutputMetalicAndRoughness ||
                            x is UnityTextureOutputRGBA)
                        {
                            //x.m_DirtyID = -1;
                        }
                    }
                    NodeEditor.RecalculateAll(canvasCache.nodeCanvas);
                }
                GUI.changed = false;

                UnityTextureOutput.ms_ExportPNG         = false;
                UnityTextureOutput.ms_ExportPNGAnimated = false;
            }

            //            if (GUILayout.Button ("Force Re-Init"))
            //				NodeEditor.ReInit (true);
            if (GUILayout.Button(new GUIContent("Double All texture Sizes", "")))
            {
                foreach (var n in canvasCache.nodeCanvas.nodes)
                {
                    if (n is TextureNode)
                    {
                        var tn = n as TextureNode;
                        tn.m_TexWidth  *= 2;
                        tn.m_TexHeight *= 2;
                    }
                }
                NodeEditor.RecalculateAll(canvasCache.nodeCanvas);
            }
            if (GUILayout.Button(new GUIContent("Set All Selected to Default Size", "")))
            {
                foreach (var n in canvasCache.editorState.selectedNodes)
                {
                    if (n is TextureNode)
                    {
                        var tn = n as TextureNode;
                        tn.m_TexWidth  = canvasCache.nodeCanvas.m_DefaultTextureWidth;
                        tn.m_TexHeight = canvasCache.nodeCanvas.m_DefaultTextureHeight;
                    }
                }

                NodeEditor.RecalculateAll(canvasCache.nodeCanvas);
            }

            if (GUILayout.Button(new GUIContent("Halve All texture Sizes", "")))
            {
                foreach (var n in canvasCache.nodeCanvas.nodes)
                {
                    if (n is TextureNode)
                    {
                        var tn = n as TextureNode;
                        tn.m_TexWidth  >>= 1;
                        tn.m_TexHeight >>= 1;
                    }
                }
                NodeEditor.RecalculateAll(canvasCache.nodeCanvas);
            }

            bool changed = GUI.changed;

            GUI.changed                  = false;
            NodeEditorGUI.knobSize       = EditorGUILayout.IntSlider(new GUIContent("Handle Size", "The size of the Node Input/Output handles"), NodeEditorGUI.knobSize, 12, 20);
            canvasCache.editorState.zoom = EditorGUILayout.Slider(new GUIContent("Zoom", "Use the Mousewheel. Seriously."), canvasCache.editorState.zoom, 0.2f, 4);
            m_OpenAppearance             = EditorGUILayout.Foldout(m_OpenAppearance, "");
            if (m_OpenAppearance)
            {
                Node.m_DropShadowMult = EditorGUILayout.Slider(new GUIContent("DropShadow", ""), Node.m_DropShadowMult,
                                                               0.0f, 1);
                Node.m_DropShadowMult2 = EditorGUILayout.Slider(new GUIContent("DropShadow Wires", ""),
                                                                Node.m_DropShadowMult2, 0.0f, 1);
                Node.m_WireSize  = EditorGUILayout.Slider(new GUIContent("m_WireSize", ""), Node.m_WireSize, 0.0f, 30);
                Node.m_WireSize2 = EditorGUILayout.Slider(new GUIContent("WireSize Shadow", ""), Node.m_WireSize2, 0.0f,
                                                          50);
                Node.m_Saturation    = EditorGUILayout.Slider(new GUIContent("Saturation", ""), Node.m_Saturation, 0.0f, 1);
                Node.m_WireColbright = EditorGUILayout.Slider(new GUIContent("m_WireColbright", ""),
                                                              Node.m_WireColbright, 0.0f, 1);

                Node.m_DropShadowOffset = EditorGUILayout.Slider(new GUIContent("DropShadowOffset", ""),
                                                                 Node.m_DropShadowOffset, -50.0f, 50);
                Node.m_DropShadowExpand = EditorGUILayout.Slider(new GUIContent("m_DropShadowExpand", ""),
                                                                 Node.m_DropShadowExpand, 0f, 50);
            }
            bool changeView = GUI.changed;

            GUI.changed = changed;
            if (canvasCache.nodeCanvas != null)
            {
                canvasCache.nodeCanvas.m_FrameCount =
                    EditorGUILayout.IntSlider(new GUIContent("Animation Frame Count", ""),
                                              canvasCache.nodeCanvas.m_FrameCount, 1, 1024);
                canvasCache.nodeCanvas.m_DefaultTextureWidth  = EditorGUILayout.IntSlider(new GUIContent("Default tex Width", ""), canvasCache.nodeCanvas.m_DefaultTextureWidth, 1, 4096);
                canvasCache.nodeCanvas.m_DefaultTextureHeight = EditorGUILayout.IntSlider(new GUIContent("Default tex Height", ""), canvasCache.nodeCanvas.m_DefaultTextureHeight, 1, 4096);

                canvasCache.nodeCanvas.m_DefaultChannelType = (ChannelType)UnityEditor.EditorGUILayout.EnumPopup(new GUIContent("pixel Depth", ""), canvasCache.nodeCanvas.m_DefaultChannelType);
            }


            //miked            mainNodeCanvas.scaleMode = (ScaleMode)EditorGUILayout.EnumPopup(new GUIContent("ScaleMode", ""), mainNodeCanvas.scaleMode, GUILayout.MaxWidth(200));



            //        m_OpType = (TexOP)UnityEditor.EditorGUILayout.EnumPopup(new GUIContent("Type", "The type of calculation performed on Input 1"), m_OpType, GUILayout.MaxWidth(200));
            //            if (mainNodeCanvas != null)
            {
                //                EditorGUILayout.LabelField("width: " + mainNodeCanvas.m_TexWidth);
                //                EditorGUILayout.LabelField("height: " + mainNodeCanvas.m_TexHeight);
            }

/*
 *          if (NodeEditor.curEditorState == null)
 *          {
 *              Debug.Log("TWWindow has no editor state " + NodeEditor.curEditorState);
 *          }
 *          else if (NodeEditor.curEditorState.selectedNode == null)
 *          {
 *              Debug.Log("TWWindow has no Selected Node " + NodeEditor.curEditorState);
 *          }
 *          else
 *          {
 *              Debug.Log(" Selected Node " + NodeEditor.curEditorState.selectedNode);
 *          }
 */
            if (canvasCache.editorState != null && canvasCache.editorState.selectedNode != null)
            // if (Event.current.type != EventType.Ignore)
            {
                RTEditorGUI.Seperator();
                GUILayout.Label(canvasCache.editorState.selectedNode.name);
                RTEditorGUI.Seperator();
                if (canvasCache.editorState.selectedNode is SubTreeNode)
                {
                    if (GUILayout.Button("Edit Sub Canvas"))
                    {
                        string NodeCanvasPath = AssetDatabase.GUIDToAssetPath((canvasCache.editorState.selectedNode as SubTreeNode).m_CanvasGuid);

                        NodeEditor.curEditorState = null;
                        canvasCache.LoadNodeCanvas(NodeCanvasPath);
                        canvasCache.NewEditorState();
                    }
                }
                if (canvasCache.editorState.selectedNode)
                {
                    canvasCache.editorState.selectedNode.DrawNodePropertyEditor();
                }
                if (GUI.changed && canvasCache.editorState.selectedNode)
                {
                    NodeEditor.RecalculateFrom(PriorLoop(canvasCache.editorState.selectedNode));
                }
                else
                if (changeView)
                {
                    Repaint();
                    Debug.Log("repaint 5");
                }
            }



            //            var assets = UnityEditor.AssetDatabase.FindAssets("NodeCanvas");
            //            foreach(var x in assets)
            //                GUILayout.Label(new GUIContent("Node Editor (" + x + ")", "Opened Canvas path: " ), NodeEditorGUI.nodeLabelBold);

            /*
             *          if (m_All == null)
             *              m_All = GetAtPath<NodeCanvas>("Node_Editor-master/Node_Editor/Resources/Saves");//Resources.LoadAll<NodeCanvas>(NodeEditor.editorPath + "Resources/Saves/");
             *
             *          scrollPos =EditorGUILayout.BeginScrollView(scrollPos, GUILayout.Width(300), GUILayout.Height(600));
             *          guiStyle.fontSize = 20;
             *          guiStyle.fixedHeight = 20;
             *          foreach (var x in m_All)
             *               EditorGUILayout.SelectableLabel("(" + x.name + ")", guiStyle);
             *          EditorGUILayout.EndScrollView();
             */
        }
        public void DrawSideWindow()
        {
            string canvasName = "Node Canvas";

            if (canvasCache != null && !string.IsNullOrEmpty(canvasCache.openedCanvasPath))
            {
                canvasName = canvasCache.openedCanvasPath.Substring(canvasCache.openedCanvasPath.LastIndexOf(@"/") + 1);
                canvasName = canvasName.Replace(".asset", "");
            }

            GUILayout.Label(new GUIContent(canvasName));

            if (GUILayout.Button(new GUIContent("Save Canvas", "Saves the Canvas to a Canvas Save File in the Assets Folder")))
            {
                string lastpath = NodeEditor.editorPathLoadSave + "Saves/";
                lastpath = GetLastUsedPath(lastpath);
                string path = EditorUtility.SaveFilePanelInProject("Save Node Canvas", canvasName, "asset", "", lastpath);
                if (!string.IsNullOrEmpty(path))
                {
                    canvasCache.SaveNodeCanvas(path);
                }

/*
 *              string path = EditorUtility.SaveFilePanelInProject ("Save Node Canvas", m_LastLoadedName, "asset", "", NodeEditor.editorPath + "Resources/Saves/");
 *                          if (!string.IsNullOrEmpty(path))
 *                          {
 *                              SaveNodeCanvas(path);
 *
 *              }
 */
                if (m_NodeSelectionWindow != null)
                {
                    m_NodeSelectionWindow.ReInit();
                }
            }

            /*
             *          if (GUILayout.Button(new GUIContent("New Canvas",
             *                  "Create a copy")))
             *          {
             *              CreateEditorCopy();
             *          }
             */

            if (GUILayout.Button(new GUIContent("Load Canvas", "Loads the Canvas from a Canvas Save File in the Assets Folder")))
            {
                string lastpath = NodeEditor.editorPathLoadSave + "Saves/";
                lastpath = GetLastUsedPath(lastpath);
                string path = EditorUtility.OpenFilePanel("Load Node Canvas", lastpath, "asset");

                if (!path.Contains(Application.dataPath))
                {
                    if (!string.IsNullOrEmpty(path))
                    {
                        ShowNotification(new GUIContent("You should select an asset inside your project folder!"));
                    }
                }
                else
                {
                    NodeEditor.curEditorState = null;
                    canvasCache.LoadNodeCanvas(path);
                    canvasCache.NewEditorState();
                }
                NodeEditor.RecalculateAll(canvasCache.nodeCanvas);
            }

            if (GUILayout.Button(new GUIContent("New TextureWang", "Create a new TextureWang Canvas")))
            {
                NewTextureWangPopup.Init(this);
            }


            if (GUILayout.Button(new GUIContent("Recalculate All", "Initiates complete recalculate. Usually does not need to be triggered manually.")))
            {
                NodeEditor.RecalculateAll(canvasCache.nodeCanvas);
                GUI.changed = false;
            }
            if (GUILayout.Button(new GUIContent("Recalculate All Export PNG'S", "Initiates complete recalculate. Usually does not need to be triggered manually.")))
            {
                UnityTextureOutput.ms_ExportPNG = true;
                NodeEditor.RecalculateAll(canvasCache.nodeCanvas);
                GUI.changed = false;
                UnityTextureOutput.ms_ExportPNG = false;
            }

//            if (GUILayout.Button ("Force Re-Init"))
//				NodeEditor.ReInit (true);
            if (GUILayout.Button(new GUIContent("Double All texture Sizes", "")))
            {
                foreach (var n in canvasCache.nodeCanvas.nodes)
                {
                    if (n is TextureNode)
                    {
                        var tn = n as TextureNode;
                        tn.m_TexWidth  *= 2;
                        tn.m_TexHeight *= 2;
                    }
                }
                NodeEditor.RecalculateAll(canvasCache.nodeCanvas);
            }
            if (GUILayout.Button(new GUIContent("Halve All texture Sizes", "")))
            {
                foreach (var n in canvasCache.nodeCanvas.nodes)
                {
                    if (n is TextureNode)
                    {
                        var tn = n as TextureNode;
                        tn.m_TexWidth  >>= 1;
                        tn.m_TexHeight >>= 1;
                    }
                }
                NodeEditor.RecalculateAll(canvasCache.nodeCanvas);
            }

            NodeEditorGUI.knobSize       = EditorGUILayout.IntSlider(new GUIContent("Handle Size", "The size of the Node Input/Output handles"), NodeEditorGUI.knobSize, 12, 20);
            canvasCache.editorState.zoom = EditorGUILayout.Slider(new GUIContent("Zoom", "Use the Mousewheel. Seriously."), canvasCache.editorState.zoom, 0.2f, 4);

            if (canvasCache.nodeCanvas != null)
            {
                canvasCache.nodeCanvas.m_DefaultTextureWidth =
                    EditorGUILayout.IntSlider(new GUIContent("Default tex Width", ""),
                                              canvasCache.nodeCanvas.m_DefaultTextureWidth, 1, 4096);
                canvasCache.nodeCanvas.m_DefaultTextureHeight =
                    EditorGUILayout.IntSlider(new GUIContent("Default tex Height", ""),
                                              canvasCache.nodeCanvas.m_DefaultTextureHeight, 1, 4096);

                canvasCache.nodeCanvas.m_DefaultChannelType = (ChannelType)UnityEditor.EditorGUILayout.EnumPopup(new GUIContent("pixel Depth", ""), canvasCache.nodeCanvas.m_DefaultChannelType);
            }


            //miked            mainNodeCanvas.scaleMode = (ScaleMode)EditorGUILayout.EnumPopup(new GUIContent("ScaleMode", ""), mainNodeCanvas.scaleMode, GUILayout.MaxWidth(200));



            //        m_OpType = (TexOP)UnityEditor.EditorGUILayout.EnumPopup(new GUIContent("Type", "The type of calculation performed on Input 1"), m_OpType, GUILayout.MaxWidth(200));
            //            if (mainNodeCanvas != null)
            {
                //                EditorGUILayout.LabelField("width: " + mainNodeCanvas.m_TexWidth);
                //                EditorGUILayout.LabelField("height: " + mainNodeCanvas.m_TexHeight);
            }

/*
 *          if (NodeEditor.curEditorState == null)
 *          {
 *              Debug.Log("TWWindow has no editor state " + NodeEditor.curEditorState);
 *          }
 *          else if (NodeEditor.curEditorState.selectedNode == null)
 *          {
 *              Debug.Log("TWWindow has no Selected Node " + NodeEditor.curEditorState);
 *          }
 *          else
 *          {
 *              Debug.Log(" Selected Node " + NodeEditor.curEditorState.selectedNode);
 *          }
 */
            if (canvasCache.editorState != null && canvasCache.editorState.selectedNode != null)
            // if (Event.current.type != EventType.Ignore)
            {
                RTEditorGUI.Seperator();
                GUILayout.Label(canvasCache.editorState.selectedNode.name);
                RTEditorGUI.Seperator();
                if (canvasCache.editorState.selectedNode is SubTreeNode)
                {
                    if (GUILayout.Button("Edit Sub Canvas"))
                    {
                        string NodeCanvasPath = AssetDatabase.GUIDToAssetPath((canvasCache.editorState.selectedNode as SubTreeNode).m_CanvasGuid);

                        NodeEditor.curEditorState = null;
                        canvasCache.LoadNodeCanvas(NodeCanvasPath);
                        canvasCache.NewEditorState();
                    }
                }
                canvasCache.editorState.selectedNode.DrawNodePropertyEditor();
                if (GUI.changed)
                {
                    NodeEditor.RecalculateFrom(PriorLoop(canvasCache.editorState.selectedNode));
                }
            }


            //            var assets = UnityEditor.AssetDatabase.FindAssets("NodeCanvas");
            //            foreach(var x in assets)
            //                GUILayout.Label(new GUIContent("Node Editor (" + x + ")", "Opened Canvas path: " ), NodeEditorGUI.nodeLabelBold);

            /*
             *          if (m_All == null)
             *              m_All = GetAtPath<NodeCanvas>("Node_Editor-master/Node_Editor/Resources/Saves");//Resources.LoadAll<NodeCanvas>(NodeEditor.editorPath + "Resources/Saves/");
             *
             *          scrollPos =EditorGUILayout.BeginScrollView(scrollPos, GUILayout.Width(300), GUILayout.Height(600));
             *          guiStyle.fontSize = 20;
             *          guiStyle.fixedHeight = 20;
             *          foreach (var x in m_All)
             *               EditorGUILayout.SelectableLabel("(" + x.name + ")", guiStyle);
             *          EditorGUILayout.EndScrollView();
             */
        }
        public void SideGUI()
        {
            GUILayout.Label(new GUIContent("" + cache.nodeCanvas.saveName + " (" + (cache.nodeCanvas.livesInScene? "Scene Save" : "Asset Save") + ")", "Opened Canvas path: " + cache.nodeCanvas.savePath), NodeEditorGUI.nodeLabelBold);
            GUILayout.Label("Type: " + cache.typeData.DisplayString + "/" + cache.nodeCanvas.GetType().Name + "");



            if (GUILayout.Button(new GUIContent("New Canvas", "Loads an Specified Empty CanvasType")))
            {
                NodeEditorFramework.Utilities.GenericMenu menu = new NodeEditorFramework.Utilities.GenericMenu();
                NodeCanvasManager.FillCanvasTypeMenu(ref menu, cache.NewNodeCanvas);
                menu.Show(createCanvasUIPos.position, createCanvasUIPos.width);
            }
            if (Event.current.type == EventType.Repaint)
            {
                Rect popupPos = GUILayoutUtility.GetLastRect();
                createCanvasUIPos = new Rect(popupPos.x + 2, popupPos.yMax + 2, popupPos.width - 4, 0);
            }
            if (cache.nodeCanvas.GetType() == typeof(NodeCanvas) && GUILayout.Button(new GUIContent("Convert Canvas", "Converts the current canvas to a new type.")))
            {
                NodeEditorFramework.Utilities.GenericMenu menu = new NodeEditorFramework.Utilities.GenericMenu();
                NodeCanvasManager.FillCanvasTypeMenu(ref menu, cache.ConvertCanvasType);
                menu.Show(convertCanvasUIPos.position, convertCanvasUIPos.width);
            }
            if (Event.current.type == EventType.Repaint)
            {
                Rect popupPos = GUILayoutUtility.GetLastRect();
                convertCanvasUIPos = new Rect(popupPos.x + 2, popupPos.yMax + 2, popupPos.width - 4, 0);
            }

            if (GUILayout.Button(new GUIContent("Save Canvas", "Save the Canvas to the load location")))
            {
                string path = cache.nodeCanvas.savePath;
                if (!string.IsNullOrEmpty(path))
                {
                    if (path.StartsWith("SCENE/"))
                    {
                        cache.SaveSceneNodeCanvas(path.Substring(6));
                    }
                    else
                    {
                        cache.SaveNodeCanvas(path);
                    }
                }
            }



                #if UNITY_EDITOR
            GUILayout.Label("Asset Saving", NodeEditorGUI.nodeLabel);

            if (GUILayout.Button(new GUIContent("Save Canvas As", "Save the canvas as an asset")))
            {
                string panelPath = NodeEditor.editorPath + "Resources/Saves/";
                if (cache.nodeCanvas != null && !string.IsNullOrEmpty(cache.nodeCanvas.savePath))
                {
                    panelPath = cache.nodeCanvas.savePath;
                }
                string path = UnityEditor.EditorUtility.SaveFilePanelInProject("Save Node Canvas", "Node Canvas", "asset", "", panelPath);
                if (!string.IsNullOrEmpty(path))
                {
                    cache.SaveNodeCanvas(path);
                }
            }

            if (GUILayout.Button(new GUIContent("Load Canvas", "Load the Canvas from an asset")))
            {
                string panelPath = NodeEditor.editorPath + "Resources/Saves/";
                if (cache.nodeCanvas != null && !string.IsNullOrEmpty(cache.nodeCanvas.savePath))
                {
                    panelPath = cache.nodeCanvas.savePath;
                }
                string path = UnityEditor.EditorUtility.OpenFilePanel("Load Node Canvas", panelPath, "asset");
                if (!path.Contains(Application.dataPath))
                {
                    if (!string.IsNullOrEmpty(path))
                    {
                        Debug.LogWarning(new GUIContent("You should select an asset inside your project folder!"));
                    }
                }
                else
                {
                    cache.LoadNodeCanvas(path);
                }
                if (cache.nodeCanvas.GetType() == typeof(NodeCanvas))
                {
                    Debug.LogWarning(new GUIContent("The Canvas has no specific type. Please use the convert button to assign a type and re-save the canvas!"));
                }
            }
                #endif

            GUILayout.Label("Scene Saving", NodeEditorGUI.nodeLabel);

            GUILayout.BeginHorizontal();
            sceneCanvasName = GUILayout.TextField(sceneCanvasName, GUILayout.ExpandWidth(true));
            if (GUILayout.Button(new GUIContent("Save to Scene", "Save the canvas to the Scene"), GUILayout.ExpandWidth(false)))
            {
                cache.SaveSceneNodeCanvas(sceneCanvasName);
            }
            GUILayout.EndHorizontal();

            if (GUILayout.Button(new GUIContent("Load from Scene", "Load the canvas from the Scene")))
            {
                NodeEditorFramework.Utilities.GenericMenu menu = new NodeEditorFramework.Utilities.GenericMenu();
                foreach (string sceneSave in NodeEditorSaveManager.GetSceneSaves())
                {
                    menu.AddItem(new GUIContent(sceneSave), false, LoadSceneCanvasCallback, (object)sceneSave);
                }
                menu.Show(loadSceneUIPos.position, loadSceneUIPos.width);
            }
            if (Event.current.type == EventType.Repaint)
            {
                Rect popupPos = GUILayoutUtility.GetLastRect();
                loadSceneUIPos = new Rect(popupPos.x + 2, popupPos.yMax + 2, popupPos.width - 4, 0);
            }



            GUILayout.Label("Utility/Debug", NodeEditorGUI.nodeLabel);

            if (GUILayout.Button(new GUIContent("Recalculate All", "Initiates complete recalculate. Usually does not need to be triggered manually.")))
            {
                cache.nodeCanvas.TraverseAll();
            }

            if (GUILayout.Button("Force Re-Init"))
            {
                NodeEditor.ReInit(true);
            }

            NodeEditorGUI.knobSize = RTEditorGUI.IntSlider(new GUIContent("Handle Size", "The size of the Node Input/Output handles"), NodeEditorGUI.knobSize, 12, 20);
            //cache.editorState.zoom = EditorGUILayout.Slider (new GUIContent ("Zoom", "Use the Mousewheel. Seriously."), cache.editorState.zoom, 0.6f, 4);
            NodeEditorUserCache.cacheIntervalSec = RTEditorGUI.IntSlider(new GUIContent("Cache Interval (Sec)", "The interval in seconds the canvas is temporarily saved into the cache as a precaution for crashes."), NodeEditorUserCache.cacheIntervalSec, 30, 300);

            screenSize = GUILayout.Toggle(screenSize, "Adapt to Screen");
            GUILayout.Label("FPS: " + FPSCounter.currentFPS);



            if (cache.editorState.selectedNode != null && Event.current.type != EventType.Ignore)
            {
                cache.editorState.selectedNode.DrawNodePropertyEditor();
            }
        }
Пример #9
0
        private void DrawSideWindow()
        {
            GUILayout.Label("Shadero Sprite v1.9.3", NodeEditorGUI.nodeLabelBold);

            if (NodeEditor._Shadero_Material == null)
            {
                Texture2D preview = ResourceManager.LoadTexture("Textures/previews/Preview_no_material.jpg");
                GUI.DrawTexture(new Rect(5, 30, 196, 196), preview);
            }
            else
            {
                if (!NodeEditor.NoBuildShader)
                {
                    Texture2D preview = ResourceManager.LoadTexture("Textures/previews/Preview_no_buildshader.jpg");
                    GUI.DrawTexture(new Rect(5, 30, 196, 196), preview);
                }
                else
                {
                    if (!NodeEditor.FlagIsSaved)
                    {
                        Texture2D preview = ResourceManager.LoadTexture("Textures/previews/Preview_no_shader.jpg");
                        GUI.DrawTexture(new Rect(5, 30, 196, 196), preview);
                    }
                    else
                    {
                        if (!NodeEditor.RGBAonBuildShader)
                        {
                            Texture2D preview = ResourceManager.LoadTexture("Textures/previews/Preview_no_rgba_buildshader.jpg");
                            GUI.DrawTexture(new Rect(5, 30, 196, 196), preview);
                        }
                        else
                        {
                            NodeEditor._Shadero_Material.shader = Shader.Find("Shadero Customs/" + Node.ShaderNameX);
                            Texture2D preview = ResourceManager.LoadTexture("Textures/previews/Preview_Shader.jpg");
                            GUI.DrawTexture(new Rect(5, 30, 196, 196), preview);

                            Texture tex = NodeEditor._Shadero_Material.mainTexture;
                            if (tex == null)
                            {
                                tex = ResourceManager.LoadTexture("Textures/previews/Preview_Shader.jpg");
                            }
                            float x = Event.current.mousePosition.x - 8;
                            float y = Event.current.mousePosition.y - 33;
                            x = x / 190;
                            y = y / 190;

                            if ((x > 0 && x < 1) && (y > 0 && y < 1))
                            {
                                EditorGUI.DrawPreviewTexture(new Rect(8, 33, 190, 190), tex, NodeEditor._Shadero_Material);

                                if (FullScreenSet > 3)
                                {
                                    EditorGUI.DrawPreviewTexture(new Rect(-(Screen.width / 2) - Screen.height / 4, 10, Screen.height, Screen.height), tex, NodeEditor._Shadero_Material);
                                }

                                FullScreenSet += Time.deltaTime;
                            }
                            else
                            {
                                FullScreenSet = 0;
                                EditorGUI.DrawPreviewTexture(new Rect(8, 33, 190, 190), tex, NodeEditor._Shadero_Material);
                            }
                        }
                    }
                }
            }
            GUILayout.Space(200);

            GUIStyle g = new GUIStyle();

            if (NodeEditor._Shadero_Material != null)
            {
                int ms = g.fontSize;
                g.fontSize         = 10;
                g.alignment        = TextAnchor.UpperRight;
                g.normal.textColor = Color.white;
                GUILayout.Label("*Preview Material", g);
                g.fontSize = ms;
            }
            else
            {
                GUILayout.Label("Preview Material");
            }
            PreviewLiveAnimation = GUILayout.Toggle(PreviewLiveAnimation, "Active live animation");
            if (PreviewLiveAnimation)
            {
                NodeEditor.RepaintClients();
            }

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

            UseOwnMaterial = GUILayout.Toggle(UseOwnMaterial, "Use your own Material");

            if (!UseOwnMaterial)
            {
                NodeEditor._Shadero_Material = AssetDatabase.LoadAssetAtPath("Assets/ShaderoSprite/Plugins/EditorResources/Preview/PreviewMaterial.mat", typeof(Material)) as Material;
            }
            else
            {
                GUILayout.Space(25);
                NodeEditor._Shadero_Material = (Material)EditorGUI.ObjectField(new Rect(5, 285, 200, 18), NodeEditor._Shadero_Material, typeof(Material), true);
                if (NodeEditor._Shadero_Material == null)
                {
                    UseOwnMaterial = false;
                }
            }

            if (MaterialChange == null)
            {
                MaterialChange = AssetDatabase.GetAssetPath(NodeEditor._Shadero_Material);
            }
            if (MaterialChange != AssetDatabase.GetAssetPath(NodeEditor._Shadero_Material))
            {
                NodeEditor.FlagIsMaterialChanged = true;
                NodeEditor.ShaderToNull          = true;
            }
            MaterialChange = AssetDatabase.GetAssetPath(NodeEditor._Shadero_Material);
            GUILayout.Space(10);

            if (NodeEditor.RecalculateFlag)
            {
                NodeEditor.ForceWriteFlag = true;
                NodeEditor.RecalculateAll(canvasCache.nodeCanvas);
                NodeEditor.RecalculateFlag = false;
            }

            if (GUILayout.Button(new GUIContent("New Shader Project", "Loads an Specified Empty Shadero project")))
            {
                _ShaderoShaderEditorFramework.Utilities.GenericMenu menu = new _ShaderoShaderEditorFramework.Utilities.GenericMenu();
                NodeCanvasManager.FillCanvasTypeMenu(ref menu, canvasCache.NewNodeCanvas);
                menu.Show(createCanvasUIPos.position, createCanvasUIPos.width);
            }
            if (NodeEditor.NewCanvasWasCalled)
            {
                UseOwnMaterial = false;
                NodeEditor._Shadero_Material  = null;
                NodeEditor.NewCanvasWasCalled = false;
            }

            if (Event.current.type == EventType.Repaint)
            {
                Rect popupPos = GUILayoutUtility.GetLastRect();
                createCanvasUIPos = new Rect(popupPos.x + 2, popupPos.yMax + 2, popupPos.width - 4, 0);
            }

            GUILayout.Space(6);

            if (GUILayout.Button(new GUIContent("Save Shader Project", "Saves the project to a project Save File in the Assets Folder")))
            {
                string path = EditorUtility.SaveFilePanelInProject("Save Shadero Shader Project", "Shadero Shader Project", "asset", "", NodeEditor.editorPath + "Shadero_Projects/");
                if (!string.IsNullOrEmpty(path))
                {
                    canvasCache.SaveNodeCanvas(path);
                    // NodeEditor.FlagIsSavedMaterial = true;
                }
            }

            if (GUILayout.Button(new GUIContent("Load Shader Project", "Loads the project from a project Save File in the Assets Folder")))
            {
                string path = EditorUtility.OpenFilePanel("Load Shadero Shader Project", NodeEditor.editorPath + "Shadero_Projects/", "asset");
                if (!path.Contains(Application.dataPath))
                {
                    if (!string.IsNullOrEmpty(path))
                    {
                        ShowNotification(new GUIContent("You should select an asset inside your project folder!"));
                    }
                }
                else
                {
                    UseOwnMaterial = false;
                    canvasCache.LoadNodeCanvas(path);
                }
            }

            GUILayout.Space(6);

            g                  = new GUIStyle();
            g.fontSize         = 12;
            g.alignment        = TextAnchor.LowerLeft;
            g.normal.textColor = Color.white;

            if (!NodeEditor.NoBuildShader)
            {
                GUILayout.Label(" ", g);
                GUILayout.Label("What to do ?", g);
                GUILayout.Label(" ", g);
                GUILayout.Label("- You need to create a ", g);
                GUILayout.Label("  Build Shader \"Node Shader\"", g);
                GUILayout.Label("  , Right Click on the", g);
                GUILayout.Label("  Node Canvas and Select ", g);
                GUILayout.Label("  \"Add Build Shader\".", g);
            }
            else
            {
                GUILayout.Label(" ", g);
                GUILayout.Label("What to do ?", g);
                GUILayout.Label(" ", g);
                GUILayout.Label("-If you want to use your ", g);
                GUILayout.Label("  own material, active ", g);
                GUILayout.Label(" the \"Use your own material\" )", g);
                GUILayout.Label(" button. ", g);
                GUILayout.Label("", g);
                GUILayout.Label("  We recommand you to always ", g);
                GUILayout.Label("  active the \"Active live animation\"", g);
                GUILayout.Label("  for a better experience.", g);
            }

            if (canvasCache.editorState.selectedNode != null && Event.current.type != EventType.Ignore)
            {
                canvasCache.editorState.selectedNode.DrawNodePropertyEditor();
            }
        }