mirror of
https://github.com/Siccity/xNode.git
synced 2025-12-20 17:26:02 +08:00
Code FixFormat
None of the code was changed, just moved around.
This commit is contained in:
parent
9abdf2995e
commit
64282028aa
Binary file not shown.
@ -1,9 +1,9 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
using UnityEngine;
|
using System.Collections.Generic;
|
||||||
using UnityEditor;
|
|
||||||
using System.Reflection;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System;
|
using System.Reflection;
|
||||||
|
using UnityEditor;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
/// <summary> Base class to derive custom Node editors from. Use this to create your own custom inspectors and editors for your nodes. </summary>
|
/// <summary> Base class to derive custom Node editors from. Use this to create your own custom inspectors and editors for your nodes. </summary>
|
||||||
public class NodeEditor {
|
public class NodeEditor {
|
||||||
@ -12,7 +12,7 @@ public class NodeEditor {
|
|||||||
|
|
||||||
/// <summary> Draws the node GUI.</summary>
|
/// <summary> Draws the node GUI.</summary>
|
||||||
/// <param name="portPositions">Port handle positions need to be returned to the NodeEditorWindow </param>
|
/// <param name="portPositions">Port handle positions need to be returned to the NodeEditorWindow </param>
|
||||||
public virtual void OnNodeGUI(out Dictionary<NodePort,Vector2> portPositions) {
|
public virtual void OnNodeGUI(out Dictionary<NodePort, Vector2> portPositions) {
|
||||||
DrawDefaultHeaderGUI();
|
DrawDefaultHeaderGUI();
|
||||||
DrawDefaultNodePortsGUI(out portPositions);
|
DrawDefaultNodePortsGUI(out portPositions);
|
||||||
DrawDefaultNodeBodyGUI();
|
DrawDefaultNodeBodyGUI();
|
||||||
@ -75,12 +75,16 @@ public class NodeEditor {
|
|||||||
Vector2 handlePoint = rect.center;
|
Vector2 handlePoint = rect.center;
|
||||||
|
|
||||||
switch (port.direction) {
|
switch (port.direction) {
|
||||||
case NodePort.IO.Input: handlePoint.x = rect.xMin; break;
|
case NodePort.IO.Input:
|
||||||
case NodePort.IO.Output: handlePoint.x = rect.xMax; break;
|
handlePoint.x = rect.xMin;
|
||||||
|
break;
|
||||||
|
case NodePort.IO.Output:
|
||||||
|
handlePoint.x = rect.xMax;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
Color col = GUI.color;
|
Color col = GUI.color;
|
||||||
Rect handleRect = new Rect(handlePoint.x-8,handlePoint.y-8,16,16);
|
Rect handleRect = new Rect(handlePoint.x - 8, handlePoint.y - 8, 16, 16);
|
||||||
GUI.color = new Color(0.29f, 0.31f, 0.32f);
|
GUI.color = new Color(0.29f, 0.31f, 0.32f);
|
||||||
GUI.DrawTexture(handleRect, NodeEditorResources.dotOuter);
|
GUI.DrawTexture(handleRect, NodeEditorResources.dotOuter);
|
||||||
GUI.color = NodeEditorPreferences.GetTypeColor(port.type);
|
GUI.color = NodeEditorPreferences.GetTypeColor(port.type);
|
||||||
@ -90,7 +94,7 @@ public class NodeEditor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static FieldInfo[] GetInspectorFields(Node node) {
|
private static FieldInfo[] GetInspectorFields(Node node) {
|
||||||
return node.GetType().GetFields().Where(f => f.IsPublic || f.GetCustomAttributes(typeof(SerializeField),false) != null).ToArray();
|
return node.GetType().GetFields().Where(f => f.IsPublic || f.GetCustomAttributes(typeof(SerializeField), false) != null).ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DrawFieldInfoDrawerGUI(FieldInfo fieldInfo) {
|
private void DrawFieldInfoDrawerGUI(FieldInfo fieldInfo) {
|
||||||
@ -111,68 +115,56 @@ public class NodeEditor {
|
|||||||
rect.width *= 0.5f;
|
rect.width *= 0.5f;
|
||||||
EditorGUI.LabelField(rect, fieldPrettyName);
|
EditorGUI.LabelField(rect, fieldPrettyName);
|
||||||
rect.x += rect.width;
|
rect.x += rect.width;
|
||||||
fieldValue = EditorGUI.IntField(rect, (int)fieldValue);
|
fieldValue = EditorGUI.IntField(rect, (int) fieldValue);
|
||||||
}
|
} else if (fieldType == typeof(bool)) {
|
||||||
else if (fieldType == typeof(bool)) {
|
fieldValue = EditorGUILayout.Toggle(fieldPrettyName, (bool) fieldValue);
|
||||||
fieldValue = EditorGUILayout.Toggle(fieldPrettyName, (bool)fieldValue);
|
} else if (fieldType.IsEnum) {
|
||||||
}
|
|
||||||
else if (fieldType.IsEnum) {
|
|
||||||
Rect rect = EditorGUILayout.GetControlRect();
|
Rect rect = EditorGUILayout.GetControlRect();
|
||||||
rect.width *= 0.5f;
|
rect.width *= 0.5f;
|
||||||
EditorGUI.LabelField(rect, fieldPrettyName);
|
EditorGUI.LabelField(rect, fieldPrettyName);
|
||||||
rect.x += rect.width;
|
rect.x += rect.width;
|
||||||
fieldValue = EditorGUI.EnumPopup(rect, (Enum)fieldValue);
|
fieldValue = EditorGUI.EnumPopup(rect, (Enum) fieldValue);
|
||||||
}
|
} else if (fieldType == typeof(string)) {
|
||||||
else if (fieldType == typeof(string)) {
|
|
||||||
|
|
||||||
if (fieldName == "name") return; //Ignore 'name'
|
if (fieldName == "name") return; //Ignore 'name'
|
||||||
TextAreaAttribute textAreaAttrib;
|
TextAreaAttribute textAreaAttrib;
|
||||||
if (NodeEditorUtilities.GetAttrib(fieldAttribs, out textAreaAttrib)) {
|
if (NodeEditorUtilities.GetAttrib(fieldAttribs, out textAreaAttrib)) {
|
||||||
fieldValue = EditorGUILayout.TextArea(fieldValue != null ? (string)fieldValue : "");
|
fieldValue = EditorGUILayout.TextArea(fieldValue != null ? (string) fieldValue : "");
|
||||||
}
|
} else
|
||||||
else
|
fieldValue = EditorGUILayout.TextField(fieldPrettyName, fieldValue != null ? (string) fieldValue : "");
|
||||||
fieldValue = EditorGUILayout.TextField(fieldPrettyName, fieldValue != null ? (string)fieldValue : "");
|
} else if (fieldType == typeof(Rect)) {
|
||||||
}
|
|
||||||
else if (fieldType == typeof(Rect)) {
|
|
||||||
if (fieldName == "rect") return; //Ignore 'rect'
|
if (fieldName == "rect") return; //Ignore 'rect'
|
||||||
fieldValue = EditorGUILayout.RectField(fieldPrettyName, (Rect)fieldValue);
|
fieldValue = EditorGUILayout.RectField(fieldPrettyName, (Rect) fieldValue);
|
||||||
}
|
} else if (fieldType == typeof(float)) {
|
||||||
else if (fieldType == typeof(float)) {
|
|
||||||
Rect rect = EditorGUILayout.GetControlRect();
|
Rect rect = EditorGUILayout.GetControlRect();
|
||||||
rect.width *= 0.5f;
|
rect.width *= 0.5f;
|
||||||
EditorGUI.LabelField(rect, fieldPrettyName);
|
EditorGUI.LabelField(rect, fieldPrettyName);
|
||||||
rect.x += rect.width;
|
rect.x += rect.width;
|
||||||
fieldValue = EditorGUI.FloatField(rect, (float)fieldValue);
|
fieldValue = EditorGUI.FloatField(rect, (float) fieldValue);
|
||||||
}
|
} else if (fieldType == typeof(Vector2)) {
|
||||||
else if (fieldType == typeof(Vector2)) {
|
fieldValue = EditorGUILayout.Vector2Field(fieldPrettyName, (Vector2) fieldValue);
|
||||||
fieldValue = EditorGUILayout.Vector2Field(fieldPrettyName, (Vector2)fieldValue);
|
} else if (fieldType == typeof(Vector3)) {
|
||||||
}
|
fieldValue = EditorGUILayout.Vector3Field(new GUIContent(fieldPrettyName), (Vector3) fieldValue);
|
||||||
else if (fieldType == typeof(Vector3)) {
|
} else if (fieldType == typeof(Vector4)) {
|
||||||
fieldValue = EditorGUILayout.Vector3Field(new GUIContent(fieldPrettyName), (Vector3)fieldValue);
|
fieldValue = EditorGUILayout.Vector4Field(fieldPrettyName, (Vector4) fieldValue);
|
||||||
}
|
} else if (fieldType == typeof(Color)) {
|
||||||
else if (fieldType == typeof(Vector4)) {
|
|
||||||
fieldValue = EditorGUILayout.Vector4Field(fieldPrettyName, (Vector4)fieldValue);
|
|
||||||
}
|
|
||||||
else if (fieldType == typeof(Color)) {
|
|
||||||
Rect rect = EditorGUILayout.GetControlRect();
|
Rect rect = EditorGUILayout.GetControlRect();
|
||||||
rect.width *= 0.5f;
|
rect.width *= 0.5f;
|
||||||
EditorGUI.LabelField(rect, fieldPrettyName);
|
EditorGUI.LabelField(rect, fieldPrettyName);
|
||||||
rect.x += rect.width;
|
rect.x += rect.width;
|
||||||
fieldValue = EditorGUI.ColorField(rect, (Color)fieldValue);
|
fieldValue = EditorGUI.ColorField(rect, (Color) fieldValue);
|
||||||
}
|
} else if (fieldType == typeof(AnimationCurve)) {
|
||||||
else if (fieldType == typeof(AnimationCurve)) {
|
|
||||||
Rect rect = EditorGUILayout.GetControlRect();
|
Rect rect = EditorGUILayout.GetControlRect();
|
||||||
rect.width *= 0.5f;
|
rect.width *= 0.5f;
|
||||||
EditorGUI.LabelField(rect, fieldPrettyName);
|
EditorGUI.LabelField(rect, fieldPrettyName);
|
||||||
rect.x += rect.width;
|
rect.x += rect.width;
|
||||||
|
|
||||||
AnimationCurve curve = fieldValue != null ? (AnimationCurve)fieldValue : new AnimationCurve();
|
AnimationCurve curve = fieldValue != null ? (AnimationCurve) fieldValue : new AnimationCurve();
|
||||||
curve = EditorGUI.CurveField(rect, curve);
|
curve = EditorGUI.CurveField(rect, curve);
|
||||||
if (fieldValue != curve) fieldInfo.SetValue(target, curve);
|
if (fieldValue != curve) fieldInfo.SetValue(target, curve);
|
||||||
}
|
} else if (fieldType.IsSubclassOf(typeof(UnityEngine.Object)) || fieldType == typeof(UnityEngine.Object)) {
|
||||||
else if (fieldType.IsSubclassOf(typeof(UnityEngine.Object)) || fieldType == typeof(UnityEngine.Object)) {
|
|
||||||
if (fieldName == "graph") return; //Ignore 'graph'
|
if (fieldName == "graph") return; //Ignore 'graph'
|
||||||
fieldValue = EditorGUILayout.ObjectField(fieldPrettyName, (UnityEngine.Object)fieldValue, fieldType, true);
|
fieldValue = EditorGUILayout.ObjectField(fieldPrettyName, (UnityEngine.Object) fieldValue, fieldType, true);
|
||||||
}
|
}
|
||||||
if (EditorGUI.EndChangeCheck()) {
|
if (EditorGUI.EndChangeCheck()) {
|
||||||
fieldInfo.SetValue(target, fieldValue);
|
fieldInfo.SetValue(target, fieldValue);
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
using System.Collections;
|
using System;
|
||||||
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using System;
|
using UnityEngine;
|
||||||
|
|
||||||
public partial class NodeEditorWindow {
|
public partial class NodeEditorWindow {
|
||||||
|
|
||||||
@ -45,18 +45,15 @@ public partial class NodeEditorWindow {
|
|||||||
if (!draggedOutput.IsConnectedTo(hoveredPort)) {
|
if (!draggedOutput.IsConnectedTo(hoveredPort)) {
|
||||||
draggedOutputTarget = hoveredPort;
|
draggedOutputTarget = hoveredPort;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
draggedOutputTarget = null;
|
draggedOutputTarget = null;
|
||||||
}
|
}
|
||||||
Repaint();
|
Repaint();
|
||||||
}
|
} else if (IsDraggingNode) {
|
||||||
else if (IsDraggingNode) {
|
|
||||||
draggedNode.rect.position = WindowToGridPosition(e.mousePosition) + dragOffset;
|
draggedNode.rect.position = WindowToGridPosition(e.mousePosition) + dragOffset;
|
||||||
Repaint();
|
Repaint();
|
||||||
}
|
}
|
||||||
}
|
} else if (e.button == 1) {
|
||||||
else if (e.button == 1) {
|
|
||||||
panOffset += e.delta * zoom;
|
panOffset += e.delta * zoom;
|
||||||
isPanning = true;
|
isPanning = true;
|
||||||
}
|
}
|
||||||
@ -71,8 +68,7 @@ public partial class NodeEditorWindow {
|
|||||||
if (IsHoveringPort) {
|
if (IsHoveringPort) {
|
||||||
if (hoveredPort.IsOutput) {
|
if (hoveredPort.IsOutput) {
|
||||||
draggedOutput = hoveredPort;
|
draggedOutput = hoveredPort;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if (hoveredPort.IsConnected) {
|
if (hoveredPort.IsConnected) {
|
||||||
NodePort output = hoveredPort.Connection;
|
NodePort output = hoveredPort.Connection;
|
||||||
hoveredPort.Disconnect(output);
|
hoveredPort.Disconnect(output);
|
||||||
@ -80,8 +76,7 @@ public partial class NodeEditorWindow {
|
|||||||
draggedOutputTarget = hoveredPort;
|
draggedOutputTarget = hoveredPort;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else if (IsHoveringNode && IsHoveringTitle(hoveredNode)) {
|
||||||
else if (IsHoveringNode && IsHoveringTitle(hoveredNode)) {
|
|
||||||
draggedNode = hoveredNode;
|
draggedNode = hoveredNode;
|
||||||
dragOffset = hoveredNode.rect.position - WindowToGridPosition(e.mousePosition);
|
dragOffset = hoveredNode.rect.position - WindowToGridPosition(e.mousePosition);
|
||||||
}
|
}
|
||||||
@ -100,12 +95,10 @@ public partial class NodeEditorWindow {
|
|||||||
draggedOutputTarget = null;
|
draggedOutputTarget = null;
|
||||||
EditorUtility.SetDirty(graph);
|
EditorUtility.SetDirty(graph);
|
||||||
Repaint();
|
Repaint();
|
||||||
}
|
} else if (IsDraggingNode) {
|
||||||
else if (IsDraggingNode) {
|
|
||||||
draggedNode = null;
|
draggedNode = null;
|
||||||
}
|
}
|
||||||
}
|
} else if (e.button == 1) {
|
||||||
else if (e.button == 1) {
|
|
||||||
if (!isPanning) ShowContextMenu();
|
if (!isPanning) ShowContextMenu();
|
||||||
isPanning = false;
|
isPanning = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,14 +1,14 @@
|
|||||||
using UnityEngine;
|
using System;
|
||||||
using UnityEditor;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using UnityEditor;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
/// <summary> Contains GUI methods </summary>
|
/// <summary> Contains GUI methods </summary>
|
||||||
public partial class NodeEditorWindow {
|
public partial class NodeEditorWindow {
|
||||||
|
|
||||||
private void OnGUI() {
|
private void OnGUI() {
|
||||||
Event e = Event.current;
|
Event e = Event.current;
|
||||||
Matrix4x4 m = GUI.matrix;
|
Matrix4x4m = GUI.matrix;
|
||||||
Controls();
|
Controls();
|
||||||
|
|
||||||
DrawGrid(position, zoom, panOffset);
|
DrawGrid(position, zoom, panOffset);
|
||||||
@ -25,9 +25,7 @@ public partial class NodeEditorWindow {
|
|||||||
GUIUtility.ScaleAroundPivot(Vector2.one / zoom, rect.size * 0.5f);
|
GUIUtility.ScaleAroundPivot(Vector2.one / zoom, rect.size * 0.5f);
|
||||||
Vector4 padding = new Vector4(0, 22, 0, 0);
|
Vector4 padding = new Vector4(0, 22, 0, 0);
|
||||||
padding *= zoom;
|
padding *= zoom;
|
||||||
GUI.BeginClip(new Rect(
|
GUI.BeginClip(new Rect(-((rect.width * zoom) - rect.width) * 0.5f, -(((rect.height * zoom) - rect.height) * 0.5f) + (22 * zoom),
|
||||||
-((rect.width * zoom) - rect.width) * 0.5f,
|
|
||||||
-(((rect.height * zoom) - rect.height) * 0.5f) + (22 * zoom),
|
|
||||||
rect.width * zoom,
|
rect.width * zoom,
|
||||||
rect.height * zoom));
|
rect.height * zoom));
|
||||||
}
|
}
|
||||||
@ -36,7 +34,7 @@ public partial class NodeEditorWindow {
|
|||||||
GUIUtility.ScaleAroundPivot(Vector2.one * zoom, rect.size * 0.5f);
|
GUIUtility.ScaleAroundPivot(Vector2.one * zoom, rect.size * 0.5f);
|
||||||
Vector3 offset = new Vector3(
|
Vector3 offset = new Vector3(
|
||||||
(((rect.width * zoom) - rect.width) * 0.5f),
|
(((rect.width * zoom) - rect.width) * 0.5f),
|
||||||
(((rect.height * zoom) - rect.height) * 0.5f) + (-22 * zoom)+22,
|
(((rect.height * zoom) - rect.height) * 0.5f) + (-22 * zoom) + 22,
|
||||||
0);
|
0);
|
||||||
GUI.matrix = Matrix4x4.TRS(offset, Quaternion.identity, Vector3.one);
|
GUI.matrix = Matrix4x4.TRS(offset, Quaternion.identity, Vector3.one);
|
||||||
}
|
}
|
||||||
@ -63,7 +61,7 @@ public partial class NodeEditorWindow {
|
|||||||
|
|
||||||
// Draw tiled background
|
// Draw tiled background
|
||||||
GUI.DrawTextureWithTexCoords(rect, gridTex, new Rect(tileOffset, tileAmount));
|
GUI.DrawTextureWithTexCoords(rect, gridTex, new Rect(tileOffset, tileAmount));
|
||||||
GUI.DrawTextureWithTexCoords(rect, crossTex, new Rect(tileOffset + new Vector2(0.5f,0.5f), tileAmount));
|
GUI.DrawTextureWithTexCoords(rect, crossTex, new Rect(tileOffset + new Vector2(0.5f, 0.5f), tileAmount));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool DropdownButton(string name, float width) {
|
public static bool DropdownButton(string name, float width) {
|
||||||
@ -78,8 +76,7 @@ public partial class NodeEditorWindow {
|
|||||||
if (hoveredNode != null) {
|
if (hoveredNode != null) {
|
||||||
Node node = hoveredNode;
|
Node node = hoveredNode;
|
||||||
contextMenu.AddItem(new GUIContent("Remove"), false, () => graph.RemoveNode(node));
|
contextMenu.AddItem(new GUIContent("Remove"), false, () => graph.RemoveNode(node));
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
for (int i = 0; i < nodeTypes.Length; i++) {
|
for (int i = 0; i < nodeTypes.Length; i++) {
|
||||||
Type type = nodeTypes[i];
|
Type type = nodeTypes[i];
|
||||||
Type editorType = GetNodeEditor(type).GetType();
|
Type editorType = GetNodeEditor(type).GetType();
|
||||||
@ -160,7 +157,7 @@ public partial class NodeEditorWindow {
|
|||||||
|
|
||||||
//GUIStyle style = (node == selectedNode) ? (GUIStyle)"flow node 0 on" : (GUIStyle)"flow node 0";
|
//GUIStyle style = (node == selectedNode) ? (GUIStyle)"flow node 0 on" : (GUIStyle)"flow node 0";
|
||||||
|
|
||||||
GUILayout.BeginArea(new Rect(nodePos,new Vector2(nodeEditor.GetWidth(), 4000)));
|
GUILayout.BeginArea(new Rect(nodePos, new Vector2(nodeEditor.GetWidth(), 4000)));
|
||||||
|
|
||||||
GUIStyle style = NodeEditorResources.styles.nodeBody;
|
GUIStyle style = NodeEditorResources.styles.nodeBody;
|
||||||
GUILayout.BeginVertical(new GUIStyle(style));
|
GUILayout.BeginVertical(new GUIStyle(style));
|
||||||
|
|||||||
@ -12,45 +12,43 @@ public static class NodeEditorPreferences {
|
|||||||
private static Dictionary<string, Color> typeColors;
|
private static Dictionary<string, Color> typeColors;
|
||||||
private static Dictionary<string, Color> generatedTypeColors;
|
private static Dictionary<string, Color> generatedTypeColors;
|
||||||
|
|
||||||
[PreferenceItem ("Node Editor")]
|
[PreferenceItem("Node Editor")]
|
||||||
private static void PreferencesGUI () {
|
private static void PreferencesGUI() {
|
||||||
if (!prefsLoaded) LoadPrefs();
|
if (!prefsLoaded) LoadPrefs();
|
||||||
EditorGUILayout.LabelField("Type colors", EditorStyles.boldLabel);
|
EditorGUILayout.LabelField("Type colors", EditorStyles.boldLabel);
|
||||||
|
|
||||||
string[] typeKeys = new string[typeColors.Count];
|
string[] typeKeys = new string[typeColors.Count];
|
||||||
typeColors.Keys.CopyTo(typeKeys, 0);
|
typeColors.Keys.CopyTo(typeKeys, 0);
|
||||||
|
|
||||||
|
|
||||||
foreach (var key in typeKeys) {
|
foreach (var key in typeKeys) {
|
||||||
EditorGUILayout.BeginHorizontal ();
|
EditorGUILayout.BeginHorizontal();
|
||||||
Color col = typeColors[key];
|
Color col = typeColors[key];
|
||||||
col = EditorGUILayout.ColorField (key, col);
|
col = EditorGUILayout.ColorField(key, col);
|
||||||
typeColors[key] = col;
|
typeColors[key] = col;
|
||||||
if (!GUILayout.Toggle(true, "")) {
|
if (!GUILayout.Toggle(true, "")) {
|
||||||
typeColors.Remove(key);
|
typeColors.Remove(key);
|
||||||
SavePrefs();
|
SavePrefs();
|
||||||
}
|
}
|
||||||
EditorGUILayout.EndHorizontal ();
|
EditorGUILayout.EndHorizontal();
|
||||||
}
|
}
|
||||||
if(GUI.changed) {
|
if (GUI.changed) {
|
||||||
SavePrefs();
|
SavePrefs();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
string[] generatedTypeKeys = new string[generatedTypeColors.Count];
|
string[] generatedTypeKeys = new string[generatedTypeColors.Count];
|
||||||
generatedTypeColors.Keys.CopyTo(generatedTypeKeys,0);
|
generatedTypeColors.Keys.CopyTo(generatedTypeKeys, 0);
|
||||||
foreach (var key in generatedTypeKeys) {
|
foreach (var key in generatedTypeKeys) {
|
||||||
EditorGUILayout.BeginHorizontal ();
|
EditorGUILayout.BeginHorizontal();
|
||||||
Color col = generatedTypeColors[key];
|
Color col = generatedTypeColors[key];
|
||||||
EditorGUI.BeginDisabledGroup(true);
|
EditorGUI.BeginDisabledGroup(true);
|
||||||
col = EditorGUILayout.ColorField (key, col);
|
col = EditorGUILayout.ColorField(key, col);
|
||||||
EditorGUI.EndDisabledGroup();
|
EditorGUI.EndDisabledGroup();
|
||||||
if (GUILayout.Toggle(false, "")) {
|
if (GUILayout.Toggle(false, "")) {
|
||||||
typeColors.Add(key,generatedTypeColors[key]);
|
typeColors.Add(key, generatedTypeColors[key]);
|
||||||
generatedTypeColors.Remove(key);
|
generatedTypeColors.Remove(key);
|
||||||
SavePrefs();
|
SavePrefs();
|
||||||
}
|
}
|
||||||
EditorGUILayout.EndHorizontal ();
|
EditorGUILayout.EndHorizontal();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,23 +62,23 @@ public static class NodeEditorPreferences {
|
|||||||
if (!prefsLoaded) return;
|
if (!prefsLoaded) return;
|
||||||
string s = "";
|
string s = "";
|
||||||
foreach (var item in typeColors) {
|
foreach (var item in typeColors) {
|
||||||
s+= item.Key+","+ColorUtility.ToHtmlStringRGB(item.Value)+ ",";
|
s += item.Key + "," + ColorUtility.ToHtmlStringRGB(item.Value) + ",";
|
||||||
}
|
}
|
||||||
EditorPrefs.SetString("unec_typecolors",s);
|
EditorPrefs.SetString("unec_typecolors", s);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SetDefaultTypeColors () {
|
public static void SetDefaultTypeColors() {
|
||||||
EditorPrefs.SetString ("unec_typecolors", "int,2568CA,string,CE743A,bool,00FF00");
|
EditorPrefs.SetString("unec_typecolors", "int,2568CA,string,CE743A,bool,00FF00");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Dictionary<string, Color> GetTypeColors () {
|
public static Dictionary<string, Color> GetTypeColors() {
|
||||||
if (prefsLoaded) return typeColors;
|
if (prefsLoaded) return typeColors;
|
||||||
if (!EditorPrefs.HasKey ("unec_typecolors")) SetDefaultTypeColors ();
|
if (!EditorPrefs.HasKey("unec_typecolors")) SetDefaultTypeColors();
|
||||||
string[] data = EditorPrefs.GetString("unec_typecolors").Split(new char[] {','}, StringSplitOptions.RemoveEmptyEntries);
|
string[] data = EditorPrefs.GetString("unec_typecolors").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
Dictionary<string, Color> dict = new Dictionary<string, Color> ();
|
Dictionary<string, Color> dict = new Dictionary<string, Color>();
|
||||||
for (int i = 0; i < data.Length; i += 2) {
|
for (int i = 0; i < data.Length; i += 2) {
|
||||||
Color col;
|
Color col;
|
||||||
if (ColorUtility.TryParseHtmlString("#"+data[i+1], out col)) {
|
if (ColorUtility.TryParseHtmlString("#" + data[i + 1], out col)) {
|
||||||
dict.Add(data[i], col);
|
dict.Add(data[i], col);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -93,8 +91,8 @@ public static class NodeEditorPreferences {
|
|||||||
if (type == null) return Color.gray;
|
if (type == null) return Color.gray;
|
||||||
if (typeColors.ContainsKey(type.Name)) return typeColors[type.Name];
|
if (typeColors.ContainsKey(type.Name)) return typeColors[type.Name];
|
||||||
if (generatedTypeColors.ContainsKey(type.Name)) return generatedTypeColors[type.Name];
|
if (generatedTypeColors.ContainsKey(type.Name)) return generatedTypeColors[type.Name];
|
||||||
UnityEngine.Random.InitState (type.Name.GetHashCode ());
|
UnityEngine.Random.InitState(type.Name.GetHashCode());
|
||||||
generatedTypeColors.Add(type.Name, new Color (UnityEngine.Random.value, UnityEngine.Random.value, UnityEngine.Random.value));
|
generatedTypeColors.Add(type.Name, new Color(UnityEngine.Random.value, UnityEngine.Random.value, UnityEngine.Random.value));
|
||||||
return generatedTypeColors[type.Name];
|
return generatedTypeColors[type.Name];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,7 +1,7 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
using System.Reflection;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System;
|
using System.Reflection;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
/// <summary> Contains reflection-related info </summary>
|
/// <summary> Contains reflection-related info </summary>
|
||||||
@ -21,7 +21,7 @@ public partial class NodeEditorWindow {
|
|||||||
return GetDerivedTypes(typeof(Node));
|
return GetDerivedTypes(typeof(Node));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void CacheCustomNodeEditors(){
|
public static void CacheCustomNodeEditors() {
|
||||||
customNodeEditor = new Dictionary<Type, NodeEditor>();
|
customNodeEditor = new Dictionary<Type, NodeEditor>();
|
||||||
customNodeEditor.Add(typeof(Node), new NodeEditor());
|
customNodeEditor.Add(typeof(Node), new NodeEditor());
|
||||||
//Get all classes deriving from NodeEditor via reflection
|
//Get all classes deriving from NodeEditor via reflection
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
using UnityEngine;
|
using System;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using System;
|
using UnityEngine;
|
||||||
|
|
||||||
public static class NodeEditorResources {
|
public static class NodeEditorResources {
|
||||||
//Unec textures
|
//Unec textures
|
||||||
@ -53,7 +53,7 @@ public static class NodeEditorResources {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Texture2D GenerateGridTexture() {
|
public static Texture2D GenerateGridTexture() {
|
||||||
Texture2D tex = new Texture2D(64,64);
|
Texture2D tex = new Texture2D(64, 64);
|
||||||
Color[] cols = new Color[64 * 64];
|
Color[] cols = new Color[64 * 64];
|
||||||
for (int y = 0; y < 64; y++) {
|
for (int y = 0; y < 64; y++) {
|
||||||
for (int x = 0; x < 64; x++) {
|
for (int x = 0; x < 64; x++) {
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
using System.Collections;
|
using System;
|
||||||
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
|
||||||
using System.Reflection;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System;
|
using System.Reflection;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
/// <summary> A set of editor-only utilities and extensions for UnityNodeEditorBase </summary>
|
/// <summary> A set of editor-only utilities and extensions for UnityNodeEditorBase </summary>
|
||||||
public static class NodeEditorUtilities {
|
public static class NodeEditorUtilities {
|
||||||
|
|||||||
@ -1,10 +1,10 @@
|
|||||||
using System.Collections;
|
using System;
|
||||||
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
|
||||||
using UnityEditor;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using UnityEditor;
|
||||||
using UnityEditor.Callbacks;
|
using UnityEditor.Callbacks;
|
||||||
using System;
|
using UnityEngine;
|
||||||
|
|
||||||
[InitializeOnLoad]
|
[InitializeOnLoad]
|
||||||
public partial class NodeEditorWindow : EditorWindow {
|
public partial class NodeEditorWindow : EditorWindow {
|
||||||
@ -36,8 +36,7 @@ public partial class NodeEditorWindow : EditorWindow {
|
|||||||
if (AssetDatabase.Contains(graph)) {
|
if (AssetDatabase.Contains(graph)) {
|
||||||
EditorUtility.SetDirty(graph);
|
EditorUtility.SetDirty(graph);
|
||||||
AssetDatabase.SaveAssets();
|
AssetDatabase.SaveAssets();
|
||||||
}
|
} else SaveAs();
|
||||||
else SaveAs();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SaveAs() {
|
public void SaveAs() {
|
||||||
@ -61,7 +60,7 @@ public partial class NodeEditorWindow : EditorWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Vector2 GridToWindowPosition(Vector2 gridPosition) {
|
public Vector2 GridToWindowPosition(Vector2 gridPosition) {
|
||||||
return (position.size * 0.5f) + (panOffset / zoom) + (gridPosition/zoom);
|
return (position.size * 0.5f) + (panOffset / zoom) + (gridPosition / zoom);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Rect GridToWindowRect(Rect gridRect) {
|
public Rect GridToWindowRect(Rect gridRect) {
|
||||||
@ -81,7 +80,6 @@ public partial class NodeEditorWindow : EditorWindow {
|
|||||||
selectedNode = node;
|
selectedNode = node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[OnOpenAsset(0)]
|
[OnOpenAsset(0)]
|
||||||
public static bool OnOpen(int instanceID, int line) {
|
public static bool OnOpen(int instanceID, int line) {
|
||||||
NodeGraph nodeGraph = EditorUtility.InstanceIDToObject(instanceID) as NodeGraph;
|
NodeGraph nodeGraph = EditorUtility.InstanceIDToObject(instanceID) as NodeGraph;
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
using System.Collections;
|
using System;
|
||||||
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System;
|
using UnityEngine;
|
||||||
|
|
||||||
/// <summary> Base class for all nodes </summary>
|
/// <summary> Base class for all nodes </summary>
|
||||||
[Serializable]
|
[Serializable]
|
||||||
@ -10,7 +10,7 @@ public abstract class Node : ScriptableObject {
|
|||||||
|
|
||||||
/// <summary> Name of the node </summary>
|
/// <summary> Name of the node </summary>
|
||||||
[NonSerialized] public NodeGraph graph;
|
[NonSerialized] public NodeGraph graph;
|
||||||
[SerializeField] public Rect rect = new Rect(0,0,200,200);
|
[SerializeField] public Rect rect = new Rect(0, 0, 200, 200);
|
||||||
/// <summary> Input <see cref="NodePort"/>s. It is recommended not to modify these at hand. Instead, see <see cref="InputAttribute"/> </summary>
|
/// <summary> Input <see cref="NodePort"/>s. It is recommended not to modify these at hand. Instead, see <see cref="InputAttribute"/> </summary>
|
||||||
[SerializeField] public List<NodePort> inputs = new List<NodePort>();
|
[SerializeField] public List<NodePort> inputs = new List<NodePort>();
|
||||||
/// <summary> Output <see cref="NodePort"/>s. It is recommended not to modify these at hand. Instead, see <see cref="InputAttribute"/> </summary>
|
/// <summary> Output <see cref="NodePort"/>s. It is recommended not to modify these at hand. Instead, see <see cref="InputAttribute"/> </summary>
|
||||||
@ -99,14 +99,12 @@ public abstract class Node : ScriptableObject {
|
|||||||
|
|
||||||
[AttributeUsage(AttributeTargets.Field, AllowMultiple = true)]
|
[AttributeUsage(AttributeTargets.Field, AllowMultiple = true)]
|
||||||
public class InputAttribute : Attribute {
|
public class InputAttribute : Attribute {
|
||||||
public InputAttribute() {
|
public InputAttribute() { }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[AttributeUsage(AttributeTargets.Field, AllowMultiple = true)]
|
[AttributeUsage(AttributeTargets.Field, AllowMultiple = true)]
|
||||||
public class OutputAttribute : Attribute {
|
public class OutputAttribute : Attribute {
|
||||||
public OutputAttribute() {
|
public OutputAttribute() { }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void GetPorts() {
|
private void GetPorts() {
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
|
||||||
using System.Reflection;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
/// <summary> Precaches reflection data in editor so we won't have to do it runtime </summary>
|
/// <summary> Precaches reflection data in editor so we won't have to do it runtime </summary>
|
||||||
public static class NodeDataCache {
|
public static class NodeDataCache {
|
||||||
@ -28,7 +28,7 @@ public static class NodeDataCache {
|
|||||||
else outputPorts.Add(new NodePort(portDataCache[nodeType][i], node));
|
else outputPorts.Add(new NodePort(portDataCache[nodeType][i], node));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = inputs.Count-1; i >= 0; i--) {
|
for (int i = inputs.Count - 1; i >= 0; i--) {
|
||||||
int index = inputPorts.FindIndex(x => inputs[i].fieldName == x.fieldName);
|
int index = inputPorts.FindIndex(x => inputs[i].fieldName == x.fieldName);
|
||||||
//If input nodeport does not exist, remove it
|
//If input nodeport does not exist, remove it
|
||||||
if (index == -1) inputs.RemoveAt(i);
|
if (index == -1) inputs.RemoveAt(i);
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using System;
|
|
||||||
|
|
||||||
/// <summary> Base class for all node graphs </summary>
|
/// <summary> Base class for all node graphs </summary>
|
||||||
[Serializable]
|
[Serializable]
|
||||||
@ -45,8 +45,7 @@ public abstract class NodeGraph : ScriptableObject, ISerializationCallbackReceiv
|
|||||||
nodes.Clear();
|
nodes.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnBeforeSerialize() {
|
public void OnBeforeSerialize() { }
|
||||||
}
|
|
||||||
|
|
||||||
public void OnAfterDeserialize() {
|
public void OnAfterDeserialize() {
|
||||||
/*for (int i = 0; i < nodes.Count; i++) {
|
/*for (int i = 0; i < nodes.Count; i++) {
|
||||||
@ -62,4 +61,3 @@ public abstract class NodeGraph : ScriptableObject, ISerializationCallbackReceiv
|
|||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
using System.Collections;
|
using System;
|
||||||
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
|
||||||
using System;
|
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public class NodePort {
|
public class NodePort {
|
||||||
@ -20,7 +20,6 @@ public class NodePort {
|
|||||||
|
|
||||||
public string fieldName { get { return _fieldName; } }
|
public string fieldName { get { return _fieldName; } }
|
||||||
|
|
||||||
|
|
||||||
[SerializeField] public Node node;
|
[SerializeField] public Node node;
|
||||||
[SerializeField] private string _fieldName;
|
[SerializeField] private string _fieldName;
|
||||||
[SerializeField] public Type type;
|
[SerializeField] public Type type;
|
||||||
@ -111,7 +110,7 @@ public class NodePort {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void ClearConnections() {
|
public void ClearConnections() {
|
||||||
while(connections.Count > 0) {
|
while (connections.Count > 0) {
|
||||||
Disconnect(connections[0].Port);
|
Disconnect(connections[0].Port);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user