Add support for updating particle effects in editor view when editing
This commit is contained in:
@@ -194,7 +194,7 @@ void LevelService::Update()
|
||||
for (int32 i = 0; i < scenes.Count(); i++)
|
||||
{
|
||||
if (scenes[i]->GetIsActive())
|
||||
scenes[i]->Ticking.Update.TickEditorScripts();
|
||||
scenes[i]->Ticking.Update.TickExecuteInEditor();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -223,7 +223,7 @@ void LevelService::LateUpdate()
|
||||
for (int32 i = 0; i < scenes.Count(); i++)
|
||||
{
|
||||
if (scenes[i]->GetIsActive())
|
||||
scenes[i]->Ticking.LateUpdate.TickEditorScripts();
|
||||
scenes[i]->Ticking.LateUpdate.TickExecuteInEditor();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -255,7 +255,7 @@ void LevelService::FixedUpdate()
|
||||
for (int32 i = 0; i < scenes.Count(); i++)
|
||||
{
|
||||
if (scenes[i]->GetIsActive())
|
||||
scenes[i]->Ticking.FixedUpdate.TickEditorScripts();
|
||||
scenes[i]->Ticking.FixedUpdate.TickExecuteInEditor();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -17,15 +17,9 @@ public:
|
||||
/// <summary>
|
||||
/// Tick function type.
|
||||
/// </summary>
|
||||
class Tick
|
||||
struct Tick
|
||||
{
|
||||
public:
|
||||
|
||||
/// <summary>
|
||||
/// Signature of the function to call
|
||||
/// </summary>
|
||||
typedef void (*Signature)();
|
||||
|
||||
typedef void (*SignatureObj)(void*);
|
||||
|
||||
template<class T, void(T::*Method)()>
|
||||
@@ -51,8 +45,7 @@ public:
|
||||
/// <summary>
|
||||
/// Calls the binded function.
|
||||
/// </summary>
|
||||
/// <returns>Function result</returns>
|
||||
void Call() const
|
||||
FORCE_INLINE void Call() const
|
||||
{
|
||||
(*FunctionObj)(Callee);
|
||||
}
|
||||
@@ -63,10 +56,11 @@ public:
|
||||
public:
|
||||
|
||||
Array<Script*> Scripts;
|
||||
Array<Tick> Ticks;
|
||||
#if USE_EDITOR
|
||||
Array<Script*> ScriptsExecuteInEditor;
|
||||
Array<Tick> TicksExecuteInEditor;
|
||||
#endif
|
||||
Array<Tick> Ticks;
|
||||
|
||||
TickData(int32 capacity)
|
||||
: Scripts(capacity)
|
||||
@@ -81,18 +75,17 @@ public:
|
||||
TickScripts(Scripts);
|
||||
|
||||
for (int32 i = 0; i < Ticks.Count(); i++)
|
||||
{
|
||||
Ticks[i].Call();
|
||||
}
|
||||
}
|
||||
|
||||
#if USE_EDITOR
|
||||
|
||||
void TickEditorScripts()
|
||||
void TickExecuteInEditor()
|
||||
{
|
||||
TickScripts(ScriptsExecuteInEditor);
|
||||
}
|
||||
|
||||
for (int32 i = 0; i < TicksExecuteInEditor.Count(); i++)
|
||||
TicksExecuteInEditor[i].Call();
|
||||
}
|
||||
#endif
|
||||
|
||||
void AddScript(Script* script);
|
||||
@@ -118,12 +111,35 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
#if USE_EDITOR
|
||||
template<class T, void(T::*Method)()>
|
||||
void AddTickExecuteInEditor(T* callee)
|
||||
{
|
||||
SceneTicking::Tick tick;
|
||||
tick.Bind<T, Method>(callee);
|
||||
TicksExecuteInEditor.Add(tick);
|
||||
}
|
||||
|
||||
void RemoveTickExecuteInEditor(void* callee)
|
||||
{
|
||||
for (int32 i = 0; i < TicksExecuteInEditor.Count(); i++)
|
||||
{
|
||||
if (TicksExecuteInEditor[i].Callee == callee)
|
||||
{
|
||||
TicksExecuteInEditor.RemoveAt(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void Clear()
|
||||
{
|
||||
Scripts.Clear();
|
||||
Ticks.Clear();
|
||||
#if USE_EDITOR
|
||||
ScriptsExecuteInEditor.Clear();
|
||||
TicksExecuteInEditor.Clear();
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
@@ -373,6 +373,18 @@ void ParticleEffect::Update()
|
||||
UpdateSimulation();
|
||||
}
|
||||
|
||||
#if USE_EDITOR
|
||||
|
||||
#include "Editor/Editor.h"
|
||||
|
||||
void ParticleEffect::UpdateExecuteInEditor()
|
||||
{
|
||||
if (!Editor::IsPlayMode)
|
||||
Update();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void ParticleEffect::CacheModifiedParameters()
|
||||
{
|
||||
if (_parameters.IsEmpty())
|
||||
@@ -649,6 +661,7 @@ void ParticleEffect::OnEnable()
|
||||
GetSceneRendering()->AddGeometry(this);
|
||||
#if USE_EDITOR
|
||||
GetSceneRendering()->AddViewportIcon(this);
|
||||
GetScene()->Ticking.Update.AddTickExecuteInEditor<ParticleEffect, &ParticleEffect::UpdateExecuteInEditor>(this);
|
||||
#endif
|
||||
|
||||
// Base
|
||||
@@ -658,6 +671,7 @@ void ParticleEffect::OnEnable()
|
||||
void ParticleEffect::OnDisable()
|
||||
{
|
||||
#if USE_EDITOR
|
||||
GetScene()->Ticking.Update.RemoveTickExecuteInEditor(this);
|
||||
GetSceneRendering()->RemoveViewportIcon(this);
|
||||
#endif
|
||||
GetSceneRendering()->RemoveGeometry(this);
|
||||
|
||||
@@ -366,6 +366,9 @@ protected:
|
||||
private:
|
||||
|
||||
void Update();
|
||||
#if USE_EDITOR
|
||||
void UpdateExecuteInEditor();
|
||||
#endif
|
||||
void CacheModifiedParameters();
|
||||
void ApplyModifiedParameters();
|
||||
void OnParticleSystemModified();
|
||||
|
||||
@@ -17,6 +17,9 @@
|
||||
#include "Engine/Profiler/ProfilerGPU.h"
|
||||
#include "Engine/Renderer/Utils/BitonicSort.h"
|
||||
#endif
|
||||
#if USE_EDITOR
|
||||
#include "Editor/Editor.h"
|
||||
#endif
|
||||
|
||||
struct SpriteParticleVertex
|
||||
{
|
||||
@@ -1155,6 +1158,13 @@ void ParticleManagerService::Update()
|
||||
// Simulation delta time can be based on a time since last update or the current delta time
|
||||
float dt = effect->UseTimeScale ? deltaTime : deltaTimeUnscaled;
|
||||
float t = effect->UseTimeScale ? time : timeUnscaled;
|
||||
#if USE_EDITOR
|
||||
if (!Editor::IsPlayMode)
|
||||
{
|
||||
dt = deltaTimeUnscaled;
|
||||
t = timeUnscaled;
|
||||
}
|
||||
#endif
|
||||
const float lastUpdateTime = instance.LastUpdateTime;
|
||||
if (lastUpdateTime > 0 && t > lastUpdateTime)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user