diff --git a/Source/Editor/Surface/Archetypes/Tools.cs b/Source/Editor/Surface/Archetypes/Tools.cs index 645a243f6..5c729a41c 100644 --- a/Source/Editor/Surface/Archetypes/Tools.cs +++ b/Source/Editor/Surface/Archetypes/Tools.cs @@ -1441,7 +1441,7 @@ namespace FlaxEditor.Surface.Archetypes Title = "As", Create = (id, context, arch, groupArch) => new AsNode(id, context, arch, groupArch), Description = "Casts the object to a different type. Returns null if cast fails.", - Flags = NodeFlags.VisualScriptGraph, + Flags = NodeFlags.VisualScriptGraph | NodeFlags.AnimGraph, Size = new Vector2(200, 20), DefaultValues = new object[] { @@ -1459,7 +1459,7 @@ namespace FlaxEditor.Surface.Archetypes Title = "Type Reference", Create = (id, context, arch, groupArch) => new TypeReferenceNode(id, context, arch, groupArch), Description = "Scripting type picker.", - Flags = NodeFlags.VisualScriptGraph, + Flags = NodeFlags.VisualScriptGraph | NodeFlags.AnimGraph, Size = new Vector2(200, 40), DefaultValues = new object[] { @@ -1477,7 +1477,7 @@ namespace FlaxEditor.Surface.Archetypes Title = "Is", Create = (id, context, arch, groupArch) => new IsNode(id, context, arch, groupArch), Description = "Checks if the object is of the given type. Return true if so, false otherwise.", - Flags = NodeFlags.VisualScriptGraph, + Flags = NodeFlags.VisualScriptGraph | NodeFlags.AnimGraph, Size = new Vector2(200, 20), DefaultValues = new object[] { @@ -1536,7 +1536,7 @@ namespace FlaxEditor.Surface.Archetypes TypeID = 27, Title = "Is Null", Description = "Checks if the object is null. Return false if it's valid.", - Flags = NodeFlags.VisualScriptGraph, + Flags = NodeFlags.VisualScriptGraph | NodeFlags.AnimGraph, Size = new Vector2(150, 20), Elements = new[] { @@ -1549,7 +1549,7 @@ namespace FlaxEditor.Surface.Archetypes TypeID = 28, Title = "Is Valid", Description = "Checks if the object is valid. Return false if it's null.", - Flags = NodeFlags.VisualScriptGraph, + Flags = NodeFlags.VisualScriptGraph | NodeFlags.AnimGraph, Size = new Vector2(150, 20), Elements = new[] { diff --git a/Source/Engine/Content/Assets/VisualScript.cpp b/Source/Engine/Content/Assets/VisualScript.cpp index 8b5a0c62e..59c84741f 100644 --- a/Source/Engine/Content/Assets/VisualScript.cpp +++ b/Source/Engine/Content/Assets/VisualScript.cpp @@ -432,51 +432,8 @@ void VisualScriptExecutor::ProcessGroupTools(Box* box, Node* node, Value& value) { // This Instance case 19: - { value = ThreadStacks.Get().Stack->Instance; break; - } - // As - case 22: - { - value = Value::Null; - const auto obj = (ScriptingObject*)tryGetValue(node->GetBox(1), Value::Null); - if (obj) - { - const StringView typeName(node->Values[0]); - const StringAsANSI<100> typeNameAnsi(typeName.Get(), typeName.Length()); - const ScriptingTypeHandle typeHandle = Scripting::FindScriptingType(StringAnsiView(typeNameAnsi.Get(), typeName.Length())); - const auto objClass = obj->GetClass(); - if (typeHandle && objClass && objClass->IsSubClassOf(typeHandle.GetType().ManagedClass)) - value = obj; - } - break; - } - // Type Reference node - case 23: - { - const StringView typeName(node->Values[0]); - if (box->ID == 0) - value.SetTypename(typeName); - else - value = typeName; - break; - } - // Is - case 24: - { - value = Value::False; - const auto obj = (ScriptingObject*)tryGetValue(node->GetBox(1), Value::Null); - if (obj) - { - const StringView typeName(node->Values[0]); - const StringAsANSI<100> typeNameAnsi(typeName.Get(), typeName.Length()); - const ScriptingTypeHandle typeHandle = Scripting::FindScriptingType(StringAnsiView(typeNameAnsi.Get(), typeName.Length())); - const auto objClass = obj->GetClass(); - value.AsBool = typeHandle && objClass && objClass->IsSubClassOf(typeHandle.GetType().ManagedClass); - } - break; - } // Cast case 25: { @@ -596,14 +553,6 @@ void VisualScriptExecutor::ProcessGroupTools(Box* box, Node* node, Value& value) } break; } - // Is Null - case 27: - value = (void*)tryGetValue(node->GetBox(1), Value::Null) == nullptr; - break; - // Is Valid - case 28: - value = (void*)tryGetValue(node->GetBox(1), Value::Null) != nullptr; - break; default: VisjectExecutor::ProcessGroupTools(box, node, value); break; diff --git a/Source/Engine/Visject/ShaderGraph.cpp b/Source/Engine/Visject/ShaderGraph.cpp index 59904135b..a15f87df1 100644 --- a/Source/Engine/Visject/ShaderGraph.cpp +++ b/Source/Engine/Visject/ShaderGraph.cpp @@ -771,11 +771,10 @@ void ShaderGenerator::ProcessGroupTools(Box* box, Node* node, Value& value) #undef PLATFORM_CASE break; } + // Reroute case 29: - { value = tryGetValue(node->GetBox(0), Value::Zero); break; - } default: break; } diff --git a/Source/Engine/Visject/VisjectGraph.cpp b/Source/Engine/Visject/VisjectGraph.cpp index fcba6c8b7..4030c2520 100644 --- a/Source/Engine/Visject/VisjectGraph.cpp +++ b/Source/Engine/Visject/VisjectGraph.cpp @@ -8,6 +8,8 @@ #include "Engine/Engine/GameplayGlobals.h" #include "Engine/Scripting/Scripting.h" #include "Engine/Level/Actor.h" +#include "Engine/Scripting/ManagedCLR/MClass.h" +#include "Engine/Utilities/StringConverter.h" #define RAND Random::Rand() @@ -374,13 +376,13 @@ void VisjectExecutor::ProcessGroupMath(Box* box, Node* node, Value& value) // Remap case 48: { - const float inVal = tryGetValue(node->GetBox(0), node->Values[0]).AsFloat; + const float inVal = tryGetValue(node->GetBox(0), node->Values[0]).AsFloat; const Vector2 rangeA = tryGetValue(node->GetBox(1), node->Values[1]).AsVector2(); const Vector2 rangeB = tryGetValue(node->GetBox(2), node->Values[2]).AsVector2(); const bool clamp = tryGetValue(node->GetBox(3), node->Values[3]).AsBool; auto mapFunc = Math::Remap(inVal, rangeA.X, rangeA.Y, rangeB.X, rangeB.Y); - + value = clamp ? Math::Clamp(mapFunc, rangeB.X, rangeB.Y) : mapFunc; break; } @@ -673,9 +675,7 @@ void VisjectExecutor::ProcessGroupTools(Box* box, Node* node, Value& value) #undef SETUP_CURVE // Get Gameplay Global case 16: - { - const auto asset = node->Assets[0].As(); - if (asset) + if (const auto asset = node->Assets[0].As()) { const StringView& name = (StringView)node->Values[1]; const auto e = asset->Variables.Find(name); @@ -686,7 +686,6 @@ void VisjectExecutor::ProcessGroupTools(Box* box, Node* node, Value& value) value = Value::Zero; } break; - } // Platform Switch case 17: { @@ -724,28 +723,69 @@ void VisjectExecutor::ProcessGroupTools(Box* box, Node* node, Value& value) } // Asset Reference case 18: - { value = ::LoadAsset((Guid)node->Values[0], Asset::TypeInitializer); break; - } // To String case 20: - { value.SetString(tryGetValue(node->GetBox(1), Value(StringView::Empty)).ToString()); break; - } // Actor Reference case 21: - { value = Scripting::FindObject((Guid)node->Values[0]); break; - } - - case 29: + // As + case 22: { - value = tryGetValue(node->GetBox(0), Value::Zero); + value = Value::Null; + const auto obj = (ScriptingObject*)tryGetValue(node->GetBox(1), Value::Null); + if (obj) + { + const StringView typeName(node->Values[0]); + const StringAsANSI<100> typeNameAnsi(typeName.Get(), typeName.Length()); + const ScriptingTypeHandle typeHandle = Scripting::FindScriptingType(StringAnsiView(typeNameAnsi.Get(), typeName.Length())); + const auto objClass = obj->GetClass(); + if (typeHandle && objClass && objClass->IsSubClassOf(typeHandle.GetType().ManagedClass)) + value = obj; + } break; } + // Type Reference node + case 23: + { + const StringView typeName(node->Values[0]); + if (box->ID == 0) + value.SetTypename(typeName); + else + value = typeName; + break; + } + // Is + case 24: + { + value = Value::False; + const auto obj = (ScriptingObject*)tryGetValue(node->GetBox(1), Value::Null); + if (obj) + { + const StringView typeName(node->Values[0]); + const StringAsANSI<100> typeNameAnsi(typeName.Get(), typeName.Length()); + const ScriptingTypeHandle typeHandle = Scripting::FindScriptingType(StringAnsiView(typeNameAnsi.Get(), typeName.Length())); + const auto objClass = obj->GetClass(); + value.AsBool = typeHandle && objClass && objClass->IsSubClassOf(typeHandle.GetType().ManagedClass); + } + break; + } + // Is Null + case 27: + value = (void*)tryGetValue(node->GetBox(1), Value::Null) == nullptr; + break; + // Is Valid + case 28: + value = (void*)tryGetValue(node->GetBox(1), Value::Null) != nullptr; + break; + // Reroute + case 29: + value = tryGetValue(node->GetBox(0), Value::Zero); + break; default: break; }