|
- using System;
- using UnityEngine;
- using UnityEngine.EventSystems;
- using UnityEngine.UI;
-
- [RequireComponent(typeof(RectTransform))]
- public class MarginElement : UIBehaviour, ILayoutElement
- {
- public float minWidth
- {
- get
- {
- return this.preferredWidth;
- }
- }
-
- public float preferredWidth { get; private set; }
-
- public float flexibleWidth
- {
- get
- {
- return 0f;
- }
- }
-
- public float minHeight
- {
- get
- {
- return this.preferredHeight;
- }
- }
-
- public float preferredHeight { get; private set; }
-
- public float flexibleHeight
- {
- get
- {
- return 0f;
- }
- }
-
- public int layoutPriority
- {
- get
- {
- return this._layoutPriority;
- }
- }
-
- public void AffectSize(float? preferredWidth, float? preferredHeight)
- {
- this._preferredWidth = preferredWidth;
- this._preferredHeight = preferredHeight;
- this.TrackerLogics();
- }
-
- public void CalculateLayoutInputHorizontal()
- {
- this.TrackerLogics();
- if (this._preferredWidth != null)
- {
- this.preferredWidth = this._preferredWidth.Value;
- }
- else
- {
- this.preferredWidth = -1f;
- }
- }
-
- public void CalculateLayoutInputVertical()
- {
- this.TrackerLogics();
- if (this._preferredHeight != null)
- {
- this.preferredHeight = this._preferredHeight.Value;
- }
- else
- {
- this.preferredHeight = -1f;
- }
- }
-
- private void TrackerLogics()
- {
- if (this._rectTransform == null)
- {
- this._rectTransform = base.GetComponent<RectTransform>();
- }
- this._tracker.Clear();
- DrivenTransformProperties drivenProperties;
- if (this._preferredWidth != null && this._preferredHeight != null)
- {
- drivenProperties = DrivenTransformProperties.SizeDelta;
- }
- else if (this._preferredWidth != null)
- {
- drivenProperties = DrivenTransformProperties.SizeDeltaX;
- }
- else
- {
- if (this._preferredHeight == null)
- {
- return;
- }
- drivenProperties = DrivenTransformProperties.SizeDeltaY;
- }
- this._tracker.Add(this, this._rectTransform, drivenProperties);
- }
-
- [SerializeField]
- private int _layoutPriority = 1;
-
- private DrivenRectTransformTracker _tracker;
-
- private RectTransform _rectTransform;
-
- private float? _preferredWidth;
-
- private float? _preferredHeight;
- }
|