mirror of
https://github.com/Cardidi/dotween-upm-fork.git
synced 2025-12-20 17:26:03 +08:00
Fixed Kill(true) not killing infinitely looping tweens
This commit is contained in:
parent
12668ae9cd
commit
4d4c89fe19
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -5,20 +5,18 @@ using System.Collections;
|
||||
|
||||
public class Temp : BrainBase
|
||||
{
|
||||
[SerializeField]
|
||||
private Vector3 pos;
|
||||
[SerializeField]
|
||||
private float duration;
|
||||
[SerializeField]
|
||||
private GameObject goToMove;
|
||||
public Transform target;
|
||||
|
||||
private Tweener moveTween;
|
||||
IEnumerator Start()
|
||||
{
|
||||
yield return new WaitForSeconds(0.6f);
|
||||
|
||||
// Update is called once per frame
|
||||
void Update() {
|
||||
if(moveTween == null) {
|
||||
moveTween = goToMove.transform.DOLocalMove(pos, duration).SetAutoKill(false);
|
||||
}
|
||||
moveTween.ChangeEndValue(pos, duration, true);
|
||||
Sequence s0 = DOTween.Sequence().Append(target.DOMoveX(3, 2)).OnComplete(()=> Debug.Log("s0 complete"));
|
||||
Sequence s1 = DOTween.Sequence().Append(target.DOMoveY(3, 2)).OnComplete(()=> Debug.Log("s1 complete"));
|
||||
Sequence s = DOTween.Sequence().Append(s0).Append(s1).OnComplete(()=> Debug.Log("MAIN COMPLETE"));
|
||||
|
||||
yield return new WaitForSeconds(0.2f);
|
||||
|
||||
s.Complete();
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@ -1,32 +1,96 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using DG.Tweening;
|
||||
using DG.Tweening.Plugins;
|
||||
using DG.Tweening.Plugins.Core;
|
||||
using DG.Tweening.Plugins.Options;
|
||||
using System;
|
||||
|
||||
public class TempTests : BrainBase
|
||||
{
|
||||
public Transform target;
|
||||
public Ease easeType;
|
||||
public float gotoTime;
|
||||
public Vector3[] waypoints;
|
||||
|
||||
Tween t;
|
||||
public float delay;
|
||||
Vector2 originalPosition;
|
||||
Vector2 targetOriginalPosition;
|
||||
SpriteRenderer targetOverlay;
|
||||
Sequence seq;
|
||||
int prevCompletedLoops;
|
||||
|
||||
IEnumerator Start()
|
||||
{
|
||||
yield return new WaitForSeconds(0.6f);
|
||||
originalPosition = transform.position;
|
||||
DOTween.Init();
|
||||
|
||||
t = target.DOPath(waypoints, 5, PathType.CatmullRom).SetEase(easeType);
|
||||
t.GotoWaypoint(2);
|
||||
yield return new WaitForSeconds(delay);
|
||||
|
||||
StartAnimationWithTarget(target);
|
||||
|
||||
yield return new WaitForSeconds(4);
|
||||
|
||||
StartCoroutine(StopAnimation());
|
||||
// Invoke("StopAnimation", 5);
|
||||
}
|
||||
|
||||
public void StartAnimationWithTarget(Transform target)
|
||||
{
|
||||
Debug.Log("StartAnimationWithTarget");
|
||||
|
||||
// Prepare
|
||||
targetOriginalPosition = target.position;
|
||||
targetOverlay = target.Find("Sprite").GetComponent<SpriteRenderer>();
|
||||
|
||||
// Execute
|
||||
Attack();
|
||||
}
|
||||
|
||||
public IEnumerator StopAnimation()
|
||||
{
|
||||
Debug.Log("Stopping animation");
|
||||
Debug.Log("Completed loops: " + seq.CompletedLoops());
|
||||
int loopTo = seq.CompletedLoops() + 1;
|
||||
// yield return seq.WaitForElapsedLoops(seq.CompletedLoops() + 1);
|
||||
yield return seq.WaitForElapsedLoops(loopTo);
|
||||
|
||||
Debug.Log("KILLING");
|
||||
|
||||
seq.Kill(true);
|
||||
}
|
||||
|
||||
void Attack()
|
||||
{
|
||||
Vector2 direction = (targetOriginalPosition - originalPosition).normalized;
|
||||
|
||||
float attackAnticipationTime = 0.05f;
|
||||
float attackMoveForwardTime = 0.08f;
|
||||
|
||||
// Attacking unit movement
|
||||
seq = DOTween.Sequence();
|
||||
seq.Append(transform.DOBlendableMoveBy(-direction * 0.05f, attackAnticipationTime));
|
||||
seq.Append(transform.DOBlendableMoveBy(direction * 0.2f, attackMoveForwardTime));
|
||||
seq.Append(transform.DOBlendableMoveBy(-((-direction * 0.05f) + (direction * 0.2f)), 0.3f));
|
||||
|
||||
// Target unit movement
|
||||
Sequence def = DOTween.Sequence();
|
||||
def.Append(target.DOBlendableMoveBy(direction * 0.2f, 0.05f));
|
||||
def.Append(target.DOBlendableMoveBy(-(direction * 0.2f), 0.3f));
|
||||
seq.Insert(attackAnticipationTime + attackMoveForwardTime, def);
|
||||
|
||||
// Target unit hit flashing
|
||||
targetOverlay.color = new Color(1, 1, 1, 0);
|
||||
Sequence flash = DOTween.Sequence();
|
||||
flash.Append(targetOverlay.DOFade(0.7f, 0.05f));
|
||||
flash.Append(targetOverlay.DOFade(0, 0.5f)).SetEase(Ease.Linear);
|
||||
seq.Insert(attackAnticipationTime + attackMoveForwardTime, flash);
|
||||
|
||||
seq.AppendInterval(1.5f);
|
||||
seq.SetLoops(-1);
|
||||
}
|
||||
|
||||
void OnGUI()
|
||||
{
|
||||
if (GUILayout.Button("Goto")) t.Goto(gotoTime);
|
||||
if (seq != null) {
|
||||
if (seq.CompletedLoops() != prevCompletedLoops) Debug.Log("LOOP CHANGE FROM " + prevCompletedLoops + " TO " + seq.CompletedLoops());
|
||||
GUILayout.Label("completed loops: " + seq.CompletedLoops() + " (duration: " + seq.Duration(false) + ")");
|
||||
prevCompletedLoops = seq.CompletedLoops();
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
@ -21,7 +21,7 @@ namespace DG.Tweening
|
||||
public class DOTween
|
||||
{
|
||||
/// <summary>DOTween's version</summary>
|
||||
public static readonly string Version = "1.0.350";
|
||||
public static readonly string Version = "1.0.351";
|
||||
|
||||
///////////////////////////////////////////////
|
||||
// Options ////////////////////////////////////
|
||||
|
||||
@ -97,7 +97,7 @@ namespace DG.Tweening
|
||||
|
||||
if (complete) {
|
||||
TweenManager.Complete(t);
|
||||
if (t.autoKill) return; // Already killed by Complete, so no need to go on
|
||||
if (t.autoKill && t.loops >= 0) return; // Already killed by Complete, so no need to go on
|
||||
}
|
||||
|
||||
if (TweenManager.isUpdateLoop) {
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user