mirror of
https://github.com/Cardidi/dotween-upm-fork.git
synced 2025-12-20 01:06:02 +08:00
96 lines
4.9 KiB
C#
96 lines
4.9 KiB
C#
// Author: Daniele Giardini - http://www.demigiant.com
|
|
// Created: 2014/09/04 17:55
|
|
//
|
|
// License Copyright (c) Daniele Giardini.
|
|
// This work is subject to the terms at http://dotween.demigiant.com/license.php
|
|
|
|
using DG.Tweening.Core;
|
|
using DG.Tweening.Core.Enums;
|
|
using DG.Tweening.Plugins.Options;
|
|
using UnityEngine;
|
|
|
|
namespace DG.Tweening
|
|
{
|
|
/// <summary>
|
|
/// Methods that extend known Unity objects and allow to directly create and control tweens from their instances.
|
|
/// These, as all DOTween43 methods, require Unity 4.3 or later.
|
|
/// </summary>
|
|
public static class ShortcutExtensions
|
|
{
|
|
#region SpriteRenderer
|
|
|
|
/// <summary>Tweens a SpriteRenderer's color to the given value.
|
|
/// Also stores the spriteRenderer as the tween's target so it can be used for filtered operations</summary>
|
|
/// <param name="endValue">The end value to reach</param><param name="duration">The duration of the tween</param>
|
|
public static Tweener DOColor(this SpriteRenderer target, Color endValue, float duration)
|
|
{
|
|
return DOTween.To(() => target.color, x => target.color = x, endValue, duration).SetTarget(target);
|
|
}
|
|
|
|
/// <summary>Tweens a Material's alpha color to the given value.
|
|
/// Also stores the spriteRenderer as the tween's target so it can be used for filtered operations</summary>
|
|
/// <param name="endValue">The end value to reach</param><param name="duration">The duration of the tween</param>
|
|
public static Tweener DOFade(this SpriteRenderer target, float endValue, float duration)
|
|
{
|
|
return DOTween.ToAlpha(() => target.color, x => target.color = x, endValue, duration)
|
|
.SetTarget(target);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Rigidbody2D Shortcuts
|
|
|
|
/// <summary>Tweens a Rigidbody2D's position to the given value.
|
|
/// Also stores the Rigidbody2D as the tween's target so it can be used for filtered operations</summary>
|
|
/// <param name="endValue">The end value to reach</param><param name="duration">The duration of the tween</param>
|
|
/// <param name="snapping">If TRUE the tween will smoothly snap all values to integers</param>
|
|
public static Tweener DOMove(this Rigidbody2D target, Vector2 endValue, float duration, bool snapping = false)
|
|
{
|
|
#if WP81
|
|
return DOTween.To(() => target.position, x=> target.MovePosition(x), endValue, duration)
|
|
#else
|
|
return DOTween.To(() => target.position, target.MovePosition, endValue, duration)
|
|
#endif
|
|
.SetOptions(snapping).SetTarget(target);
|
|
}
|
|
|
|
/// <summary>Tweens a Rigidbody2D's X position to the given value.
|
|
/// Also stores the Rigidbody2D as the tween's target so it can be used for filtered operations</summary>
|
|
/// <param name="endValue">The end value to reach</param><param name="duration">The duration of the tween</param>
|
|
/// <param name="snapping">If TRUE the tween will smoothly snap all values to integers</param>
|
|
public static Tweener DOMoveX(this Rigidbody2D target, float endValue, float duration, bool snapping = false)
|
|
{
|
|
#if WP81
|
|
return DOTween.To(() => target.position, x => target.MovePosition(x), new Vector2(endValue, 0), duration)
|
|
#else
|
|
return DOTween.To(() => target.position, target.MovePosition, new Vector2(endValue, 0), duration)
|
|
#endif
|
|
.SetOptions(AxisConstraint.X, snapping).SetTarget(target);
|
|
}
|
|
|
|
/// <summary>Tweens a Rigidbody2D's Y position to the given value.
|
|
/// Also stores the Rigidbody2D as the tween's target so it can be used for filtered operations</summary>
|
|
/// <param name="endValue">The end value to reach</param><param name="duration">The duration of the tween</param>
|
|
/// <param name="snapping">If TRUE the tween will smoothly snap all values to integers</param>
|
|
public static Tweener DOMoveY(this Rigidbody2D target, float endValue, float duration, bool snapping = false)
|
|
{
|
|
#if WP81
|
|
return DOTween.To(() => target.position, x => target.MovePosition(x), new Vector2(0, endValue), duration)
|
|
#else
|
|
return DOTween.To(() => target.position, target.MovePosition, new Vector2(0, endValue), duration)
|
|
#endif
|
|
.SetOptions(AxisConstraint.Y, snapping).SetTarget(target);
|
|
}
|
|
|
|
/// <summary>Tweens a Rigidbody2D's rotation to the given value.
|
|
/// Also stores the Rigidbody2D as the tween's target so it can be used for filtered operations</summary>
|
|
/// <param name="endValue">The end value to reach</param><param name="duration">The duration of the tween</param>
|
|
public static Tweener DORotate(this Rigidbody2D target, float endValue, float duration)
|
|
{
|
|
return DOTween.To(() => target.rotation, target.MoveRotation, endValue, duration)
|
|
.SetTarget(target);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
} |