using System; using UnityEngine; using UnityEngine.UI; public class VRMiniGameGaugeeManager : VRWfChangeCanvas { public bool isPlay { get; private set; } public float gaugeValue { get { return (this.m_gaugeValue > 1f) ? (1f - (this.m_gaugeValue - 1f)) : this.m_gaugeValue; } } public override void ChangeDrawMode(bool worldMode) { if (worldMode) { base.renderMode = RenderMode.WorldSpace; this.rectTransform.localScale = new Vector3(0.001f, 0.001f, 0.001f); this.rectTransform.rotation = Quaternion.Euler(0f, -90f, 0f); this.transPowerGaugeBG.localPosition = new Vector3(-4f, 137.7966f, 786f); } else { base.renderMode = RenderMode.ScreenSpaceOverlay; this.rectTransform.localScale = Vector3.one; this.rectTransform.rotation = Quaternion.identity; this.transPowerGaugeBG.localPosition = new Vector3(-413f, -443.3871f, 0f); } } public void Play() { if (!this.isVisible) { return; } this.isPlay = true; this.m_gaugeValue = 0f; } public void Stop() { this.isPlay = false; this.m_gaugeValue = 0f; this.spritePowerGauge.fillAmount = 0f; } private void Update() { if (this.enabledMouseClickEvent && this.isVisible) { if (NInput.GetMouseButtonDown(0) && this.onMouseClickDownEvent != null) { this.onMouseClickDownEvent(this); } if (NInput.GetMouseButtonUp(0) && this.onMouseClickUpEvent != null) { this.onMouseClickUpEvent(this); } } if (this.isPlay) { this.m_gaugeValue += this.addGaugeValue * Time.deltaTime; } this.m_gaugeValue = Mathf.Clamp(this.m_gaugeValue, 0f, 2f); if (this.m_gaugeValue == 2f) { this.m_gaugeValue = 0f; } this.spritePowerGauge.fillAmount = ((this.m_gaugeValue > 1f) ? (1f - (this.m_gaugeValue - 1f)) : this.m_gaugeValue); } [SerializeField] [Tooltip("1秒間に加算されるゲージのパワー")] private float addGaugeValue = 0.01f; [SerializeField] [Tooltip("2D用ゲージ背景スプライト")] private RectTransform transPowerGaugeBG; [SerializeField] [Tooltip("2D用ゲージスプライト")] private Image spritePowerGauge; [NonSerialized] public bool enabledMouseClickEvent = true; [NonSerialized] public VRMiniGameGaugeeManager.OnMouseClickEvent onMouseClickDownEvent; [NonSerialized] public VRMiniGameGaugeeManager.OnMouseClickEvent onMouseClickUpEvent; private float m_gaugeValue; public delegate void OnMouseClickEvent(VRMiniGameGaugeeManager thisObject); }