public void UpdateLine() { if (state == PainterAnimationState.None || state == PainterAnimationState.Complete) { return; } float end = Time.time; if (end < startTime) { return; } float elapsed = end - startTime; if (elapsed >= duration) { // complete if (state == PainterAnimationState.Forward) { SetMaskValue(1f); } else if (state == PainterAnimationState.Rewind) { SetMaskValue(0f); } state = PainterAnimationState.Complete; } else { // update float changeVal = 0f; if (state == PainterAnimationState.Forward) { if (easing != null) { changeVal = easing(elapsed, 0f, 1f, duration); } else { changeVal = (elapsed / duration * 1.0f); } } else if (state == PainterAnimationState.Rewind) { if (easing != null) { changeVal = 1.0f - easing(elapsed, 0f, 1f, duration); } else { changeVal = 1.0f - (elapsed / duration * 1.0f); } } SetMaskValue(changeVal); } }
// Update is called once per frame void Update() { if (instanciate != null) { if (state == PainterState.Complete) { return; } if (instanciate.painters.Count >= 1) { int checkCompleteCount = 0; for (int i = 0; i < instanciate.painters.Count; i++) { instanciate.painters[i].UpdateLine(); PainterAnimationState pstate = instanciate.painters[i].GetState(); if (pstate == PainterAnimationState.Complete) { checkCompleteCount++; } } if (checkCompleteCount >= instanciate.painters.Count) { state = PainterState.Complete; if (onRewindComplete != null) { onRewindComplete(); onRewindComplete = null; } if (onComplete != null) { onComplete(); onComplete = null; } } } } }
public void Stop(bool showAll = false) { state = PainterAnimationState.Complete; SetMaskValue((showAll) ? 1f : 0f); }
public void Rewind(float _delay = 0f, System.Func <float, float, float, float, float> _easing = null) { state = PainterAnimationState.Rewind; SetUpParams(_delay, _easing); }