Refactor AnimGraph debug flows to use scripting API event
This commit is contained in:
@@ -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<AnimGraphDebugFlowInfo> AnimGraphDebugFlow;
|
||||
|
||||
internal static void Internal_OnAnimGraphDebugFlow(ref AnimGraphDebugFlowInfo debugFlow)
|
||||
{
|
||||
AnimGraphDebugFlow?.Invoke(debugFlow);
|
||||
}
|
||||
|
||||
private static void RequestStartPlayOnEditMode()
|
||||
{
|
||||
if (Instance.StateMachine.IsEditMode)
|
||||
|
||||
@@ -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<OnBrushModified>();
|
||||
Log::Logger::OnMessage.Bind<OnLogMessage>();
|
||||
VisualScripting::DebugFlow.Bind<OnVisualScriptingDebugFlow>();
|
||||
AnimGraphExecutor::DebugFlow.Bind<OnAnimGraphDebugFlow>();
|
||||
}
|
||||
|
||||
ManagedEditor::~ManagedEditor()
|
||||
@@ -204,7 +170,6 @@ ManagedEditor::~ManagedEditor()
|
||||
CSG::Builder::OnBrushModified.Unbind<OnBrushModified>();
|
||||
Log::Logger::OnMessage.Unbind<OnLogMessage>();
|
||||
VisualScripting::DebugFlow.Unbind<OnVisualScriptingDebugFlow>();
|
||||
AnimGraphExecutor::DebugFlow.Unbind<OnAnimGraphDebugFlow>();
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
@@ -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<Editor.AnimGraphDebugFlowInfo> _debugFlows = new List<Editor.AnimGraphDebugFlowInfo>();
|
||||
private readonly List<AnimGraphDebugFlowInfo> _debugFlows = new List<AnimGraphDebugFlowInfo>();
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
||||
/// <inheritdoc />
|
||||
public override void OnDestroy()
|
||||
{
|
||||
Editor.AnimGraphDebugFlow -= OnDebugFlow;
|
||||
Animations.DebugFlow -= OnDebugFlow;
|
||||
|
||||
_properties = null;
|
||||
_navigationBar = null;
|
||||
|
||||
@@ -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<Asset*, ScriptingObject*, uint32, uint32> Animations::DebugFlow;
|
||||
|
||||
void AnimationsService::Update()
|
||||
{
|
||||
|
||||
@@ -2,14 +2,23 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Engine/Scripting/ScriptingType.h"
|
||||
#include "Engine/Core/Delegate.h"
|
||||
|
||||
class AnimatedModel;
|
||||
class Asset;
|
||||
|
||||
/// <summary>
|
||||
/// The animations service.
|
||||
/// The animations playback service.
|
||||
/// </summary>
|
||||
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<Asset*, ScriptingObject*, uint32, uint32> DebugFlow;
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Adds an animated model to update.
|
||||
|
||||
@@ -80,10 +80,6 @@ namespace AnimGraphInternal
|
||||
}
|
||||
}
|
||||
|
||||
#if USE_EDITOR
|
||||
Delegate<Asset*, ScriptingObject*, uint32, uint32> AnimGraphExecutor::DebugFlow;
|
||||
#endif
|
||||
|
||||
void AnimGraphExecutor::initRuntime()
|
||||
{
|
||||
ADD_INTERNAL_CALL("FlaxEngine.AnimationGraph::Internal_HasConnection", &AnimGraphInternal::HasConnection);
|
||||
|
||||
@@ -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<Node>()->ID, box->ID);
|
||||
Animations::DebugFlow(_graph._owner, context.Data->Object, box->GetParent<Node>()->ID, box->ID);
|
||||
#endif
|
||||
|
||||
// Call per group custom processing event
|
||||
|
||||
@@ -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<Asset*, ScriptingObject*, uint32, uint32> DebugFlow;
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the managed runtime calls.
|
||||
|
||||
Reference in New Issue
Block a user