mirror of
https://github.com/Siccity/xNode.git
synced 2026-03-26 22:49:02 +08:00
added namespaces
This commit is contained in:
parent
1e8f2b081c
commit
ca86007745
@ -7,151 +7,153 @@ using UnityEngine;
|
|||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
|
|
||||||
using XNode;
|
using XNode;
|
||||||
using XNodeEditor;
|
|
||||||
|
|
||||||
[CustomEditor(typeof(XNode.NodeGraph), true)]
|
namespace XNodeEditor
|
||||||
public class NodeGraphInspector : Editor
|
|
||||||
{
|
{
|
||||||
SerializedProperty nodesProp;
|
[CustomEditor(typeof(XNode.NodeGraph), true)]
|
||||||
SerializedProperty variablesProp;
|
public class NodeGraphInspector : Editor
|
||||||
|
|
||||||
void OnEnable()
|
|
||||||
{
|
{
|
||||||
nodesProp = serializedObject.FindProperty("nodes");
|
SerializedProperty nodesProp;
|
||||||
variablesProp = serializedObject.FindProperty("variables");
|
SerializedProperty variablesProp;
|
||||||
}
|
|
||||||
|
|
||||||
public override void OnInspectorGUI()
|
void OnEnable()
|
||||||
{
|
|
||||||
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<string> options = new List<string>();
|
|
||||||
options.Add(typeProp.stringValue);
|
|
||||||
int idx = 0;
|
|
||||||
|
|
||||||
List<string> additionalTypes = new List<string>();
|
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
var type = asm.GetType(colorPair.Key, false);
|
nodesProp = serializedObject.FindProperty("nodes");
|
||||||
Debug.Log(colorPair.Key + " " + type);
|
variablesProp = serializedObject.FindProperty("variables");
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
List<string> prettyOptions = new List<string>();
|
public override void OnInspectorGUI()
|
||||||
|
|
||||||
foreach (var option in options)
|
|
||||||
{
|
{
|
||||||
prettyOptions.Add(System.Type.GetType(option, false).PrettyName());
|
serializedObject.Update();
|
||||||
|
|
||||||
|
DrawVariables();
|
||||||
|
|
||||||
|
serializedObject.ApplyModifiedProperties();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DrawVariables()
|
||||||
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();
|
EditorGUILayout.LabelField("Variables");
|
||||||
type = NodeGraph.GetSafeType(type);
|
EditorGUILayout.Space();
|
||||||
|
for (int i = 0; i < variablesProp.arraySize; i++)
|
||||||
|
DrawVariable(i);
|
||||||
|
DrawVariablesActions();
|
||||||
|
}
|
||||||
|
|
||||||
var valprop = variableProp.FindPropertyRelative(type + "Value");
|
void DrawVariable(int index)
|
||||||
|
{
|
||||||
|
var variableProp = variablesProp.GetArrayElementAtIndex(index);
|
||||||
|
|
||||||
if (valprop == null && type != "object")
|
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<string> options = new List<string>();
|
||||||
|
options.Add(typeProp.stringValue);
|
||||||
|
int idx = 0;
|
||||||
|
|
||||||
|
List<string> additionalTypes = new List<string>();
|
||||||
|
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)
|
||||||
{
|
{
|
||||||
type = "object";
|
var type = asm.GetType(colorPair.Key, false);
|
||||||
valprop = variableProp.FindPropertyRelative(type + "Value");
|
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)
|
List<string> prettyOptions = new List<string>();
|
||||||
EditorGUILayout.PropertyField(valprop);
|
|
||||||
|
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
|
else
|
||||||
EditorGUILayout.LabelField("Value");
|
EditorGUILayout.LabelField("Value");
|
||||||
}
|
}
|
||||||
else
|
|
||||||
EditorGUILayout.LabelField("Value");
|
|
||||||
}
|
|
||||||
|
|
||||||
void DrawVariableActions(int index)
|
void DrawVariableActions(int index)
|
||||||
{
|
|
||||||
if (GUILayout.Button("Remove variable", GUILayout.Width(120)))
|
|
||||||
{
|
{
|
||||||
variablesProp.DeleteArrayElementAtIndex(index);
|
if (GUILayout.Button("Remove variable", GUILayout.Width(120)))
|
||||||
}
|
{
|
||||||
}
|
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,8 +5,12 @@ using UnityEditor;
|
|||||||
|
|
||||||
using XNode;
|
using XNode;
|
||||||
|
|
||||||
[CustomEditor(typeof(Node), true)]
|
namespace XNodeEditor
|
||||||
public class NodeInspector : Editor
|
|
||||||
{
|
{
|
||||||
public override void OnInspectorGUI() { /*hides unneeded info*/ }
|
[CustomEditor(typeof(Node), true)]
|
||||||
|
public class NodeInspector : Editor
|
||||||
|
{
|
||||||
|
public override void OnInspectorGUI() { /*hides unneeded info*/ }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2,51 +2,54 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
[System.Serializable]
|
namespace XNode
|
||||||
public class Variable
|
|
||||||
{
|
{
|
||||||
public string id;
|
[System.Serializable]
|
||||||
public string typeString;
|
public class Variable
|
||||||
public System.Type type
|
|
||||||
{
|
{
|
||||||
get
|
public string id;
|
||||||
|
public string typeString;
|
||||||
|
public System.Type type
|
||||||
{
|
{
|
||||||
if (typeString == typeof(float).AssemblyQualifiedName) return typeof(float);
|
get
|
||||||
if (typeString == typeof(int).AssemblyQualifiedName) return typeof(int);
|
{
|
||||||
if (typeString == typeof(string).AssemblyQualifiedName) return typeof(string);
|
if (typeString == typeof(float).AssemblyQualifiedName) return typeof(float);
|
||||||
if (typeString == typeof(bool).AssemblyQualifiedName) return typeof(bool);
|
if (typeString == typeof(int).AssemblyQualifiedName) return typeof(int);
|
||||||
if (typeString == typeof(Vector3).AssemblyQualifiedName) return typeof(Vector3);
|
if (typeString == typeof(string).AssemblyQualifiedName) return typeof(string);
|
||||||
return typeof(Object);
|
if (typeString == typeof(bool).AssemblyQualifiedName) return typeof(bool);
|
||||||
|
if (typeString == typeof(Vector3).AssemblyQualifiedName) return typeof(Vector3);
|
||||||
|
return typeof(Object);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public object Value
|
public object Value
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
{
|
||||||
if (typeString == typeof(float).AssemblyQualifiedName) return floatValue;
|
get
|
||||||
if (typeString == typeof(int).AssemblyQualifiedName) return intValue;
|
{
|
||||||
if (typeString == typeof(string).AssemblyQualifiedName) return stringValue;
|
if (typeString == typeof(float).AssemblyQualifiedName) return floatValue;
|
||||||
if (typeString == typeof(bool).AssemblyQualifiedName) return boolValue;
|
if (typeString == typeof(int).AssemblyQualifiedName) return intValue;
|
||||||
if (typeString == typeof(Vector3).AssemblyQualifiedName) return vector3Value;
|
if (typeString == typeof(string).AssemblyQualifiedName) return stringValue;
|
||||||
return objectValue;
|
if (typeString == typeof(bool).AssemblyQualifiedName) return boolValue;
|
||||||
|
if (typeString == typeof(Vector3).AssemblyQualifiedName) return vector3Value;
|
||||||
|
return objectValue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public string stringValue;
|
public string stringValue;
|
||||||
public float floatValue;
|
public float floatValue;
|
||||||
public int intValue;
|
public int intValue;
|
||||||
public bool boolValue;
|
public bool boolValue;
|
||||||
public Vector3 vector3Value;
|
public Vector3 vector3Value;
|
||||||
|
|
||||||
// more here
|
// more here
|
||||||
|
|
||||||
public Object objectValue;
|
public Object objectValue;
|
||||||
|
|
||||||
|
|
||||||
public Variable()
|
public Variable()
|
||||||
{
|
{
|
||||||
id = "new_variable";
|
id = "new_variable";
|
||||||
typeString = typeof(float).AssemblyQualifiedName;
|
typeString = typeof(float).AssemblyQualifiedName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user