Merge pull request #412 from SHADE-DP/SP3-22-AnimationController
Added time scale for animation system
This commit is contained in:
commit
6b4172e673
|
@ -38,6 +38,7 @@
|
||||||
idleClip: 227450439
|
idleClip: 227450439
|
||||||
runClip: 229125027
|
runClip: 229125027
|
||||||
pickUpClip: 219605278
|
pickUpClip: 219605278
|
||||||
|
controlAniSys: true
|
||||||
- EID: 1
|
- EID: 1
|
||||||
Name: Default
|
Name: Default
|
||||||
IsActive: true
|
IsActive: true
|
||||||
|
@ -80,3 +81,4 @@
|
||||||
idleClip: 0
|
idleClip: 0
|
||||||
runClip: 0
|
runClip: 0
|
||||||
pickUpClip: 0
|
pickUpClip: 0
|
||||||
|
controlAniSys: false
|
|
@ -13,6 +13,8 @@ namespace SHADE.Test
|
||||||
private AnimationClipAsset runClip;
|
private AnimationClipAsset runClip;
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
private AnimationClipAsset pickUpClip;
|
private AnimationClipAsset pickUpClip;
|
||||||
|
[SerializeField]
|
||||||
|
private bool controlAniSys = false;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Components
|
#region Components
|
||||||
|
@ -52,6 +54,13 @@ namespace SHADE.Test
|
||||||
if (pickUpClip)
|
if (pickUpClip)
|
||||||
playFunc(pickUpClip);
|
playFunc(pickUpClip);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Play and pause
|
||||||
|
if (controlAniSys && Input.GetKeyUp(Input.KeyCode.Space))
|
||||||
|
{
|
||||||
|
AnimationSystem.TimeScale = AnimationSystem.TimeScale > 0.0f ? 0.0f
|
||||||
|
: AnimationSystem.DefaultTimeScale;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ namespace SHADE
|
||||||
void SHAnimationSystem::UpdateRoutine::Execute(double dt) noexcept
|
void SHAnimationSystem::UpdateRoutine::Execute(double dt) noexcept
|
||||||
{
|
{
|
||||||
auto& animators = SHComponentManager::GetDense<SHAnimatorComponent>();
|
auto& animators = SHComponentManager::GetDense<SHAnimatorComponent>();
|
||||||
|
dt *= reinterpret_cast<SHAnimationSystem*>(system)->TimeScale;
|
||||||
for (auto& animator : animators)
|
for (auto& animator : animators)
|
||||||
{
|
{
|
||||||
animator.Update(dt);
|
animator.Update(dt);
|
||||||
|
|
|
@ -42,6 +42,23 @@ namespace SHADE
|
||||||
void Execute(double dt) noexcept override final;
|
void Execute(double dt) noexcept override final;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Constants */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/// <summary>
|
||||||
|
/// Default time scale used by the system.
|
||||||
|
/// </summary>
|
||||||
|
static constexpr double DEFAULT_TIME_SCALE = 1.0;
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Public Data Members */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/// <summary>
|
||||||
|
/// Used by the system to multiply the given delta time to scale the animation
|
||||||
|
/// speed.
|
||||||
|
/// </summary>
|
||||||
|
double TimeScale = DEFAULT_TIME_SCALE;
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
/* Constructors */
|
/* Constructors */
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
/************************************************************************************//*!
|
||||||
|
\file AnimationSystem.cxx
|
||||||
|
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||||
|
\par email: kahwei.tng\@digipen.edu
|
||||||
|
\date Mar 10, 2023
|
||||||
|
\brief Contains the definition of the functions of the managed AnimationSystem
|
||||||
|
static class.
|
||||||
|
|
||||||
|
Note: This file is written in C++17/CLI.
|
||||||
|
|
||||||
|
Copyright (C) 2023 DigiPen Institute of Technology.
|
||||||
|
Reproduction or disclosure of this file or its contents without the prior written consent
|
||||||
|
of DigiPen Institute of Technology is prohibited.
|
||||||
|
*//*************************************************************************************/
|
||||||
|
// Precompiled Headers
|
||||||
|
#include "SHpch.h"
|
||||||
|
// Primary Header
|
||||||
|
#include "AnimationSystem.hxx"
|
||||||
|
// External Dependencies
|
||||||
|
#include "ECS_Base/Managers/SHSystemManager.h"
|
||||||
|
|
||||||
|
namespace SHADE
|
||||||
|
{
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Properties */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
double AnimationSystem::TimeScale::get()
|
||||||
|
{
|
||||||
|
auto sys = SHSystemManager::GetSystem<SHAnimationSystem>();
|
||||||
|
return sys->TimeScale;
|
||||||
|
}
|
||||||
|
void AnimationSystem::TimeScale::set(double value)
|
||||||
|
{
|
||||||
|
auto sys = SHSystemManager::GetSystem<SHAnimationSystem>();
|
||||||
|
sys->TimeScale = value;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,47 @@
|
||||||
|
/************************************************************************************//*!
|
||||||
|
\file AnimationSystem.hxx
|
||||||
|
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||||
|
\par email: kahwei.tng\@digipen.edu
|
||||||
|
\date Mar 10, 2023
|
||||||
|
\brief Contains the definition of the managed AnimationSystem static class.
|
||||||
|
|
||||||
|
Note: This file is written in C++17/CLI.
|
||||||
|
|
||||||
|
Copyright (C) 2023 DigiPen Institute of Technology.
|
||||||
|
Reproduction or disclosure of this file or its contents without the prior written consent
|
||||||
|
of DigiPen Institute of Technology is prohibited.
|
||||||
|
*//*************************************************************************************/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Animation/SHAnimationSystem.h"
|
||||||
|
|
||||||
|
namespace SHADE
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Static class for interfacing with the animation system.
|
||||||
|
/// </summary>
|
||||||
|
public ref class AnimationSystem abstract sealed
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Constants */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/// <summary>
|
||||||
|
/// Default time scale used by the system.
|
||||||
|
/// </summary>
|
||||||
|
literal double DefaultTimeScale = SHAnimationSystem::DEFAULT_TIME_SCALE;
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Properties */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/// <summary>
|
||||||
|
/// Used by the system to multiply the given delta time to scale the animation
|
||||||
|
/// speed.
|
||||||
|
/// </summary>
|
||||||
|
static property double TimeScale
|
||||||
|
{
|
||||||
|
double get();
|
||||||
|
void set(double value);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
Loading…
Reference in New Issue