1
0
mirror of https://github.com/Cardidi/dotween-upm-fork.git synced 2025-12-20 09:16:02 +08:00

Added DOBlendablePunchRotation (thanks to Steve Streeting)

This commit is contained in:
Demigiant 2017-10-09 21:44:46 +02:00
parent 26e2e7f155
commit c4366240e1
24 changed files with 142 additions and 37 deletions

View File

@ -0,0 +1,24 @@
using System.Collections;
using System.Collections.Generic;
using DG.Tweening;
using UnityEngine;
public class DOJumpLookAtPath : MonoBehaviour
{
public Transform target;
public float duration;
public float jumpPower;
public Vector3 jumpEnd;
IEnumerator Start()
{
yield return new WaitForSeconds(0.8f);
float midP = duration * 0.25f; // approximate mid point when using an OutQuad ease
Vector3 jumpPeak = jumpEnd - target.position + new Vector3(0, jumpPower, 0);
Sequence s = DOTween.Sequence()
.Join(target.DOJump(jumpEnd, jumpPower, 1, duration))
.Join(target.DOLookAt(jumpPeak, midP * 0.05f)) // Make this faster so it looks almost immediately
.Insert(midP, target.DOLookAt(jumpEnd, duration - midP, AxisConstraint.Z));
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: acf2ce93692191740920bab74b5b7d9e
timeCreated: 1506945621
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 74761f122846fbc4a834d4d3660a6668
timeCreated: 1506945613
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@ -7,37 +7,17 @@ using UnityEngine.SceneManagement;
public class TempPro : MonoBehaviour public class TempPro : MonoBehaviour
{ {
public Transform target; public Transform target;
public Vector3 damageShakeStrength = new Vector3( 0.4f, 0.2f, 0 );
public int damageShakeVibration = 7;
public float damageShakeRandomness = 15;
public float damageShakeDuration = 1.5f;
private Tweener screenShake;
private Vector3 original;
// Use this for initialization
void Start() void Start()
{ {
original = target.position; // target.DOScale(2, 0.1f).SetLoops(2, LoopType.Yoyo).SetAutoKill(false).Pause();
} }
// Update is called once per frame
void Update() void Update()
{ {
if ( Input.GetKeyDown( KeyCode.K ) ) if (Input.GetKeyDown(KeyCode.Space)) {
Time.timeScale = Time.timeScale < 1 ? Time.timeScale = 1 : 0; Debug.Log(DOTween.TweensByTarget(target).Count);
target.DOPlay();
if ( Input.GetKeyDown( KeyCode.S ) ) } else if (Input.GetKeyDown(KeyCode.E)) target.GetComponent<DOTweenAnimation>().DOPlay();
{
Vector3 shakeOffset = new Vector3();
screenShake = DOTween.Shake( () => shakeOffset, x => { shakeOffset = x; target.position += x; }, damageShakeDuration, damageShakeStrength, damageShakeVibration, damageShakeRandomness, false )
.SetUpdate( false );
// screenShake = target.DOMoveX(10, damageShakeDuration);
// screenShake = target.DOShakePosition(damageShakeDuration, damageShakeStrength, damageShakeVibration, damageShakeRandomness, false);
screenShake.OnComplete( () =>
{
screenShake = target.DOMove( original, 0.5f ).OnComplete( () => screenShake = null ).SetUpdate( false );
} );
}
} }
} }

View File

@ -10,13 +10,13 @@ public class IndexOutOfRangeOnKill : BrainBase
transform.DOScale(Vector3.zero, 1000).OnKill(() => transform.gameObject.SetActive(false)); transform.DOScale(Vector3.zero, 1000).OnKill(() => transform.gameObject.SetActive(false));
yield return new WaitForSeconds(1.5f); yield return new WaitForSeconds(1.5f);
transform.DOKill(); transform.DOKill();
Debug.Log("START COMPLETION"); Debug.Log("Start() completed");
} }
void OnDisable() void OnDisable()
{ {
Debug.Log("DISABLE"); Debug.Log("OnDisable()");
transform.DOKill(); transform.DOKill();
} }
} }

View File

@ -0,0 +1,34 @@
using System.Collections;
using System.Collections.Generic;
using DG.Tweening;
using UnityEngine;
public class IndexOutOfRangeOnKill02 : MonoBehaviour
{
// Can't replicate the error
void Start()
{
Debug.Log("Start() ► Disabling safe mode");
DOTween.Init(false, false);
Tween t = transform.DOMoveX(2, 2);
t.OnComplete(() => {
Debug.Log("OnComplete()");
TweenKiller();
Destroy(gameObject);
});
}
void OnDestroy()
{
Debug.Log("OnDestroy()");
TweenKiller();
}
void TweenKiller()
{
Debug.Log("TweenKiller()");
transform.DOKill(true);
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 1640399a20baa4b49a8159d55b1b5633
timeCreated: 1507028404
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: f6e7f8051bf9e5e419cb197ecdb0105b
timeCreated: 1507028396
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@ -12,16 +12,11 @@ using UnityEngine.UI;
public class TempTests : BrainBase public class TempTests : BrainBase
{ {
public Rigidbody target; public Rigidbody target;
public float duration = 1f;
void Start() void Start()
{ {
target.DOMoveY(10, 0.3f).OnComplete(()=> { target.transform.DOJump(new Vector3(2.5f, 1.5f, -4.5f), 2, 1, duration).SetDelay(1)
Debug.Log("complete"); .OnComplete(()=> Debug.Log(target.position));
});
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Space)) SceneManager.LoadScene(SceneManager.GetActiveScene().name);
} }
} }

View File

@ -1 +1 @@
m_EditorVersion: 5.6.3p1 m_EditorVersion: 5.6.3p4

View File

@ -32,7 +32,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.1.650"; public static readonly string Version = "1.1.655";
/////////////////////////////////////////////// ///////////////////////////////////////////////
// Options //////////////////////////////////// // Options ////////////////////////////////////

View File

@ -1283,6 +1283,38 @@ namespace DG.Tweening
return t; return t;
} }
// Added by Steve Streeting > https://github.com/sinbad
/// <summary>Punches a Transform's localRotation BY the given value and then back to the starting one
/// as if it was connected to the starting rotation via an elastic. Does it in a way that allows other
/// DOBlendableRotate tweens to work together on the same target</summary>
/// <param name="punch">The punch strength (added to the Transform's current rotation)</param>
/// <param name="duration">The duration of the tween</param>
/// <param name="vibrato">Indicates how much will the punch vibrate</param>
/// <param name="elasticity">Represents how much (0 to 1) the vector will go beyond the starting rotation when bouncing backwards.
/// 1 creates a full oscillation between the punch rotation and the opposite rotation,
/// while 0 oscillates only between the punch and the start rotation</param>
public static Tweener DOBlendablePunchRotation(this Transform target, Vector3 punch, float duration, int vibrato = 10, float elasticity = 1)
{
if (duration <= 0) {
if (Debugger.logPriority > 0) Debug.LogWarning("DOBlendablePunchRotation: duration can't be 0, returning NULL without creating a tween");
return null;
}
Vector3 to = Vector3.zero;
TweenerCore<DOVector3, DOVector3[], Vector3ArrayOptions> t = DOTween.Punch(() => to, v => {
Quaternion qto = Quaternion.Euler(to.x, to.y, to.z);
Quaternion qnew = Quaternion.Euler(v.x, v.y, v.z);
#if COMPATIBLE
Quaternion diff = x.value * Quaternion.Inverse(qto);
#else
Quaternion diff = qnew * Quaternion.Inverse(qto);
#endif
to = v;
target.rotation = target.rotation * Quaternion.Inverse(target.rotation) * diff * target.rotation;
}, punch, duration, vibrato, elasticity)
.Blendable().SetTarget(target);
return t;
}
/// <summary>Tweens a Transform's localScale BY the given value (as if you chained a <code>SetRelative</code>), /// <summary>Tweens a Transform's localScale BY the given value (as if you chained a <code>SetRelative</code>),
/// in a way that allows other DOBlendableScale tweens to work together on the same target, /// in a way that allows other DOBlendableScale tweens to work together on the same target,
/// instead than fight each other as multiple DOScale would do. /// instead than fight each other as multiple DOScale would do.

Binary file not shown.