Added OnDrawGizmos for debug draw for scripts
This commit is contained in:
parent
715699b63b
commit
e89f5b4b9e
|
@ -106,6 +106,7 @@ namespace Sandbox
|
|||
SHSystemManager::RegisterRoutine<SHTransformSystem, SHTransformSystem::TransformPostPhysicsUpdate>();
|
||||
SHSystemManager::RegisterRoutine<SHDebugDrawSystem, SHDebugDrawSystem::ProcessPointsRoutine>();
|
||||
|
||||
SHSystemManager::RegisterRoutine<SHScriptEngine, SHScriptEngine::GizmosDrawRoutine>();
|
||||
SHSystemManager::RegisterRoutine<SHGraphicsSystem, SHGraphicsSystem::BatcherDispatcherRoutine>();
|
||||
SHSystemManager::RegisterRoutine<SHGraphicsSystem, SHGraphicsSystem::BeginRoutine>();
|
||||
|
||||
|
|
|
@ -379,6 +379,12 @@ namespace SHADE
|
|||
DEFAULT_CSHARP_LIB_NAME,
|
||||
DEFAULT_CSHARP_NAMESPACE + ".ScriptStore",
|
||||
"ExecuteLateUpdate"
|
||||
);
|
||||
csScriptsExecuteDrawGizmos = dotNet.GetFunctionPtr<CsFuncPtr>
|
||||
(
|
||||
DEFAULT_CSHARP_LIB_NAME,
|
||||
DEFAULT_CSHARP_NAMESPACE + ".ScriptStore",
|
||||
"ExecuteOnDrawGizmos"
|
||||
);
|
||||
csScriptsExecutePhysicsEvents = dotNet.GetFunctionPtr<CsFuncPtr>
|
||||
(
|
||||
|
|
|
@ -55,6 +55,12 @@ namespace SHADE
|
|||
LateUpdateRoutine();
|
||||
void Execute(double dt) noexcept override final;
|
||||
};
|
||||
class SH_API GizmosDrawRoutine final : public SHSystemRoutine
|
||||
{
|
||||
public:
|
||||
GizmosDrawRoutine();
|
||||
void Execute(double dt) noexcept override final;
|
||||
};
|
||||
class SH_API FrameCleanUpRoutine final : public SHSystemRoutine
|
||||
{
|
||||
public:
|
||||
|
@ -250,6 +256,7 @@ namespace SHADE
|
|||
CsFuncPtr csScriptsExecuteFixedUpdate = nullptr;
|
||||
CsFuncPtr csScriptsExecuteUpdate = nullptr;
|
||||
CsFuncPtr csScriptsExecuteLateUpdate = nullptr;
|
||||
CsFuncPtr csScriptsExecuteDrawGizmos = nullptr;
|
||||
CsFuncPtr csScriptsExecutePhysicsEvents = nullptr;
|
||||
CsFuncPtr csScriptsFrameCleanUp = nullptr;
|
||||
CsScriptManipFuncPtr csScriptsAdd = nullptr;
|
||||
|
|
|
@ -50,6 +50,17 @@ namespace SHADE
|
|||
reinterpret_cast<SHScriptEngine*>(system)->csScriptsExecuteLateUpdate();
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* System Routine Functions - GizmosDrawRoutine */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
SHScriptEngine::GizmosDrawRoutine::GizmosDrawRoutine()
|
||||
: SHSystemRoutine("Script Engine Gizmos Draw", true)
|
||||
{}
|
||||
void SHScriptEngine::GizmosDrawRoutine::Execute(double dt) noexcept
|
||||
{
|
||||
reinterpret_cast<SHScriptEngine*>(system)->csScriptsExecuteDrawGizmos();
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* System Routine Functions - FrameCleanUpRoutine */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
|
|
@ -140,6 +140,13 @@ namespace SHADE
|
|||
lateUpdate();
|
||||
SAFE_NATIVE_CALL_END(this)
|
||||
}
|
||||
void Script::OnDrawGizmos()
|
||||
{
|
||||
SAFE_NATIVE_CALL_BEGIN
|
||||
OnGizmosDrawOverriden = true;
|
||||
onDrawGizmos();
|
||||
SAFE_NATIVE_CALL_END(this)
|
||||
}
|
||||
void Script::OnDestroy()
|
||||
{
|
||||
SAFE_NATIVE_CALL_BEGIN
|
||||
|
@ -194,6 +201,7 @@ namespace SHADE
|
|||
/*---------------------------------------------------------------------------------*/
|
||||
Script::Script(GameObject gameObj)
|
||||
: owner { gameObj }
|
||||
, OnGizmosDrawOverriden { false }
|
||||
{}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
@ -210,6 +218,10 @@ namespace SHADE
|
|||
void Script::fixedUpdate() {}
|
||||
void Script::update() {}
|
||||
void Script::lateUpdate() {}
|
||||
void Script::onDrawGizmos()
|
||||
{
|
||||
OnGizmosDrawOverriden = false;
|
||||
}
|
||||
void Script::onDestroy() {}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
|
|
@ -164,6 +164,14 @@ namespace SHADE
|
|||
static operator bool(Script^ s);
|
||||
|
||||
internal:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Properties */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// If true, the OnGizmosDraw function was overridden.
|
||||
/// </summary>
|
||||
bool OnGizmosDrawOverriden;
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* "All-Time" Lifecycle Functions */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
|
@ -208,6 +216,11 @@ namespace SHADE
|
|||
/// </summary>
|
||||
void LateUpdate();
|
||||
/// <summary>
|
||||
/// Used to call onDrawGizmos(). This should be called just before rendering
|
||||
/// the scene. This will only be called when working in the editor.
|
||||
/// </summary>
|
||||
void OnDrawGizmos();
|
||||
/// <summary>
|
||||
/// Used to call onDestroy(). This should be called at the end of the frame
|
||||
/// where the attached GameObject or this script is destroyed directly or
|
||||
/// indirectly due to destruction of the owner.
|
||||
|
@ -308,6 +321,10 @@ namespace SHADE
|
|||
/// </summary>
|
||||
virtual void lateUpdate();
|
||||
/// <summary>
|
||||
/// Called every frame just before rendering but only if working in the editor.
|
||||
/// </summary>
|
||||
virtual void onDrawGizmos();
|
||||
/// <summary>
|
||||
/// Called just before the end of the frame where the attached GameObject or
|
||||
/// this script is destroyed directly or indirectly due to destruction of the
|
||||
/// owner.
|
||||
|
|
|
@ -478,6 +478,24 @@ namespace SHADE
|
|||
SAFE_NATIVE_CALL_END_N("SHADE_Managed.ScriptStore")
|
||||
}
|
||||
|
||||
void ScriptStore::ExecuteOnDrawGizmos()
|
||||
{
|
||||
SAFE_NATIVE_CALL_BEGIN
|
||||
for each (System::Collections::Generic::KeyValuePair<Entity, ScriptList^> entity in scripts)
|
||||
{
|
||||
// Check active state
|
||||
if (!isEntityActive(entity.Key))
|
||||
continue;
|
||||
|
||||
// Update each script
|
||||
for each (Script^ script in entity.Value)
|
||||
{
|
||||
script->OnDrawGizmos();
|
||||
}
|
||||
}
|
||||
SAFE_NATIVE_CALL_END_N("SHADE_Managed.ScriptStore")
|
||||
}
|
||||
|
||||
void ScriptStore::ExecuteCollisionFunctions()
|
||||
{
|
||||
SAFE_NATIVE_CALL_BEGIN
|
||||
|
|
|
@ -234,6 +234,10 @@ namespace SHADE
|
|||
/// </summary>
|
||||
static void ExecuteLateUpdate();
|
||||
/// <summary>
|
||||
/// Executes OnDrawGizmos() for all scripts.
|
||||
/// </summary>
|
||||
static void ExecuteOnDrawGizmos();
|
||||
/// <summary>
|
||||
/// Executes OnCollision*() and OnTrigger*() for all scripts.
|
||||
/// </summary>
|
||||
static void ExecuteCollisionFunctions();
|
||||
|
|
Loading…
Reference in New Issue