using System; using UnityEngine; [RequireComponent(typeof(UIWidget))] [AddComponentMenu("NGUI/Tween/Tween Width")] public class TweenWidth : UITweener { public UIWidget cachedWidget { get { if (this.mWidget == null) { this.mWidget = base.GetComponent(); } return this.mWidget; } } [Obsolete("Use 'value' instead")] public int width { get { return this.value; } set { this.value = value; } } public int value { get { return this.cachedWidget.width; } set { this.cachedWidget.width = 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(base.gameObject); if (this.mTable == null) { this.updateTable = false; return; } } this.mTable.repositionNow = true; } } public static TweenWidth Begin(UIWidget widget, float duration, int width) { TweenWidth tweenWidth = UITweener.Begin(widget.gameObject, duration); tweenWidth.from = widget.width; tweenWidth.to = width; if (duration <= 0f) { tweenWidth.Sample(1f, true); tweenWidth.enabled = false; } return tweenWidth; } [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; }