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

Added FlowNode abstract classes

This commit is contained in:
Oli 2023-01-09 21:35:40 +00:00
parent 8ecea0c636
commit a44b58b19a
7 changed files with 106 additions and 1 deletions

3
Editor/Flow.meta Normal file
View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 1e14c6504b4b4601bb79db0271af5e61
timeCreated: 1673299690

View File

@ -0,0 +1,15 @@

using XNode.Flow;
namespace XNodeEditor.Flow
{
[CustomNodeEditor(typeof(FlowNode))]
public class FlowNodeEditor : NodeEditor
{
public override void OnBodyGUI()
{
NodeEditorGUILayout.PortPair(target.GetPort("previousNode"), target.GetPort("nextNode"));
base.OnBodyGUI();
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: efc69c086ec342a8b6aef9ff7ad81f5b
timeCreated: 1673299707

View File

@ -6,6 +6,7 @@ using System.Reflection;
using UnityEditor;
using UnityEditorInternal;
using UnityEngine;
using XNode.Flow;
namespace XNodeEditor {
/// <summary> xNode-specific version of <see cref="EditorGUILayout"/> </summary>
@ -194,7 +195,8 @@ namespace XNodeEditor {
if (port == null) return;
if (options == null) options = new GUILayoutOption[] { GUILayout.MinWidth(30) };
Vector2 position = Vector3.zero;
GUIContent content = label != null ? label : new GUIContent(ObjectNames.NicifyVariableName(port.fieldName));
GUIContent content = label ?? new GUIContent(ObjectNames.NicifyVariableName(port.fieldName));
if (label == null && port.ValueType.IsAssignableFrom(typeof(FlowNode))) content = EditorGUIUtility.TrIconContent("Animation.Play", content.text);
// If property is an input, display a regular property field and put a port handle on the left side
if (port.direction == XNode.NodePort.IO.Input) {

8
Runtime/Flow.meta Normal file
View File

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

71
Runtime/Flow/FlowNode.cs Normal file
View File

@ -0,0 +1,71 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace XNode.Flow
{
public abstract class FlowNode : Node
{
public override object GetValue(NodePort port)
{
if (port.IsConnected && port.Connection.node is FlowNode flowNode) return flowNode;
return null;
}
public virtual IEnumerator Perform()
{
yield break;
}
public virtual IEnumerable<FlowNode> PreviousNodes => Array.Empty<FlowNode>();
public virtual IEnumerable<FlowNode> NextNodes => Array.Empty<FlowNode>();
public FlowNode GetFlowNode(string portName) => GetValue(GetPort(portName)) as FlowNode;
}
public abstract class InFlowNode : FlowNode
{
[Input(ShowBackingValue.Never, ConnectionType.Multiple, TypeConstraint.Inherited)]
[SerializeField, HideInInspector]
public FlowNode previousNode;
public override IEnumerable<FlowNode> PreviousNodes
{
get { yield return GetFlowNode("previousNodes"); }
}
}
public abstract class OutFlowNode : FlowNode
{
[Output(ShowBackingValue.Never, ConnectionType.Multiple, TypeConstraint.Inherited)]
[SerializeField, HideInInspector]
public FlowNode nextNode;
public override IEnumerable<FlowNode> NextNodes
{
get { yield return GetFlowNode("nextNode"); }
}
}
public abstract class InOutFlowNode : FlowNode
{
[Input(ShowBackingValue.Never, ConnectionType.Multiple, TypeConstraint.Inherited)]
[SerializeField, HideInInspector]
public FlowNode previousNode;
[Output(ShowBackingValue.Never, ConnectionType.Multiple, TypeConstraint.Inherited)]
[SerializeField, HideInInspector]
public FlowNode nextNode;
public override IEnumerable<FlowNode> PreviousNodes
{
get { yield return GetFlowNode("previousNodes"); }
}
public override IEnumerable<FlowNode> NextNodes
{
get { yield return GetFlowNode("nextNode"); }
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 19577700addb44bfbe0004ed13078931
timeCreated: 1673298639