You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

52 lines
1.7 KiB

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<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);
}
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);
}
}