123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- using System;
- using UnityEngine;
- [RequireComponent(typeof(UIWidget))]
- [AddComponentMenu("NGUI/Tween/Tween Height")]
- public class TweenHeight : UITweener
- {
- public UIWidget cachedWidget
- {
- get
- {
- if (this.mWidget == null)
- {
- this.mWidget = base.GetComponent<UIWidget>();
- }
- return this.mWidget;
- }
- }
- [Obsolete("Use 'value' instead")]
- public int height
- {
- get
- {
- return this.value;
- }
- set
- {
- this.value = value;
- }
- }
- public int value
- {
- get
- {
- return this.cachedWidget.height;
- }
- set
- {
- this.cachedWidget.height = value;
- }
- }
- protected override void OnUpdate(float factor, bool isFinished)
- {
- this.value = Mathf.RoundToInt((float)this.from * (1f - factor) + (float)this.to * factor);
- if (this.updateTable)
- {
- if (this.mTable == null)
- {
- this.mTable = NGUITools.FindInParents<UITable>(base.gameObject);
- if (this.mTable == null)
- {
- this.updateTable = false;
- return;
- }
- }
- this.mTable.repositionNow = true;
- }
- }
- public static TweenHeight Begin(UIWidget widget, float duration, int height)
- {
- TweenHeight tweenHeight = UITweener.Begin<TweenHeight>(widget.gameObject, duration);
- tweenHeight.from = widget.height;
- tweenHeight.to = height;
- if (duration <= 0f)
- {
- tweenHeight.Sample(1f, true);
- tweenHeight.enabled = false;
- }
- return tweenHeight;
- }
- [ContextMenu("Set 'From' to current value")]
- public override void SetStartToCurrentValue()
- {
- this.from = this.value;
- }
- [ContextMenu("Set 'To' to current value")]
- public override void SetEndToCurrentValue()
- {
- this.to = this.value;
- }
- [ContextMenu("Assume value of 'From'")]
- private void SetCurrentValueToStart()
- {
- this.value = this.from;
- }
- [ContextMenu("Assume value of 'To'")]
- private void SetCurrentValueToEnd()
- {
- this.value = this.to;
- }
- public int from = 100;
- public int to = 100;
- public bool updateTable;
- private UIWidget mWidget;
- private UITable mTable;
- }
|