Rewrite property panel to adapt to ruleset config.

This commit is contained in:
2023-07-27 22:07:20 +08:00
parent 9b091a0084
commit bc51a45df8
39 changed files with 825 additions and 298 deletions

View File

@@ -0,0 +1,50 @@
using UnityEngine;
using UnityEngine.EventSystems;
namespace Cryville.Crtr.Config {
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();
}
}
}