UIVolumeController.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System;
  2. using DG.Tweening;
  3. using DG.Tweening.Core;
  4. using DG.Tweening.Plugins.Options;
  5. using UnityEngine;
  6. public class UIVolumeController : MonoBehaviour
  7. {
  8. public YieldInstruction Show(float volume)
  9. {
  10. this._widget.gameObject.SetActive(true);
  11. this._widget.alpha = 0f;
  12. if ((double)Mathf.Abs(volume) < 0.0001)
  13. {
  14. this._volumeOffSprite.gameObject.SetActive(true);
  15. this._volumeUpSprite.gameObject.SetActive(false);
  16. this._volumeBar.gameObject.SetActive(false);
  17. }
  18. else
  19. {
  20. this._volumeOffSprite.gameObject.SetActive(false);
  21. this._volumeUpSprite.gameObject.SetActive(true);
  22. this._volumeBar.gameObject.SetActive(true);
  23. }
  24. this._volumeBar.value = volume;
  25. return DOTween.To(() => this._widget.alpha, delegate(float a)
  26. {
  27. this._widget.alpha = a;
  28. }, 1f, 1f).WaitForCompletion();
  29. }
  30. public YieldInstruction Hide()
  31. {
  32. return DOTween.To(() => this._widget.alpha, delegate(float a)
  33. {
  34. this._widget.alpha = a;
  35. }, 0f, 1f).WaitForCompletion();
  36. }
  37. public YieldInstruction BarAnim(float endValue, float duration)
  38. {
  39. if ((double)Mathf.Abs(endValue) > 0.0001 && this._volumeOffSprite.gameObject.activeInHierarchy)
  40. {
  41. this._volumeOffSprite.gameObject.SetActive(false);
  42. this._volumeUpSprite.gameObject.SetActive(true);
  43. this._volumeBar.gameObject.SetActive(true);
  44. }
  45. return DOTween.To(() => this._volumeBar.value, delegate(float v)
  46. {
  47. this._volumeBar.value = v;
  48. }, endValue, duration).OnComplete(delegate
  49. {
  50. if ((double)Mathf.Abs(endValue) < 0.0001)
  51. {
  52. this._volumeOffSprite.gameObject.SetActive(true);
  53. this._volumeUpSprite.gameObject.SetActive(false);
  54. this._volumeBar.gameObject.SetActive(false);
  55. }
  56. }).WaitForCompletion();
  57. }
  58. [SerializeField]
  59. private UIWidget _widget;
  60. [SerializeField]
  61. private UISprite _volumeUpSprite;
  62. [SerializeField]
  63. private UISprite _volumeOffSprite;
  64. [SerializeField]
  65. private UIProgressBar _volumeBar;
  66. }