CopyPreferredSize.cs 927 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. namespace SRF.UI
  5. {
  6. [RequireComponent(typeof(RectTransform))]
  7. [ExecuteInEditMode]
  8. [AddComponentMenu("SRF/UI/Copy Preferred Size")]
  9. public class CopyPreferredSize : LayoutElement
  10. {
  11. public override float preferredWidth
  12. {
  13. get
  14. {
  15. if (this.CopySource == null || !this.IsActive())
  16. {
  17. return -1f;
  18. }
  19. return LayoutUtility.GetPreferredWidth(this.CopySource) + this.PaddingWidth;
  20. }
  21. }
  22. public override float preferredHeight
  23. {
  24. get
  25. {
  26. if (this.CopySource == null || !this.IsActive())
  27. {
  28. return -1f;
  29. }
  30. return LayoutUtility.GetPreferredHeight(this.CopySource) + this.PaddingHeight;
  31. }
  32. }
  33. public override int layoutPriority
  34. {
  35. get
  36. {
  37. return 2;
  38. }
  39. }
  40. public RectTransform CopySource;
  41. public float PaddingHeight;
  42. public float PaddingWidth;
  43. }
  44. }