2023-02-18 22:21:23 +08:00
|
|
|
|
using SHADE;
|
2023-03-04 00:19:35 +08:00
|
|
|
|
using SHADE_Scripting.Audio;
|
2023-02-18 22:21:23 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
2023-03-08 18:49:36 +08:00
|
|
|
|
|
2023-02-18 22:21:23 +08:00
|
|
|
|
public class JumpPad : Script
|
|
|
|
|
{
|
2023-03-08 18:49:36 +08:00
|
|
|
|
private Transform tran;
|
2023-03-09 00:33:36 +08:00
|
|
|
|
private Vector3 defaultScale;
|
|
|
|
|
public float scaleYMaxSize = 2.0f;
|
|
|
|
|
private float scaleXZMaxSize;
|
2023-03-08 18:49:36 +08:00
|
|
|
|
public float scaleDuration = 0.25f;
|
|
|
|
|
private bool landed = false;
|
|
|
|
|
private bool scaleUpDone = false;
|
2023-03-24 21:28:33 +08:00
|
|
|
|
public float itemUpwardForce = 6.0f;
|
2023-03-08 18:49:36 +08:00
|
|
|
|
|
|
|
|
|
[NonSerialized]
|
2023-03-09 00:33:36 +08:00
|
|
|
|
private TweenThread scaleYUp;
|
2023-03-08 18:49:36 +08:00
|
|
|
|
[NonSerialized]
|
2023-03-09 00:33:36 +08:00
|
|
|
|
private TweenThread scaleXZUp;
|
|
|
|
|
[NonSerialized]
|
|
|
|
|
private TweenThreadVec3 scaleDown;
|
2023-03-08 18:49:36 +08:00
|
|
|
|
|
2023-02-18 22:21:23 +08:00
|
|
|
|
protected override void awake()
|
|
|
|
|
{
|
2023-03-04 00:19:35 +08:00
|
|
|
|
AudioHandler.audioClipHandlers["SFXJumpPad"] = Audio.CreateAudioClip("event:/Props/jumppad_boing");
|
2023-03-08 18:49:36 +08:00
|
|
|
|
|
|
|
|
|
tran = GameObject.GetComponent<Transform>();
|
|
|
|
|
if (!tran)
|
|
|
|
|
Debug.LogError("NO TRANSFORM");
|
|
|
|
|
|
2023-03-09 00:33:36 +08:00
|
|
|
|
defaultScale = tran.LocalScale;
|
|
|
|
|
scaleXZMaxSize = scaleYMaxSize * 0.3f;
|
2023-03-08 18:49:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void start()
|
|
|
|
|
{
|
2023-03-09 00:33:36 +08:00
|
|
|
|
scaleYUp = TweenManager.CreateTweenThread(scaleDuration, tran.LocalScale.y, scaleYMaxSize, EASING_METHOD.EASE_IN_SINE);
|
|
|
|
|
scaleXZUp = TweenManager.CreateTweenThread(scaleDuration, tran.LocalScale.y, scaleXZMaxSize, EASING_METHOD.EASE_IN_SINE);
|
2023-02-18 22:21:23 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void update()
|
|
|
|
|
{
|
2023-03-08 18:49:36 +08:00
|
|
|
|
if (landed && tran)
|
|
|
|
|
{
|
2023-03-09 00:33:36 +08:00
|
|
|
|
tran.LocalScale = new Vector3(scaleXZUp.GetValue(), scaleYUp.GetValue(), scaleXZUp.GetValue());
|
|
|
|
|
if (scaleYUp.IsCompleted() && scaleXZUp.IsCompleted())
|
2023-03-08 18:49:36 +08:00
|
|
|
|
{
|
|
|
|
|
landed = false;
|
|
|
|
|
scaleUpDone = true;
|
2023-03-09 00:33:36 +08:00
|
|
|
|
scaleDown = TweenManager.CreateTweenThreadVec3(scaleDuration, tran.LocalScale, defaultScale, EASING_METHOD.EASE_IN_SINE);
|
2023-03-08 18:49:36 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (scaleUpDone && !landed)
|
|
|
|
|
{
|
2023-03-09 00:33:36 +08:00
|
|
|
|
tran.LocalScale = scaleDown.GetValue();
|
2023-03-08 18:49:36 +08:00
|
|
|
|
if (scaleDown.IsCompleted())
|
|
|
|
|
{
|
|
|
|
|
scaleUpDone = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-18 22:21:23 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void onCollisionEnter(CollisionInfo info)
|
|
|
|
|
{
|
|
|
|
|
if (info.GameObject.GetScript<PlayerController>() && info.GameObject.GetScript<PlayerController>().currentState == PlayerController.RaccoonStates.FALLING)
|
|
|
|
|
{
|
2023-03-04 00:19:35 +08:00
|
|
|
|
Audio.AttachAudioClipToObject(AudioHandler.audioClipHandlers["SFXJumpPad"], GameObject.EntityId);
|
|
|
|
|
AudioHandler.audioClipHandlers["SFXJumpPad"].Play();
|
2023-02-18 22:21:23 +08:00
|
|
|
|
info.GameObject.GetScript<PlayerController>().landedOnJumpPad = true;
|
2023-03-08 18:49:36 +08:00
|
|
|
|
landed = true;
|
2023-03-09 00:33:36 +08:00
|
|
|
|
scaleYUp.Reset();
|
|
|
|
|
scaleXZUp.Reset();
|
2023-02-18 22:21:23 +08:00
|
|
|
|
}
|
2023-03-24 21:28:33 +08:00
|
|
|
|
else if (info.GameObject.GetComponent<RigidBody>())
|
|
|
|
|
{
|
|
|
|
|
Audio.AttachAudioClipToObject(AudioHandler.audioClipHandlers["SFXJumpPad"], GameObject.EntityId);
|
|
|
|
|
AudioHandler.audioClipHandlers["SFXJumpPad"].Play();
|
|
|
|
|
info.GameObject.GetComponent<RigidBody>().AddForce(new Vector3(0, itemUpwardForce, 0));
|
|
|
|
|
landed = true;
|
|
|
|
|
scaleYUp.Reset();
|
|
|
|
|
scaleXZUp.Reset();
|
|
|
|
|
}
|
2023-02-18 22:21:23 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2023-03-08 18:49:36 +08:00
|
|
|
|
|