using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityStandardAssets.CinematicEffects; public class ScreenEffects : MonoBehaviour { public DepthOfField depthOfField; private float originalNearRadius; private float originalFarRadius; void Start () { depthOfField = GetComponent(); if (depthOfField == null) depthOfField = gameObject.AddComponent(); originalNearRadius = depthOfField.focus.nearBlurRadius; originalFarRadius = depthOfField.focus.farBlurRadius; NotificationServer.register("show GameUI", showGame); NotificationServer.register("hide GameUI", hideGame); } 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, 0f, 0.5f).setEaseInOutQuad().setOnUpdate((float val)=>{ focus.nearBlurRadius = startNear * val; focus.farBlurRadius = startFar * val; }).setOnComplete(()=>{ 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, 0f, 1f, 0.5f).setEaseInOutQuad().setOnUpdate((float val)=>{ focus.nearBlurRadius = startNear + (originalNearRadius-startNear) * val; focus.farBlurRadius = startFar + (originalFarRadius-startFar) * val; }).setIgnoreTimeScale(true); } }