VRMiniGameGaugeeManager.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. public class VRMiniGameGaugeeManager : VRWfChangeCanvas
  5. {
  6. public bool isPlay { get; private set; }
  7. public float gaugeValue
  8. {
  9. get
  10. {
  11. return (this.m_gaugeValue > 1f) ? (1f - (this.m_gaugeValue - 1f)) : this.m_gaugeValue;
  12. }
  13. }
  14. public override void ChangeDrawMode(bool worldMode)
  15. {
  16. if (worldMode)
  17. {
  18. base.renderMode = RenderMode.WorldSpace;
  19. this.rectTransform.localScale = new Vector3(0.001f, 0.001f, 0.001f);
  20. this.rectTransform.rotation = Quaternion.Euler(0f, -90f, 0f);
  21. this.transPowerGaugeBG.localPosition = new Vector3(-4f, 137.7966f, 786f);
  22. }
  23. else
  24. {
  25. base.renderMode = RenderMode.ScreenSpaceOverlay;
  26. this.rectTransform.localScale = Vector3.one;
  27. this.rectTransform.rotation = Quaternion.identity;
  28. this.transPowerGaugeBG.localPosition = new Vector3(-413f, -443.3871f, 0f);
  29. }
  30. }
  31. public void Play()
  32. {
  33. if (!this.isVisible)
  34. {
  35. return;
  36. }
  37. this.isPlay = true;
  38. this.m_gaugeValue = 0f;
  39. }
  40. public void Stop()
  41. {
  42. this.isPlay = false;
  43. this.m_gaugeValue = 0f;
  44. this.spritePowerGauge.fillAmount = 0f;
  45. }
  46. private void Update()
  47. {
  48. if (this.enabledMouseClickEvent && this.isVisible)
  49. {
  50. if (NInput.GetMouseButtonDown(0) && this.onMouseClickDownEvent != null)
  51. {
  52. this.onMouseClickDownEvent(this);
  53. }
  54. if (NInput.GetMouseButtonUp(0) && this.onMouseClickUpEvent != null)
  55. {
  56. this.onMouseClickUpEvent(this);
  57. }
  58. }
  59. if (this.isPlay)
  60. {
  61. this.m_gaugeValue += this.addGaugeValue * Time.deltaTime;
  62. }
  63. this.m_gaugeValue = Mathf.Clamp(this.m_gaugeValue, 0f, 2f);
  64. if (this.m_gaugeValue == 2f)
  65. {
  66. this.m_gaugeValue = 0f;
  67. }
  68. this.spritePowerGauge.fillAmount = ((this.m_gaugeValue > 1f) ? (1f - (this.m_gaugeValue - 1f)) : this.m_gaugeValue);
  69. }
  70. [SerializeField]
  71. [Tooltip("1秒間に加算されるゲージのパワー")]
  72. private float addGaugeValue = 0.01f;
  73. [SerializeField]
  74. [Tooltip("2D用ゲージ背景スプライト")]
  75. private RectTransform transPowerGaugeBG;
  76. [SerializeField]
  77. [Tooltip("2D用ゲージスプライト")]
  78. private Image spritePowerGauge;
  79. [NonSerialized]
  80. public bool enabledMouseClickEvent = true;
  81. [NonSerialized]
  82. public VRMiniGameGaugeeManager.OnMouseClickEvent onMouseClickDownEvent;
  83. [NonSerialized]
  84. public VRMiniGameGaugeeManager.OnMouseClickEvent onMouseClickUpEvent;
  85. private float m_gaugeValue;
  86. public delegate void OnMouseClickEvent(VRMiniGameGaugeeManager thisObject);
  87. }