From ca860077459019f37584e79dbb33d3cdd71b5355 Mon Sep 17 00:00:00 2001 From: Joram Date: Sun, 4 Feb 2018 12:58:17 +0100 Subject: [PATCH] added namespaces --- Scripts/Editor/NodeGraphInspector.cs | 248 ++++++++++++++------------- Scripts/Editor/NodeInspector.cs | 10 +- Scripts/Variable.cs | 73 ++++---- 3 files changed, 170 insertions(+), 161 deletions(-) diff --git a/Scripts/Editor/NodeGraphInspector.cs b/Scripts/Editor/NodeGraphInspector.cs index 135277a..025d79b 100644 --- a/Scripts/Editor/NodeGraphInspector.cs +++ b/Scripts/Editor/NodeGraphInspector.cs @@ -7,151 +7,153 @@ using UnityEngine; using UnityEditor; using XNode; -using XNodeEditor; -[CustomEditor(typeof(XNode.NodeGraph), true)] -public class NodeGraphInspector : Editor +namespace XNodeEditor { - SerializedProperty nodesProp; - SerializedProperty variablesProp; - - void OnEnable() + [CustomEditor(typeof(XNode.NodeGraph), true)] + public class NodeGraphInspector : Editor { - nodesProp = serializedObject.FindProperty("nodes"); - variablesProp = serializedObject.FindProperty("variables"); - } + SerializedProperty nodesProp; + SerializedProperty variablesProp; - public override void OnInspectorGUI() - { - serializedObject.Update(); - - DrawVariables(); - - serializedObject.ApplyModifiedProperties(); - } - - void DrawVariables() - { - EditorGUILayout.LabelField("Variables"); - EditorGUILayout.Space(); - for (int i = 0; i < variablesProp.arraySize; i++) - DrawVariable(i); - DrawVariablesActions(); - } - - void DrawVariable(int index) - { - var variableProp = variablesProp.GetArrayElementAtIndex(index); - - var idProp = variableProp.FindPropertyRelative("id"); - var typeProp = variableProp.FindPropertyRelative("typeString"); - - - DrawVariableId(idProp); - DrawVariableType(typeProp); - DrawVariableValue(variableProp, typeProp.stringValue); - DrawVariableActions(index); - - EditorGUILayout.Space(); - } - - void DrawVariableId(SerializedProperty idProp) - { - EditorGUILayout.PropertyField(idProp); - } - - void DrawVariableType(SerializedProperty typeProp) - { - List options = new List(); - options.Add(typeProp.stringValue); - int idx = 0; - - List additionalTypes = new List(); - additionalTypes.Add(typeof(float).AssemblyQualifiedName); - additionalTypes.Add(typeof(int).AssemblyQualifiedName); - additionalTypes.Add(typeof(bool).AssemblyQualifiedName); - additionalTypes.Add(typeof(string).AssemblyQualifiedName); - additionalTypes.Add(typeof(Vector3).AssemblyQualifiedName); - - /* - Assembly asm = typeof(Vector3).Assembly; - foreach (var colorPair in NodeEditorPreferences.typeColors) + void OnEnable() { - var type = asm.GetType(colorPair.Key, false); - Debug.Log(colorPair.Key + " " + type); - - if (type == null) - continue; - if (additionalTypes.Contains(type.AssemblyQualifiedName)) - continue; - additionalTypes.Add(colorPair.Key); - } - */ - - foreach (var addType in additionalTypes) - { - if (!options.Contains(addType)) - options.Add(addType); + nodesProp = serializedObject.FindProperty("nodes"); + variablesProp = serializedObject.FindProperty("variables"); } - List prettyOptions = new List(); - - foreach (var option in options) + public override void OnInspectorGUI() { - prettyOptions.Add(System.Type.GetType(option, false).PrettyName()); + serializedObject.Update(); + + DrawVariables(); + + serializedObject.ApplyModifiedProperties(); } - - idx = EditorGUILayout.Popup(idx, prettyOptions.ToArray()); - - typeProp.stringValue = options[idx]; - } - - void DrawVariableValue(SerializedProperty variableProp, string type) - { - if (type != "") + void DrawVariables() { - type = System.Type.GetType(type, false).PrettyName(); - type = NodeGraph.GetSafeType(type); + EditorGUILayout.LabelField("Variables"); + EditorGUILayout.Space(); + for (int i = 0; i < variablesProp.arraySize; i++) + DrawVariable(i); + DrawVariablesActions(); + } + + void DrawVariable(int index) + { + var variableProp = variablesProp.GetArrayElementAtIndex(index); - var valprop = variableProp.FindPropertyRelative(type + "Value"); + var idProp = variableProp.FindPropertyRelative("id"); + var typeProp = variableProp.FindPropertyRelative("typeString"); + + + DrawVariableId(idProp); + DrawVariableType(typeProp); + DrawVariableValue(variableProp, typeProp.stringValue); + DrawVariableActions(index); + + EditorGUILayout.Space(); + } + + void DrawVariableId(SerializedProperty idProp) + { + EditorGUILayout.PropertyField(idProp); + } + + void DrawVariableType(SerializedProperty typeProp) + { + List options = new List(); + options.Add(typeProp.stringValue); + int idx = 0; + + List additionalTypes = new List(); + additionalTypes.Add(typeof(float).AssemblyQualifiedName); + additionalTypes.Add(typeof(int).AssemblyQualifiedName); + additionalTypes.Add(typeof(bool).AssemblyQualifiedName); + additionalTypes.Add(typeof(string).AssemblyQualifiedName); + additionalTypes.Add(typeof(Vector3).AssemblyQualifiedName); - if (valprop == null && type != "object") + /* + Assembly asm = typeof(Vector3).Assembly; + foreach (var colorPair in NodeEditorPreferences.typeColors) { - type = "object"; - valprop = variableProp.FindPropertyRelative(type + "Value"); + var type = asm.GetType(colorPair.Key, false); + Debug.Log(colorPair.Key + " " + type); + + if (type == null) + continue; + if (additionalTypes.Contains(type.AssemblyQualifiedName)) + continue; + additionalTypes.Add(colorPair.Key); + } + */ + + foreach (var addType in additionalTypes) + { + if (!options.Contains(addType)) + options.Add(addType); } - if (valprop != null) - EditorGUILayout.PropertyField(valprop); + List prettyOptions = new List(); + + foreach (var option in options) + { + prettyOptions.Add(System.Type.GetType(option, false).PrettyName()); + } + + + idx = EditorGUILayout.Popup(idx, prettyOptions.ToArray()); + + typeProp.stringValue = options[idx]; + } + + void DrawVariableValue(SerializedProperty variableProp, string type) + { + if (type != "") + { + type = System.Type.GetType(type, false).PrettyName(); + type = NodeGraph.GetSafeType(type); + + var valprop = variableProp.FindPropertyRelative(type + "Value"); + + if (valprop == null && type != "object") + { + type = "object"; + valprop = variableProp.FindPropertyRelative(type + "Value"); + } + + if (valprop != null) + EditorGUILayout.PropertyField(valprop); + else + EditorGUILayout.LabelField("Value"); + } else EditorGUILayout.LabelField("Value"); } - else - EditorGUILayout.LabelField("Value"); - } - void DrawVariableActions(int index) - { - if (GUILayout.Button("Remove variable", GUILayout.Width(120))) + void DrawVariableActions(int index) { - variablesProp.DeleteArrayElementAtIndex(index); - } - } - - void DrawVariablesActions() - { - GUILayout.BeginHorizontal(); - - GUILayout.FlexibleSpace(); - if (GUILayout.Button("Add new variable", GUILayout.Width(120))) - { - variablesProp.InsertArrayElementAtIndex(variablesProp.arraySize); - var newVarProp = variablesProp.GetArrayElementAtIndex(variablesProp.arraySize -1); - newVarProp.FindPropertyRelative("id").stringValue = (target as NodeGraph).GetSafeId("new_variable"); - newVarProp.FindPropertyRelative("typeString").stringValue = typeof(float).AssemblyQualifiedName; + if (GUILayout.Button("Remove variable", GUILayout.Width(120))) + { + variablesProp.DeleteArrayElementAtIndex(index); + } } - GUILayout.EndHorizontal(); + void DrawVariablesActions() + { + GUILayout.BeginHorizontal(); + + GUILayout.FlexibleSpace(); + if (GUILayout.Button("Add new variable", GUILayout.Width(120))) + { + variablesProp.InsertArrayElementAtIndex(variablesProp.arraySize); + var newVarProp = variablesProp.GetArrayElementAtIndex(variablesProp.arraySize -1); + newVarProp.FindPropertyRelative("id").stringValue = (target as NodeGraph).GetSafeId("new_variable"); + newVarProp.FindPropertyRelative("typeString").stringValue = typeof(float).AssemblyQualifiedName; + } + + GUILayout.EndHorizontal(); + } } } diff --git a/Scripts/Editor/NodeInspector.cs b/Scripts/Editor/NodeInspector.cs index da797cc..49602aa 100644 --- a/Scripts/Editor/NodeInspector.cs +++ b/Scripts/Editor/NodeInspector.cs @@ -5,8 +5,12 @@ using UnityEditor; using XNode; -[CustomEditor(typeof(Node), true)] -public class NodeInspector : Editor +namespace XNodeEditor { - public override void OnInspectorGUI() { /*hides unneeded info*/ } + [CustomEditor(typeof(Node), true)] + public class NodeInspector : Editor + { + public override void OnInspectorGUI() { /*hides unneeded info*/ } + } } + diff --git a/Scripts/Variable.cs b/Scripts/Variable.cs index 9d57c6c..474a4ff 100644 --- a/Scripts/Variable.cs +++ b/Scripts/Variable.cs @@ -2,51 +2,54 @@ using System.Collections.Generic; using UnityEngine; -[System.Serializable] -public class Variable +namespace XNode { - public string id; - public string typeString; - public System.Type type + [System.Serializable] + public class Variable { - get + public string id; + public string typeString; + public System.Type type { - if (typeString == typeof(float).AssemblyQualifiedName) return typeof(float); - if (typeString == typeof(int).AssemblyQualifiedName) return typeof(int); - if (typeString == typeof(string).AssemblyQualifiedName) return typeof(string); - if (typeString == typeof(bool).AssemblyQualifiedName) return typeof(bool); - if (typeString == typeof(Vector3).AssemblyQualifiedName) return typeof(Vector3); - return typeof(Object); + get + { + if (typeString == typeof(float).AssemblyQualifiedName) return typeof(float); + if (typeString == typeof(int).AssemblyQualifiedName) return typeof(int); + if (typeString == typeof(string).AssemblyQualifiedName) return typeof(string); + if (typeString == typeof(bool).AssemblyQualifiedName) return typeof(bool); + if (typeString == typeof(Vector3).AssemblyQualifiedName) return typeof(Vector3); + return typeof(Object); + } } - } - public object Value - { - get + public object Value { - if (typeString == typeof(float).AssemblyQualifiedName) return floatValue; - if (typeString == typeof(int).AssemblyQualifiedName) return intValue; - if (typeString == typeof(string).AssemblyQualifiedName) return stringValue; - if (typeString == typeof(bool).AssemblyQualifiedName) return boolValue; - if (typeString == typeof(Vector3).AssemblyQualifiedName) return vector3Value; - return objectValue; + get + { + if (typeString == typeof(float).AssemblyQualifiedName) return floatValue; + if (typeString == typeof(int).AssemblyQualifiedName) return intValue; + if (typeString == typeof(string).AssemblyQualifiedName) return stringValue; + if (typeString == typeof(bool).AssemblyQualifiedName) return boolValue; + if (typeString == typeof(Vector3).AssemblyQualifiedName) return vector3Value; + return objectValue; + } } - } - public string stringValue; - public float floatValue; - public int intValue; - public bool boolValue; - public Vector3 vector3Value; - - // more here + public string stringValue; + public float floatValue; + public int intValue; + public bool boolValue; + public Vector3 vector3Value; + + // more here - public Object objectValue; + public Object objectValue; - public Variable() - { - id = "new_variable"; - typeString = typeof(float).AssemblyQualifiedName; + public Variable() + { + id = "new_variable"; + typeString = typeof(float).AssemblyQualifiedName; + } } }