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

Commit 70a06e8

Browse files
author
Seneral
committed
First clean release with all WIP stuff removed and structure improved
-> Action Node, UnityFunc and State system removed -> removed redundancies -> improved structure of files and nodes -> Fixed bugs regarding for loops replaced with foreach loops
1 parent 7f8699a commit 70a06e8

24 files changed

+767
-489
lines changed

Editor/Node_Editor/NodeEditorWindow.cs

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,14 @@ public static bool AutoOpenCanvas (int instanceID, int line)
6464
public void OnDestroy ()
6565
{
6666
NodeEditor.ClientRepaints -= _editor.Repaint;
67-
//SaveCache ();
6867

6968
#if UNITY_EDITOR
7069
// Remove callbacks
71-
//EditorLoadingControl.beforeEnteringPlayMode -= SaveCache;
7270
EditorLoadingControl.lateEnteredPlayMode -= LoadCache;
73-
//EditorLoadingControl.beforeLeavingPlayMode -= SaveCache;
7471
EditorLoadingControl.justLeftPlayMode -= LoadCache;
7572
EditorLoadingControl.justOpenedNewScene -= LoadCache;
7673

7774
NodeEditorCallbacks.OnAddNode -= SaveNewNode;
78-
NodeEditorCallbacks.OnAddTransition -= SaveNewTransition;
79-
80-
// TODO: BeforeOpenedScene to save Cache, aswell as assembly reloads...
8175
#endif
8276
}
8377

@@ -90,13 +84,9 @@ private void OnEnable ()
9084

9185
#if UNITY_EDITOR
9286
// This makes sure the Node Editor is reinitiated after the Playmode changed
93-
//EditorLoadingControl.beforeEnteringPlayMode -= SaveCache;
94-
//EditorLoadingControl.beforeEnteringPlayMode += SaveCache;
9587
EditorLoadingControl.lateEnteredPlayMode -= LoadCache;
9688
EditorLoadingControl.lateEnteredPlayMode += LoadCache;
9789

98-
//EditorLoadingControl.beforeLeavingPlayMode -= SaveCache;
99-
//EditorLoadingControl.beforeLeavingPlayMode += SaveCache;
10090
EditorLoadingControl.justLeftPlayMode -= LoadCache;
10191
EditorLoadingControl.justLeftPlayMode += LoadCache;
10292

@@ -105,10 +95,6 @@ private void OnEnable ()
10595

10696
NodeEditorCallbacks.OnAddNode -= SaveNewNode;
10797
NodeEditorCallbacks.OnAddNode += SaveNewNode;
108-
NodeEditorCallbacks.OnAddTransition -= SaveNewTransition;
109-
NodeEditorCallbacks.OnAddTransition += SaveNewTransition;
110-
111-
// TODO: BeforeOpenedScene to save Cache, aswell as assembly reloads...
11298
#endif
11399
}
114100

@@ -192,9 +178,6 @@ private void DrawSideWindow ()
192178
if (GUILayout.Button ("Force Re-Init"))
193179
NodeEditor.ReInit (true);
194180

195-
if (NodeEditor.isTransitioning (mainNodeCanvas) && GUILayout.Button ("Stop Transitioning"))
196-
NodeEditor.StopTransitioning (mainNodeCanvas);
197-
198181
NodeEditorGUI.knobSize = EditorGUILayout.IntSlider (new GUIContent ("Handle Size", "The size of the Node Input/Output handles"), NodeEditorGUI.knobSize, 12, 20);
199182
mainEditorState.zoom = EditorGUILayout.Slider (new GUIContent ("Zoom", "Use the Mousewheel. Seriously."), mainEditorState.zoom, 0.6f, 2);
200183

@@ -215,34 +198,15 @@ private void SaveNewNode (Node node)
215198
if (AssetDatabase.GetAssetPath (mainNodeCanvas) != path)
216199
throw new UnityException ("Cache system error: Current Canvas is not saved as the temporary cache!");
217200
NodeEditorSaveManager.AddSubAsset (node, path);
218-
for (int knobCnt = 0; knobCnt < node.nodeKnobs.Count; knobCnt++)
219-
NodeEditorSaveManager.AddSubAsset (node.nodeKnobs [knobCnt], path);
220-
for (int transCnt = 0; transCnt < node.transitions.Count; transCnt++)
221-
{
222-
if (node.transitions[transCnt].startNode == node)
223-
NodeEditorSaveManager.AddSubAsset (node.transitions [transCnt], path);
224-
}
225-
226-
AssetDatabase.SaveAssets ();
227-
AssetDatabase.Refresh ();
228-
}
229-
230-
private void SaveNewTransition (Transition transition)
231-
{
232-
if (!mainNodeCanvas.nodes.Contains (transition.startNode) || !mainNodeCanvas.nodes.Contains (transition.endNode))
233-
throw new UnityException ("Cache system: Writing new Transition to save file failed as Node members are not part of the Cache!");
234-
string path = tempSessionPath + "/LastSession.asset";
235-
if (AssetDatabase.GetAssetPath (mainNodeCanvas) != path)
236-
throw new UnityException ("Cache system error: Current Canvas is not saved as the temporary cache!");
237-
NodeEditorSaveManager.AddSubAsset (transition, path);
201+
foreach (NodeKnob knob in node.nodeKnobs)
202+
NodeEditorSaveManager.AddSubAsset (knob, path);
238203

239204
AssetDatabase.SaveAssets ();
240205
AssetDatabase.Refresh ();
241206
}
242207

243208
private void SaveCache ()
244209
{
245-
//DeleteCache (); // Delete old cache
246210
string canvasName = mainNodeCanvas.name;
247211
EditorPrefs.SetString ("NodeEditorLastSession", canvasName);
248212
NodeEditorSaveManager.SaveNodeCanvas (tempSessionPath + "/LastSession.asset", false, mainNodeCanvas, mainEditorState);
@@ -296,7 +260,6 @@ private void DeleteCache ()
296260
public void SaveNodeCanvas (string path)
297261
{
298262
NodeEditorSaveManager.SaveNodeCanvas (path, true, mainNodeCanvas, mainEditorState);
299-
//SaveCache ();
300263
Repaint ();
301264
}
302265

@@ -305,9 +268,6 @@ public void SaveNodeCanvas (string path)
305268
/// </summary>
306269
public void LoadNodeCanvas (string path)
307270
{
308-
// Else it will be stuck forever
309-
NodeEditor.StopTransitioning (mainNodeCanvas);
310-
311271
// Load the NodeCanvas
312272
mainNodeCanvas = NodeEditorSaveManager.LoadNodeCanvas (path, true);
313273
if (mainNodeCanvas == null)
@@ -342,9 +302,6 @@ public void LoadNodeCanvas (string path)
342302
/// </summary>
343303
public void NewNodeCanvas ()
344304
{
345-
// Else it will be stuck forever
346-
NodeEditor.StopTransitioning (mainNodeCanvas);
347-
348305
// New NodeCanvas
349306
mainNodeCanvas = CreateInstance<NodeCanvas> ();
350307
mainNodeCanvas.name = "New Canvas";

Node_Editor/Framework/ConnectionTypes.cs

Lines changed: 109 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,67 @@ public static class ConnectionTypes
2121
private static Dictionary<string, TypeData> types;
2222

2323
/// <summary>
24-
/// Gets the Type the specified type name representates, if declared
24+
/// Gets the Type the specified identifier representates or, if not declared and checked, creates a new type data for the passed type
2525
/// </summary>
26-
public static Type GetType (string typeName)
26+
public static Type GetType (string typeName, bool createIfNotDeclared)
2727
{
28-
return GetTypeData (typeName).Type ?? NullType;
28+
TypeData data = GetTypeData (typeName, createIfNotDeclared);
29+
return data != null? data.Type : NullType;
2930
}
3031

3132
/// <summary>
32-
/// Gets the type data for the specified type name, if declared
33+
/// Gets the type data with the specified identifier or, if not declared and checked, creates a new one when a valid type name with namespace is passed
3334
/// </summary>
34-
public static TypeData GetTypeData (string typeName)
35+
public static TypeData GetTypeData (string typeName, bool createIfNotDeclared)
3536
{
3637
if (types == null || types.Count == 0)
3738
NodeEditor.ReInit (false);
3839
TypeData typeData;
3940
if (!types.TryGetValue (typeName, out typeData))
4041
{
41-
Debug.LogError ("No TypeData defined for: " + typeName);
42-
typeData = types.First ().Value;
42+
if (createIfNotDeclared)
43+
{
44+
Type type = Type.GetType (typeName);
45+
if (type == null)
46+
{
47+
typeData = types.First ().Value;
48+
Debug.LogError ("No TypeData defined for: " + typeName + " and type could not be found either!");
49+
}
50+
else
51+
{
52+
typeData = new TypeData (type);
53+
types.Add (typeName, typeData);
54+
}
55+
}
56+
else
57+
{
58+
typeData = types.First ().Value;
59+
Debug.LogError ("No TypeData defined for: " + typeName + "!");
60+
}
4361
}
44-
if (typeData.declaration == null || typeData.InputKnob == null || typeData.OutputKnob == null)
45-
{
62+
return typeData;
63+
}
64+
65+
/// <summary>
66+
/// Gets the type data for the specified type or, if not declared and checked, creates a new one for that type
67+
/// </summary>
68+
public static TypeData GetTypeData (Type type, bool createIfNotDeclared)
69+
{
70+
if (types == null || types.Count == 0)
4671
NodeEditor.ReInit (false);
47-
typeData = GetTypeData (typeName);
72+
TypeData typeData = types.Values.First ((TypeData tData) => tData.Type == type);
73+
if (typeData == null)
74+
{
75+
if (createIfNotDeclared)
76+
{
77+
typeData = new TypeData (type);
78+
types.Add (type.FullName, typeData);
79+
}
80+
else
81+
{
82+
typeData = types.First ().Value;
83+
Debug.LogError ("No TypeData defined for: " + type.FullName + "!");
84+
}
4885
}
4986
return typeData;
5087
}
@@ -54,60 +91,92 @@ public static TypeData GetTypeData (string typeName)
5491
/// </summary>
5592
internal static void FetchTypes ()
5693
{
57-
types = new Dictionary<string, TypeData> ();
94+
types = new Dictionary<string, TypeData> { { "None", new TypeData () } };
5895

59-
List<Assembly> scriptAssemblies = AppDomain.CurrentDomain.GetAssemblies ().Where ((Assembly assembly) => assembly.FullName.Contains ("Assembly")).ToList ();
60-
if (!scriptAssemblies.Contains (Assembly.GetExecutingAssembly ()))
61-
scriptAssemblies.Add (Assembly.GetExecutingAssembly ());
96+
IEnumerable<Assembly> scriptAssemblies = AppDomain.CurrentDomain.GetAssemblies ().Where ((Assembly assembly) => assembly.FullName.Contains ("Assembly"));
6297
foreach (Assembly assembly in scriptAssemblies)
63-
{
64-
foreach (Type type in assembly.GetTypes ().Where (T => T.IsClass && !T.IsAbstract && T.GetInterfaces ().Contains (typeof (ITypeDeclaration))))
65-
{
66-
ITypeDeclaration typeDecl = assembly.CreateInstance (type.FullName) as ITypeDeclaration;
98+
{ // Iterate through each script assembly
99+
IEnumerable<Type> typeDeclarations = assembly.GetTypes ().Where (T => T.IsClass && !T.IsAbstract && T.GetInterface (typeof (IConnectionTypeDeclaration).FullName) != null);
100+
foreach (Type type in typeDeclarations)
101+
{ // get all type declarations and create a typeData for them
102+
IConnectionTypeDeclaration typeDecl = assembly.CreateInstance (type.FullName) as IConnectionTypeDeclaration;
67103
if (typeDecl == null)
68104
throw new UnityException ("Error with Type Declaration " + type.FullName);
69-
types.Add (typeDecl.name, new TypeData (typeDecl));
105+
types.Add (typeDecl.Identifier, new TypeData (typeDecl));
70106
}
71107
}
72108
}
73109
}
74110

75-
public struct TypeData
111+
public class TypeData
76112
{
77-
public ITypeDeclaration declaration;
78-
public Type Type;
79-
public Color col;
80-
public Texture2D InputKnob;
81-
public Texture2D OutputKnob;
82-
83-
public TypeData (ITypeDeclaration typeDecl)
113+
private IConnectionTypeDeclaration declaration;
114+
public Type Type { get; private set; }
115+
public Color Color { get; private set; }
116+
public Texture2D InKnobTex { get; private set; }
117+
public Texture2D OutKnobTex { get; private set; }
118+
119+
internal TypeData (IConnectionTypeDeclaration typeDecl)
84120
{
85121
declaration = typeDecl;
86122
Type = declaration.Type;
87-
col = declaration.col;
123+
Color = declaration.Color;
124+
125+
InKnobTex = ResourceManager.GetTintedTexture (declaration.InKnobTex, Color);
126+
OutKnobTex = ResourceManager.GetTintedTexture (declaration.OutKnobTex, Color);
127+
128+
if (InKnobTex == null || InKnobTex == null)
129+
throw new UnityException ("Invalid textures for default typeData " + declaration.Identifier + "!");
130+
}
131+
132+
internal TypeData (Type type)
133+
{
134+
declaration = null;
135+
Type = type;
136+
Color = Color.white;//(float)type.GetHashCode() / (int.MaxValue/3);
88137

89-
InputKnob = ResourceManager.GetTintedTexture (declaration.InputKnob_TexPath, col);
90-
OutputKnob = ResourceManager.GetTintedTexture (declaration.OutputKnob_TexPath, col);
138+
InKnobTex = ResourceManager.GetTintedTexture ("Textures/In_Knob.png", Color);
139+
OutKnobTex = ResourceManager.GetTintedTexture ("Textures/Out_Knob.png", Color);
140+
141+
if (InKnobTex == null || InKnobTex == null)
142+
throw new UnityException ("Invalid textures for default typeData " + type.ToString () + "!");
143+
}
144+
145+
internal TypeData ()
146+
{
147+
declaration = null;
148+
Type = typeof(object);
149+
Color = Color.white;
150+
InKnobTex = ResourceManager.LoadTexture ("Textures/In_Knob.png");
151+
OutKnobTex = ResourceManager.LoadTexture ("Textures/Out_Knob.png");
152+
153+
if (InKnobTex == null || InKnobTex == null)
154+
throw new UnityException ("Invalid textures for default typeData!");
155+
}
156+
157+
public bool isValid ()
158+
{
159+
return Type != null && InKnobTex != null && OutKnobTex != null;
91160
}
92161
}
93162

94-
public interface ITypeDeclaration
163+
public interface IConnectionTypeDeclaration
95164
{
96-
string name { get; }
97-
Color col { get; }
98-
string InputKnob_TexPath { get; }
99-
string OutputKnob_TexPath { get; }
165+
string Identifier { get; }
100166
Type Type { get; }
167+
Color Color { get; }
168+
string InKnobTex { get; }
169+
string OutKnobTex { get; }
101170
}
102171

103172
// TODO: Node Editor: Built-In Connection Types
104-
public class FloatType : ITypeDeclaration
173+
public class FloatType : IConnectionTypeDeclaration
105174
{
106-
public string name { get { return "Float"; } }
107-
public Color col { get { return Color.cyan; } }
108-
public string InputKnob_TexPath { get { return "Textures/In_Knob.png"; } }
109-
public string OutputKnob_TexPath { get { return "Textures/Out_Knob.png"; } }
175+
public string Identifier { get { return "Float"; } }
110176
public Type Type { get { return typeof(float); } }
177+
public Color Color { get { return Color.cyan; } }
178+
public string InKnobTex { get { return "Textures/In_Knob.png"; } }
179+
public string OutKnobTex { get { return "Textures/Out_Knob.png"; } }
111180
}
112181

113182

0 commit comments

Comments
 (0)