mirror of
https://github.com/Siccity/xNode.git
synced 2026-02-04 14:24:54 +08:00
Refactored 'comment' to 'group'
This commit is contained in:
parent
0020bf87e3
commit
ab87555c63
@ -6,7 +6,7 @@ using UnityEngine;
|
|||||||
|
|
||||||
namespace XNodeEditor {
|
namespace XNodeEditor {
|
||||||
public partial class NodeEditorWindow {
|
public partial class NodeEditorWindow {
|
||||||
public enum NodeActivity { Idle, HoldNode, DragNode, HoldGrid, DragGrid, HoldComment, ResizeComment }
|
public enum NodeActivity { Idle, HoldNode, DragNode, HoldGrid, DragGrid, HoldGroup, ResizeGroup }
|
||||||
public static NodeActivity currentActivity = NodeActivity.Idle;
|
public static NodeActivity currentActivity = NodeActivity.Idle;
|
||||||
public static bool isPanning { get; private set; }
|
public static bool isPanning { get; private set; }
|
||||||
public static Vector2[] dragOffset;
|
public static Vector2[] dragOffset;
|
||||||
@ -15,18 +15,18 @@ namespace XNodeEditor {
|
|||||||
private bool IsHoveringPort { get { return hoveredPort != null; } }
|
private bool IsHoveringPort { get { return hoveredPort != null; } }
|
||||||
private bool IsHoveringNode { get { return hoveredNode != null; } }
|
private bool IsHoveringNode { get { return hoveredNode != null; } }
|
||||||
private bool IsHoveringReroute { get { return hoveredReroute.port != null; } }
|
private bool IsHoveringReroute { get { return hoveredReroute.port != null; } }
|
||||||
private bool IsHoveringComment { get { return hoveredComment != null; } }
|
private bool IsHoveringGroup { get { return hoveredGroup != null; } }
|
||||||
private bool IsResizingComment { get { return resizingComment != null; } }
|
private bool IsResizingGroup { get { return resizingGroup != null; } }
|
||||||
private XNode.Node hoveredNode = null;
|
private XNode.Node hoveredNode = null;
|
||||||
[NonSerialized] private XNode.NodePort hoveredPort = null;
|
[NonSerialized] private XNode.NodePort hoveredPort = null;
|
||||||
[NonSerialized] private XNode.NodePort draggedOutput = null;
|
[NonSerialized] private XNode.NodePort draggedOutput = null;
|
||||||
[NonSerialized] private XNode.NodePort draggedOutputTarget = null;
|
[NonSerialized] private XNode.NodePort draggedOutputTarget = null;
|
||||||
[NonSerialized] private List<Vector2> draggedOutputReroutes = new List<Vector2>();
|
[NonSerialized] private List<Vector2> draggedOutputReroutes = new List<Vector2>();
|
||||||
[NonSerialized] private XNode.NodeGraphComment hoveredComment = null;
|
[NonSerialized] private XNode.NodeGroup hoveredGroup = null;
|
||||||
[NonSerialized] private XNode.NodeGraphComment resizingComment = null;
|
[NonSerialized] private XNode.NodeGroup resizingGroup = null;
|
||||||
private bool deselectingComment = false;
|
private bool deselectingGroup = false;
|
||||||
public enum NodeGraphCommentSide { Top, TopRight, Right, BottomRight, Bottom, BottomLeft, Left, TopLeft }
|
public enum NodeGroupSide { Top, TopRight, Right, BottomRight, Bottom, BottomLeft, Left, TopLeft }
|
||||||
public static NodeGraphCommentSide resizingCommentSide;
|
public static NodeGroupSide resizingGroupSide;
|
||||||
private RerouteReference hoveredReroute = new RerouteReference();
|
private RerouteReference hoveredReroute = new RerouteReference();
|
||||||
private List<RerouteReference> selectedReroutes = new List<RerouteReference>();
|
private List<RerouteReference> selectedReroutes = new List<RerouteReference>();
|
||||||
private Rect nodeRects;
|
private Rect nodeRects;
|
||||||
@ -75,8 +75,8 @@ namespace XNodeEditor {
|
|||||||
draggedOutputTarget = null;
|
draggedOutputTarget = null;
|
||||||
}
|
}
|
||||||
Repaint();
|
Repaint();
|
||||||
} else if (currentActivity == NodeActivity.HoldNode || currentActivity == NodeActivity.HoldComment) {
|
} else if (currentActivity == NodeActivity.HoldNode || currentActivity == NodeActivity.HoldGroup) {
|
||||||
deselectingComment = false;
|
deselectingGroup = false;
|
||||||
RecalculateDragOffsets(e);
|
RecalculateDragOffsets(e);
|
||||||
currentActivity = NodeActivity.DragNode;
|
currentActivity = NodeActivity.DragNode;
|
||||||
Repaint();
|
Repaint();
|
||||||
@ -118,13 +118,13 @@ namespace XNodeEditor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(Selection.objects[i] is XNode.NodeGraphComment) {
|
else if(Selection.objects[i] is XNode.NodeGroup) {
|
||||||
XNode.NodeGraphComment comment = Selection.objects[i] as XNode.NodeGraphComment;
|
XNode.NodeGroup group = Selection.objects[i] as XNode.NodeGroup;
|
||||||
Vector2 initial = comment.position;
|
Vector2 initial = group.position;
|
||||||
comment.position = mousePos + dragOffset[i];
|
group.position = mousePos + dragOffset[i];
|
||||||
if (gridSnap) {
|
if (gridSnap) {
|
||||||
comment.position.x = (Mathf.Round((comment.position.x + 8) / 16) * 16) - 8;
|
group.position.x = (Mathf.Round((group.position.x + 8) / 16) * 16) - 8;
|
||||||
comment.position.y = (Mathf.Round((comment.position.y + 8) / 16) * 16) - 8;
|
group.position.y = (Mathf.Round((group.position.y + 8) / 16) * 16) - 8;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -151,40 +151,40 @@ namespace XNodeEditor {
|
|||||||
if (boxSize.y < 0) { boxStartPos.y += boxSize.y; boxSize.y = Mathf.Abs(boxSize.y); }
|
if (boxSize.y < 0) { boxStartPos.y += boxSize.y; boxSize.y = Mathf.Abs(boxSize.y); }
|
||||||
selectionBox = new Rect(boxStartPos, boxSize);
|
selectionBox = new Rect(boxStartPos, boxSize);
|
||||||
Repaint();
|
Repaint();
|
||||||
} else if (currentActivity == NodeActivity.ResizeComment) {
|
} else if (currentActivity == NodeActivity.ResizeGroup) {
|
||||||
switch (resizingCommentSide) {
|
switch (resizingGroupSide) {
|
||||||
case NodeGraphCommentSide.Top:
|
case NodeGroupSide.Top:
|
||||||
resizingComment.size.y -= e.delta.y;
|
resizingGroup.size.y -= e.delta.y;
|
||||||
resizingComment.position.y += e.delta.y;
|
resizingGroup.position.y += e.delta.y;
|
||||||
break;
|
break;
|
||||||
case NodeGraphCommentSide.TopRight:
|
case NodeGroupSide.TopRight:
|
||||||
resizingComment.size.y -= e.delta.y;
|
resizingGroup.size.y -= e.delta.y;
|
||||||
resizingComment.position.y += e.delta.y;
|
resizingGroup.position.y += e.delta.y;
|
||||||
resizingComment.size.x += e.delta.x;
|
resizingGroup.size.x += e.delta.x;
|
||||||
break;
|
break;
|
||||||
case NodeGraphCommentSide.Right:
|
case NodeGroupSide.Right:
|
||||||
resizingComment.size.x += e.delta.x;
|
resizingGroup.size.x += e.delta.x;
|
||||||
break;
|
break;
|
||||||
case NodeGraphCommentSide.BottomRight:
|
case NodeGroupSide.BottomRight:
|
||||||
resizingComment.size += e.delta;
|
resizingGroup.size += e.delta;
|
||||||
break;
|
break;
|
||||||
case NodeGraphCommentSide.Bottom:
|
case NodeGroupSide.Bottom:
|
||||||
resizingComment.size.y += e.delta.y;
|
resizingGroup.size.y += e.delta.y;
|
||||||
break;
|
break;
|
||||||
case NodeGraphCommentSide.BottomLeft:
|
case NodeGroupSide.BottomLeft:
|
||||||
resizingComment.size.x -= e.delta.x;
|
resizingGroup.size.x -= e.delta.x;
|
||||||
resizingComment.position.x += e.delta.x;
|
resizingGroup.position.x += e.delta.x;
|
||||||
resizingComment.size.y += e.delta.y;
|
resizingGroup.size.y += e.delta.y;
|
||||||
break;
|
break;
|
||||||
case NodeGraphCommentSide.Left:
|
case NodeGroupSide.Left:
|
||||||
resizingComment.size.x -= e.delta.x;
|
resizingGroup.size.x -= e.delta.x;
|
||||||
resizingComment.position.x += e.delta.x;
|
resizingGroup.position.x += e.delta.x;
|
||||||
break;
|
break;
|
||||||
case NodeGraphCommentSide.TopLeft:
|
case NodeGroupSide.TopLeft:
|
||||||
resizingComment.size.x -= e.delta.x;
|
resizingGroup.size.x -= e.delta.x;
|
||||||
resizingComment.position.x += e.delta.x;
|
resizingGroup.position.x += e.delta.x;
|
||||||
resizingComment.size.y -= e.delta.y;
|
resizingGroup.size.y -= e.delta.y;
|
||||||
resizingComment.position.y += e.delta.y;
|
resizingGroup.position.y += e.delta.y;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -246,26 +246,26 @@ namespace XNodeEditor {
|
|||||||
e.Use();
|
e.Use();
|
||||||
currentActivity = NodeActivity.HoldNode;
|
currentActivity = NodeActivity.HoldNode;
|
||||||
}
|
}
|
||||||
else if (IsHoveringComment && !IsHoveringNode) {
|
else if (IsHoveringGroup && !IsHoveringNode) {
|
||||||
if (!Selection.Contains(hoveredComment)) {
|
if (!Selection.Contains(hoveredGroup)) {
|
||||||
if (e.shift) {
|
if (e.shift) {
|
||||||
SelectComment(hoveredComment, true);
|
SelectGroup(hoveredGroup, true);
|
||||||
SelectNodesInComment(hoveredComment);
|
SelectNodesInGroup(hoveredGroup);
|
||||||
}
|
}
|
||||||
else SelectComment(hoveredComment, e.control || e.shift);
|
else SelectGroup(hoveredGroup, e.control || e.shift);
|
||||||
} else deselectingComment = true;
|
} else deselectingGroup = true;
|
||||||
|
|
||||||
e.Use();
|
e.Use();
|
||||||
currentActivity = NodeActivity.HoldComment;
|
currentActivity = NodeActivity.HoldGroup;
|
||||||
} else if (IsResizingComment && !e.control && !e.shift) {
|
} else if (IsResizingGroup && !e.control && !e.shift) {
|
||||||
selectedReroutes.Clear();
|
selectedReroutes.Clear();
|
||||||
Selection.activeObject = null;
|
Selection.activeObject = null;
|
||||||
|
|
||||||
e.Use();
|
e.Use();
|
||||||
currentActivity = NodeActivity.ResizeComment;
|
currentActivity = NodeActivity.ResizeGroup;
|
||||||
}
|
}
|
||||||
// If mousedown on grid background, deselect all
|
// If mousedown on grid background, deselect all
|
||||||
else if (!IsHoveringNode && !IsHoveringComment) {
|
else if (!IsHoveringNode && !IsHoveringGroup) {
|
||||||
currentActivity = NodeActivity.HoldGrid;
|
currentActivity = NodeActivity.HoldGrid;
|
||||||
if (!e.control && !e.shift) {
|
if (!e.control && !e.shift) {
|
||||||
selectedReroutes.Clear();
|
selectedReroutes.Clear();
|
||||||
@ -300,7 +300,7 @@ namespace XNodeEditor {
|
|||||||
IEnumerable<XNode.Node> nodes = Selection.objects.Where(x => x is XNode.Node).Select(x => x as XNode.Node);
|
IEnumerable<XNode.Node> nodes = Selection.objects.Where(x => x is XNode.Node).Select(x => x as XNode.Node);
|
||||||
foreach (XNode.Node node in nodes) EditorUtility.SetDirty(node);
|
foreach (XNode.Node node in nodes) EditorUtility.SetDirty(node);
|
||||||
if (NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets();
|
if (NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets();
|
||||||
} else if (!IsHoveringNode && !IsHoveringComment && !IsResizingComment) {
|
} else if (!IsHoveringNode && !IsHoveringGroup && !IsResizingGroup) {
|
||||||
// If click outside node, release field focus
|
// If click outside node, release field focus
|
||||||
if (!isPanning) {
|
if (!isPanning) {
|
||||||
EditorGUI.FocusTextInControl(null);
|
EditorGUI.FocusTextInControl(null);
|
||||||
@ -314,13 +314,13 @@ namespace XNodeEditor {
|
|||||||
SelectNode(hoveredNode, false);
|
SelectNode(hoveredNode, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentActivity == NodeActivity.HoldComment && deselectingComment) {
|
if (currentActivity == NodeActivity.HoldGroup && deselectingGroup) {
|
||||||
DeselectComment(hoveredComment);
|
DeselectGroup(hoveredGroup);
|
||||||
if (e.shift) {
|
if (e.shift) {
|
||||||
DeselectNodesInComment(hoveredComment);
|
DeselectNodesInGroup(hoveredGroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
deselectingComment = false;
|
deselectingGroup = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If click reroute, select it.
|
// If click reroute, select it.
|
||||||
@ -347,10 +347,10 @@ namespace XNodeEditor {
|
|||||||
GenericMenu menu = new GenericMenu();
|
GenericMenu menu = new GenericMenu();
|
||||||
NodeEditor.GetEditor(hoveredNode).AddContextMenuItems(menu);
|
NodeEditor.GetEditor(hoveredNode).AddContextMenuItems(menu);
|
||||||
menu.DropDown(new Rect(Event.current.mousePosition, Vector2.zero));
|
menu.DropDown(new Rect(Event.current.mousePosition, Vector2.zero));
|
||||||
} else if (IsHoveringComment && !IsHoveringNode) {
|
} else if (IsHoveringGroup && !IsHoveringNode) {
|
||||||
if (!Selection.Contains(hoveredComment)) SelectComment(hoveredComment, false);
|
if (!Selection.Contains(hoveredGroup)) SelectGroup(hoveredGroup, false);
|
||||||
GenericMenu menu = new GenericMenu();
|
GenericMenu menu = new GenericMenu();
|
||||||
graphEditor.AddCommentContextMenuItems(menu);
|
graphEditor.AddGroupContextMenuItems(menu);
|
||||||
menu.DropDown(new Rect(Event.current.mousePosition, Vector2.zero));
|
menu.DropDown(new Rect(Event.current.mousePosition, Vector2.zero));
|
||||||
} else if (!IsHoveringNode) {
|
} else if (!IsHoveringNode) {
|
||||||
GenericMenu menu = new GenericMenu();
|
GenericMenu menu = new GenericMenu();
|
||||||
@ -402,9 +402,9 @@ namespace XNodeEditor {
|
|||||||
XNode.Node node = Selection.objects[i] as XNode.Node;
|
XNode.Node node = Selection.objects[i] as XNode.Node;
|
||||||
dragOffset[i] = node.position - WindowToGridPosition(current.mousePosition);
|
dragOffset[i] = node.position - WindowToGridPosition(current.mousePosition);
|
||||||
}
|
}
|
||||||
else if (Selection.objects[i] is XNode.NodeGraphComment) {
|
else if (Selection.objects[i] is XNode.NodeGroup) {
|
||||||
XNode.NodeGraphComment comment = Selection.objects[i] as XNode.NodeGraphComment;
|
XNode.NodeGroup group = Selection.objects[i] as XNode.NodeGroup;
|
||||||
dragOffset[i] = comment.position - WindowToGridPosition(current.mousePosition);
|
dragOffset[i] = group.position - WindowToGridPosition(current.mousePosition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -433,9 +433,9 @@ namespace XNodeEditor {
|
|||||||
XNode.Node node = item as XNode.Node;
|
XNode.Node node = item as XNode.Node;
|
||||||
graphEditor.RemoveNode(node);
|
graphEditor.RemoveNode(node);
|
||||||
}
|
}
|
||||||
else if (item is XNode.NodeGraphComment) {
|
else if (item is XNode.NodeGroup) {
|
||||||
XNode.NodeGraphComment comment = item as XNode.NodeGraphComment;
|
XNode.NodeGroup group = item as XNode.NodeGroup;
|
||||||
graphEditor.RemoveComment(comment);
|
graphEditor.RemoveGroup(group);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -448,10 +448,10 @@ namespace XNodeEditor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Initiate a rename on the currently selected comment </summary>
|
/// <summary> Initiate a rename on the currently selected group </summary>
|
||||||
public void RenameSelectedComment() {
|
public void RenameSelectedGroup() {
|
||||||
if (Selection.objects.Length == 1 && Selection.activeObject is XNode.NodeGraphComment) {
|
if (Selection.objects.Length == 1 && Selection.activeObject is XNode.NodeGroup) {
|
||||||
renamingComment = Selection.activeObject as XNode.NodeGraphComment;
|
renamingGroup = Selection.activeObject as XNode.NodeGroup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -476,12 +476,12 @@ namespace XNodeEditor {
|
|||||||
substitutes.Add(srcNode, newNode);
|
substitutes.Add(srcNode, newNode);
|
||||||
newNode.position = srcNode.position + new Vector2(30, 30);
|
newNode.position = srcNode.position + new Vector2(30, 30);
|
||||||
newNodes[i] = newNode;
|
newNodes[i] = newNode;
|
||||||
} else if (Selection.objects[i] is XNode.NodeGraphComment) {
|
} else if (Selection.objects[i] is XNode.NodeGroup) {
|
||||||
XNode.NodeGraphComment srcComment = Selection.objects[i] as XNode.NodeGraphComment;
|
XNode.NodeGroup srcGroup = Selection.objects[i] as XNode.NodeGroup;
|
||||||
if (srcComment.graph != graph) continue; // ignore comments selected in another graph
|
if (srcGroup.graph != graph) continue; // ignore groups selected in another graph
|
||||||
XNode.NodeGraphComment newComment = graphEditor.CopyComment(srcComment);
|
XNode.NodeGroup newGroup = graphEditor.CopyGroup(srcGroup);
|
||||||
newComment.position = srcComment.position + new Vector2(30, 30);
|
newGroup.position = srcGroup.position + new Vector2(30, 30);
|
||||||
newNodes[i] = newComment;
|
newNodes[i] = newGroup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -13,7 +13,7 @@ namespace XNodeEditor {
|
|||||||
private int topPadding { get { return isDocked() ? 19 : 22; } }
|
private int topPadding { get { return isDocked() ? 19 : 22; } }
|
||||||
/// <summary> Executed after all other window GUI. Useful if Zoom is ruining your day. Automatically resets after being run.</summary>
|
/// <summary> Executed after all other window GUI. Useful if Zoom is ruining your day. Automatically resets after being run.</summary>
|
||||||
public event Action onLateGUI;
|
public event Action onLateGUI;
|
||||||
public XNode.NodeGraphComment renamingComment;
|
public XNode.NodeGroup renamingGroup;
|
||||||
public bool renamingStarted = false;
|
public bool renamingStarted = false;
|
||||||
private Matrix4x4 _prevGuiMatrix;
|
private Matrix4x4 _prevGuiMatrix;
|
||||||
|
|
||||||
@ -31,7 +31,7 @@ namespace XNodeEditor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
DrawGrid(position, zoom, panOffset);
|
DrawGrid(position, zoom, panOffset);
|
||||||
DrawComments();
|
DrawGroups();
|
||||||
DrawConnections();
|
DrawConnections();
|
||||||
DrawDraggedConnection();
|
DrawDraggedConnection();
|
||||||
DrawNodes();
|
DrawNodes();
|
||||||
@ -441,7 +441,7 @@ namespace XNodeEditor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DrawComments()
|
private void DrawGroups()
|
||||||
{
|
{
|
||||||
Event e = Event.current;
|
Event e = Event.current;
|
||||||
|
|
||||||
@ -449,8 +449,8 @@ namespace XNodeEditor {
|
|||||||
Vector2 mousePos = Event.current.mousePosition;
|
Vector2 mousePos = Event.current.mousePosition;
|
||||||
|
|
||||||
if (e.type != EventType.Layout) {
|
if (e.type != EventType.Layout) {
|
||||||
hoveredComment = null;
|
hoveredGroup = null;
|
||||||
if (currentActivity != NodeActivity.ResizeComment) resizingComment = null;
|
if (currentActivity != NodeActivity.ResizeGroup) resizingGroup = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<UnityEngine.Object> preSelection = preBoxSelection != null ? new List<UnityEngine.Object>(preBoxSelection) : new List<UnityEngine.Object>();
|
List<UnityEngine.Object> preSelection = preBoxSelection != null ? new List<UnityEngine.Object>(preBoxSelection) : new List<UnityEngine.Object>();
|
||||||
@ -461,17 +461,17 @@ namespace XNodeEditor {
|
|||||||
if (boxSize.y < 0) { boxStartPos.y += boxSize.y; boxSize.y = Mathf.Abs(boxSize.y); }
|
if (boxSize.y < 0) { boxStartPos.y += boxSize.y; boxSize.y = Mathf.Abs(boxSize.y); }
|
||||||
Rect selectionBox = new Rect(boxStartPos, boxSize);
|
Rect selectionBox = new Rect(boxStartPos, boxSize);
|
||||||
|
|
||||||
for (int n = 0; n < graph.comments.Count; n++) {
|
for (int n = 0; n < graph.groups.Count; n++) {
|
||||||
XNode.NodeGraphComment comment = graph.comments[n];
|
XNode.NodeGroup group = graph.groups[n];
|
||||||
if (comment == null) continue;
|
if (group == null) continue;
|
||||||
|
|
||||||
Vector2 commentPos = GridToWindowPositionNoClipped(comment.position);
|
Vector2 groupPos = GridToWindowPositionNoClipped(group.position);
|
||||||
GUILayout.BeginArea(new Rect(commentPos, new Vector2(comment.size.x, comment.size.y)));
|
GUILayout.BeginArea(new Rect(groupPos, new Vector2(group.size.x, group.size.y)));
|
||||||
|
|
||||||
bool selected = selectionCache.Contains(comment);
|
bool selected = selectionCache.Contains(group);
|
||||||
|
|
||||||
if (selected) {
|
if (selected) {
|
||||||
GUIStyle style = new GUIStyle(NodeEditorResources.styles.commentBody);
|
GUIStyle style = new GUIStyle(NodeEditorResources.styles.groupBody);
|
||||||
GUIStyle highlightStyle = new GUIStyle(NodeEditorResources.styles.nodeHighlight);
|
GUIStyle highlightStyle = new GUIStyle(NodeEditorResources.styles.nodeHighlight);
|
||||||
highlightStyle.padding = style.padding;
|
highlightStyle.padding = style.padding;
|
||||||
style.padding = new RectOffset();
|
style.padding = new RectOffset();
|
||||||
@ -480,41 +480,41 @@ namespace XNodeEditor {
|
|||||||
GUI.color = NodeEditorPreferences.GetSettings().highlightColor;
|
GUI.color = NodeEditorPreferences.GetSettings().highlightColor;
|
||||||
GUILayout.BeginVertical(new GUIStyle(highlightStyle));
|
GUILayout.BeginVertical(new GUIStyle(highlightStyle));
|
||||||
} else {
|
} else {
|
||||||
GUIStyle style = new GUIStyle(NodeEditorResources.styles.commentBody);
|
GUIStyle style = new GUIStyle(NodeEditorResources.styles.groupBody);
|
||||||
GUI.color = Color.white;
|
GUI.color = Color.white;
|
||||||
GUILayout.BeginVertical(style);
|
GUILayout.BeginVertical(style);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (renamingComment == comment) {
|
if (renamingGroup == group) {
|
||||||
if (Selection.Contains(renamingComment)) {
|
if (Selection.Contains(renamingGroup)) {
|
||||||
int controlID = EditorGUIUtility.GetControlID(FocusType.Keyboard) + 1;
|
int controlID = EditorGUIUtility.GetControlID(FocusType.Keyboard) + 1;
|
||||||
if (!renamingStarted) {
|
if (!renamingStarted) {
|
||||||
EditorGUIUtility.keyboardControl = controlID;
|
EditorGUIUtility.keyboardControl = controlID;
|
||||||
EditorGUIUtility.editingTextField = true;
|
EditorGUIUtility.editingTextField = true;
|
||||||
renamingStarted = true;
|
renamingStarted = true;
|
||||||
}
|
}
|
||||||
comment.comment = EditorGUILayout.TextField(comment.comment, NodeEditorResources.styles.commentHeader, GUILayout.Height(26));
|
group.name = EditorGUILayout.TextField(group.name, NodeEditorResources.styles.groupHeader, GUILayout.Height(26));
|
||||||
if (!EditorGUIUtility.editingTextField) {
|
if (!EditorGUIUtility.editingTextField) {
|
||||||
Debug.Log("Finish renaming");
|
Debug.Log("Finish renaming");
|
||||||
renamingComment = null;
|
renamingGroup = null;
|
||||||
renamingStarted = false;
|
renamingStarted = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Selection changed, so stop renaming.
|
// Selection changed, so stop renaming.
|
||||||
GUILayout.Label(comment.comment, NodeEditorResources.styles.commentHeader, GUILayout.Height(26));
|
GUILayout.Label(group.name, NodeEditorResources.styles.groupHeader, GUILayout.Height(26));
|
||||||
renamingComment = null;
|
renamingGroup = null;
|
||||||
renamingStarted = false;
|
renamingStarted = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
GUIStyle blackStyle = new GUIStyle(NodeEditorResources.styles.commentHeader);
|
GUIStyle blackStyle = new GUIStyle(NodeEditorResources.styles.groupHeader);
|
||||||
blackStyle.normal.textColor = new Color(0.2f, 0.2f, 0.2f);
|
blackStyle.normal.textColor = new Color(0.2f, 0.2f, 0.2f);
|
||||||
|
|
||||||
GUILayout.Label(comment.comment, blackStyle, GUILayout.Height(26));
|
GUILayout.Label(group.name, blackStyle, GUILayout.Height(26));
|
||||||
|
|
||||||
Rect lastRect = GUILayoutUtility.GetLastRect();
|
Rect lastRect = GUILayoutUtility.GetLastRect();
|
||||||
lastRect.x -= 0.5f;
|
lastRect.x -= 0.5f;
|
||||||
lastRect.y -= 1;
|
lastRect.y -= 1;
|
||||||
GUI.Label(lastRect, comment.comment, NodeEditorResources.styles.commentHeader);
|
GUI.Label(lastRect, group.name, NodeEditorResources.styles.groupHeader);
|
||||||
}
|
}
|
||||||
|
|
||||||
GUILayout.FlexibleSpace();
|
GUILayout.FlexibleSpace();
|
||||||
@ -523,23 +523,23 @@ namespace XNodeEditor {
|
|||||||
|
|
||||||
if (selected) GUILayout.EndVertical();
|
if (selected) GUILayout.EndVertical();
|
||||||
|
|
||||||
if (e.type != EventType.Layout && currentActivity != NodeActivity.ResizeComment) {
|
if (e.type != EventType.Layout && currentActivity != NodeActivity.ResizeGroup) {
|
||||||
//Check if we are hovering this node
|
//Check if we are hovering this node
|
||||||
Vector2 commentSize = GUILayoutUtility.GetLastRect().size;
|
Vector2 groupSize = GUILayoutUtility.GetLastRect().size;
|
||||||
Rect windowRect = new Rect(commentPos, commentSize);
|
Rect windowRect = new Rect(groupPos, groupSize);
|
||||||
|
|
||||||
float padding = 12;
|
float padding = 12;
|
||||||
|
|
||||||
// Resizing areas
|
// Resizing areas
|
||||||
// Follows the NodeGraphCommentSide order
|
// Follows the NodeGroupSide order
|
||||||
Rect[] resizeRects = new[] {
|
Rect[] resizeRects = new[] {
|
||||||
new Rect(padding, 0, commentSize.x - padding * 2, padding),
|
new Rect(padding, 0, groupSize.x - padding * 2, padding),
|
||||||
new Rect(commentSize.x - padding, 0, padding, padding),
|
new Rect(groupSize.x - padding, 0, padding, padding),
|
||||||
new Rect(commentSize.x - padding, padding, padding, commentSize.y - padding * 2),
|
new Rect(groupSize.x - padding, padding, padding, groupSize.y - padding * 2),
|
||||||
new Rect(commentSize.x - padding, commentSize.y - padding, padding, padding),
|
new Rect(groupSize.x - padding, groupSize.y - padding, padding, padding),
|
||||||
new Rect(padding, commentSize.y - padding, commentSize.x - padding * 2, padding),
|
new Rect(padding, groupSize.y - padding, groupSize.x - padding * 2, padding),
|
||||||
new Rect(0, commentSize.y - padding, padding, padding),
|
new Rect(0, groupSize.y - padding, padding, padding),
|
||||||
new Rect(0, padding, padding, commentSize.y - padding * 2),
|
new Rect(0, padding, padding, groupSize.y - padding * 2),
|
||||||
new Rect(0, 0, padding, padding),
|
new Rect(0, 0, padding, padding),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -559,35 +559,35 @@ namespace XNodeEditor {
|
|||||||
EditorGUIUtility.AddCursorRect(resizeRects[i], resizeIcons[i]);
|
EditorGUIUtility.AddCursorRect(resizeRects[i], resizeIcons[i]);
|
||||||
|
|
||||||
// Transform the locations now to gui space locations
|
// Transform the locations now to gui space locations
|
||||||
resizeRects[i].position += commentPos;
|
resizeRects[i].position += groupPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (windowRect.Contains(mousePos)) {
|
if (windowRect.Contains(mousePos)) {
|
||||||
//If dragging a selection box, add nodes inside to selection
|
//If dragging a selection box, add nodes inside to selection
|
||||||
if (currentActivity == NodeActivity.DragGrid) {
|
if (currentActivity == NodeActivity.DragGrid) {
|
||||||
if (windowRect.Overlaps(selectionBox)) preSelection.Add(comment);
|
if (windowRect.Overlaps(selectionBox)) preSelection.Add(group);
|
||||||
} else {
|
} else {
|
||||||
// Check if we should resize or select
|
// Check if we should resize or select
|
||||||
bool resizeAreaClicked = false;
|
bool resizeAreaClicked = false;
|
||||||
for (int i = 0; i < resizeRects.Length; i++) {
|
for (int i = 0; i < resizeRects.Length; i++) {
|
||||||
if (resizeRects[i].Contains(mousePos)) {
|
if (resizeRects[i].Contains(mousePos)) {
|
||||||
resizingComment = comment;
|
resizingGroup = group;
|
||||||
// i can be cast to NodeGraphCommentSide as resizeRects
|
// i can be cast to NodeGroupSide as resizeRects
|
||||||
// has one element per NodeGraphCommentSide value and
|
// has one element per NodeGroupSide value and
|
||||||
// uses the same order
|
// uses the same order
|
||||||
resizingCommentSide = (NodeGraphCommentSide)i;
|
resizingGroupSide = (NodeGroupSide)i;
|
||||||
resizeAreaClicked = true;
|
resizeAreaClicked = true;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!resizeAreaClicked) hoveredComment = comment;
|
if (!resizeAreaClicked) hoveredGroup = group;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//If dragging a selection box, add nodes inside to selection
|
//If dragging a selection box, add nodes inside to selection
|
||||||
if (currentActivity == NodeActivity.DragGrid) {
|
if (currentActivity == NodeActivity.DragGrid) {
|
||||||
if (windowRect.Overlaps(selectionBox)) preSelection.Add(comment);
|
if (windowRect.Overlaps(selectionBox)) preSelection.Add(group);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -12,15 +12,15 @@ namespace XNodeEditor {
|
|||||||
private static Texture2D _nodeBody;
|
private static Texture2D _nodeBody;
|
||||||
public static Texture2D nodeHighlight { get { return _nodeHighlight != null ? _nodeHighlight : _nodeHighlight = Resources.Load<Texture2D>("xnode_node_highlight"); } }
|
public static Texture2D nodeHighlight { get { return _nodeHighlight != null ? _nodeHighlight : _nodeHighlight = Resources.Load<Texture2D>("xnode_node_highlight"); } }
|
||||||
private static Texture2D _nodeHighlight;
|
private static Texture2D _nodeHighlight;
|
||||||
public static Texture2D commentBody { get { return _commentBody != null ? _commentBody : _commentBody = Resources.Load<Texture2D>("xnode_comment"); } }
|
public static Texture2D groupBody { get { return _groupBody != null ? _groupBody : _groupBody = Resources.Load<Texture2D>("xnode_group"); } }
|
||||||
private static Texture2D _commentBody;
|
private static Texture2D _groupBody;
|
||||||
|
|
||||||
// Styles
|
// Styles
|
||||||
public static Styles styles { get { return _styles != null ? _styles : _styles = new Styles(); } }
|
public static Styles styles { get { return _styles != null ? _styles : _styles = new Styles(); } }
|
||||||
public static Styles _styles = null;
|
public static Styles _styles = null;
|
||||||
public static GUIStyle OutputPort { get { return new GUIStyle(EditorStyles.label) { alignment = TextAnchor.UpperRight }; } }
|
public static GUIStyle OutputPort { get { return new GUIStyle(EditorStyles.label) { alignment = TextAnchor.UpperRight }; } }
|
||||||
public class Styles {
|
public class Styles {
|
||||||
public GUIStyle inputPort, nodeHeader, nodeBody, tooltip, nodeHighlight, commentHeader, commentBody;
|
public GUIStyle inputPort, nodeHeader, nodeBody, tooltip, nodeHighlight, groupHeader, groupBody;
|
||||||
|
|
||||||
public Styles() {
|
public Styles() {
|
||||||
GUIStyle baseStyle = new GUIStyle("Label");
|
GUIStyle baseStyle = new GUIStyle("Label");
|
||||||
@ -47,16 +47,16 @@ namespace XNodeEditor {
|
|||||||
tooltip = new GUIStyle("helpBox");
|
tooltip = new GUIStyle("helpBox");
|
||||||
tooltip.alignment = TextAnchor.MiddleCenter;
|
tooltip.alignment = TextAnchor.MiddleCenter;
|
||||||
|
|
||||||
commentHeader = new GUIStyle();
|
groupHeader = new GUIStyle();
|
||||||
commentHeader.alignment = TextAnchor.MiddleCenter;
|
groupHeader.alignment = TextAnchor.MiddleCenter;
|
||||||
commentHeader.fontStyle = FontStyle.Bold;
|
groupHeader.fontStyle = FontStyle.Bold;
|
||||||
commentHeader.fontSize = 20;
|
groupHeader.fontSize = 20;
|
||||||
commentHeader.normal.textColor = new Color(0.93f, 0.93f, 0.93f);
|
groupHeader.normal.textColor = new Color(0.93f, 0.93f, 0.93f);
|
||||||
|
|
||||||
commentBody = new GUIStyle();
|
groupBody = new GUIStyle();
|
||||||
commentBody.normal.background = NodeEditorResources.commentBody;
|
groupBody.normal.background = NodeEditorResources.groupBody;
|
||||||
commentBody.border = new RectOffset(32, 32, 32, 32);
|
groupBody.border = new RectOffset(32, 32, 32, 32);
|
||||||
commentBody.padding = new RectOffset(16, 16, 4, 16);
|
groupBody.padding = new RectOffset(16, 16, 4, 16);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -142,38 +142,38 @@ namespace XNodeEditor {
|
|||||||
Selection.objects = selection.ToArray();
|
Selection.objects = selection.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SelectComment(XNode.NodeGraphComment comment, bool add) {
|
public void SelectGroup(XNode.NodeGroup group, bool add) {
|
||||||
if (add) {
|
if (add) {
|
||||||
List<Object> selection = new List<Object>(Selection.objects);
|
List<Object> selection = new List<Object>(Selection.objects);
|
||||||
selection.Add(comment);
|
selection.Add(group);
|
||||||
Selection.objects = selection.ToArray();
|
Selection.objects = selection.ToArray();
|
||||||
} else Selection.objects = new Object[] { comment };
|
} else Selection.objects = new Object[] { group };
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeselectComment(XNode.NodeGraphComment comment) {
|
public void DeselectGroup(XNode.NodeGroup group) {
|
||||||
List<Object> selection = new List<Object>(Selection.objects);
|
List<Object> selection = new List<Object>(Selection.objects);
|
||||||
selection.Remove(comment);
|
selection.Remove(group);
|
||||||
Selection.objects = selection.ToArray();
|
Selection.objects = selection.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SelectNodesInComment(XNode.NodeGraphComment comment) {
|
public void SelectNodesInGroup(XNode.NodeGroup group) {
|
||||||
Rect commentRect = new Rect(comment.position, comment.size);
|
Rect groupRect = new Rect(group.position, group.size);
|
||||||
for (int i = 0; i < graph.nodes.Count; i++) {
|
for (int i = 0; i < graph.nodes.Count; i++) {
|
||||||
XNode.Node node = graph.nodes[i];
|
XNode.Node node = graph.nodes[i];
|
||||||
if (!node) continue;
|
if (!node) continue;
|
||||||
if (commentRect.Contains(node.position)) SelectNode(node, true);
|
if (groupRect.Contains(node.position)) SelectNode(node, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeselectNodesInComment(XNode.NodeGraphComment comment)
|
public void DeselectNodesInGroup(XNode.NodeGroup group)
|
||||||
{
|
{
|
||||||
List<Object> selection = new List<Object>(Selection.objects);
|
List<Object> selection = new List<Object>(Selection.objects);
|
||||||
Rect commentRect = new Rect(comment.position, comment.size);
|
Rect groupRect = new Rect(group.position, group.size);
|
||||||
for (int i = 0; i < graph.nodes.Count; i++) {
|
for (int i = 0; i < graph.nodes.Count; i++) {
|
||||||
XNode.Node node = graph.nodes[i];
|
XNode.Node node = graph.nodes[i];
|
||||||
if (!node) continue;
|
if (!node) continue;
|
||||||
|
|
||||||
if (commentRect.Contains(node.position)) selection.Remove(node);
|
if (groupRect.Contains(node.position)) selection.Remove(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
Selection.objects = selection.ToArray();
|
Selection.objects = selection.ToArray();
|
||||||
|
|||||||
@ -53,14 +53,14 @@ namespace XNodeEditor {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
menu.AddSeparator("");
|
menu.AddSeparator("");
|
||||||
menu.AddItem(new GUIContent("Add comment"), false, () => CreateComment(pos));
|
menu.AddItem(new GUIContent("Add group"), false, () => CreateGroup(pos));
|
||||||
menu.AddSeparator("");
|
menu.AddSeparator("");
|
||||||
menu.AddItem(new GUIContent("Preferences"), false, () => NodeEditorWindow.OpenPreferences());
|
menu.AddItem(new GUIContent("Preferences"), false, () => NodeEditorWindow.OpenPreferences());
|
||||||
NodeEditorWindow.AddCustomContextMenuItems(menu, target);
|
NodeEditorWindow.AddCustomContextMenuItems(menu, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Add items for the context menu when right-clicking this node. Override to add custom menu items. </summary>
|
/// <summary> Add items for the context menu when right-clicking this node. Override to add custom menu items. </summary>
|
||||||
public virtual void AddCommentContextMenuItems(GenericMenu menu) {
|
public virtual void AddGroupContextMenuItems(GenericMenu menu) {
|
||||||
Vector2 pos = NodeEditorWindow.current.WindowToGridPosition(Event.current.mousePosition);
|
Vector2 pos = NodeEditorWindow.current.WindowToGridPosition(Event.current.mousePosition);
|
||||||
for (int i = 0; i < NodeEditorWindow.nodeTypes.Length; i++) {
|
for (int i = 0; i < NodeEditorWindow.nodeTypes.Length; i++) {
|
||||||
Type type = NodeEditorWindow.nodeTypes[i];
|
Type type = NodeEditorWindow.nodeTypes[i];
|
||||||
@ -75,12 +75,12 @@ namespace XNodeEditor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
menu.AddSeparator("");
|
menu.AddSeparator("");
|
||||||
menu.AddItem(new GUIContent("Add comment"), false, () => CreateComment(pos));
|
menu.AddItem(new GUIContent("Add group"), false, () => CreateGroup(pos));
|
||||||
menu.AddSeparator("");
|
menu.AddSeparator("");
|
||||||
// Actions if only one node is selected
|
// Actions if only one node is selected
|
||||||
if (Selection.objects.Length == 1 && Selection.activeObject is XNode.NodeGraphComment) {
|
if (Selection.objects.Length == 1 && Selection.activeObject is XNode.NodeGroup) {
|
||||||
XNode.NodeGraphComment comment = Selection.activeObject as XNode.NodeGraphComment;
|
XNode.NodeGroup group = Selection.activeObject as XNode.NodeGroup;
|
||||||
menu.AddItem(new GUIContent("Rename"), false, NodeEditorWindow.current.RenameSelectedComment);
|
menu.AddItem(new GUIContent("Rename"), false, NodeEditorWindow.current.RenameSelectedGroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add actions to any number of selected nodes
|
// Add actions to any number of selected nodes
|
||||||
@ -118,29 +118,29 @@ namespace XNodeEditor {
|
|||||||
if (NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets();
|
if (NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Create a comment and save it in the graph asset </summary>
|
/// <summary> Create a group and save it in the graph asset </summary>
|
||||||
public void CreateComment(Vector2 position) {
|
public void CreateGroup(Vector2 position) {
|
||||||
XNode.NodeGraphComment comment = target.AddComment();
|
XNode.NodeGroup group = target.AddGroup();
|
||||||
comment.position = position;
|
group.position = position;
|
||||||
comment.comment = "New comment";
|
group.name = "New group";
|
||||||
AssetDatabase.AddObjectToAsset(comment, target);
|
AssetDatabase.AddObjectToAsset(group, target);
|
||||||
if (NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets();
|
if (NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets();
|
||||||
NodeEditorWindow.RepaintAll();
|
NodeEditorWindow.RepaintAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Creates a copy of the original comment in the graph </summary>
|
/// <summary> Creates a copy of the original group in the graph </summary>
|
||||||
public XNode.NodeGraphComment CopyComment(XNode.NodeGraphComment original) {
|
public XNode.NodeGroup CopyGroup(XNode.NodeGroup original) {
|
||||||
XNode.NodeGraphComment comment = target.CopyComment(original);
|
XNode.NodeGroup group = target.CopyGroup(original);
|
||||||
comment.name = original.name;
|
group.name = original.name;
|
||||||
AssetDatabase.AddObjectToAsset(comment, target);
|
AssetDatabase.AddObjectToAsset(group, target);
|
||||||
if (NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets();
|
if (NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets();
|
||||||
return comment;
|
return group;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Safely remove a comment </summary>
|
/// <summary> Safely remove a group </summary>
|
||||||
public void RemoveComment(XNode.NodeGraphComment comment) {
|
public void RemoveGroup(XNode.NodeGroup group) {
|
||||||
UnityEngine.Object.DestroyImmediate(comment, true);
|
UnityEngine.Object.DestroyImmediate(group, true);
|
||||||
target.RemoveComment(comment);
|
target.RemoveGroup(group);
|
||||||
if (NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets();
|
if (NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 999 B After Width: | Height: | Size: 999 B |
@ -10,9 +10,9 @@ namespace XNode {
|
|||||||
/// <summary> All nodes in the graph. <para/>
|
/// <summary> All nodes in the graph. <para/>
|
||||||
/// See: <see cref="AddNode{T}"/> </summary>
|
/// See: <see cref="AddNode{T}"/> </summary>
|
||||||
[SerializeField] public List<Node> nodes = new List<Node>();
|
[SerializeField] public List<Node> nodes = new List<Node>();
|
||||||
/// <summary> All comments in the graph. <para/>
|
/// <summary> All groups in the graph. <para/>
|
||||||
/// See: <see cref="AddComment"/> </summary>
|
/// See: <see cref="AddGroup"/> </summary>
|
||||||
[SerializeField] public List<NodeGraphComment> comments = new List<NodeGraphComment>();
|
[SerializeField] public List<NodeGroup> groups = new List<NodeGroup>();
|
||||||
|
|
||||||
/// <summary> Add a node to the graph by type </summary>
|
/// <summary> Add a node to the graph by type </summary>
|
||||||
public T AddNode<T>() where T : Node {
|
public T AddNode<T>() where T : Node {
|
||||||
@ -56,26 +56,26 @@ namespace XNode {
|
|||||||
nodes.Clear();
|
nodes.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Add a comment to the graph</summary>
|
/// <summary> Add a group to the graph</summary>
|
||||||
public NodeGraphComment AddComment() {
|
public NodeGroup AddGroup() {
|
||||||
NodeGraphComment comment = ScriptableObject.CreateInstance<NodeGraphComment>();
|
NodeGroup group = ScriptableObject.CreateInstance<NodeGroup>();
|
||||||
comment.graph = this;
|
group.graph = this;
|
||||||
comments.Add(comment);
|
groups.Add(group);
|
||||||
return comment;
|
return group;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Creates a copy of the comment node in the graph </summary>
|
/// <summary> Creates a copy of the group node in the graph </summary>
|
||||||
public virtual NodeGraphComment CopyComment(NodeGraphComment original) {
|
public virtual NodeGroup CopyGroup(NodeGroup original) {
|
||||||
NodeGraphComment comment = ScriptableObject.Instantiate(original);
|
NodeGroup group = ScriptableObject.Instantiate(original);
|
||||||
comment.graph = this;
|
group.graph = this;
|
||||||
comments.Add(comment);
|
groups.Add(group);
|
||||||
return comment;
|
return group;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Safely remove a comment </summary>
|
/// <summary> Safely remove a group </summary>
|
||||||
public void RemoveComment(NodeGraphComment comment) {
|
public void RemoveGroup(NodeGroup group) {
|
||||||
comments.Remove(comment);
|
groups.Remove(group);
|
||||||
if (Application.isPlaying) Destroy(comment);
|
if (Application.isPlaying) Destroy(group);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Create a new deep copy of this graph </summary>
|
/// <summary> Create a new deep copy of this graph </summary>
|
||||||
@ -91,6 +91,14 @@ namespace XNode {
|
|||||||
graph.nodes[i] = node;
|
graph.nodes[i] = node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Instantiate all groups inside the graph
|
||||||
|
for (int i = 0; i < groups.Count; i++) {
|
||||||
|
if (groups[i] == null) continue;
|
||||||
|
NodeGroup group = Instantiate(groups[i]) as NodeGroup;
|
||||||
|
group.graph = graph;
|
||||||
|
graph.groups[i] = group;
|
||||||
|
}
|
||||||
|
|
||||||
// Redirect all connections
|
// Redirect all connections
|
||||||
for (int i = 0; i < graph.nodes.Count; i++) {
|
for (int i = 0; i < graph.nodes.Count; i++) {
|
||||||
if (graph.nodes[i] == null) continue;
|
if (graph.nodes[i] == null) continue;
|
||||||
|
|||||||
@ -4,11 +4,10 @@ using UnityEngine;
|
|||||||
namespace XNode
|
namespace XNode
|
||||||
{
|
{
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public class NodeGraphComment : ScriptableObject
|
public class NodeGroup : ScriptableObject
|
||||||
{
|
{
|
||||||
[SerializeField] public NodeGraph graph;
|
[SerializeField] public NodeGraph graph;
|
||||||
[SerializeField] public Vector2 position;
|
[SerializeField] public Vector2 position;
|
||||||
[SerializeField] public Vector2 size = new Vector2(200, 300);
|
[SerializeField] public Vector2 size = new Vector2(200, 300);
|
||||||
[SerializeField] public string comment;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user