123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- 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<UIWidget>();
- }
- 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<UITable>(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<TweenWidth>(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;
- }
|