diff --git a/Source/Editor/Editor.cs b/Source/Editor/Editor.cs index d549bb907..70f52268c 100644 --- a/Source/Editor/Editor.cs +++ b/Source/Editor/Editor.cs @@ -1306,22 +1306,6 @@ namespace FlaxEditor VisualScriptingDebugFlow?.Invoke(debugFlow); } - [StructLayout(LayoutKind.Sequential)] - internal struct AnimGraphDebugFlowInfo - { - public Asset Asset; - public FlaxEngine.Object Object; - public uint NodeId; - public int BoxId; - } - - internal static event Action AnimGraphDebugFlow; - - internal static void Internal_OnAnimGraphDebugFlow(ref AnimGraphDebugFlowInfo debugFlow) - { - AnimGraphDebugFlow?.Invoke(debugFlow); - } - private static void RequestStartPlayOnEditMode() { if (Instance.StateMachine.IsEditMode) diff --git a/Source/Editor/Managed/ManagedEditor.cpp b/Source/Editor/Managed/ManagedEditor.cpp index 18a905d4b..6a83ceeb5 100644 --- a/Source/Editor/Managed/ManagedEditor.cpp +++ b/Source/Editor/Managed/ManagedEditor.cpp @@ -34,7 +34,6 @@ MMethod* Internal_GetGameWinPtr = nullptr; MMethod* Internal_GetGameWindowSize = nullptr; MMethod* Internal_OnAppExit = nullptr; MMethod* Internal_OnVisualScriptingDebugFlow = nullptr; -MMethod* Internal_OnAnimGraphDebugFlow = nullptr; MMethod* Internal_RequestStartPlayOnEditMode = nullptr; void OnLightmapsBake(ShadowsOfMordor::BuildProgressStep step, float stepProgress, float totalProgress, bool isProgressEvent) @@ -138,38 +137,6 @@ void OnVisualScriptingDebugFlow() } } -struct AnimGraphDebugFlowInfo -{ - MonoObject* Asset; - MonoObject* Object; - uint32 NodeId; - int32 BoxId; -}; - -void OnAnimGraphDebugFlow(Asset* asset, ScriptingObject* object, uint32 nodeId, uint32 boxId) -{ - if (Internal_OnAnimGraphDebugFlow == nullptr) - { - Internal_OnAnimGraphDebugFlow = ManagedEditor::GetStaticClass()->GetMethod("Internal_OnAnimGraphDebugFlow", 1); - ASSERT(Internal_OnAnimGraphDebugFlow); - } - - AnimGraphDebugFlowInfo flowInfo; - flowInfo.Asset = asset ? asset->GetOrCreateManagedInstance() : nullptr; - flowInfo.Object = object ? object->GetOrCreateManagedInstance() : nullptr; - flowInfo.NodeId = nodeId; - flowInfo.BoxId = boxId; - MonoObject* exception = nullptr; - void* params[1]; - params[0] = &flowInfo; - Internal_OnAnimGraphDebugFlow->Invoke(nullptr, params, &exception); - if (exception) - { - MException ex(exception); - ex.Log(LogType::Error, TEXT("OnAnimGraphDebugFlow")); - } -} - void OnLogMessage(LogType type, const StringView& msg); ManagedEditor::ManagedEditor() @@ -187,7 +154,6 @@ ManagedEditor::ManagedEditor() CSG::Builder::OnBrushModified.Bind(); Log::Logger::OnMessage.Bind(); VisualScripting::DebugFlow.Bind(); - AnimGraphExecutor::DebugFlow.Bind(); } ManagedEditor::~ManagedEditor() @@ -204,7 +170,6 @@ ManagedEditor::~ManagedEditor() CSG::Builder::OnBrushModified.Unbind(); Log::Logger::OnMessage.Unbind(); VisualScripting::DebugFlow.Unbind(); - AnimGraphExecutor::DebugFlow.Unbind(); } void ManagedEditor::Init() @@ -530,7 +495,6 @@ void ManagedEditor::DestroyManaged() Internal_GetGameWinPtr = nullptr; Internal_OnAppExit = nullptr; Internal_OnVisualScriptingDebugFlow = nullptr; - Internal_OnAnimGraphDebugFlow = nullptr; // Base PersistentScriptingObject::DestroyManaged(); diff --git a/Source/Editor/Windows/Assets/AnimationGraphWindow.cs b/Source/Editor/Windows/Assets/AnimationGraphWindow.cs index 634202061..603fc6c7c 100644 --- a/Source/Editor/Windows/Assets/AnimationGraphWindow.cs +++ b/Source/Editor/Windows/Assets/AnimationGraphWindow.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; +using System.Runtime.InteropServices; using FlaxEditor.Content; using FlaxEditor.CustomEditors; using FlaxEditor.CustomEditors.Editors; @@ -13,6 +14,7 @@ using FlaxEditor.Viewport.Cameras; using FlaxEditor.Viewport.Previews; using FlaxEngine; using FlaxEngine.GUI; +using Object = FlaxEngine.Object; // ReSharper disable UnusedMember.Local // ReSharper disable UnusedMember.Global @@ -206,11 +208,18 @@ namespace FlaxEditor.Windows.Assets } } + [StructLayout(LayoutKind.Sequential)] + private struct AnimGraphDebugFlowInfo + { + public uint NodeId; + public int BoxId; + } + private FlaxObjectRefPickerControl _debugPicker; private NavigationBar _navigationBar; private PropertiesProxy _properties; private Tab _previewTab; - private readonly List _debugFlows = new List(); + private readonly List _debugFlows = new List(); /// /// Gets the animated model actor used for the animation preview. @@ -285,7 +294,7 @@ namespace FlaxEditor.Windows.Assets Parent = this }; - Editor.AnimGraphDebugFlow += OnDebugFlow; + Animations.DebugFlow += OnDebugFlow; } private void OnSurfaceContextChanged(VisjectSurfaceContext context) @@ -293,26 +302,27 @@ namespace FlaxEditor.Windows.Assets _surface.UpdateNavigationBar(_navigationBar, _toolstrip); } - private bool OnCheckValid(FlaxEngine.Object obj, ScriptType type) + private bool OnCheckValid(Object obj, ScriptType type) { return obj is AnimatedModel player && player.AnimationGraph == OriginalAsset; } - private void OnDebugFlow(Editor.AnimGraphDebugFlowInfo flowInfo) + private void OnDebugFlow(Asset asset, Object obj, uint nodeId, uint boxId) { // Filter the flow if (_debugPicker.Value != null) { - if (flowInfo.Asset != OriginalAsset || _debugPicker.Value != flowInfo.Object) + if (asset != OriginalAsset || _debugPicker.Value != obj) return; } else { - if (flowInfo.Asset != Asset || _preview.PreviewActor != flowInfo.Object) + if (asset != Asset || _preview.PreviewActor != obj) return; } // Register flow to show it in UI on a surface + var flowInfo = new AnimGraphDebugFlowInfo { NodeId = nodeId, BoxId = (int)boxId }; lock (_debugFlows) { _debugFlows.Add(flowInfo); @@ -457,7 +467,7 @@ namespace FlaxEditor.Windows.Assets /// public override void OnDestroy() { - Editor.AnimGraphDebugFlow -= OnDebugFlow; + Animations.DebugFlow -= OnDebugFlow; _properties = null; _navigationBar = null; diff --git a/Source/Engine/Animations/Animations.cpp b/Source/Engine/Animations/Animations.cpp index d2e095fa6..037c87a5f 100644 --- a/Source/Engine/Animations/Animations.cpp +++ b/Source/Engine/Animations/Animations.cpp @@ -1,6 +1,7 @@ // Copyright (c) 2012-2021 Wojciech Figat. All rights reserved. #include "Animations.h" +#include "Engine/Engine/Engine.h" #include "Engine/Profiler/ProfilerCPU.h" #include "Engine/Level/Actors/AnimatedModel.h" #include "Engine/Engine/Time.h" @@ -22,6 +23,7 @@ public: }; AnimationsService AnimationManagerInstance; +Delegate Animations::DebugFlow; void AnimationsService::Update() { diff --git a/Source/Engine/Animations/Animations.h b/Source/Engine/Animations/Animations.h index a1b90e753..8b5b79c67 100644 --- a/Source/Engine/Animations/Animations.h +++ b/Source/Engine/Animations/Animations.h @@ -2,14 +2,23 @@ #pragma once +#include "Engine/Scripting/ScriptingType.h" +#include "Engine/Core/Delegate.h" + class AnimatedModel; +class Asset; /// -/// The animations service. +/// The animations playback service. /// -class FLAXENGINE_API Animations +API_CLASS(Static) class FLAXENGINE_API Animations { -public: +DECLARE_SCRIPTING_TYPE_NO_SPAWN(Content); + +#if USE_EDITOR + // Custom event that is called every time the Anim Graph signal flows over the graph (including the data connections). Can be used to read and visualize the animation blending logic. Args are: anim graph asset, animated object, node id, box id + API_EVENT() static Delegate DebugFlow; +#endif /// /// Adds an animated model to update. diff --git a/Source/Engine/Animations/Graph/AnimGraph.Custom.cpp b/Source/Engine/Animations/Graph/AnimGraph.Custom.cpp index 22fc6af28..60ae46f16 100644 --- a/Source/Engine/Animations/Graph/AnimGraph.Custom.cpp +++ b/Source/Engine/Animations/Graph/AnimGraph.Custom.cpp @@ -80,10 +80,6 @@ namespace AnimGraphInternal } } -#if USE_EDITOR -Delegate AnimGraphExecutor::DebugFlow; -#endif - void AnimGraphExecutor::initRuntime() { ADD_INTERNAL_CALL("FlaxEngine.AnimationGraph::Internal_HasConnection", &AnimGraphInternal::HasConnection); diff --git a/Source/Engine/Animations/Graph/AnimGraph.cpp b/Source/Engine/Animations/Graph/AnimGraph.cpp index 2932f7c3f..321c5a944 100644 --- a/Source/Engine/Animations/Graph/AnimGraph.cpp +++ b/Source/Engine/Animations/Graph/AnimGraph.cpp @@ -312,7 +312,7 @@ VisjectExecutor::Value AnimGraphExecutor::eatBox(Node* caller, Box* box) _callStack.Add(caller); #if USE_EDITOR - DebugFlow(_graph._owner, _data->Object, box->GetParent()->ID, box->ID); + Animations::DebugFlow(_graph._owner, context.Data->Object, box->GetParent()->ID, box->ID); #endif // Call per group custom processing event diff --git a/Source/Engine/Animations/Graph/AnimGraph.h b/Source/Engine/Animations/Graph/AnimGraph.h index 8ca4b7247..a8f055033 100644 --- a/Source/Engine/Animations/Graph/AnimGraph.h +++ b/Source/Engine/Animations/Graph/AnimGraph.h @@ -828,10 +828,6 @@ private: public: -#if USE_EDITOR - // Custom event that is called every time the Anim Graph signal flows over the graph (including the data connections). Can be used to read and visualize the animation blending logic. - static Delegate DebugFlow; -#endif /// /// Initializes the managed runtime calls.