1
0
mirror of https://github.com/Siccity/xNodeGroups.git synced 2025-12-20 01:06:02 +08:00

Initial Commit

This commit is contained in:
Thor Brigsted 2020-04-18 02:44:40 +02:00
commit 76aa652102
8 changed files with 274 additions and 0 deletions

8
Editor.meta Normal file
View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e508ac6a4c9135b4c8d431c36489713e
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

84
Editor/NodeGroupEditor.cs Normal file
View File

@ -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<Texture2D>("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<Object> 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);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5f2eb5cc14b9c934faf132ed93a29460
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

8
Editor/Resources.meta Normal file
View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ab4e14ed9e4b2434a833863714a7cbc5
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

View File

@ -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:

31
NodeGroup.cs Normal file
View File

@ -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;
}
/// <summary> Gets nodes in this group </summary>
public List<Node> GetNodes() {
List<Node> result = new List<Node>();
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;
}
}
}

11
NodeGroup.cs.meta Normal file
View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 03f96cea6ada90b4984cf627badd4634
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: