using UnityEngine; using UnityEngine.EventSystems; namespace Cryville.Crtr.Config.UI { public class PVPBool : PropertyValuePanel, IPointerClickHandler { [SerializeField] RectTransform m_on; [SerializeField] RectTransform m_handle; protected override void OnValueUpdated() { } public void Toggle() { RawValue = !(bool)RawValue; } const float SPEED = 8; float _ratio; #pragma warning disable IDE0051 void Update() { if ((bool)RawValue && _ratio != 1) { _ratio += SPEED * Time.deltaTime; if (_ratio > 1) _ratio = 1; UpdateGraphics(); } else if (!(bool)RawValue && _ratio != 0) { _ratio -= SPEED * Time.deltaTime; if (_ratio < 0) _ratio = 0; UpdateGraphics(); } } #pragma warning restore IDE0051 void UpdateGraphics() { m_on.anchorMax = new Vector2(_ratio, m_on.anchorMax.y); m_handle.anchorMin = new Vector2(_ratio, m_handle.anchorMin.y); m_handle.anchorMax = new Vector2(_ratio, m_handle.anchorMax.y); } public void OnPointerClick(PointerEventData eventData) { Toggle(); } } }