From 3d76b2c10f21627090ba96cd6cf269549e869c1c Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Wed, 13 Apr 2022 21:25:11 +0200 Subject: [PATCH] Add `Array Add Unique` node to Visual Scripting --- .../Editor/Surface/Archetypes/Collections.cs | 18 ++++++++++++++++++ Source/Engine/Visject/VisjectGraph.cpp | 7 +++++++ 2 files changed, 25 insertions(+) diff --git a/Source/Editor/Surface/Archetypes/Collections.cs b/Source/Editor/Surface/Archetypes/Collections.cs index 72f76825c..d09b02a69 100644 --- a/Source/Editor/Surface/Archetypes/Collections.cs +++ b/Source/Editor/Surface/Archetypes/Collections.cs @@ -258,6 +258,24 @@ namespace FlaxEditor.Surface.Archetypes NodeElementArchetype.Factory.Output(0, string.Empty, null, 1) } }, + new NodeArchetype + { + TypeID = 14, + Title = "Array Add Unique", + Description = "Adds the unique item to the array (to the end). Does nothing it specified item was already added.", + Flags = NodeFlags.VisualScriptGraph | NodeFlags.AnimGraph, + Size = new Vector2(170, 40), + ConnectionsHints = ConnectionsHint.Array, + IndependentBoxes = new int[] { 0 }, + DependentBoxes = new int[] { 1, 2 }, + DependentBoxFilter = GetArrayItemType, + Elements = new[] + { + NodeElementArchetype.Factory.Input(0, "Array", true, null, 0), + NodeElementArchetype.Factory.Input(1, "Item", true, typeof(object), 1), + NodeElementArchetype.Factory.Output(0, string.Empty, null, 2) + } + }, // first 100 IDs reserved for arrays }; } diff --git a/Source/Engine/Visject/VisjectGraph.cpp b/Source/Engine/Visject/VisjectGraph.cpp index df5d56fec..3f6fd60c4 100644 --- a/Source/Engine/Visject/VisjectGraph.cpp +++ b/Source/Engine/Visject/VisjectGraph.cpp @@ -1344,6 +1344,13 @@ void VisjectExecutor::ProcessGroupCollections(Box* box, Node* node, Value& value array.Reverse(); value = MoveTemp(v); break; + // Add Unique + case 14: + b = node->GetBox(1); + ENSURE(b->HasConnection(), TEXT("Missing value to add.")); + array.AddUnique(eatBox(b->GetParent(), b->FirstConnection())); + value = MoveTemp(v); + break; } } }