Skip to content

Commit

Permalink
Very efficient non-EditorGui lines/curves!! Added NodeEditorFramework…
Browse files Browse the repository at this point in the history
… namespace
  • Loading branch information
Seneral committed Aug 3, 2015
1 parent 47340b9 commit ade698b
Show file tree
Hide file tree
Showing 18 changed files with 1,543 additions and 1,513 deletions.
204 changes: 106 additions & 98 deletions Framework/ConnectionTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,120 +5,128 @@
using System.Diagnostics;
using System.Collections;
using System.Collections.Generic;
using NodeEditorFramework;

public static class ConnectionTypes
namespace NodeEditorFramework
{
public static Type NullType { get { return typeof(ConnectionTypes); } }

// Static consistent information about types
static Dictionary<string, TypeData> types = new Dictionary<string, TypeData> ();
public static TypeData GetTypeData (string typeName)
{
if (types == null || types.Count == 0)
FetchTypes();
TypeData res;
if (types.TryGetValue(typeName, out res) )
return res;
UnityEngine.Debug.LogError("No TypeData defined for: " + typeName);
return types.First().Value;
}

public static Type GetInputType (string typeName)
{
if (types == null || types.Count == 0)
FetchTypes();
TypeData res;
if (types.TryGetValue(typeName, out res))
return res.InputType ?? NullType;
UnityEngine.Debug.LogError("No TypeData defined for: " + typeName);
return NullType;
}

public static Type GetOutputType (string typeName)
public static class ConnectionTypes
{
if (types == null || types.Count == 0)
FetchTypes();
TypeData res;
if (types.TryGetValue(typeName, out res))
return res.OutputType ?? NullType;
UnityEngine.Debug.LogError("No TypeData defined for: " + typeName);
return NullType;
}

/// <summary>
/// Fetches every Type Declaration in the assembly
/// </summary>
public static void FetchTypes ()
{ // Search the current and (if the NodeEditor is packed into a .dll) the calling one
types = new Dictionary<string, TypeData> ();

Assembly assembly = Assembly.GetExecutingAssembly ();
foreach (Type type in assembly.GetTypes ().Where (T => T.IsClass && !T.IsAbstract && T.GetInterfaces ().Contains (typeof (ITypeDeclaration))))
public static Type NullType { get { return typeof(ConnectionTypes); } }

// Static consistent information about types
static Dictionary<string, TypeData> types = new Dictionary<string, TypeData> ();
public static TypeData GetTypeData (string typeName)
{
ITypeDeclaration typeDecl = assembly.CreateInstance (type.Name) as ITypeDeclaration;
Texture2D InputKnob = NodeEditor.LoadTexture(typeDecl.InputKnob_TexPath);
Texture2D OutputKnob = NodeEditor.LoadTexture(typeDecl.OutputKnob_TexPath);
types.Add(typeDecl.name, new TypeData(typeDecl.col, InputKnob, OutputKnob, typeDecl.InputType, typeDecl.OutputType));
if (types == null || types.Count == 0)
FetchTypes();
TypeData res;
if (types.TryGetValue(typeName, out res) )
return res;
UnityEngine.Debug.LogError("No TypeData defined for: " + typeName);
return types.First().Value;
}

if (assembly != Assembly.GetCallingAssembly ())
public static Type GetInputType (string typeName)
{
assembly = Assembly.GetCallingAssembly ();
if (types == null || types.Count == 0)
FetchTypes();
TypeData res;
if (types.TryGetValue(typeName, out res))
return res.InputType ?? NullType;
UnityEngine.Debug.LogError("No TypeData defined for: " + typeName);
return NullType;
}

public static Type GetOutputType (string typeName)
{
if (types == null || types.Count == 0)
FetchTypes();
TypeData res;
if (types.TryGetValue(typeName, out res))
return res.OutputType ?? NullType;
UnityEngine.Debug.LogError("No TypeData defined for: " + typeName);
return NullType;
}

/// <summary>
/// Fetches every Type Declaration in the assembly
/// </summary>
public static void FetchTypes ()
{ // Search the current and (if the NodeEditor is packed into a .dll) the calling one
types = new Dictionary<string, TypeData> ();

Assembly assembly = Assembly.GetExecutingAssembly ();
foreach (Type type in assembly.GetTypes ().Where (T => T.IsClass && !T.IsAbstract && T.GetInterfaces ().Contains (typeof (ITypeDeclaration))))
{
ITypeDeclaration typeDecl = assembly.CreateInstance (type.Name) as ITypeDeclaration;
ITypeDeclaration typeDecl = assembly.CreateInstance (type.FullName) as ITypeDeclaration;
if (typeDecl == null)
{
UnityEngine.Debug.LogError ("Error with Type Declaration " + type.FullName);
return;
}
Texture2D InputKnob = NodeEditor.LoadTexture(typeDecl.InputKnob_TexPath);
Texture2D OutputKnob = NodeEditor.LoadTexture(typeDecl.OutputKnob_TexPath);
types.Add (typeDecl.name, new TypeData (typeDecl.col, InputKnob, OutputKnob, typeDecl.InputType, typeDecl.OutputType));
types.Add(typeDecl.name, new TypeData(typeDecl.col, InputKnob, OutputKnob, typeDecl.InputType, typeDecl.OutputType));
}

// if (assembly != Assembly.GetCallingAssembly ())
// {
// assembly = Assembly.GetCallingAssembly ();
// foreach (Type type in assembly.GetTypes ().Where (T => T.IsClass && !T.IsAbstract && T.GetInterfaces ().Contains (typeof (ITypeDeclaration))))
// {
// ITypeDeclaration typeDecl = assembly.CreateInstance (type.FullName) as ITypeDeclaration;
// Texture2D InputKnob = NodeEditor.LoadTexture(typeDecl.InputKnob_TexPath);
// Texture2D OutputKnob = NodeEditor.LoadTexture(typeDecl.OutputKnob_TexPath);
// types.Add (typeDecl.name, new TypeData (typeDecl.col, InputKnob, OutputKnob, typeDecl.InputType, typeDecl.OutputType));
// }
// }
}
}
}

public struct TypeData
{
public Color col;
public Texture2D InputKnob;
public Texture2D OutputKnob;
public Type InputType;
public Type OutputType;

public TypeData (Color color, Texture2D inKnob, Texture2D outKnob, Type inputType, Type outputType)
public struct TypeData
{
col = color;
InputKnob = NodeEditor.Tint (inKnob, color);
OutputKnob = NodeEditor.Tint (outKnob, color);
InputType = inputType;
OutputType = outputType;
public Color col;
public Texture2D InputKnob;
public Texture2D OutputKnob;
public Type InputType;
public Type OutputType;

public TypeData (Color color, Texture2D inKnob, Texture2D outKnob, Type inputType, Type outputType)
{
col = color;
InputKnob = NodeEditor.Tint (inKnob, color);
OutputKnob = NodeEditor.Tint (outKnob, color);
InputType = inputType;
OutputType = outputType;
}
}
}

public interface ITypeDeclaration
{
string name { get; }
Color col { get; }
string InputKnob_TexPath { get; }
string OutputKnob_TexPath { get; }
Type InputType { get; }
Type OutputType { get; }
}

// TODO: Node Editor: Built-In Connection Types
public class FloatType : ITypeDeclaration
{
public string name { get { return "Float"; } }
public Color col { get { return Color.cyan; } }
public string InputKnob_TexPath { get { return "Textures/In_Knob.png"; } }
public string OutputKnob_TexPath { get { return "Textures/Out_Knob.png"; } }
public Type InputType { get { return null; } }
public Type OutputType { get { return typeof(FloatValue); } }
}

[Serializable]
public class FloatValue
{
[NonSerialized]
public float value;
}
public interface ITypeDeclaration
{
string name { get; }
Color col { get; }
string InputKnob_TexPath { get; }
string OutputKnob_TexPath { get; }
Type InputType { get; }
Type OutputType { get; }
}

// TODO: Node Editor: Built-In Connection Types
public class FloatType : ITypeDeclaration
{
public string name { get { return "Float"; } }
public Color col { get { return Color.cyan; } }
public string InputKnob_TexPath { get { return "Textures/In_Knob.png"; } }
public string OutputKnob_TexPath { get { return "Textures/Out_Knob.png"; } }
public Type InputType { get { return null; } }
public Type OutputType { get { return typeof(FloatValue); } }
}

[Serializable]
public class FloatValue
{
public FloatValue () {}
[NonSerialized]
public float value;
}
}
3 changes: 3 additions & 0 deletions Framework/GUIExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ public static string TextField (GUIContent label, string text)
private static string activeFloatField;
// private static float startSlideValue = 0;
// private static float startSlidePos = 0;
#if UNITY_EDITOR
#else
private static Dictionary<string, string> floatFields = new Dictionary<string, string> ();
#endif
/// <summary>
/// Mimics UnityEditor.EditorGUILayout.FloatField by taking a float and returning the edited float.
/// </summary>
Expand Down
Loading

0 comments on commit ade698b

Please sign in to comment.