PrimeTweenの onCompleteが呼ばれるタイミング
結論
- startDelay
– startDelayを足した分遅れて完了が通知される
- endDelay
– endDelayを足した分遅れて完了が通知される
そりゃそう
using System;
using PrimeTween;
using UnityEngine;
using UnityEngine.UI;
public class TweenOnCompleteCheck : MonoBehaviour
{
[SerializeField]
Transform noDelay;
[SerializeField]
Transform withStartDelay;
[SerializeField]
Transform withEndDelay;
[SerializeField]
Transform withBothDelays;
[SerializeField]
float startDelayDuration = 1.0f;
[SerializeField]
float endDelayDuration = 1.0f;
[SerializeField]
float animationDuration = 4.0f;
[SerializeField]
float targetPositionX = 5.0f;
[SerializeField]
Text durationText;
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
StartTween();
}
}
void StartTween()
{
noDelay.position = new Vector2(0, noDelay.position.y);
withStartDelay.position = new Vector2(0, withStartDelay.position.y);
withEndDelay.position = new Vector2(0, withEndDelay.position.y);
withBothDelays.position = new Vector2(0, withBothDelays.position.y);
Tween.PositionX(noDelay, targetPositionX, animationDuration, ease: Ease.Linear).OnComplete(() =>
{
noDelay.GetComponent<SpriteRenderer>().color = Color.red;
Debug.Log("Tween without delay completed");
});
Tween.PositionX(withStartDelay, targetPositionX, animationDuration, startDelay: startDelayDuration, ease: Ease.Linear).OnComplete(() =>
{
withStartDelay.GetComponent<SpriteRenderer>().color = Color.green;
Debug.Log("Tween with start delay completed");
});
Tween.PositionX(withEndDelay, targetPositionX, animationDuration, endDelay: endDelayDuration, ease: Ease.Linear).OnComplete(() =>
{
withEndDelay.GetComponent<SpriteRenderer>().color = Color.blue;
Debug.Log("Tween with end delay completed");
});
Tween.PositionX(withBothDelays, targetPositionX, animationDuration, startDelay: startDelayDuration, endDelay: endDelayDuration, ease: Ease.Linear).OnComplete(() =>
{
withBothDelays.GetComponent<SpriteRenderer>().color = Color.yellow;
Debug.Log("Tween with both delays completed");
});
Tween.Custom(0f, 10f, duration: 10, onValueChange: value => durationText.text = value.ToString(), Ease.Linear);
}
}