init
This commit is contained in:
commit
16da8e4dde
333 changed files with 109229 additions and 0 deletions
40
Assets/Tools/Cinemachine/ScreenShake.cs
Normal file
40
Assets/Tools/Cinemachine/ScreenShake.cs
Normal file
|
@ -0,0 +1,40 @@
|
|||
using Cinemachine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public static class ScreenShake{
|
||||
|
||||
static CinemachineBrain brain;
|
||||
static CinemachineVirtualCamera vCam;
|
||||
static ScreenShakeUpdate shakeUpdate;
|
||||
|
||||
class ScreenShakeUpdate : MonoBehaviour {
|
||||
[HideInInspector] public float shakeTimer;
|
||||
[HideInInspector] public float shakeTimerTotal;
|
||||
[HideInInspector] public float startingIntensity;
|
||||
|
||||
void Update(){
|
||||
if (shakeTimer > 0){
|
||||
shakeTimer -= Time.deltaTime;
|
||||
CinemachineBasicMultiChannelPerlin multiChannelPerlin = vCam.GetCinemachineComponent<CinemachineBasicMultiChannelPerlin>();
|
||||
multiChannelPerlin.m_AmplitudeGain = Mathf.Lerp(startingIntensity, 0f, 1 - (shakeTimer / shakeTimerTotal));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void Shake(float intensity, float time){
|
||||
if(brain == null || shakeUpdate == null){
|
||||
brain = Camera.main.GetComponent<CinemachineBrain>();
|
||||
vCam = Camera.main.GetComponent<CinemachineBrain>().ActiveVirtualCamera.VirtualCameraGameObject.GetComponent<CinemachineVirtualCamera>();
|
||||
shakeUpdate = new GameObject("ShakeUpdate").AddComponent<ScreenShakeUpdate>();
|
||||
}
|
||||
|
||||
CinemachineVirtualCamera currentCam = brain.ActiveVirtualCamera.VirtualCameraGameObject.GetComponent<CinemachineVirtualCamera>();
|
||||
if (vCam == null || vCam != currentCam){
|
||||
vCam = currentCam;
|
||||
}
|
||||
shakeUpdate.startingIntensity = 2.5f;
|
||||
shakeUpdate.shakeTimer = shakeUpdate.shakeTimerTotal = .25f;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue