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

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityStandardAssets.CinematicEffects;
  5. public class ScreenEffects : MonoBehaviour
  6. {
  7. public DepthOfField depthOfField;
  8. private float originalNearRadius;
  9. private float originalFarRadius;
  10. void Start ()
  11. {
  12. depthOfField = GetComponent<DepthOfField>();
  13. if (depthOfField == null)
  14. depthOfField = gameObject.AddComponent<DepthOfField>();
  15. originalNearRadius = depthOfField.focus.nearBlurRadius;
  16. originalFarRadius = depthOfField.focus.farBlurRadius;
  17. NotificationServer.register("show GameUI", showGame);
  18. NotificationServer.register("hide GameUI", hideGame);
  19. }
  20. public void showGame()
  21. {
  22. LeanTween.cancel(gameObject, false);
  23. float startNear = depthOfField.focus.nearBlurRadius;
  24. float startFar = depthOfField.focus.farBlurRadius;
  25. DepthOfField.FocusSettings focus = depthOfField.focus;
  26. LeanTween.value(gameObject, 1f, 0f, 0.5f).setEaseInOutQuad().setOnUpdate((float val)=>{
  27. focus.nearBlurRadius = startNear * val;
  28. focus.farBlurRadius = startFar * val;
  29. }).setOnComplete(()=>{
  30. depthOfField.enabled = false;
  31. }).setIgnoreTimeScale(true);
  32. }
  33. public void hideGame()
  34. {
  35. LeanTween.cancel(gameObject, false);
  36. depthOfField.enabled = true;
  37. float startNear = depthOfField.focus.nearBlurRadius;
  38. float startFar = depthOfField.focus.farBlurRadius;
  39. DepthOfField.FocusSettings focus = depthOfField.focus;
  40. LeanTween.value(gameObject, 0f, 1f, 0.5f).setEaseInOutQuad().setOnUpdate((float val)=>{
  41. focus.nearBlurRadius = startNear + (originalNearRadius-startNear) * val;
  42. focus.farBlurRadius = startFar + (originalFarRadius-startFar) * val;
  43. }).setIgnoreTimeScale(true);
  44. }
  45. }