commit 76aa6521024884f2bc35ad82d4c6ab545ca82f0f Author: Thor Brigsted Date: Sat Apr 18 02:44:40 2020 +0200 Initial Commit diff --git a/Editor.meta b/Editor.meta new file mode 100644 index 0000000..2f79f6b --- /dev/null +++ b/Editor.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: e508ac6a4c9135b4c8d431c36489713e +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/NodeGroupEditor.cs b/Editor/NodeGroupEditor.cs new file mode 100644 index 0000000..6a9df8f --- /dev/null +++ b/Editor/NodeGroupEditor.cs @@ -0,0 +1,84 @@ +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using UnityEditor; +using UnityEngine; +using XNode; +using XNode.NodeGroups; + +namespace XNodeEditor.NodeGroups { + [CustomNodeEditor(typeof(NodeGroup))] + public class NodeGroupEditor : NodeEditor { + private NodeGroup group { get { return _group != null ? _group : _group = target as NodeGroup; } } + private NodeGroup _group; + public static Texture2D corner { get { return _corner != null ? _corner : _corner = Resources.Load("xnode_corner"); } } + private static Texture2D _corner; + private bool isDragging; + private Vector2 size; + + public override void OnBodyGUI() { + Event e = Event.current; + switch (e.type) { + case EventType.MouseDrag: + if (isDragging) { + group.width = Mathf.Max(200, (int) e.mousePosition.x + 16); + group.height = Mathf.Max(100, (int) e.mousePosition.y - 34); + NodeEditorWindow.current.Repaint(); + } + break; + case EventType.MouseDown: + // Ignore everything except left clicks + if (e.button != 0) return; + if (NodeEditorWindow.current.nodeSizes.TryGetValue(target, out size)) { + // Mouse position checking is in node local space + Rect lowerRight = new Rect(size.x - 34, size.y - 34, 30, 30); + if (lowerRight.Contains(e.mousePosition)) { + isDragging = true; + } + } + break; + case EventType.MouseUp: + isDragging = false; + // Select nodes inside the group + if (Selection.Contains(target)) { + List selection = Selection.objects.ToList(); + selection.AddRange(group.GetNodes()); + Selection.objects = selection.Distinct().ToArray(); + } + break; + case EventType.Repaint: + // Move to bottom + if (target.graph.nodes.IndexOf(target) != 0) { + target.graph.nodes.Remove(target); + target.graph.nodes.Insert(0, target); + } + // Add scale cursors + if (NodeEditorWindow.current.nodeSizes.TryGetValue(target, out size)) { + Rect lowerRight = new Rect(target.position, new Vector2(30, 30)); + lowerRight.y += size.y - 34; + lowerRight.x += size.x - 34; + lowerRight = NodeEditorWindow.current.GridToWindowRect(lowerRight); + NodeEditorWindow.current.onLateGUI += () => AddMouseRect(lowerRight); + } + break; + } + + // Control height of node + GUILayout.Space(group.height); + + GUI.DrawTexture(new Rect(group.width - 34, group.height + 16, 24, 24), corner); + } + + public override int GetWidth() { + return group.width; + } + + public override Color GetTint() { + return group.color; + } + + public static void AddMouseRect(Rect rect) { + EditorGUIUtility.AddCursorRect(rect, MouseCursor.ResizeUpLeft); + } + } +} \ No newline at end of file diff --git a/Editor/NodeGroupEditor.cs.meta b/Editor/NodeGroupEditor.cs.meta new file mode 100644 index 0000000..88b7547 --- /dev/null +++ b/Editor/NodeGroupEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5f2eb5cc14b9c934faf132ed93a29460 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Resources.meta b/Editor/Resources.meta new file mode 100644 index 0000000..d48284a --- /dev/null +++ b/Editor/Resources.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: ab4e14ed9e4b2434a833863714a7cbc5 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Resources/xnode_corner.png b/Editor/Resources/xnode_corner.png new file mode 100644 index 0000000..12d25fa Binary files /dev/null and b/Editor/Resources/xnode_corner.png differ diff --git a/Editor/Resources/xnode_corner.png.meta b/Editor/Resources/xnode_corner.png.meta new file mode 100644 index 0000000..da80b17 --- /dev/null +++ b/Editor/Resources/xnode_corner.png.meta @@ -0,0 +1,121 @@ +fileFormatVersion: 2 +guid: da88db0dcd776d146bd3d03396552f11 +TextureImporter: + fileIDToRecycleName: {} + externalObjects: {} + serializedVersion: 9 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: -1 + aniso: 1 + mipBias: -100 + wrapU: 1 + wrapV: 1 + wrapW: -1 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 1 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 2 + textureShape: 1 + singleChannelComponent: 0 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + platformSettings: + - serializedVersion: 2 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: Android + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + vertices: [] + indices: + edges: [] + weights: [] + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/NodeGroup.cs b/NodeGroup.cs new file mode 100644 index 0000000..05138dc --- /dev/null +++ b/NodeGroup.cs @@ -0,0 +1,31 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using XNode; + +namespace XNode.NodeGroups { + [CreateNodeMenu("Group")] + public class NodeGroup : Node { + public int width = 400; + public int height = 400; + public Color color = new Color(1f, 1f, 1f, 0.1f); + + public override object GetValue(NodePort port) { + return null; + } + + /// Gets nodes in this group + public List GetNodes() { + List result = new List(); + foreach (Node node in graph.nodes) { + if (node == this) continue; + if (node.position.x < this.position.x) continue; + if (node.position.y < this.position.y) continue; + if (node.position.x > this.position.x + width) continue; + if (node.position.y > this.position.y + height + 30) continue; + result.Add(node); + } + return result; + } + } +} \ No newline at end of file diff --git a/NodeGroup.cs.meta b/NodeGroup.cs.meta new file mode 100644 index 0000000..a55da90 --- /dev/null +++ b/NodeGroup.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 03f96cea6ada90b4984cf627badd4634 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: