- Added custom func to fetch information for nodes that need special treatment like Array, Enum or Un/Pack nodes
- More refactoring and cleanup
This commit is contained in:
@@ -7,6 +7,8 @@ using Real = System.Single;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using FlaxEditor.CustomEditors.Editors;
|
using FlaxEditor.CustomEditors.Editors;
|
||||||
using FlaxEditor.GUI;
|
using FlaxEditor.GUI;
|
||||||
@@ -182,6 +184,13 @@ namespace FlaxEditor.Surface.Archetypes
|
|||||||
|
|
||||||
base.OnDestroy();
|
base.OnDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static void GetInputOutputDescription(NodeArchetype nodeArch, out (string, ScriptType)[] inputs, out (string, ScriptType)[] outputs)
|
||||||
|
{
|
||||||
|
var type = new ScriptType(nodeArch.DefaultValues[0].GetType());
|
||||||
|
inputs = null;
|
||||||
|
outputs = [(type.Name, type)];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ArrayNode : SurfaceNode
|
private class ArrayNode : SurfaceNode
|
||||||
@@ -321,6 +330,12 @@ namespace FlaxEditor.Surface.Archetypes
|
|||||||
array.SetValue(value, box.ID - 1);
|
array.SetValue(value, box.ID - 1);
|
||||||
SetValue(0, array);
|
SetValue(0, array);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static void GetInputOutputDescription(NodeArchetype nodeArch, out (string, ScriptType)[] inputs, out (string, ScriptType)[] outputs)
|
||||||
|
{
|
||||||
|
inputs = null;
|
||||||
|
outputs = [("", new ScriptType(typeof(Array)))];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class DictionaryNode : SurfaceNode
|
private class DictionaryNode : SurfaceNode
|
||||||
@@ -449,6 +464,12 @@ namespace FlaxEditor.Surface.Archetypes
|
|||||||
array.SetValue(value, box.ID - 1);
|
array.SetValue(value, box.ID - 1);
|
||||||
SetValue(0, array);
|
SetValue(0, array);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static void GetInputOutputDescription(NodeArchetype nodeArch, out (string, ScriptType)[] inputs, out (string, ScriptType)[] outputs)
|
||||||
|
{
|
||||||
|
inputs = null;
|
||||||
|
outputs = [("", new ScriptType(typeof(Dictionary<int, string>)))];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -743,6 +764,7 @@ namespace FlaxEditor.Surface.Archetypes
|
|||||||
Title = "Enum",
|
Title = "Enum",
|
||||||
Create = (id, context, arch, groupArch) => new EnumNode(id, context, arch, groupArch),
|
Create = (id, context, arch, groupArch) => new EnumNode(id, context, arch, groupArch),
|
||||||
Description = "Enum constant value.",
|
Description = "Enum constant value.",
|
||||||
|
GetInputOutputDescription = EnumNode.GetInputOutputDescription,
|
||||||
Flags = NodeFlags.VisualScriptGraph | NodeFlags.AnimGraph | NodeFlags.NoSpawnViaGUI,
|
Flags = NodeFlags.VisualScriptGraph | NodeFlags.AnimGraph | NodeFlags.NoSpawnViaGUI,
|
||||||
Size = new Float2(180, 20),
|
Size = new Float2(180, 20),
|
||||||
DefaultValues = new object[]
|
DefaultValues = new object[]
|
||||||
@@ -779,6 +801,7 @@ namespace FlaxEditor.Surface.Archetypes
|
|||||||
Title = "Array",
|
Title = "Array",
|
||||||
Create = (id, context, arch, groupArch) => new ArrayNode(id, context, arch, groupArch),
|
Create = (id, context, arch, groupArch) => new ArrayNode(id, context, arch, groupArch),
|
||||||
Description = "Constant array value.",
|
Description = "Constant array value.",
|
||||||
|
GetInputOutputDescription = ArrayNode.GetInputOutputDescription,
|
||||||
Flags = NodeFlags.VisualScriptGraph | NodeFlags.AnimGraph,
|
Flags = NodeFlags.VisualScriptGraph | NodeFlags.AnimGraph,
|
||||||
Size = new Float2(150, 20),
|
Size = new Float2(150, 20),
|
||||||
DefaultValues = new object[] { new int[] { 0, 1, 2 } },
|
DefaultValues = new object[] { new int[] { 0, 1, 2 } },
|
||||||
@@ -790,6 +813,7 @@ namespace FlaxEditor.Surface.Archetypes
|
|||||||
Title = "Dictionary",
|
Title = "Dictionary",
|
||||||
Create = (id, context, arch, groupArch) => new DictionaryNode(id, context, arch, groupArch),
|
Create = (id, context, arch, groupArch) => new DictionaryNode(id, context, arch, groupArch),
|
||||||
Description = "Creates an empty dictionary.",
|
Description = "Creates an empty dictionary.",
|
||||||
|
GetInputOutputDescription = DictionaryNode.GetInputOutputDescription,
|
||||||
Flags = NodeFlags.VisualScriptGraph | NodeFlags.AnimGraph,
|
Flags = NodeFlags.VisualScriptGraph | NodeFlags.AnimGraph,
|
||||||
Size = new Float2(150, 40),
|
Size = new Float2(150, 40),
|
||||||
DefaultValues = new object[] { typeof(int).FullName, typeof(string).FullName },
|
DefaultValues = new object[] { typeof(int).FullName, typeof(string).FullName },
|
||||||
|
|||||||
@@ -245,6 +245,21 @@ namespace FlaxEditor.Surface.Archetypes
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static void GetInputOutputDescription(NodeArchetype nodeArch, out (string, ScriptType)[] inputs, out (string, ScriptType)[] outputs)
|
||||||
|
{
|
||||||
|
var type = TypeUtils.GetType((string)nodeArch.DefaultValues[0]);
|
||||||
|
outputs = [(type.Name, type)];
|
||||||
|
|
||||||
|
var fields = type.GetMembers(BindingFlags.Public | BindingFlags.Instance).Where(x => x.IsField).ToArray();
|
||||||
|
var fieldsLength = fields.Length;
|
||||||
|
inputs = new (string, ScriptType)[fieldsLength];
|
||||||
|
for (var i = 0; i < fieldsLength; i++)
|
||||||
|
{
|
||||||
|
var field = fields[i];
|
||||||
|
inputs[i] = (field.Name, field.ValueType);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private sealed class UnpackStructureNode : StructureNode
|
private sealed class UnpackStructureNode : StructureNode
|
||||||
@@ -283,6 +298,21 @@ namespace FlaxEditor.Surface.Archetypes
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static void GetInputOutputDescription(NodeArchetype nodeArch, out (string, ScriptType)[] inputs, out (string, ScriptType)[] outputs)
|
||||||
|
{
|
||||||
|
var type = TypeUtils.GetType((string)nodeArch.DefaultValues[0]);
|
||||||
|
inputs = [(type.Name, type)];
|
||||||
|
|
||||||
|
var fields = type.GetMembers(BindingFlags.Public | BindingFlags.Instance).Where(x => x.IsField).ToArray();
|
||||||
|
var fieldsLength = fields.Length;
|
||||||
|
outputs = new (string, ScriptType)[fieldsLength];
|
||||||
|
for (var i = 0; i < fieldsLength; i++)
|
||||||
|
{
|
||||||
|
var field = fields[i];
|
||||||
|
outputs[i] = (field.Name, field.ValueType);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -411,6 +441,7 @@ namespace FlaxEditor.Surface.Archetypes
|
|||||||
Create = (id, context, arch, groupArch) => new PackStructureNode(id, context, arch, groupArch),
|
Create = (id, context, arch, groupArch) => new PackStructureNode(id, context, arch, groupArch),
|
||||||
IsInputCompatible = PackStructureNode.IsInputCompatible,
|
IsInputCompatible = PackStructureNode.IsInputCompatible,
|
||||||
IsOutputCompatible = PackStructureNode.IsOutputCompatible,
|
IsOutputCompatible = PackStructureNode.IsOutputCompatible,
|
||||||
|
GetInputOutputDescription = PackStructureNode.GetInputOutputDescription,
|
||||||
Description = "Makes the structure data to from the components.",
|
Description = "Makes the structure data to from the components.",
|
||||||
Flags = NodeFlags.VisualScriptGraph | NodeFlags.AnimGraph | NodeFlags.NoSpawnViaGUI,
|
Flags = NodeFlags.VisualScriptGraph | NodeFlags.AnimGraph | NodeFlags.NoSpawnViaGUI,
|
||||||
Size = new Float2(180, 20),
|
Size = new Float2(180, 20),
|
||||||
@@ -523,6 +554,7 @@ namespace FlaxEditor.Surface.Archetypes
|
|||||||
Create = (id, context, arch, groupArch) => new UnpackStructureNode(id, context, arch, groupArch),
|
Create = (id, context, arch, groupArch) => new UnpackStructureNode(id, context, arch, groupArch),
|
||||||
IsInputCompatible = UnpackStructureNode.IsInputCompatible,
|
IsInputCompatible = UnpackStructureNode.IsInputCompatible,
|
||||||
IsOutputCompatible = UnpackStructureNode.IsOutputCompatible,
|
IsOutputCompatible = UnpackStructureNode.IsOutputCompatible,
|
||||||
|
GetInputOutputDescription = UnpackStructureNode.GetInputOutputDescription,
|
||||||
Description = "Breaks the structure data to allow extracting components from it.",
|
Description = "Breaks the structure data to allow extracting components from it.",
|
||||||
Flags = NodeFlags.VisualScriptGraph | NodeFlags.AnimGraph | NodeFlags.NoSpawnViaGUI,
|
Flags = NodeFlags.VisualScriptGraph | NodeFlags.AnimGraph | NodeFlags.NoSpawnViaGUI,
|
||||||
Size = new Float2(180, 20),
|
Size = new Float2(180, 20),
|
||||||
|
|||||||
@@ -663,13 +663,10 @@ namespace FlaxEditor.Surface.ContextMenu
|
|||||||
|
|
||||||
Profiler.BeginEvent("VisjectCM.SetDescriptionPanelArchetype");
|
Profiler.BeginEvent("VisjectCM.SetDescriptionPanelArchetype");
|
||||||
|
|
||||||
ScriptType declaringType;
|
|
||||||
string elementName, elementTypeName;
|
|
||||||
|
|
||||||
_descriptionInputPanel.RemoveChildren();
|
_descriptionInputPanel.RemoveChildren();
|
||||||
_descriptionOutputPanel.RemoveChildren();
|
_descriptionOutputPanel.RemoveChildren();
|
||||||
|
|
||||||
|
ScriptType declaringType;
|
||||||
if (archetype.Tag is ScriptMemberInfo memberInfo)
|
if (archetype.Tag is ScriptMemberInfo memberInfo)
|
||||||
{
|
{
|
||||||
var name = memberInfo.Name;
|
var name = memberInfo.Name;
|
||||||
@@ -710,24 +707,25 @@ namespace FlaxEditor.Surface.ContextMenu
|
|||||||
declaringType = archetype.DefaultType;
|
declaringType = archetype.DefaultType;
|
||||||
|
|
||||||
// Special handling for Pack nodes
|
// Special handling for Pack nodes
|
||||||
if (archetype == Packing.Nodes[6] || archetype == Packing.Nodes[13])
|
if (archetype.GetInputOutputDescription != null)
|
||||||
{
|
{
|
||||||
bool isOutput = archetype == Packing.Nodes[6];
|
archetype.GetInputOutputDescription.Invoke(archetype, out (string, ScriptType)[] inputs, out (string, ScriptType)[] outputs);
|
||||||
var type = TypeUtils.GetType((string)archetype.DefaultValues[0]);
|
|
||||||
AddInputOutputElement(archetype, type, isOutput, $"{type.Name}");
|
if (inputs != null)
|
||||||
|
|
||||||
var fields = type.GetMembers(BindingFlags.Public | BindingFlags.Instance).Where(x => x.IsField).ToArray();
|
|
||||||
var fieldsLength = fields.Length;
|
|
||||||
for (var i = 0; i < fieldsLength; i++)
|
|
||||||
{
|
{
|
||||||
var field = fields[i];
|
for (int i = 0; i < inputs.Length; i++)
|
||||||
AddInputOutputElement(archetype, field.ValueType, !isOutput, $"{field.Name} ({field.ValueType.Name})");
|
{
|
||||||
|
AddInputOutputElement(archetype, inputs[i].Item2, false, $"{inputs[i].Item1} ({inputs[i].Item2.Name})");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (outputs != null)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < outputs.Length; i++)
|
||||||
|
{
|
||||||
|
AddInputOutputElement(archetype, outputs[i].Item2, true, $"{outputs[i].Item1} ({outputs[i].Item2.Name})");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else if (archetype == Archetypes.Constants.Nodes[10])
|
|
||||||
{
|
|
||||||
var t = new ScriptType(archetype.DefaultValues[0].GetType());
|
|
||||||
AddInputOutputElement(archetype, t, true, $"ENUM {t.Name}");
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -737,17 +735,9 @@ namespace FlaxEditor.Surface.ContextMenu
|
|||||||
{
|
{
|
||||||
bool isOutput = element.Type == NodeElementType.Output;
|
bool isOutput = element.Type == NodeElementType.Output;
|
||||||
if (element.ConnectionsType == null)
|
if (element.ConnectionsType == null)
|
||||||
{
|
AddInputOutputElement(archetype, element.ConnectionsType, isOutput, $"-{element.Text} ({archetype.ConnectionsHints.ToString()})");
|
||||||
if(archetype == Archetypes.Constants.Nodes[12])
|
else
|
||||||
AddInputOutputElement(archetype, element.ConnectionsType, isOutput, $"-{element.Text} ({ConnectionsHint.Array.ToString()})");
|
AddInputOutputElement(archetype, element.ConnectionsType, isOutput, $"-{element.Text} ({element.ConnectionsType.Name})");
|
||||||
else if (archetype == Archetypes.Constants.Nodes[13])
|
|
||||||
AddInputOutputElement(archetype, element.ConnectionsType, isOutput, $"-{element.Text} ({ConnectionsHint.Dictionary.ToString()})");
|
|
||||||
else
|
|
||||||
AddInputOutputElement(archetype, element.ConnectionsType, isOutput, $"-{element.Text} ({archetype.ConnectionsHints.ToString()})");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
AddInputOutputElement(archetype, element.ConnectionsType, isOutput, $"-{element.Text} ({element.ConnectionsType.Name})");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -90,10 +90,15 @@ namespace FlaxEditor.Surface
|
|||||||
public delegate SurfaceNode CreateCustomNodeFunc(uint id, VisjectSurfaceContext context, NodeArchetype nodeArch, GroupArchetype groupArch);
|
public delegate SurfaceNode CreateCustomNodeFunc(uint id, VisjectSurfaceContext context, NodeArchetype nodeArch, GroupArchetype groupArch);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Checks if the given type is compatible with the given node archetype. Used for custom nodes
|
/// Checks if the given type is compatible with the given node archetype. Used for custom nodes.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public delegate bool IsCompatible(NodeArchetype nodeArch, ScriptType portType, ConnectionsHint hint, VisjectSurfaceContext context);
|
public delegate bool IsCompatible(NodeArchetype nodeArch, ScriptType portType, ConnectionsHint hint, VisjectSurfaceContext context);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets description of inputs and outputs of the archetype. Used for special cases for the description panel.
|
||||||
|
/// </summary>
|
||||||
|
public delegate void GetElementsDescriptionFunc(NodeArchetype nodeArch, out (string, ScriptType)[] inputs, out (string, ScriptType)[] outputs);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Unique node type ID within a single group.
|
/// Unique node type ID within a single group.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -144,6 +149,11 @@ namespace FlaxEditor.Surface
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string Description;
|
public string Description;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Custom function to get descriptions of input and output elements. Used for description panel (optional).
|
||||||
|
/// </summary>
|
||||||
|
public GetElementsDescriptionFunc GetInputOutputDescription;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Alternative node titles.
|
/// Alternative node titles.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -217,6 +227,7 @@ namespace FlaxEditor.Surface
|
|||||||
SubTitle = SubTitle,
|
SubTitle = SubTitle,
|
||||||
Signature = Signature,
|
Signature = Signature,
|
||||||
Description = Description,
|
Description = Description,
|
||||||
|
GetInputOutputDescription = GetInputOutputDescription,
|
||||||
AlternativeTitles = (string[])AlternativeTitles?.Clone(),
|
AlternativeTitles = (string[])AlternativeTitles?.Clone(),
|
||||||
Tag = Tag,
|
Tag = Tag,
|
||||||
SortScore = SortScore,
|
SortScore = SortScore,
|
||||||
|
|||||||
Reference in New Issue
Block a user