mirror of
https://github.com/Siccity/xNode.git
synced 2025-12-20 09:16:01 +08:00
Fixed issue #12
This commit is contained in:
parent
73172a1c48
commit
5b79757667
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
@ -197,16 +198,42 @@ namespace XNodeEditor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// <summary> Dublicate selected nodes and select the dublicates
|
/// <summary> Dublicate selected nodes and select the dublicates </summary>
|
||||||
public void DublicateSelectedNodes() {
|
public void DublicateSelectedNodes() {
|
||||||
UnityEngine.Object[] newNodes = new UnityEngine.Object[Selection.objects.Length];
|
UnityEngine.Object[] newNodes = new UnityEngine.Object[Selection.objects.Length];
|
||||||
|
Dictionary<XNode.Node, XNode.Node> substitutes = new Dictionary<XNode.Node, XNode.Node>();
|
||||||
for (int i = 0; i < Selection.objects.Length; i++) {
|
for (int i = 0; i < Selection.objects.Length; i++) {
|
||||||
if (Selection.objects[i] is XNode.Node) {
|
if (Selection.objects[i] is XNode.Node) {
|
||||||
XNode.Node node = Selection.objects[i] as XNode.Node;
|
XNode.Node srcNode = Selection.objects[i] as XNode.Node;
|
||||||
if (node.graph != graph) continue; // ignore nodes selected in another graph
|
if (srcNode.graph != graph) continue; // ignore nodes selected in another graph
|
||||||
XNode.Node n = graph.CopyNode(node);
|
XNode.Node newNode = graph.CopyNode(srcNode);
|
||||||
n.position = node.position + new Vector2(30, 30);
|
substitutes.Add(srcNode, newNode);
|
||||||
newNodes[i] = n;
|
newNode.position = srcNode.position + new Vector2(30, 30);
|
||||||
|
newNodes[i] = newNode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Walk through the selected nodes again, recreate connections, using the new nodes
|
||||||
|
for (int i = 0; i < Selection.objects.Length; i++) {
|
||||||
|
if (Selection.objects[i] is XNode.Node) {
|
||||||
|
XNode.Node srcNode = Selection.objects[i] as XNode.Node;
|
||||||
|
if (srcNode.graph != graph) continue; // ignore nodes selected in another graph
|
||||||
|
foreach (XNode.NodePort port in srcNode.Ports) {
|
||||||
|
for (int c = 0; c < port.ConnectionCount; c++) {
|
||||||
|
XNode.NodePort inputPort = port.direction == XNode.NodePort.IO.Input ? port : port.GetConnection(c);
|
||||||
|
XNode.NodePort outputPort = port.direction == XNode.NodePort.IO.Output ? port : port.GetConnection(c);
|
||||||
|
|
||||||
|
if (substitutes.ContainsKey(inputPort.node) && substitutes.ContainsKey(outputPort.node)) {
|
||||||
|
XNode.Node newNodeIn = substitutes[inputPort.node];
|
||||||
|
XNode.Node newNodeOut = substitutes[outputPort.node];
|
||||||
|
newNodeIn.UpdateStaticPorts();
|
||||||
|
newNodeOut.UpdateStaticPorts();
|
||||||
|
inputPort = newNodeIn.GetInputPort(inputPort.fieldName);
|
||||||
|
outputPort = newNodeOut.GetOutputPort(outputPort.fieldName);
|
||||||
|
}
|
||||||
|
if (!inputPort.IsConnectedTo(outputPort)) inputPort.Connect(outputPort);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Selection.objects = newNodes;
|
Selection.objects = newNodes;
|
||||||
|
|||||||
@ -61,10 +61,15 @@ namespace XNode {
|
|||||||
[SerializeField] private NodePortDictionary ports = new NodePortDictionary();
|
[SerializeField] private NodePortDictionary ports = new NodePortDictionary();
|
||||||
|
|
||||||
protected void OnEnable() {
|
protected void OnEnable() {
|
||||||
NodeDataCache.UpdatePorts(this, ports);
|
UpdateStaticPorts();
|
||||||
Init();
|
Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary> Update static ports to reflect class fields. This happens automatically on enable. </summary>
|
||||||
|
public void UpdateStaticPorts() {
|
||||||
|
NodeDataCache.UpdatePorts(this, ports);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary> Initialize node. Called on creation. </summary>
|
/// <summary> Initialize node. Called on creation. </summary>
|
||||||
protected virtual void Init() { name = GetType().Name; }
|
protected virtual void Init() { name = GetType().Name; }
|
||||||
|
|
||||||
@ -206,13 +211,13 @@ namespace XNode {
|
|||||||
public class InputAttribute : Attribute {
|
public class InputAttribute : Attribute {
|
||||||
public ShowBackingValue backingValue;
|
public ShowBackingValue backingValue;
|
||||||
public ConnectionType connectionType;
|
public ConnectionType connectionType;
|
||||||
|
|
||||||
/// <summary> Mark a serializable field as an input port. You can access this through <see cref="GetInputPort(string)"/> </summary>
|
/// <summary> Mark a serializable field as an input port. You can access this through <see cref="GetInputPort(string)"/> </summary>
|
||||||
/// <param name="backingValue">Should we display the backing value for this port as an editor field? </param>
|
/// <param name="backingValue">Should we display the backing value for this port as an editor field? </param>
|
||||||
/// <param name="connectionType">Should we allow multiple connections? </param>
|
/// <param name="connectionType">Should we allow multiple connections? </param>
|
||||||
public InputAttribute(ShowBackingValue backingValue = ShowBackingValue.Unconnected, ConnectionType connectionType = ConnectionType.Multiple) {
|
public InputAttribute(ShowBackingValue backingValue = ShowBackingValue.Unconnected, ConnectionType connectionType = ConnectionType.Multiple) {
|
||||||
this.backingValue = backingValue;
|
this.backingValue = backingValue;
|
||||||
this.connectionType = connectionType;
|
this.connectionType = connectionType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user