Raccoon animation and scene changes #415

Merged
glencelow merged 16 commits from PlayerController into main 2023-03-10 17:28:16 +08:00
3 changed files with 292 additions and 251 deletions
Showing only changes of commit 10555f646c - Show all commits

View File

@ -2,15 +2,60 @@
using SHADE_Scripting.Audio;
using System;
public class JumpPad : Script
{
private Transform tran;
private float defaultScale;
public float scaleMaxSize = 2.0f;
public float scaleDuration = 0.25f;
private bool landed = false;
private bool scaleUpDone = false;
[NonSerialized]
private TweenThread scaleUp;
[NonSerialized]
private TweenThread scaleDown;
protected override void awake()
{
AudioHandler.audioClipHandlers["SFXJumpPad"] = Audio.CreateAudioClip("event:/Props/jumppad_boing");
tran = GameObject.GetComponent<Transform>();
if (!tran)
Debug.LogError("NO TRANSFORM");
defaultScale = tran.LocalScale.y;
}
protected override void start()
{
scaleUp = TweenManager.CreateTweenThread(scaleDuration, tran.LocalScale.y, scaleMaxSize, EASING_METHOD.EASE_IN_SINE);
scaleDown = TweenManager.CreateTweenThread(scaleDuration, tran.LocalScale.y, defaultScale, EASING_METHOD.EASE_IN_SINE);
}
protected override void update()
{
if (landed && tran)
{
tran.LocalScale = new Vector3(tran.LocalScale.x, scaleUp.GetValue(), tran.LocalScale.z);
if (scaleUp.IsCompleted())
{
landed = false;
scaleUpDone = true;
scaleDown.Reset();
}
}
if (scaleUpDone && !landed)
{
tran.LocalScale = new Vector3(tran.LocalScale.x, scaleDown.GetValue(), tran.LocalScale.z);
if (scaleDown.IsCompleted())
{
scaleUpDone = false;
}
}
}
protected override void onCollisionEnter(CollisionInfo info)
@ -20,7 +65,10 @@ public class JumpPad : Script
Audio.AttachAudioClipToObject(AudioHandler.audioClipHandlers["SFXJumpPad"], GameObject.EntityId);
AudioHandler.audioClipHandlers["SFXJumpPad"].Play();
info.GameObject.GetScript<PlayerController>().landedOnJumpPad = true;
landed = true;
scaleUp.Reset();
}
}
}

View File

@ -4,9 +4,6 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SHADE_Scripting.UI
{
public enum EASING_METHOD
{
EASE_IN_SINE,
@ -16,84 +13,88 @@ namespace SHADE_Scripting.UI
EASE_INOUT_BOUNCE
}
public static class EasingHelper
public static class EasingHelper
{
public static float EaseHelp(float value, EASING_METHOD method)
{
switch (method)
{
public static float EaseHelp(float value, EASING_METHOD method)
case EASING_METHOD.EASE_IN_SINE:
{
switch (method)
{
case EASING_METHOD.EASE_IN_SINE:
{
return EaseInSine(value);
}break;
case EASING_METHOD.EASE_OUT_SINE:
{
return EaseOutSine(value);
}break;
case EASING_METHOD.EASE_OUT_BOUNCE:
{
return EaseOutBounce(value);
}break;
case EASING_METHOD.EASE_IN_BOUNCE:
{
return EaseInBounce(value);
}
break;
case EASING_METHOD.EASE_INOUT_BOUNCE:
{
return EaseInOutBounce(value);
}
break;
default:
return 0.0f;
}
return EaseInSine(value);
}
private static float EaseInSine(float value)
break;
case EASING_METHOD.EASE_OUT_SINE:
{
return (float)(1.0f - Math.Cos((value * Math.PI / 2.0f) ));
return EaseOutSine(value);
}
private static float EaseOutSine(float value)
break;
case EASING_METHOD.EASE_OUT_BOUNCE:
{
return (float)(Math.Sin(value * Math.PI / 2.0f) );
return EaseOutBounce(value);
}
private static float EaseOutBounce(float value)
break;
case EASING_METHOD.EASE_IN_BOUNCE:
{
const float n1 = 7.5625f;
const float d1 = 2.75f;
if (value < 1.0f / d1)
{
return n1 * value * value;
} else if (value < 2.0f / d1)
{
return n1 * (value -= 2.25f / d1) * value + 0.9375f;
}
else
{
return n1 * (value -= 2.625f / d1) * value + 0.984375f;
}
return EaseInBounce(value);
}
private static float EaseInBounce(float value)
break;
case EASING_METHOD.EASE_INOUT_BOUNCE:
{
return 1 - EaseOutBounce(1 - value);
return EaseInOutBounce(value);
}
break;
default:
return 0.0f;
}
}
private static float EaseInSine(float value)
{
return (float)(1.0f - Math.Cos((value * Math.PI / 2.0f)));
}
private static float EaseOutSine(float value)
{
return (float)(Math.Sin(value * Math.PI / 2.0f));
}
private static float EaseInOutBounce(float value)
{
return (value < 0.5f)
?(1.0f - EaseOutBounce(1.0f - 2.0f * value)) / 2.0f
: (1.0f + EaseOutBounce(2.0f * value - 1.0f)) / 2.0f;
}
private static float EaseOutBounce(float value)
{
const float n1 = 7.5625f;
const float d1 = 2.75f;
if (value < 1.0f / d1)
{
return n1 * value * value;
}
else if (value < 2.0f / d1)
{
return n1 * (value -= 2.25f / d1) * value + 0.9375f;
}
else
{
return n1 * (value -= 2.625f / d1) * value + 0.984375f;
}
}
private static float EaseInBounce(float value)
{
return 1 - EaseOutBounce(1 - value);
}
private static float EaseInOutBounce(float value)
{
return (value < 0.5f)
? (1.0f - EaseOutBounce(1.0f - 2.0f * value)) / 2.0f
: (1.0f + EaseOutBounce(2.0f * value - 1.0f)) / 2.0f;
}
}

View File

@ -4,190 +4,182 @@ using System;
using System.Collections.Generic;
using System.Threading;
namespace SHADE_Scripting.UI
public class TweenThread
{
private float timer = 0.0f;
public float duration = 1.0f;
public EASING_METHOD method;
private float value = 0.0f;
public float startValue = 0.0f;
public float endValue = 1.0f;
public TweenThread(float duration, float startValue, float endValue, EASING_METHOD method)
{
this.duration = duration;
this.method = method;
this.startValue = startValue;
this.endValue = endValue;
}
public void Update(float deltaTime)
{
if (timer >= duration)
return;
timer += deltaTime;
if (timer >= duration)
timer = duration;
value = EasingHelper.EaseHelp(timer / duration, method) * (endValue - startValue) + startValue;
}
public bool IsCompleted()
{
return timer >= duration;
}
public void Reset()
{
timer = 0.0f;
value = startValue;
}
public void Reset(float startValue, float endValue)
{
Reset();
this.startValue = startValue;
this.endValue = endValue;
}
public void ResetInvert()
{
Reset();
float temp = startValue;
startValue = endValue;
endValue = temp;
}
public float GetValue()
{
return value;
}
}
public class TweenThreadVec3
{
private float timer = 0.0f;
public float duration = 1.0f;
public EASING_METHOD method;
private Vector3 value = Vector3.Zero;
public Vector3 startValue = Vector3.Zero;
public Vector3 endValue = Vector3.Zero;
public TweenThreadVec3(float duration, Vector3 startValue, Vector3 endValue, EASING_METHOD method)
{
this.duration = duration;
this.method = method;
this.startValue = startValue;
this.endValue = endValue;
}
public void Update(float deltaTime)
{
if (timer >= duration)
return;
timer += deltaTime;
if (timer >= duration)
timer = duration;
value = (endValue - startValue) * EasingHelper.EaseHelp(timer / duration, method) + startValue;
}
public bool IsCompleted()
{
return timer >= duration;
}
public void Reset()
{
timer = 0.0f;
value = startValue;
}
public void Reset(Vector3 startValue, Vector3 endValue)
{
Reset();
this.startValue = startValue;
this.endValue = endValue;
}
public void ResetInvert()
{
Reset();
Vector3 temp = startValue;
startValue = endValue;
endValue = temp;
}
public Vector3 GetValue()
{
return value;
}
}
public class TweenManager : Script
{
public static TweenManager Instance { get; private set; }
[NonSerialized]
private List<TweenThread> threadList;
[NonSerialized]
private List<TweenThreadVec3> threadVec3List;
protected override void awake()
{
if (Instance != null && Instance != this)
RemoveScript<TweenManager>();
else
Instance = this;
threadList = new List<TweenThread>();
threadVec3List = new List<TweenThreadVec3>();
}
protected override void onDestroy()
{
if (Instance == this)
Instance = null;
}
protected override void update()
{
foreach (TweenThread thread in threadList)
{
thread.Update(Time.DeltaTimeF);
}
foreach (TweenThreadVec3 thread in threadVec3List)
{
thread.Update(Time.DeltaTimeF);
}
}
public static TweenThread CreateTweenThread(float duration, float startValue, float endValue, EASING_METHOD method)
{
if (Instance == null)
return null;
TweenThread thread = new TweenThread(duration, startValue, endValue, method);
Instance.threadList.Add(thread);
thread.Reset();
return thread;
}
public static TweenThreadVec3 CreateTweenThreadVec3(float duration, Vector3 startValue, Vector3 endValue, EASING_METHOD method)
{
if (Instance == null)
return null;
TweenThreadVec3 thread = new TweenThreadVec3(duration, startValue, endValue, method);
Instance.threadVec3List.Add(thread);
thread.Reset();
return thread;
}
public class TweenThread
{
private float timer = 0.0f;
public float duration = 1.0f;
public EASING_METHOD method;
private float value = 0.0f;
public float startValue = 0.0f;
public float endValue = 1.0f;
public TweenThread(float duration, float startValue, float endValue, EASING_METHOD method)
{
this.duration = duration;
this.method = method;
this.startValue = startValue;
this.endValue = endValue;
}
public void Update(float deltaTime)
{
if (timer >= duration)
return;
timer += deltaTime;
if (timer >= duration)
timer = duration;
value = EasingHelper.EaseHelp(timer/duration, method) * (endValue - startValue) + startValue ;
}
public bool IsCompleted()
{
return timer >= duration;
}
public void Reset()
{
timer = 0.0f;
value = startValue;
}
public void Reset(float startValue, float endValue)
{
Reset();
this.startValue = startValue;
this.endValue = endValue;
}
public void ResetInvert()
{
Reset();
float temp = startValue;
startValue = endValue;
endValue = temp;
}
public float GetValue()
{
return value;
}
}
public class TweenThreadVec3
{
private float timer = 0.0f;
public float duration = 1.0f;
public EASING_METHOD method;
private Vector3 value = Vector3.Zero;
public Vector3 startValue = Vector3.Zero;
public Vector3 endValue = Vector3.Zero;
public TweenThreadVec3(float duration, Vector3 startValue, Vector3 endValue, EASING_METHOD method)
{
this.duration = duration;
this.method = method;
this.startValue = startValue;
this.endValue = endValue;
}
public void Update(float deltaTime)
{
if (timer >= duration)
return;
timer += deltaTime;
if (timer >= duration)
timer = duration;
value = (endValue - startValue) * EasingHelper.EaseHelp(timer / duration, method) + startValue;
}
public bool IsCompleted()
{
return timer >= duration;
}
public void Reset()
{
timer = 0.0f;
value = startValue;
}
public void Reset(Vector3 startValue, Vector3 endValue)
{
Reset();
this.startValue = startValue;
this.endValue = endValue;
}
public void ResetInvert()
{
Reset();
Vector3 temp = startValue;
startValue = endValue;
endValue = temp;
}
public Vector3 GetValue()
{
return value;
}
}
public class TweenManager : Script
{
public static TweenManager Instance { get; private set; }
[NonSerialized]
private List<TweenThread> threadList;
[NonSerialized]
private List<TweenThreadVec3> threadVec3List;
protected override void awake()
{
if (Instance != null && Instance != this)
RemoveScript<TweenManager>();
else
Instance = this;
threadList = new List<TweenThread>();
threadVec3List = new List<TweenThreadVec3>();
}
protected override void onDestroy()
{
if (Instance == this)
Instance = null;
}
protected override void update()
{
foreach (TweenThread thread in threadList)
{
thread.Update(Time.DeltaTimeF);
}
foreach (TweenThreadVec3 thread in threadVec3List)
{
thread.Update(Time.DeltaTimeF);
}
}
public static TweenThread CreateTweenThread(float duration, float startValue, float endValue, EASING_METHOD method)
{
if (Instance == null)
return null;
TweenThread thread = new TweenThread(duration, startValue, endValue, method);
Instance.threadList.Add(thread);
thread.Reset();
return thread;
}
public static TweenThreadVec3 CreateTweenThreadVec3(float duration, Vector3 startValue, Vector3 endValue, EASING_METHOD method)
{
if (Instance == null)
return null;
TweenThreadVec3 thread = new TweenThreadVec3(duration, startValue, endValue, method);
Instance.threadVec3List.Add(thread);
thread.Reset();
return thread;
}
}
}