FRC fix, stealfood popup almost done and reset dt when load

This commit is contained in:
Glence 2023-02-28 21:42:05 +08:00
parent 0da61aa842
commit bd9349eae7
8 changed files with 127 additions and 8 deletions

View File

@ -5255,14 +5255,14 @@
IsActive: true IsActive: true
Scripts: ~ Scripts: ~
- EID: 460 - EID: 460
Name: RetryButton Name: StealFoodLogo
IsActive: true IsActive: true
NumberOfChildren: 0 NumberOfChildren: 0
Components: Components:
Transform Component: Transform Component:
Translate: {x: 0, y: -100, z: 0} Translate: {x: 0, y: 0, z: 0}
Rotate: {x: 0, y: 0, z: 0} Rotate: {x: 0, y: 0, z: 0}
Scale: {x: 300, y: 300, z: 500} Scale: {x: 0, y: 0, z: 1}
IsActive: true IsActive: true
Renderable Component: Renderable Component:
Mesh: 141771688 Mesh: 141771688
@ -5273,4 +5273,20 @@
Hovered: false Hovered: false
Clicked: false Clicked: false
IsActive: true IsActive: true
Scripts: ~ Scripts:
- Type: SHADE_Scripting.UI.StealFoodPopUp
Enabled: true
popInDuration: 0.5
popOutDuration: 0.5
stayDuration: 1
rotationAmt: 1800
scaleAmtX: 538
scaleAmtY: 377
- EID: 463
Name: TweenManager
IsActive: true
NumberOfChildren: 0
Components: ~
Scripts:
- Type: SHADE_Scripting.UI.TweenManager
Enabled: true

View File

@ -0,0 +1,90 @@
using System;
using SHADE;
namespace SHADE_Scripting.UI
{
public class StealFoodPopUp : Script
{
[NonSerialized]
private TweenThread rot;
[NonSerialized]
private TweenThread scaleX;
[NonSerialized]
private TweenThread scaleY;
[NonSerialized]
private TweenThread scaleOutX;
[NonSerialized]
private TweenThread scaleOutY;
private Transform tran;
public float popInDuration = 0.3f;
public float popOutDuration = 0.3f;
public float stayDuration = 1.0f;
public float rotationAmt = 1800;
public float scaleAmtX = 538;
public float scaleAmtY = 377;
private bool popInDone = false;
private bool stayDone = false;
private bool createThreadOnce = true;
private float timer = 0;
protected override void start()
{
rot = TweenManager.CreateTweenThread(popInDuration, 0, rotationAmt, EASING_METHOD.EASE_IN_SINE);
scaleX = TweenManager.CreateTweenThread(popInDuration, 0, scaleAmtX, EASING_METHOD.EASE_IN_SINE);
scaleY = TweenManager.CreateTweenThread(popInDuration, 0, scaleAmtY, EASING_METHOD.EASE_IN_SINE);
tran = GetComponent<Transform>();
if (!tran)
Debug.LogError("Missing Transform");
else
{
tran.LocalScale = new Vector3(0.0f,0.0f,1.0f);
tran.LocalEulerAngles = new Vector3(0.0f,0.0f,0.0f);
}
}
//538x377
protected override void update()
{
if (!popInDone)
{
tran.LocalEulerAngles = new Vector3(0.0f, 0.0f, SHADE.Math.DegreesToRadians(rot.GetValue()));
tran.LocalScale = new Vector3(scaleX.GetValue(), scaleY.GetValue(), 1);
}
else
{
timer += Time.DeltaTimeF;
if (timer >= stayDuration)
stayDone = true;
}
if (rot.IsCompleted() && scaleX.IsCompleted() && scaleY.IsCompleted())
popInDone = true;
if (stayDone)
{
if (createThreadOnce)
{
scaleOutX = TweenManager.CreateTweenThread(popOutDuration, scaleAmtX, 0, EASING_METHOD.EASE_IN_SINE);
scaleOutY = TweenManager.CreateTweenThread(popOutDuration, scaleAmtY, 0, EASING_METHOD.EASE_IN_SINE);
createThreadOnce = false;
}
tran.LocalScale = new Vector3(scaleOutX.GetValue(), scaleOutY.GetValue(), 1);
if (scaleOutX.IsCompleted() && scaleOutY.IsCompleted())
{
GameObject.SetActive(false);
}
}
}
}
}

View File

@ -0,0 +1,3 @@
Name: SC_StealFoodPopUp
ID: 159004097
Type: 9

View File

@ -28,10 +28,11 @@ namespace SHADE_Scripting.UI
public void Update(float deltaTime) public void Update(float deltaTime)
{ {
if (timer > duration) if (timer >= duration)
return; return;
timer += deltaTime; timer += deltaTime;
if (timer > duration) if (timer >= duration)
timer = duration; timer = duration;
value = EasingHelper.EaseHelp(timer/duration, method) * (endValue - startValue) + startValue ; value = EasingHelper.EaseHelp(timer/duration, method) * (endValue - startValue) + startValue ;
@ -96,7 +97,6 @@ namespace SHADE_Scripting.UI
protected override void update() protected override void update()
{ {
foreach (TweenThread thread in threadList) foreach (TweenThread thread in threadList)
{ {
thread.Update(Time.DeltaTimeF); thread.Update(Time.DeltaTimeF);

View File

@ -15,6 +15,7 @@
#include "Physics/Interface/SHColliderComponent.h" #include "Physics/Interface/SHColliderComponent.h"
#include "Graphics/MiddleEnd/Lights/SHLightComponent.h" #include "Graphics/MiddleEnd/Lights/SHLightComponent.h"
#include "Graphics/MiddleEnd/TextRendering/SHTextRenderableComponent.h" #include "Graphics/MiddleEnd/TextRendering/SHTextRenderableComponent.h"
#include "FRC/SHFramerateController.h"
#include "Assets/SHAssetManager.h" #include "Assets/SHAssetManager.h"
#include "Camera/SHCameraComponent.h" #include "Camera/SHCameraComponent.h"
@ -43,6 +44,7 @@ namespace Sandbox
void SBMainScene::Init() void SBMainScene::Init()
{ {
sceneName = SHSerialization::DeserializeSceneFromFile(sceneAssetID); sceneName = SHSerialization::DeserializeSceneFromFile(sceneAssetID);
SHFrameRateController::ResetDT();
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
/* TESTING CODE */ /* TESTING CODE */

View File

@ -25,7 +25,7 @@
#include "SHEditorWidgets.hpp" #include "SHEditorWidgets.hpp"
#include "Math/Transform/SHTransformSystem.h" #include "Math/Transform/SHTransformSystem.h"
#include "FRC/SHFramerateController.h"
//#==============================================================# //#==============================================================#
//|| Editor Window Includes || //|| Editor Window Includes ||
//#==============================================================# //#==============================================================#
@ -612,6 +612,7 @@ namespace SHADE
editorState = State::PLAY; editorState = State::PLAY;
SHCommandManager::SwapStacks(); SHCommandManager::SwapStacks();
SHEventManager::BroadcastEvent<SHEditorStateChangeEvent>(STATE_CHANGE_EVENT, SH_EDITOR_ON_PLAY_EVENT); SHEventManager::BroadcastEvent<SHEditorStateChangeEvent>(STATE_CHANGE_EVENT, SH_EDITOR_ON_PLAY_EVENT);
SHFrameRateController::ResetDT();
} }
else if (editorState == State::PAUSE) else if (editorState == State::PAUSE)
{ {

View File

@ -32,6 +32,11 @@ namespace SHADE
rawDeltaTime = deltaTime.count(); rawDeltaTime = deltaTime.count();
elapsedTime += rawDeltaTime; elapsedTime += rawDeltaTime;
} }
void SHFrameRateController::ResetDT() noexcept
{
prevFrameTime = std::chrono::high_resolution_clock::now();
}
} }
//TODO Legacy code. Delete soon //TODO Legacy code. Delete soon

View File

@ -43,6 +43,8 @@ namespace SHADE
//Updates the raw delta time accordingly //Updates the raw delta time accordingly
static void UpdateFRC() noexcept; static void UpdateFRC() noexcept;
static void ResetDT() noexcept;
}; };
} }