Code structure cleanup. (2)
This commit is contained in:
50
Assets/Cryville/Crtr/Config/UI/PVPBool.cs
Normal file
50
Assets/Cryville/Crtr/Config/UI/PVPBool.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user