private void Tween(bool open, float timeout, TweenDirection tweenDirection) { if (open && (State == TweenPanelState.Opened || State == TweenPanelState.Opening)) { return; } if (!open && (State == TweenPanelState.Hidden || State == TweenPanelState.Hiding)) { return; } TaskScheduler.Kill(Id); State = open ? TweenPanelState.Opening : TweenPanelState.Hiding; TaskScheduler.CreateTask(() => State = open ? TweenPanelState.Opened : TweenPanelState.Hidden, Id, timeout); Vector3 target; if (open && State != TweenPanelState.Hiding) { transform.localPosition = GetHiddenPosition(tweenDirection); if (Transparency) { GetComponent <UIPanel>().alpha = 0; } } if (open) { target = Vector3.zero; gameObject.SetActive(true); } else { target = GetHiddenPosition(tweenDirection); if (timeout > 0) { TaskScheduler.CreateTask(() => gameObject.SetActive(false), Id, timeout); } else { gameObject.SetActive(true); } } if (timeout > 0) { TweenPosition.Begin(gameObject, timeout, target).animationCurve = AnimationCurve; if (Transparency) { TaskScheduler.CreateTask(() => TweenAlpha.Begin(gameObject, timeout / 2, open ? 1 : 0), Id, open ? timeout / 2 : 0); } } else { transform.localPosition = target; if (Transparency) { GetComponent <UIPanel>().alpha = open ? 1 : 0; } } }
public void Start() { State = TweenPanelState.Opened; }