您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

124 行
2.2 KiB

  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.EventSystems;
  4. using UnityEngine.UI;
  5. [RequireComponent(typeof(RectTransform))]
  6. public class MarginElement : UIBehaviour, ILayoutElement
  7. {
  8. public float minWidth
  9. {
  10. get
  11. {
  12. return this.preferredWidth;
  13. }
  14. }
  15. public float preferredWidth { get; private set; }
  16. public float flexibleWidth
  17. {
  18. get
  19. {
  20. return 0f;
  21. }
  22. }
  23. public float minHeight
  24. {
  25. get
  26. {
  27. return this.preferredHeight;
  28. }
  29. }
  30. public float preferredHeight { get; private set; }
  31. public float flexibleHeight
  32. {
  33. get
  34. {
  35. return 0f;
  36. }
  37. }
  38. public int layoutPriority
  39. {
  40. get
  41. {
  42. return this._layoutPriority;
  43. }
  44. }
  45. public void AffectSize(float? preferredWidth, float? preferredHeight)
  46. {
  47. this._preferredWidth = preferredWidth;
  48. this._preferredHeight = preferredHeight;
  49. this.TrackerLogics();
  50. }
  51. public void CalculateLayoutInputHorizontal()
  52. {
  53. this.TrackerLogics();
  54. if (this._preferredWidth != null)
  55. {
  56. this.preferredWidth = this._preferredWidth.Value;
  57. }
  58. else
  59. {
  60. this.preferredWidth = -1f;
  61. }
  62. }
  63. public void CalculateLayoutInputVertical()
  64. {
  65. this.TrackerLogics();
  66. if (this._preferredHeight != null)
  67. {
  68. this.preferredHeight = this._preferredHeight.Value;
  69. }
  70. else
  71. {
  72. this.preferredHeight = -1f;
  73. }
  74. }
  75. private void TrackerLogics()
  76. {
  77. if (this._rectTransform == null)
  78. {
  79. this._rectTransform = base.GetComponent<RectTransform>();
  80. }
  81. this._tracker.Clear();
  82. DrivenTransformProperties drivenProperties;
  83. if (this._preferredWidth != null && this._preferredHeight != null)
  84. {
  85. drivenProperties = DrivenTransformProperties.SizeDelta;
  86. }
  87. else if (this._preferredWidth != null)
  88. {
  89. drivenProperties = DrivenTransformProperties.SizeDeltaX;
  90. }
  91. else
  92. {
  93. if (this._preferredHeight == null)
  94. {
  95. return;
  96. }
  97. drivenProperties = DrivenTransformProperties.SizeDeltaY;
  98. }
  99. this._tracker.Add(this, this._rectTransform, drivenProperties);
  100. }
  101. [SerializeField]
  102. private int _layoutPriority = 1;
  103. private DrivenRectTransformTracker _tracker;
  104. private RectTransform _rectTransform;
  105. private float? _preferredWidth;
  106. private float? _preferredHeight;
  107. }