9 [RequireComponent(typeof(RectTransform), typeof(LayoutElement))]
10 [AddComponentMenu(
"UI/Extensions/Accordion/Accordion Element")]
14 [SerializeField]
private float m_MinHeight = 18f;
17 private RectTransform m_RectTransform;
18 private LayoutElement m_LayoutElement;
21 private readonly TweenRunner<FloatTween> m_FloatTweenRunner;
25 if (this.m_FloatTweenRunner ==
null)
26 this.m_FloatTweenRunner =
new TweenRunner<FloatTween>();
28 this.m_FloatTweenRunner.Init(
this);
34 base.transition = Transition.None;
35 base.toggleTransition = ToggleTransition.None;
36 this.m_Accordion = this.gameObject.GetComponentInParent<
Accordion>();
37 this.m_RectTransform = this.transform as RectTransform;
38 this.m_LayoutElement = this.gameObject.GetComponent<LayoutElement>();
43 protected override void OnValidate()
47 if (this.group ==
null)
49 ToggleGroup tg = this.GetComponentInParent<ToggleGroup>();
57 LayoutElement le = this.gameObject.GetComponent<LayoutElement>();
63 le.preferredHeight = -1f;
67 le.preferredHeight = this.m_MinHeight;
75 if (this.m_LayoutElement ==
null)
84 this.m_LayoutElement.preferredHeight = -1f;
88 this.m_LayoutElement.preferredHeight = this.m_MinHeight;
99 this.
StartTween(this.m_RectTransform.rect.height,
this.m_MinHeight);
106 if (this.m_LayoutElement ==
null)
107 return this.m_MinHeight;
109 float originalPrefH = this.m_LayoutElement.preferredHeight;
110 this.m_LayoutElement.preferredHeight = -1f;
111 float h = LayoutUtility.GetPreferredHeight(this.m_RectTransform);
112 this.m_LayoutElement.preferredHeight = originalPrefH;
117 protected void StartTween(
float startFloat,
float targetFloat)
119 float duration = (this.m_Accordion !=
null) ? this.m_Accordion.
transitionDuration : 0.3f;
124 startFloat = startFloat,
125 targetFloat = targetFloat
128 info.ignoreTimeScale =
true;
129 this.m_FloatTweenRunner.StartTween(info);
134 if (this.m_LayoutElement ==
null)
137 this.m_LayoutElement.preferredHeight = height;
void SetHeight(float height)
void OnValueChanged(bool state)
float GetExpandedHeight()
void StartTween(float startFloat, float targetFloat)
float transitionDuration
Gets or sets the duration of the transition.
Transition transition
Gets or sets the transition.
Credit Erdener Gonenc - @PixelEnvision.
void AddOnChangedCallback(UnityAction< float > callback)
Adds a on changed callback.