mirror of
https://github.com/Siccity/xNode.git
synced 2025-12-20 17:26:02 +08:00
WIP implementing INode and INodeGraph
This commit is contained in:
parent
5436b74313
commit
1be9cb0217
@ -15,7 +15,7 @@ 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 XNode.Node hoveredNode = null;
|
private XNode.INode 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;
|
||||||
@ -81,8 +81,8 @@ namespace XNodeEditor {
|
|||||||
Vector2 mousePos = WindowToGridPosition(e.mousePosition);
|
Vector2 mousePos = WindowToGridPosition(e.mousePosition);
|
||||||
// Move selected nodes with offset
|
// Move selected nodes with offset
|
||||||
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.INode) {
|
||||||
XNode.Node node = Selection.objects[i] as XNode.Node;
|
XNode.INode node = Selection.objects[i] as XNode.INode;
|
||||||
Vector2 initial = node.position;
|
Vector2 initial = node.position;
|
||||||
node.position = mousePos + dragOffset[i];
|
node.position = mousePos + dragOffset[i];
|
||||||
if (gridSnap) {
|
if (gridSnap) {
|
||||||
@ -151,7 +151,7 @@ namespace XNodeEditor {
|
|||||||
} else {
|
} else {
|
||||||
hoveredPort.VerifyConnections();
|
hoveredPort.VerifyConnections();
|
||||||
if (hoveredPort.IsConnected) {
|
if (hoveredPort.IsConnected) {
|
||||||
XNode.Node node = hoveredPort.node;
|
XNode.INode node = hoveredPort.node;
|
||||||
XNode.NodePort output = hoveredPort.Connection;
|
XNode.NodePort output = hoveredPort.Connection;
|
||||||
int outputConnectionIndex = output.GetConnectionIndex(hoveredPort);
|
int outputConnectionIndex = output.GetConnectionIndex(hoveredPort);
|
||||||
draggedOutputReroutes = output.GetReroutePoints(outputConnectionIndex);
|
draggedOutputReroutes = output.GetReroutePoints(outputConnectionIndex);
|
||||||
@ -206,7 +206,7 @@ namespace XNodeEditor {
|
|||||||
if (IsDraggingPort) {
|
if (IsDraggingPort) {
|
||||||
//If connection is valid, save it
|
//If connection is valid, save it
|
||||||
if (draggedOutputTarget != null) {
|
if (draggedOutputTarget != null) {
|
||||||
XNode.Node node = draggedOutputTarget.node;
|
XNode.INode node = draggedOutputTarget.node;
|
||||||
if (graph.nodes.Count != 0) draggedOutput.Connect(draggedOutputTarget);
|
if (graph.nodes.Count != 0) draggedOutput.Connect(draggedOutputTarget);
|
||||||
|
|
||||||
// ConnectionIndex can be -1 if the connection is removed instantly after creation
|
// ConnectionIndex can be -1 if the connection is removed instantly after creation
|
||||||
@ -223,8 +223,8 @@ namespace XNodeEditor {
|
|||||||
EditorUtility.SetDirty(graph);
|
EditorUtility.SetDirty(graph);
|
||||||
if (NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets();
|
if (NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets();
|
||||||
} else if (currentActivity == NodeActivity.DragNode) {
|
} else if (currentActivity == NodeActivity.DragNode) {
|
||||||
IEnumerable<XNode.Node> nodes = Selection.objects.Where(x => x is XNode.Node).Select(x => x as XNode.Node);
|
IEnumerable<XNode.INode> nodes = Selection.objects.Where(x => x is XNode.INode).Select(x => x as XNode.INode);
|
||||||
foreach (XNode.Node node in nodes) EditorUtility.SetDirty(node);
|
foreach (XNode.INode node in nodes) EditorUtility.SetDirty(node);
|
||||||
if (NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets();
|
if (NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets();
|
||||||
} else if (!IsHoveringNode) {
|
} else if (!IsHoveringNode) {
|
||||||
// If click outside node, release field focus
|
// If click outside node, release field focus
|
||||||
@ -328,8 +328,8 @@ namespace XNodeEditor {
|
|||||||
dragOffset = new Vector2[Selection.objects.Length + selectedReroutes.Count];
|
dragOffset = new Vector2[Selection.objects.Length + selectedReroutes.Count];
|
||||||
// Selected nodes
|
// Selected nodes
|
||||||
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.INode) {
|
||||||
XNode.Node node = Selection.objects[i] as XNode.Node;
|
XNode.INode node = Selection.objects[i] as XNode.INode;
|
||||||
dragOffset[i] = node.position - WindowToGridPosition(current.mousePosition);
|
dragOffset[i] = node.position - WindowToGridPosition(current.mousePosition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,7 +15,7 @@ namespace XNodeEditor {
|
|||||||
[SerializeField] private Rect[] _rects = new Rect[0];
|
[SerializeField] private Rect[] _rects = new Rect[0];
|
||||||
|
|
||||||
[System.Serializable] private class NodePortReference {
|
[System.Serializable] private class NodePortReference {
|
||||||
[SerializeField] private XNode.Node _node;
|
[SerializeField] private UnityEngine.Object _node;
|
||||||
[SerializeField] private string _name;
|
[SerializeField] private string _name;
|
||||||
|
|
||||||
public NodePortReference(XNode.NodePort nodePort) {
|
public NodePortReference(XNode.NodePort nodePort) {
|
||||||
@ -27,7 +27,7 @@ namespace XNodeEditor {
|
|||||||
if (_node == null) {
|
if (_node == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return _node.GetPort(_name);
|
return (_node as XNode.INode).GetPort(_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
8
Scripts/Interfaces.meta
Normal file
8
Scripts/Interfaces.meta
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: ac61dc94b559a5243bbfb2368d301f2a
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
27
Scripts/Interfaces/INode.cs
Normal file
27
Scripts/Interfaces/INode.cs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace XNode {
|
||||||
|
public interface INode {
|
||||||
|
string name { get; set; }
|
||||||
|
INodeGraph Graph { get; }
|
||||||
|
Vector2 Position { get; set; }
|
||||||
|
object GetValue(NodePort port);
|
||||||
|
bool HasPort(string fieldName);
|
||||||
|
NodePort GetPort(string fieldName);
|
||||||
|
void UpdateStaticPorts();
|
||||||
|
IEnumerable<NodePort> Ports { get; }
|
||||||
|
IEnumerable<NodePort> Outputs { get; }
|
||||||
|
IEnumerable<NodePort> Inputs { get; }
|
||||||
|
IEnumerable<NodePort> InstancePorts { get; }
|
||||||
|
NodePort AddInstanceOutput(Type type, XNode.Node.ConnectionType connectionType = XNode.Node.ConnectionType.Multiple, string fieldName = null);
|
||||||
|
NodePort AddInstanceInput(Type type, XNode.Node.ConnectionType connectionType = XNode.Node.ConnectionType.Multiple, string fieldName = null);
|
||||||
|
NodePort GetInputPort(string fieldName);
|
||||||
|
NodePort GetOutputPort(string fieldName);
|
||||||
|
void OnCreateConnection(NodePort from, NodePort to);
|
||||||
|
void OnRemoveConnection(NodePort port);
|
||||||
|
void ClearConnections();
|
||||||
|
void RemoveInstancePort(string fieldName);
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Scripts/Interfaces/INode.cs.meta
Normal file
11
Scripts/Interfaces/INode.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: f38ad625580bbf445aa3885c5ec3c5af
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
13
Scripts/Interfaces/INodeGraph.cs
Normal file
13
Scripts/Interfaces/INodeGraph.cs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace XNode {
|
||||||
|
/// <summary> Used by advanced extensions that need to alter the base classes of NodeGraphs </summary>
|
||||||
|
public interface INodeGraph {
|
||||||
|
int NodesCount { get; }
|
||||||
|
void MoveNodeToTop(INode node);
|
||||||
|
INode[] GetNodes();
|
||||||
|
INode AddNode(Type type);
|
||||||
|
INode CopyNode(INode original);
|
||||||
|
void RemoveNode(INode node);
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Scripts/Interfaces/INodeGraph.cs.meta
Normal file
11
Scripts/Interfaces/INodeGraph.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: e5821d1c7c3ead04c8da1e04ed850a3c
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -23,7 +23,7 @@ namespace XNode {
|
|||||||
/// </code>
|
/// </code>
|
||||||
/// </example>
|
/// </example>
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public abstract class Node : ScriptableObject {
|
public abstract class Node : ScriptableObject, XNode.INode {
|
||||||
/// <summary> Used by <see cref="InputAttribute"/> and <see cref="OutputAttribute"/> to determine when to display the field value associated with a <see cref="NodePort"/> </summary>
|
/// <summary> Used by <see cref="InputAttribute"/> and <see cref="OutputAttribute"/> to determine when to display the field value associated with a <see cref="NodePort"/> </summary>
|
||||||
public enum ShowBackingValue {
|
public enum ShowBackingValue {
|
||||||
/// <summary> Never show the backing value </summary>
|
/// <summary> Never show the backing value </summary>
|
||||||
@ -105,7 +105,9 @@ namespace XNode {
|
|||||||
/// <summary> Iterate over all dynamic inputs on this node. </summary>
|
/// <summary> Iterate over all dynamic inputs on this node. </summary>
|
||||||
public IEnumerable<NodePort> DynamicInputs { get { foreach (NodePort port in Ports) { if (port.IsDynamic && port.IsInput) yield return port; } } }
|
public IEnumerable<NodePort> DynamicInputs { get { foreach (NodePort port in Ports) { if (port.IsDynamic && port.IsInput) yield return port; } } }
|
||||||
/// <summary> Parent <see cref="NodeGraph"/> </summary>
|
/// <summary> Parent <see cref="NodeGraph"/> </summary>
|
||||||
[SerializeField] public NodeGraph graph;
|
public NodeGraph Graph { get { return graph; } }
|
||||||
|
/// <summary> Parent <see cref="NodeGraph"/> </summary>
|
||||||
|
[SerializeField] private NodeGraph graph;
|
||||||
/// <summary> Position on the <see cref="NodeGraph"/> </summary>
|
/// <summary> Position on the <see cref="NodeGraph"/> </summary>
|
||||||
[SerializeField] public Vector2 position;
|
[SerializeField] public Vector2 position;
|
||||||
/// <summary> It is recommended not to modify these at hand. Instead, see <see cref="InputAttribute"/> and <see cref="OutputAttribute"/> </summary>
|
/// <summary> It is recommended not to modify these at hand. Instead, see <see cref="InputAttribute"/> and <see cref="OutputAttribute"/> </summary>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user