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.

54 lines
1.7 KiB

7 years ago
7 years ago
7 years ago
7 years ago
  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. public float strength = 0f;
  9. private float originalNearRadius;
  10. private float originalFarRadius;
  11. void Start ()
  12. {
  13. depthOfField = GetComponent<DepthOfField>();
  14. if (depthOfField == null)
  15. depthOfField = gameObject.AddComponent<DepthOfField>();
  16. originalNearRadius = depthOfField.focus.nearBlurRadius;
  17. originalFarRadius = depthOfField.focus.farBlurRadius;
  18. NotificationServer.register("show GameUI", showGame);
  19. NotificationServer.register("hide GameUI", hideGame);
  20. }
  21. public void showGame()
  22. {
  23. LeanTween.cancel(gameObject, false);
  24. float startNear = depthOfField.focus.nearBlurRadius;
  25. float startFar = depthOfField.focus.farBlurRadius;
  26. DepthOfField.FocusSettings focus = depthOfField.focus;
  27. LeanTween.value(gameObject, 1f, 1f*strength, 0.5f).setEaseInOutQuad().setOnUpdate((float val)=>{
  28. focus.nearBlurRadius = startNear * val;
  29. focus.farBlurRadius = startFar * val;
  30. }).setOnComplete(()=>{
  31. if (strength == 0f)
  32. depthOfField.enabled = false;
  33. }).setIgnoreTimeScale(true);
  34. }
  35. public void hideGame()
  36. {
  37. LeanTween.cancel(gameObject, false);
  38. depthOfField.enabled = true;
  39. float startNear = depthOfField.focus.nearBlurRadius;
  40. float startFar = depthOfField.focus.farBlurRadius;
  41. DepthOfField.FocusSettings focus = depthOfField.focus;
  42. LeanTween.value(gameObject, 1f*strength, 1f, 0.5f).setEaseInOutQuad().setOnUpdate((float val)=>{
  43. focus.nearBlurRadius = startNear + (originalNearRadius-startNear) * val;
  44. focus.farBlurRadius = startFar + (originalFarRadius-startFar) * val;
  45. }).setIgnoreTimeScale(true);
  46. }
  47. }