mirror of
https://github.com/Siccity/xNode.git
synced 2026-02-16 12:01:43 +08:00
Visual representation in DrawConnections
This commit is contained in:
parent
0132c16448
commit
34e195e33d
@ -217,6 +217,8 @@ namespace XNodeEditor {
|
|||||||
|
|
||||||
/// <summary> Draws all connections </summary>
|
/// <summary> Draws all connections </summary>
|
||||||
public void DrawConnections() {
|
public void DrawConnections() {
|
||||||
|
List<int> drawnReroutes = new List<int>();
|
||||||
|
|
||||||
foreach (XNode.Node node in graph.nodes) {
|
foreach (XNode.Node node in graph.nodes) {
|
||||||
//If a null node is found, return. This can happen if the nodes associated script is deleted. It is currently not possible in Unity to delete a null asset.
|
//If a null node is found, return. This can happen if the nodes associated script is deleted. It is currently not possible in Unity to delete a null asset.
|
||||||
if (node == null) continue;
|
if (node == null) continue;
|
||||||
@ -224,16 +226,29 @@ namespace XNodeEditor {
|
|||||||
foreach (XNode.NodePort output in node.Outputs) {
|
foreach (XNode.NodePort output in node.Outputs) {
|
||||||
//Needs cleanup. Null checks are ugly
|
//Needs cleanup. Null checks are ugly
|
||||||
if (!portConnectionPoints.ContainsKey(output)) continue;
|
if (!portConnectionPoints.ContainsKey(output)) continue;
|
||||||
|
|
||||||
|
Color connectionColor = graphEditor.GetTypeColor(output.ValueType);
|
||||||
|
|
||||||
Vector2 from = _portConnectionPoints[output].center;
|
Vector2 from = _portConnectionPoints[output].center;
|
||||||
for (int k = 0; k < output.ConnectionCount; k++) {
|
for (int k = 0; k < output.ConnectionCount; k++) {
|
||||||
|
|
||||||
XNode.NodePort input = output.GetConnection(k);
|
XNode.NodePort input = output.GetConnection(k);
|
||||||
|
|
||||||
|
// Error handling
|
||||||
if (input == null) continue; //If a script has been updated and the port doesn't exist, it is removed and null is returned. If this happens, return.
|
if (input == null) continue; //If a script has been updated and the port doesn't exist, it is removed and null is returned. If this happens, return.
|
||||||
if (!input.IsConnectedTo(output)) input.Connect(output);
|
if (!input.IsConnectedTo(output)) input.Connect(output);
|
||||||
if (!_portConnectionPoints.ContainsKey(input)) continue;
|
if (!_portConnectionPoints.ContainsKey(input)) continue;
|
||||||
Vector2 to = _portConnectionPoints[input].center;
|
|
||||||
Color connectionColor = graphEditor.GetTypeColor(output.ValueType);
|
Vector2 to = Vector2.zero;
|
||||||
DrawConnection(from, to, connectionColor);
|
int[] rerouteIndices = output.GetReroutes(k);
|
||||||
|
for (int i = 0; i < rerouteIndices.Length + 1; i++) {
|
||||||
|
if (i != rerouteIndices.Length) to = graph.reroutes[rerouteIndices[i]];
|
||||||
|
else to = _portConnectionPoints[input].center;
|
||||||
|
DrawConnection(from, to, connectionColor);
|
||||||
|
from = to;
|
||||||
|
|
||||||
|
if (drawnReroutes.Contains(i)) break;
|
||||||
|
else drawnReroutes.Add(i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,11 +10,8 @@ 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> Nodes used primarily for organization </summary>
|
||||||
#if UNITY_EDITOR
|
[SerializeField] public List<Vector2> reroutes = new List<Vector2>();
|
||||||
/// <summary> Nodes used primarily for organization (Editor only) </summary>
|
|
||||||
public List<Vector2> reroutes = new List<Vector2>();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/// <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 {
|
||||||
|
|||||||
@ -250,6 +250,12 @@ namespace XNode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary> Get reroute indices. This is used for graph organization purposes </summary>
|
||||||
|
/// <param name="i"> Connection index </param>
|
||||||
|
public int[] GetReroutes(int i) {
|
||||||
|
return connections[i].reroutes;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary> Swap connected nodes from the old list with nodes from the new list </summary>
|
/// <summary> Swap connected nodes from the old list with nodes from the new list </summary>
|
||||||
public void Redirect(List<Node> oldNodes, List<Node> newNodes) {
|
public void Redirect(List<Node> oldNodes, List<Node> newNodes) {
|
||||||
foreach (PortConnection connection in connections) {
|
foreach (PortConnection connection in connections) {
|
||||||
@ -263,6 +269,8 @@ namespace XNode {
|
|||||||
[SerializeField] public string fieldName;
|
[SerializeField] public string fieldName;
|
||||||
[SerializeField] public Node node;
|
[SerializeField] public Node node;
|
||||||
public NodePort Port { get { return port != null ? port : port = GetPort(); } }
|
public NodePort Port { get { return port != null ? port : port = GetPort(); } }
|
||||||
|
/// <summary> Used for organization</summary>
|
||||||
|
[SerializeField] public int[] reroutes = new int[0];
|
||||||
|
|
||||||
[NonSerialized] private NodePort port;
|
[NonSerialized] private NodePort port;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user