LayoutGroup.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using UnityEngine;
  2. namespace EZXR.Glass.UI
  3. {
  4. [ExecuteInEditMode]
  5. public class LayoutGroup : MonoBehaviour
  6. {
  7. protected SpatialUIElement spatialUIElement;
  8. protected bool needReLayout;
  9. protected bool startLayout;
  10. public virtual void OnValidate()
  11. {
  12. }
  13. public virtual void OnEnable()
  14. {
  15. Debug.Log("GridLayoutGroup must be attached on Object with SpatialUIElement, or it's parent has SpatialUIElement attached");
  16. GetSpatialUIElement();
  17. if (spatialUIElement == null)
  18. {
  19. Debug.LogError("GridLayoutGroup must be attached on Object with SpatialUIElement, or it's parent has SpatialUIElement attached");
  20. }
  21. else
  22. {
  23. startLayout = true;
  24. needReLayout = true;
  25. }
  26. }
  27. public void ReLayout()
  28. {
  29. needReLayout = true;
  30. }
  31. protected void GetSpatialUIElement()
  32. {
  33. if (spatialUIElement == null)
  34. {
  35. spatialUIElement = transform.GetComponent<SpatialUIElement>();
  36. if (spatialUIElement == null && transform.parent != null)
  37. {
  38. spatialUIElement = transform.GetComponentInParent<SpatialUIElement>(true);
  39. }
  40. }
  41. }
  42. }
  43. }