1
0
mirror of https://github.com/Cardidi/dotween-upm-fork.git synced 2025-12-21 17:56:08 +08:00

Fixed Kill(true) not killing infinitely looping tweens

This commit is contained in:
Daniele Giardini 2015-03-25 17:45:23 +01:00
parent 12668ae9cd
commit 4d4c89fe19
15 changed files with 91 additions and 29 deletions

View File

@ -5,20 +5,18 @@ using System.Collections;
public class Temp : BrainBase public class Temp : BrainBase
{ {
[SerializeField] public Transform target;
private Vector3 pos;
[SerializeField]
private float duration;
[SerializeField]
private GameObject goToMove;
private Tweener moveTween; IEnumerator Start()
{
yield return new WaitForSeconds(0.6f);
// Update is called once per frame Sequence s0 = DOTween.Sequence().Append(target.DOMoveX(3, 2)).OnComplete(()=> Debug.Log("s0 complete"));
void Update() { Sequence s1 = DOTween.Sequence().Append(target.DOMoveY(3, 2)).OnComplete(()=> Debug.Log("s1 complete"));
if(moveTween == null) { Sequence s = DOTween.Sequence().Append(s0).Append(s1).OnComplete(()=> Debug.Log("MAIN COMPLETE"));
moveTween = goToMove.transform.DOLocalMove(pos, duration).SetAutoKill(false);
} yield return new WaitForSeconds(0.2f);
moveTween.ChangeEndValue(pos, duration, true);
s.Complete();
} }
} }

View File

@ -1,32 +1,96 @@
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using DG.Tweening; using DG.Tweening;
using DG.Tweening.Plugins;
using DG.Tweening.Plugins.Core;
using DG.Tweening.Plugins.Options;
using System;
public class TempTests : BrainBase public class TempTests : BrainBase
{ {
public Transform target; public Transform target;
public Ease easeType; public float delay;
public float gotoTime; Vector2 originalPosition;
public Vector3[] waypoints; Vector2 targetOriginalPosition;
SpriteRenderer targetOverlay;
Tween t; Sequence seq;
int prevCompletedLoops;
IEnumerator Start() IEnumerator Start()
{ {
yield return new WaitForSeconds(0.6f); originalPosition = transform.position;
DOTween.Init();
t = target.DOPath(waypoints, 5, PathType.CatmullRom).SetEase(easeType); yield return new WaitForSeconds(delay);
t.GotoWaypoint(2);
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() 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();
}
} }
} }

View File

@ -21,7 +21,7 @@ namespace DG.Tweening
public class DOTween public class DOTween
{ {
/// <summary>DOTween's version</summary> /// <summary>DOTween's version</summary>
public static readonly string Version = "1.0.350"; public static readonly string Version = "1.0.351";
/////////////////////////////////////////////// ///////////////////////////////////////////////
// Options //////////////////////////////////// // Options ////////////////////////////////////

View File

@ -97,7 +97,7 @@ namespace DG.Tweening
if (complete) { if (complete) {
TweenManager.Complete(t); 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) { if (TweenManager.isUpdateLoop) {

Binary file not shown.