CopyLayoutElement.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.EventSystems;
  4. using UnityEngine.UI;
  5. namespace SRF.UI
  6. {
  7. [RequireComponent(typeof(RectTransform))]
  8. [AddComponentMenu("SRF/UI/Copy Layout Element")]
  9. [ExecuteInEditMode]
  10. public class CopyLayoutElement : UIBehaviour, ILayoutElement
  11. {
  12. public float preferredWidth
  13. {
  14. get
  15. {
  16. if (!this.CopyPreferredWidth || this.CopySource == null || !this.IsActive())
  17. {
  18. return -1f;
  19. }
  20. return LayoutUtility.GetPreferredWidth(this.CopySource) + this.PaddingPreferredWidth;
  21. }
  22. }
  23. public float preferredHeight
  24. {
  25. get
  26. {
  27. if (!this.CopyPreferredHeight || this.CopySource == null || !this.IsActive())
  28. {
  29. return -1f;
  30. }
  31. return LayoutUtility.GetPreferredHeight(this.CopySource) + this.PaddingPreferredHeight;
  32. }
  33. }
  34. public float minWidth
  35. {
  36. get
  37. {
  38. if (!this.CopyMinWidth || this.CopySource == null || !this.IsActive())
  39. {
  40. return -1f;
  41. }
  42. return LayoutUtility.GetMinWidth(this.CopySource) + this.PaddingMinWidth;
  43. }
  44. }
  45. public float minHeight
  46. {
  47. get
  48. {
  49. if (!this.CopyMinHeight || this.CopySource == null || !this.IsActive())
  50. {
  51. return -1f;
  52. }
  53. return LayoutUtility.GetMinHeight(this.CopySource) + this.PaddingMinHeight;
  54. }
  55. }
  56. public int layoutPriority
  57. {
  58. get
  59. {
  60. return 2;
  61. }
  62. }
  63. public float flexibleHeight
  64. {
  65. get
  66. {
  67. return -1f;
  68. }
  69. }
  70. public float flexibleWidth
  71. {
  72. get
  73. {
  74. return -1f;
  75. }
  76. }
  77. public void CalculateLayoutInputHorizontal()
  78. {
  79. }
  80. public void CalculateLayoutInputVertical()
  81. {
  82. }
  83. public bool CopyMinHeight;
  84. public bool CopyMinWidth;
  85. public bool CopyPreferredHeight;
  86. public bool CopyPreferredWidth;
  87. public RectTransform CopySource;
  88. public float PaddingMinHeight;
  89. public float PaddingMinWidth;
  90. public float PaddingPreferredHeight;
  91. public float PaddingPreferredWidth;
  92. }
  93. }