Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Commit

Permalink
Zoom works as the first complete solution for Unity inside groups! Yo…
Browse files Browse the repository at this point in the history
…u could copy paste GUIScaleUtility and use it for your own GUI:)
  • Loading branch information
Seneral committed Sep 26, 2015
1 parent 2c9372d commit 36ca904
Show file tree
Hide file tree
Showing 20 changed files with 751 additions and 344 deletions.
22 changes: 13 additions & 9 deletions Editor/Node_Editor/NodeEditorWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,13 @@ public void OnDestroy ()
public void OnGUI ()
{
NodeEditor.checkInit ();
AssureHasEditor ();
if (NodeEditor.InitiationError)
{
GUILayout.Label ("Initiation failed! Check console for more information!");
return;
}
AssureHasEditor ();

// Example of creating Nodes and Connections through code
// CalcNode calcNode1 = CalcNode.Create (new Rect (200, 200, 200, 100));
// CalcNode calcNode2 = CalcNode.Create (new Rect (600, 200, 200, 100));
Expand All @@ -74,7 +75,7 @@ public void OnGUI ()
mainEditorState.canvasRect = canvasWindowRect;
try
{
NodeEditor.DrawCanvas (mainNodeCanvas, mainEditorState, new Rect (0, 23, position.width, position.height));
NodeEditor.DrawCanvas (mainNodeCanvas, mainEditorState);
}
catch (UnityException e)
{ // on exceptions in drawing flush the canvas to avoid locking the ui.
Expand All @@ -84,20 +85,22 @@ public void OnGUI ()
}
// Draw Side Window
sideWindowWidth = Math.Min (600, Math.Max (200, (int)(position.width / 5)));
GUILayout.BeginArea (sideWindowRect, NodeEditor.nodeBox);
NodeEditorGUI.StartNodeGUI ();
GUILayout.BeginArea (sideWindowRect, GUI.skin.box);
DrawSideWindow ();
GUILayout.EndArea ();
NodeEditorGUI.EndNodeGUI ();
}

public void DrawSideWindow ()
{
GUILayout.Label (new GUIContent ("Node Editor (" + openedCanvas + ")", "The currently opened canvas in the Node Editor"), NodeEditor.nodeLabelBold);
GUILayout.Label (new GUIContent ("Do note that changes will be saved automatically!", "All changes are automatically saved to the currently opened canvas (see above) if it's present in the Project view."), NodeEditor.nodeLabel);
if (GUILayout.Button (new GUIContent ("Save Canvas", "Saves the canvas as a new Canvas Asset File in the Assets Folder"), NodeEditor.nodeButton))
GUILayout.Label (new GUIContent ("Node Editor (" + openedCanvas + ")", "The currently opened canvas in the Node Editor"), NodeEditorGUI.nodeLabelBold);
GUILayout.Label (new GUIContent ("Do note that changes will be saved automatically!", "All changes are automatically saved to the currently opened canvas (see above) if it's present in the Project view."));
if (GUILayout.Button (new GUIContent ("Save Canvas", "Saves the canvas as a new Canvas Asset File in the Assets Folder")))
{
SaveNodeCanvas (EditorUtility.SaveFilePanelInProject ("Save Node Canvas", "Node Canvas", "asset", "Saving to a file is only needed once.", NodeEditor.resourcePath + "Saves/"));
}
if (GUILayout.Button (new GUIContent ("Load Canvas", "Loads the canvas from a Canvas Asset File in the Assets Folder"), NodeEditor.nodeButton))
if (GUILayout.Button (new GUIContent ("Load Canvas", "Loads the canvas from a Canvas Asset File in the Assets Folder")))
{
string path = EditorUtility.OpenFilePanel ("Load Node Canvas", NodeEditor.resourcePath + "Saves/", "asset");
if (!path.Contains (Application.dataPath))
Expand All @@ -109,14 +112,15 @@ public void DrawSideWindow ()
path = path.Replace (Application.dataPath, "Assets");
LoadNodeCanvas (path);
}
if (GUILayout.Button (new GUIContent ("New Canvas", "Creates a new Canvas (remember to save the previous one to a referenced Canvas Asset File at least once before! Else it'll be lost!)"), NodeEditor.nodeButton))
if (GUILayout.Button (new GUIContent ("New Canvas", "Creates a new Canvas (remember to save the previous one to a referenced Canvas Asset File at least once before! Else it'll be lost!)")))
{
NewNodeCanvas ();
}
if (GUILayout.Button (new GUIContent ("Recalculate All", "Starts to calculate from the beginning off."), NodeEditor.nodeButton))
if (GUILayout.Button (new GUIContent ("Recalculate All", "Starts to calculate from the beginning off.")))
{
NodeEditor.RecalculateAll (mainNodeCanvas);
}

NodeEditor.knobSize = EditorGUILayout.IntSlider (new GUIContent ("Handle Size", "The size of the handles of the Node Inputs/Outputs"), NodeEditor.knobSize, 12, 20);
mainEditorState.zoom = EditorGUILayout.Slider (new GUIContent ("Zoom"), mainEditorState.zoom, 0.6f, 2);
}
Expand Down
8 changes: 4 additions & 4 deletions Node_Editor/Framework/ConnectionTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public static void FetchTypes ()
UnityEngine.Debug.LogError ("Error with Type Declaration " + type.FullName);
return;
}
Texture2D InputKnob = NodeEditor.LoadTexture(typeDecl.InputKnob_TexPath);
Texture2D OutputKnob = NodeEditor.LoadTexture(typeDecl.OutputKnob_TexPath);
Texture2D InputKnob = NodeEditorGUI.LoadTexture(typeDecl.InputKnob_TexPath);
Texture2D OutputKnob = NodeEditorGUI.LoadTexture(typeDecl.OutputKnob_TexPath);
types.Add(typeDecl.name, new TypeData(typeDecl.col, InputKnob, OutputKnob, typeDecl.Type));
}
}
Expand All @@ -75,8 +75,8 @@ public struct TypeData
public TypeData (Color color, Texture2D inKnob, Texture2D outKnob, Type type)
{
col = color;
InputKnob = NodeEditor.Tint (inKnob, color);
OutputKnob = NodeEditor.Tint (outKnob, color);
InputKnob = NodeEditorGUI.Tint (inKnob, color);
OutputKnob = NodeEditorGUI.Tint (outKnob, color);
Type = type;
}
}
Expand Down
53 changes: 43 additions & 10 deletions Node_Editor/Framework/GUIExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using System.Linq;
using System.Collections.Generic;

using NodeEditorFramework;

public static class GUIExt
{

Expand Down Expand Up @@ -157,6 +159,41 @@ public static float ForceParse (this string str)
return value;
}

public static T ObjectField<T> (T obj, bool allowSceneObjects) where T : Object
{
return ObjectField<T> (GUIContent.none, obj, allowSceneObjects);
}

public static T ObjectField<T> (GUIContent label, T obj, bool allowSceneObjects) where T : Object
{
#if UNITY_EDITOR
if (!Application.isPlaying)
obj = UnityEditor.EditorGUILayout.ObjectField (GUIContent.none, obj, typeof (T), allowSceneObjects) as T;
#endif
if (Application.isPlaying)
{
bool open = false;
if (typeof(T).Name == "UnityEngine.Texture2D")
{
label.image = obj as Texture2D;
GUIStyle style = new GUIStyle (GUI.skin.box);
style.imagePosition = ImagePosition.ImageAbove;
open = GUILayout.Button (label, style);
}
else
{
GUIStyle style = new GUIStyle (GUI.skin.box);
open = GUILayout.Button (label, style);
}
if (open)
{
Debug.Log ("Selecting Object!");
}
}
return obj;
}


public static int SelectableListPopup (GUIContent[] contents, int selected)
{
return selected;
Expand Down Expand Up @@ -212,8 +249,6 @@ public class GenericMenu
public delegate void MenuFunctionData (object userData);

private static GUIStyle backgroundStyle;
private static GUIStyle itemStyle;
private static GUIStyle selectedStyle;
private static Texture2D expandRight;
private static float itemHeight;
public static GUIStyle seperator;
Expand Down Expand Up @@ -242,11 +277,8 @@ public GenericMenu ()
{
backgroundStyle = new GUIStyle (GUI.skin.box);
backgroundStyle.contentOffset = new Vector2 (2, 2);
itemStyle = new GUIStyle (GUI.skin.label);
selectedStyle = new GUIStyle (GUI.skin.label);
selectedStyle.normal.background = GUIExt.ColorToTex (new Color (0.75f, 0.75f, 0.75f));
expandRight = NodeEditorFramework.NodeEditor.LoadTexture ("Textures/expandRight.png");
itemHeight = itemStyle.CalcHeight (new GUIContent ("text"), 100);
expandRight = NodeEditorGUI.LoadTexture ("Textures/expandRight.png");
itemHeight = GUI.skin.label.CalcHeight (new GUIContent ("text"), 100);

seperator = new GUIStyle();
seperator.normal.background = GUIExt.ColorToTex (new Color (0.6f, 0.6f, 0.6f));
Expand Down Expand Up @@ -390,7 +422,8 @@ private void DrawItem (MenuItem item, Rect groupRect)
{
if (item.separator)
{
GUI.Box (new Rect (backgroundStyle.contentOffset.x+1, currentItemHeight+1, groupRect.width-2, 1), GUIContent.none, seperator);
if (Event.current.type == EventType.Repaint)
seperator.Draw (new Rect (backgroundStyle.contentOffset.x+1, currentItemHeight+1, groupRect.width-2, 1), GUIContent.none, "Seperator".GetHashCode ());
currentItemHeight += 3;
}
else
Expand All @@ -404,7 +437,7 @@ private void DrawItem (MenuItem item, Rect groupRect)
selected = true;
}

GUI.Label (labelRect, item.content, selected? selectedStyle : itemStyle);
GUI.Label (labelRect, item.content, selected? NodeEditorGUI.nodeLabelSelected : NodeEditorGUI.nodeLabel);

if (item.group)
{
Expand Down Expand Up @@ -447,7 +480,7 @@ private static Rect calculateRect (Vector2 position, List<MenuItem> menuItems)
height += 3;
else
{
width = Mathf.Max (width, itemStyle.CalcSize (item.content).x + (item.group? 22 : 10));
width = Mathf.Max (width, GUI.skin.label.CalcSize (item.content).x + (item.group? 22 : 10));
height += itemHeight;
}
}
Expand Down
Loading

0 comments on commit 36ca904

Please sign in to comment.