Code structure cleanup. (2)

This commit is contained in:
2023-08-24 16:18:16 +08:00
parent 1f58390298
commit 8fa2bd1e81
55 changed files with 77 additions and 65 deletions

View File

@@ -0,0 +1,50 @@
using UnityEngine;
using UnityEngine.EventSystems;
namespace Cryville.Crtr.Config.UI {
public class PVPBool : PropertyValuePanel, IPointerClickHandler {
[SerializeField]
RectTransform m_on;
[SerializeField]
RectTransform m_handleArea;
[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();
}
}
void OnRectTransformDimensionsChange() {
m_handleArea.sizeDelta = new Vector2(m_handle.rect.height - m_handle.rect.width, 0);
}
#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();
}
}
}