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

Commit

Permalink
- Major library update for RTEditorGUI that increases stability and s…
Browse files Browse the repository at this point in the history
…imilarity to the original EditorControls, improves API and adds alot of controls

- Fixed saving stability issues
- Allowed saving old scene canvases to assets with a warning about possible lost scene references
- Extended overlay to allow a minimum popup  width, ultimately resulting in the popup from 'Load from 'Scene' to always show up
- Changed ResourceManager to use AssetDatabase in playmode instead of resources to allow for saving/loading in playmode
  • Loading branch information
Seneral committed Jun 15, 2016
1 parent 23c875b commit da3d8b9
Show file tree
Hide file tree
Showing 10 changed files with 509 additions and 158 deletions.
8 changes: 4 additions & 4 deletions Editor/Node_Editor/NodeEditorWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class NodeEditorWindow : EditorWindow

// GUI
private string sceneCanvasName = "";
private Vector2 loadScenePos;
private Rect loadScenePos;
public static int sideWindowWidth = 400;
private static Texture iconTexture;
public Rect sideWindowRect { get { return new Rect (position.width - sideWindowWidth, 0, sideWindowWidth, position.height); } }
Expand Down Expand Up @@ -133,7 +133,7 @@ private void OnGUI ()
{ // on exceptions in drawing flush the canvas to avoid locking the ui.
NewNodeCanvas ();
NodeEditor.ReInit (true);
Debug.LogError ("Unloaded Canvas due to exception when drawing!");
Debug.LogError ("Unloaded Canvas due to an exception during the drawing phase!");
Debug.LogException (e);
}

Expand Down Expand Up @@ -189,12 +189,12 @@ private void DrawSideWindow ()
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 (loadScenePos);
menu.Show (loadScenePos.position, loadScenePos.width);
}
if (Event.current.type == EventType.Repaint)
{
Rect popupPos = GUILayoutUtility.GetLastRect ();
loadScenePos = new Vector2 (popupPos.x+2, popupPos.yMax+2);
loadScenePos = new Rect (popupPos.x+2, popupPos.yMax+2, popupPos.width-4, 0);
}

GUILayout.Space (6);
Expand Down
8 changes: 5 additions & 3 deletions Node_Editor/Framework/ConnectionTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ public static TypeData GetTypeData (string typeName)
}
else
{
List<TypeData> typeDatas = types.Values.ToList ();
//typeData = typeDatas.First ((TypeData data) => data.isValid () && data.Type == type);
typeData = typeDatas.Find ((TypeData data) => data.isValid () && data.Type == type);
//typeData = types.Values.First ((TypeData data) => data.isValid () && data.Type == type);
typeData = types.Values.ToList ().Find ((TypeData data) => data.isValid () && data.Type == type);
if (typeData == null)
types.Add (typeName, typeData = new TypeData (type));
}
Expand Down Expand Up @@ -94,6 +93,9 @@ public TypeData (ITypeDeclaration typeDecl)

InputKnob = ResourceManager.GetTintedTexture (declaration.InputKnob_TexPath, col);
OutputKnob = ResourceManager.GetTintedTexture (declaration.OutputKnob_TexPath, col);

if (!isValid ())
throw new DataMisalignedException ("Type Declaration " + typeDecl.name + " contains invalid data!");
}

public TypeData (Type type)
Expand Down
5 changes: 5 additions & 0 deletions Node_Editor/Framework/NodeCanvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ public void Validate ()
editorStates = new NodeEditorState[0];
}
editorStates = editorStates.Where ((NodeEditorState state) => state != null).ToArray ();
foreach (NodeEditorState state in editorStates)
{
if (!nodes.Contains (state.selectedNode))
state.selectedNode = null;
}
}
}
}
13 changes: 12 additions & 1 deletion Node_Editor/Framework/NodeEditorSaveManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,13 @@ public static void SaveNodeCanvas (string path, NodeCanvas nodeCanvas, bool crea

if (string.IsNullOrEmpty (path)) throw new UnityException ("Cannot save NodeCanvas: No spath specified to save the NodeCanvas " + (nodeCanvas != null? nodeCanvas.name : "") + " to!");
if (nodeCanvas == null) throw new UnityException ("Cannot save NodeCanvas: The specified NodeCanvas that should be saved to path " + path + " is null!");
if (nodeCanvas.livesInScene) throw new UnityException ("Cannot save NodeCanvas: The specified NodeCanvas '" + nodeCanvas.name + "' lives in the scene and thus cannot be saved as an asset!");
if (nodeCanvas.livesInScene)
Debug.LogWarning ("Attempting to save scene canvas " + nodeCanvas.name + " to an asset, scene object references will be broken!" + (!createWorkingCopy? " No workingCopy is going to be created, so your scene save is broken, too!" : ""));
#if UNITY_EDITOR
if (!createWorkingCopy && UnityEditor.AssetDatabase.Contains (nodeCanvas) && UnityEditor.AssetDatabase.GetAssetPath (nodeCanvas) != path) { Debug.LogError ("Trying to create a duplicate save file for '" + nodeCanvas.name + "'! Forcing to create a working copy!"); createWorkingCopy = true; }
#endif

nodeCanvas.livesInScene = false;
nodeCanvas.Validate ();

#if UNITY_EDITOR
Expand Down Expand Up @@ -343,7 +345,16 @@ public static NodeCanvas CreateWorkingCopy (NodeCanvas nodeCanvas, bool editorSt
}

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;
}
Expand Down
5 changes: 4 additions & 1 deletion Node_Editor/Framework/NodeInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,11 @@ protected override void ReloadTexture ()

private void CheckType ()
{
if (_typeData == null || !_typeData.isValid ())
if (_typeData == null || !_typeData.isValid ())
_typeData = ConnectionTypes.GetTypeData (typeID);
if (_typeData == null || !_typeData.isValid ())
{
ConnectionTypes.FetchTypes ();
_typeData = ConnectionTypes.GetTypeData (typeID);
if (_typeData == null || !_typeData.isValid ())
throw new UnityException ("Could not find type " + typeID + "!");
Expand Down
2 changes: 1 addition & 1 deletion Node_Editor/Framework/NodeKnob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ protected void ReloadKnobTexture ()
{
ReloadTexture ();
if (knobTexture == null)
throw new UnityException ("Knob texture could not be loaded!");
throw new UnityException ("Knob texture of " + name + " could not be loaded!");
if (side != defaultSide)
{ // Rotate Knob texture according to the side it's used on
ResourceManager.SetDefaultResourcePath (NodeEditor.editorPath + "Resources/");
Expand Down
7 changes: 7 additions & 0 deletions Node_Editor/Framework/NodeOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ private void CheckType ()
{
if (_typeData == null || !_typeData.isValid ())
_typeData = ConnectionTypes.GetTypeData (typeID);
if (_typeData == null || !_typeData.isValid ())
{
ConnectionTypes.FetchTypes ();
_typeData = ConnectionTypes.GetTypeData (typeID);
if (_typeData == null || !_typeData.isValid ())
throw new UnityException ("Could not find type " + typeID + "!");
}
}

#endregion
Expand Down
21 changes: 12 additions & 9 deletions Node_Editor/Utilities/GUI/OverlayGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public class PopupMenu
public static Texture2D expandRight;
public static float itemHeight;
public static GUIStyle selectedLabel;

public float minWidth;

public PopupMenu ()
{
Expand All @@ -72,10 +74,11 @@ public void SetupGUI ()
selectedLabel = new GUIStyle (GUI.skin.label);
selectedLabel.normal.background = NodeEditorFramework.Utilities.RTEditorGUI.ColorToTex (1, new Color (0.4f, 0.4f, 0.4f));
}
public void Show (Vector2 pos)

public void Show (Vector2 pos, float MinWidth = 40)
{
position = calculateRect (pos, menuItems);
minWidth = MinWidth;
position = calculateRect (pos, menuItems, minWidth);
selectedPath = "";
OverlayGUI.currentPopup = this;
}
Expand Down Expand Up @@ -178,7 +181,7 @@ public void Draw ()

private bool DrawGroup (Rect pos, List<MenuItem> menuItems)
{
Rect rect = calculateRect (pos.position, menuItems);
Rect rect = calculateRect (pos.position, menuItems, minWidth);

Rect clickRect = new Rect (rect);
clickRect.xMax += 20;
Expand Down Expand Up @@ -214,7 +217,7 @@ private void DrawItem (MenuItem item, Rect groupRect)
if (labelRect.Contains (Event.current.mousePosition))
selectedPath = item.path;

bool selected = selectedPath.Contains (item.path);
bool selected = selectedPath == item.path || selectedPath.Contains (item.path + "/");
GUI.Label (labelRect, item.content, selected? selectedLabel : GUI.skin.label);

if (item.group)
Expand Down Expand Up @@ -246,10 +249,10 @@ private static Rect extendRect (Rect rect, Vector2 extendValue)
return rect;
}

private static Rect calculateRect (Vector2 position, List<MenuItem> menuItems)
private static Rect calculateRect (Vector2 position, List<MenuItem> menuItems, float minWidth)
{
Vector2 size;
float width = 40, height = 0;
float width = minWidth, height = 0;

for (int itemCnt = 0; itemCnt < menuItems.Count; itemCnt++)
{
Expand Down Expand Up @@ -349,9 +352,9 @@ public void ShowAsContext ()
popup.Show (GUIScaleUtility.GUIToScreenSpace (Event.current.mousePosition));
}

public void Show (Vector2 pos)
public void Show (Vector2 pos, float MinWidth = 40)
{
popup.Show (GUIScaleUtility.GUIToScreenSpace (pos));
popup.Show (GUIScaleUtility.GUIToScreenSpace (pos), MinWidth);
}

public void AddItem (GUIContent content, bool on, PopupMenu.MenuFunctionData func, object userData)
Expand Down
Loading

0 comments on commit da3d8b9

Please sign in to comment.