|
|
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityStandardAssets.CinematicEffects;
-
- public class ScreenEffects : MonoBehaviour
- {
- public DepthOfField depthOfField;
- public float strength = 0f;
- public CanvasGroup flashCanvas;
-
- private float originalNearRadius;
- private float originalFarRadius;
-
- private int flashID;
-
- void Start ()
- {
- depthOfField = GetComponent<DepthOfField>();
- if (depthOfField == null)
- depthOfField = gameObject.AddComponent<DepthOfField>();
- originalNearRadius = depthOfField.focus.nearBlurRadius;
- originalFarRadius = depthOfField.focus.farBlurRadius;
-
- NotificationServer.register("show GameUI", showGame);
- NotificationServer.register("hide GameUI", hideGame);
- NotificationServer.register("flash damage", flashDamage);
- }
-
- public void showGame()
- {
- LeanTween.cancel(gameObject, false);
- float startNear = depthOfField.focus.nearBlurRadius;
- float startFar = depthOfField.focus.farBlurRadius;
- DepthOfField.FocusSettings focus = depthOfField.focus;
- LeanTween.value(gameObject, 1f, 1f*strength, 0.5f).setEaseInOutQuad().setOnUpdate((float val)=>{
- focus.nearBlurRadius = startNear * val;
- focus.farBlurRadius = startFar * val;
- }).setOnComplete(()=>{
- if (strength == 0f)
- depthOfField.enabled = false;
- }).setIgnoreTimeScale(true);
- }
-
- public void hideGame()
- {
- LeanTween.cancel(gameObject, false);
- depthOfField.enabled = true;
- float startNear = depthOfField.focus.nearBlurRadius;
- float startFar = depthOfField.focus.farBlurRadius;
- DepthOfField.FocusSettings focus = depthOfField.focus;
- LeanTween.value(gameObject, 1f*strength, 1f, 0.5f).setEaseInOutQuad().setOnUpdate((float val)=>{
- focus.nearBlurRadius = startNear + (originalNearRadius-startNear) * val;
- focus.farBlurRadius = startFar + (originalFarRadius-startFar) * val;
- }).setIgnoreTimeScale(true);
- }
-
- public void flashDamage()
- {
- LeanTween.cancel(flashID);
- flashID = LeanTween.alphaCanvas(flashCanvas, 1f, 0.2f).setEaseInOutCubic().setOnComplete(()=>{
- LeanTween.alphaCanvas(flashCanvas, 0f, 0.6f).setEaseInOutCubic();
- }).uniqueId;
- }
- }
|