59 lines
1.8 KiB
C#
59 lines
1.8 KiB
C#
using UnityEngine;
|
|
using DG.Tweening;
|
|
[RequireComponent(typeof(Camera))]
|
|
public class CameraEffects : MonoBehaviour
|
|
{
|
|
public static CameraEffects instance;
|
|
Camera cam;
|
|
|
|
[SerializeField]private float stretchFactor = 0;
|
|
[SerializeField]private bool isBeingStretched = false;
|
|
[SerializeField]private float minFov = 5;
|
|
[SerializeField]private float maxFov = 10;
|
|
[SerializeField]private float fovSpeed = 10;
|
|
[SerializeField] private float bounceDuration = 0.35f;
|
|
[SerializeField] private float bounceElasticity = 0.7f;
|
|
[SerializeField] private float bounceOvershoot = 0.2f;
|
|
void Awake()
|
|
{
|
|
instance = this;
|
|
cam = Camera.main;
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
if(isBeingStretched){
|
|
float targetFov = minFov + stretchFactor * (maxFov - minFov);
|
|
cam.orthographicSize = Mathf.Lerp(cam.orthographicSize, targetFov, Time.deltaTime * fovSpeed);
|
|
}
|
|
}
|
|
|
|
public void SetStretchFactor(float stretchFactor){
|
|
this.stretchFactor = stretchFactor;
|
|
isBeingStretched = true;
|
|
}
|
|
|
|
public void SetUpsideDown(bool isUpsideDown){
|
|
if(isUpsideDown){
|
|
transform.rotation = Quaternion.Euler(0, 0, 180);
|
|
transform.position = new Vector3(transform.position.x, Mathf.Abs(transform.position.y), transform.position.z);
|
|
}else{
|
|
transform.rotation = Quaternion.Euler(0, 0, 0);
|
|
transform.position = new Vector3(transform.position.x, -Mathf.Abs(transform.position.y), transform.position.z);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public void ReleaseStretchFactor(){
|
|
stretchFactor = 0;
|
|
isBeingStretched = false;
|
|
cam.DOOrthoSize(minFov, bounceDuration)
|
|
.SetEase(Ease.OutElastic, bounceElasticity, bounceOvershoot)
|
|
.OnComplete(() => {
|
|
stretchFactor = 0;
|
|
});
|
|
}
|
|
|
|
}
|