ResponsiveBase.cs 773 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System;
  2. using UnityEngine;
  3. namespace SRF.UI
  4. {
  5. [RequireComponent(typeof(RectTransform))]
  6. [ExecuteInEditMode]
  7. public abstract class ResponsiveBase : SRMonoBehaviour
  8. {
  9. protected RectTransform RectTransform
  10. {
  11. get
  12. {
  13. return (RectTransform)base.CachedTransform;
  14. }
  15. }
  16. protected void OnEnable()
  17. {
  18. this._queueRefresh = true;
  19. }
  20. protected void OnRectTransformDimensionsChange()
  21. {
  22. this._queueRefresh = true;
  23. }
  24. protected void Update()
  25. {
  26. if (this._queueRefresh)
  27. {
  28. this.Refresh();
  29. this._queueRefresh = false;
  30. }
  31. }
  32. protected abstract void Refresh();
  33. [ContextMenu("Refresh")]
  34. private void DoRefresh()
  35. {
  36. this.Refresh();
  37. }
  38. private bool _queueRefresh;
  39. }
  40. }