You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
CrowdControl/Assets/3rd/StompyRobot/SRF/Scripts/UI/ResponsiveBase.cs

56 lines
1.1 KiB
C#

3 months ago
namespace SRF.UI
{
using UnityEngine;
[ExecuteInEditMode]
[RequireComponent(typeof (RectTransform))]
public abstract class ResponsiveBase : SRMonoBehaviour
{
private bool _queueRefresh;
protected RectTransform RectTransform
{
get { return (RectTransform) CachedTransform; }
}
protected void OnEnable()
{
_queueRefresh = true;
}
protected void OnRectTransformDimensionsChange()
{
_queueRefresh = true;
}
protected void Update()
{
#if UNITY_EDITOR
// Refresh whenever we can in the editor, since layout has quirky update behaviour
// when not in play mode
if (!Application.isPlaying)
{
Refresh();
return;
}
#endif
if (_queueRefresh)
{
Refresh();
_queueRefresh = false;
}
}
protected abstract void Refresh();
[ContextMenu("Refresh")]
private void DoRefresh()
{
Refresh();
}
}
}