1
0
mirror of https://github.com/Siccity/xNode.git synced 2026-02-06 15:24:55 +08:00

Merge branch 'development'

This commit is contained in:
Thor Brigsted 2017-10-06 19:54:52 +02:00
commit 91ccab60db
9 changed files with 147 additions and 39 deletions

View File

@ -19,8 +19,8 @@ public class NodeEditor {
}
protected void DrawDefaultHeaderGUI() {
GUILayout.Label(target.name, NodeEditorResources.styles.headerStyle, GUILayout.Height(30));
GUI.color = Color.white;
GUILayout.Label(target.name, NodeEditorResources.styles.nodeHeader, GUILayout.Height(30));
}
/// <summary> Draws standard editors for all fields marked with <see cref="Node.InputAttribute"/> or <see cref="Node.OutputAttribute"/> </summary>
@ -63,14 +63,14 @@ public class NodeEditor {
/// <summary> Draw node port GUI using automatic layouting. Returns port handle position. </summary>
protected Vector2 DrawNodePortGUI(NodePort port) {
GUIStyle style = port.direction == NodePort.IO.Input ? NodeEditorResources.styles.inputStyle : NodeEditorResources.styles.outputStyle;
GUIStyle style = port.direction == NodePort.IO.Input ? NodeEditorResources.styles.inputPort : NodeEditorResources.styles.outputPort;
Rect rect = GUILayoutUtility.GetRect(new GUIContent(port.name.PrettifyCamelCase()), style);
return DrawNodePortGUI(rect, port);
}
/// <summary> Draw node port GUI in rect. Returns port handle position. </summary>
protected Vector2 DrawNodePortGUI(Rect rect, NodePort port) {
GUIStyle style = port.direction == NodePort.IO.Input ? NodeEditorResources.styles.inputStyle : NodeEditorResources.styles.outputStyle;
GUIStyle style = port.direction == NodePort.IO.Input ? NodeEditorResources.styles.inputPort : NodeEditorResources.styles.outputPort;
GUI.Label(rect, new GUIContent(port.name.PrettifyCamelCase()), style);
Vector2 handlePoint = rect.center;
@ -79,6 +79,14 @@ public class NodeEditor {
case NodePort.IO.Input: handlePoint.x = rect.xMin; break;
case NodePort.IO.Output: handlePoint.x = rect.xMax; break;
}
Color col = GUI.color;
Rect handleRect = new Rect(handlePoint.x-8,handlePoint.y-8,16,16);
GUI.color = new Color(0.29f, 0.31f, 0.32f);
GUI.DrawTexture(handleRect, NodeEditorResources.dotOuter);
GUI.color = NodeEditorUtilities.GetTypeColor(port.type);
GUI.DrawTexture(handleRect, NodeEditorResources.dot);
GUI.color = col;
return handlePoint;
}
@ -106,7 +114,11 @@ public class NodeEditor {
fieldValue = EditorGUILayout.Toggle(fieldPrettyName, (bool)fieldValue);
}
else if (fieldType.IsEnum) {
fieldValue = EditorGUILayout.EnumPopup(fieldPrettyName, (Enum)fieldValue);
Rect rect = EditorGUILayout.GetControlRect();
rect.width *= 0.5f;
EditorGUI.LabelField(rect, fieldPrettyName);
rect.x += rect.width;
fieldValue = EditorGUI.EnumPopup(rect, (Enum)fieldValue);
}
else if (fieldType == typeof(string)) {

View File

@ -12,10 +12,9 @@ public partial class NodeEditorWindow {
Controls();
DrawGrid(position, zoom, panOffset);
DrawNodes();
DrawConnections();
DrawDraggedConnection();
DrawPortHandles();
DrawNodes();
DrawToolbar();
GUI.matrix = m;
@ -115,7 +114,7 @@ public partial class NodeEditorWindow {
Color prevCol = GUI.color;
Color edgeCol = new Color(0.1f, 0.1f, 0.1f, col.a);
Handles.DrawBezier(startPoint, endPoint, startTangent, endTangent, edgeCol, null, 4);
Handles.DrawBezier(startPoint, endPoint, startTangent, endTangent, col, null, 2);
Handles.DrawBezier(startPoint, endPoint, startTangent, endTangent, col, null, 4);
GUI.color = prevCol;
}
@ -137,20 +136,6 @@ public partial class NodeEditorWindow {
}
}
/// <summary> Draws the draggable circle handles on the ports </summary>
public void DrawPortHandles() {
Color col = GUI.color;
foreach(var kvp in portConnectionPoints) {
Rect rect = GridToWindowRect(kvp.Value);
GUI.color = new Color(0.29f, 0.31f, 0.32f);
GUI.DrawTexture(rect, NodeEditorResources.dotOuter);
GUI.color = NodeEditorUtilities.GetTypeColor(kvp.Key.type);
GUI.DrawTexture(rect, NodeEditorResources.dot);
}
GUI.color = col;
}
private void DrawNodes() {
Event e = Event.current;
if (e.type == EventType.Repaint) portConnectionPoints.Clear();
@ -172,11 +157,12 @@ public partial class NodeEditorWindow {
//Get node position
Vector2 nodePos = GridToWindowPositionNoClipped(node.rect.position);
GUIStyle style = (node == selectedNode) ? (GUIStyle)"flow node 0 on" : (GUIStyle)"flow node 0";
style = new GUIStyle(style);
style.padding.top = 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.BeginVertical(style);
GUIStyle style = NodeEditorResources.styles.nodeBody;
GUILayout.BeginVertical(new GUIStyle(style));
//Draw node contents
Dictionary<NodePort, Vector2> portHandlePoints;

View File

@ -3,42 +3,52 @@ using UnityEditor;
using System;
public static class NodeEditorResources {
//Unec textures
public static Texture2D gridTexture { get { return _gridTexture != null ? _gridTexture : _gridTexture = GenerateGridTexture(); } }
private static Texture2D _gridTexture;
public static Texture2D crossTexture { get { return _crossTexture != null ? _crossTexture : _crossTexture = GenerateCrossTexture(); } }
private static Texture2D _crossTexture;
public static Texture2D dot { get { return _dot != null ? _dot : _dot = Resources.Load<Texture2D>("dot"); } }
public static Texture2D dot { get { return _dot != null ? _dot : _dot = Resources.Load<Texture2D>("unec_dot"); } }
private static Texture2D _dot;
public static Texture2D dotOuter { get { return _dotOuter != null ? _dotOuter : _dotOuter = Resources.Load<Texture2D>("dot_outer"); } }
public static Texture2D dotOuter { get { return _dotOuter != null ? _dotOuter : _dotOuter = Resources.Load<Texture2D>("unec_dot_outer"); } }
private static Texture2D _dotOuter;
public static Texture2D nodeBody { get { return _nodeBody != null ? _nodeBody : _nodeBody = Resources.Load<Texture2D>("unec_node"); } }
private static Texture2D _nodeBody;
//Grid colors
private static Color backgroundColor = new Color(0.18f, 0.18f, 0.18f);
private static Color veinColor = new Color(0.25f, 0.25f, 0.25f);
private static Color arteryColor = new Color(0.34f, 0.34f, 0.34f);
private static Color crossColor = new Color(0.45f, 0.45f, 0.45f);
//Unec styles
public static Styles styles { get { return _styles != null ? _styles : _styles = new Styles(); } }
public static Styles _styles = null;
public class Styles {
public GUIStyle inputStyle, outputStyle, headerStyle;
public GUIStyle inputPort, outputPort, nodeHeader, nodeBody;
public Styles() {
GUIStyle baseStyle = new GUIStyle("Label");
baseStyle.fixedHeight = 18;
inputStyle = new GUIStyle(baseStyle);
inputStyle.alignment = TextAnchor.UpperLeft;
inputStyle.padding.left = 10;
inputPort = new GUIStyle(baseStyle);
inputPort.alignment = TextAnchor.UpperLeft;
inputPort.padding.left = 10;
outputStyle = new GUIStyle(baseStyle);
outputStyle.alignment = TextAnchor.UpperRight;
outputStyle.padding.right = 10;
outputPort = new GUIStyle(baseStyle);
outputPort.alignment = TextAnchor.UpperRight;
outputPort.padding.right = 10;
headerStyle = new GUIStyle();
headerStyle.alignment = TextAnchor.MiddleCenter;
headerStyle.fontStyle = FontStyle.Bold;
nodeHeader = new GUIStyle();
nodeHeader.alignment = TextAnchor.MiddleCenter;
nodeHeader.fontStyle = FontStyle.Bold;
nodeHeader.normal.textColor = Color.white;
nodeBody = new GUIStyle();
nodeBody.normal.background = NodeEditorResources.nodeBody;
nodeBody.border = new RectOffset(32, 32, 32, 32);
nodeBody.padding = new RectOffset(10, 10, 2, 2);
}
}

View File

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

View File

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

View File

@ -0,0 +1,100 @@
fileFormatVersion: 2
guid: 526e7d4dc27d75e41b5d751e4d390d8b
timeCreated: 1506975350
licenseType: Free
TextureImporter:
fileIDToRecycleName: {}
serializedVersion: 4
mipmaps:
mipMapMode: 0
enableMipMap: 0
sRGBTexture: 0
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
filterMode: -1
aniso: 1
mipBias: -1
wrapMode: 1
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spritePixelsToUnits: 100
alphaUsage: 1
alphaIsTransparency: 1
spriteTessellationDetail: -1
textureType: 2
textureShape: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
platformSettings:
- buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
- buildTarget: Standalone
maxTextureSize: 2048
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
- buildTarget: iPhone
maxTextureSize: 2048
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
- buildTarget: Android
maxTextureSize: 2048
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
- buildTarget: WebGL
maxTextureSize: 2048
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
spritePackingTag:
userData:
assetBundleName:
assetBundleVariant: