fix:1
This commit is contained in:
145
Assets/Scripts/Anim/AnimExtension.cs
Normal file
145
Assets/Scripts/Anim/AnimExtension.cs
Normal file
@@ -0,0 +1,145 @@
|
||||
using DG.Tweening;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
//动画扩展类
|
||||
public static class AnimExtension
|
||||
{
|
||||
//数字格式化
|
||||
private static string Format(double num, string format = "f1", bool symbol = false, string unit = "")
|
||||
{
|
||||
if (num > 0 && symbol)
|
||||
{
|
||||
return "+" + num.ToString(format) + unit;
|
||||
}
|
||||
else
|
||||
{
|
||||
return num.ToString(format) + unit;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 文本动画
|
||||
/// </summary>
|
||||
/// <param name="text">文本组件</param>
|
||||
/// <param name="num">目标数值</param>
|
||||
/// <param name="format">显示格式</param>
|
||||
/// <param name="duration">持续时间</param>
|
||||
/// <param name="delay">延迟时间</param>
|
||||
/// <param name="symbol">正数前是否显示"+"号</param>
|
||||
public static Tweener DOTextAnim(this Text text, double num, float duration = 1f, string format = "f1", float delay = 0f, string unit = "", bool symbol = false)
|
||||
{
|
||||
if (text == null) return null;
|
||||
double data = 0;
|
||||
text.text = Format(data, format, symbol, unit);
|
||||
return DOTween.To(() => data, (x) => { data = x; text.text = Format(data, format, symbol, unit); }, num, duration).SetDelay(delay);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 文本动画
|
||||
/// </summary>
|
||||
/// <param name="text">文本组件</param>
|
||||
/// <param name="fromNum">起始数值</param>
|
||||
/// <param name="toNum">目标数值</param>
|
||||
/// <param name="duration">持续时间</param>
|
||||
/// <param name="format">显示格式</param>
|
||||
/// <param name="delay">延迟事件</param>
|
||||
/// <param name="unit">单位</param>
|
||||
/// <param name="symbol">是否显示"+"号</param>
|
||||
public static Tweener DOTextAnim(this Text text, double fromNum, double toNum, float duration = 1f, string format = "f1", float delay = 0f, string unit = "", bool symbol = false)
|
||||
{
|
||||
if (text == null) return null;
|
||||
double data = fromNum;
|
||||
text.text = Format(data, format, symbol);
|
||||
return DOTween.To(() => data, (x) => { data = x; text.text = Format(data, format, symbol); }, toNum, duration).SetDelay(delay);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Slider 动画
|
||||
/// </summary>
|
||||
/// <param name="slider">Slider 组件</param>
|
||||
/// <param name="num">目标数值</param>
|
||||
/// <param name="duration">持续时间</param>
|
||||
/// <param name="delay">延迟时间</param>
|
||||
public static Tweener DOSliderAnim(this Slider slider, float num, float duration = 1f, float delay = 0f)
|
||||
{
|
||||
if (slider == null) return null;
|
||||
slider.value = 0;
|
||||
return DOTween.To(() => slider.value, (x) => slider.value = x, num, duration).SetDelay(delay);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Image 的 fillAmount 动画
|
||||
/// </summary>
|
||||
/// <param name="image">Image组件</param>
|
||||
/// <param name="num">目标数值</param>
|
||||
/// <param name="duration">持续时间</param>
|
||||
/// <param name="delay">延迟时间</param>
|
||||
public static Tweener DOFillAnim(this Image image, float num, float duration = 1f, float delay = 0f)
|
||||
{
|
||||
if (image == null) return null;
|
||||
image.fillAmount = 0;
|
||||
return image.DOFillAmount(num, duration).SetDelay(delay);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scroll 垂直滚动动画
|
||||
/// </summary>
|
||||
/// <param name="scroll">Scroll 组件</param>
|
||||
/// <param name="duration">持续时间</param>
|
||||
/// <param name="delay">延迟时间</param>
|
||||
public static Tweener DOVerticalAnim(this ScrollRect scroll, float duration = 30f, float delay = 1f)
|
||||
{
|
||||
scroll.DOKill();
|
||||
scroll.verticalNormalizedPosition = 1f;
|
||||
return scroll.DOVerticalNormalizedPos(0, duration).SetEase(Ease.Linear).SetLoops(-1, LoopType.Restart).SetDelay(delay);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scroll 水平滚动动画
|
||||
/// </summary>
|
||||
/// <param name="scroll">Scroll 组件</param>
|
||||
/// <param name="duration">持续时间</param>
|
||||
/// <param name="delay">延迟时间</param>
|
||||
public static Tweener DOHorizontalAnim(this ScrollRect scroll, float duration = 30f, float delay = 1f)
|
||||
{
|
||||
scroll.DOKill();
|
||||
scroll.horizontalNormalizedPosition = 0f;
|
||||
return scroll.DOHorizontalNormalizedPos(1, duration).SetEase(Ease.Linear).SetLoops(-1, LoopType.Restart).SetDelay(delay);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 材质动画
|
||||
/// </summary>
|
||||
/// <param name="material">材质对象</param>
|
||||
/// <param name="property">属性名称</param>
|
||||
/// <param name="endValue">目标值</param>
|
||||
/// <param name="startValue">初始值</param>
|
||||
/// <param name="duration">动画时间</param>
|
||||
/// <param name="delay">延迟</param>
|
||||
public static Tweener DoPropertyAnim(this Material material, string property, float endValue, float startValue = 0f, float duration = 1f, float delay = 0f)
|
||||
{
|
||||
if (material == null) { return null; }
|
||||
if (!material.HasProperty(property)) { return null; }
|
||||
material.SetFloat(property, startValue);
|
||||
float data = startValue;
|
||||
return DOTween.To(() => data, (x) => { data = x; material.SetFloat(property, x); }, endValue, duration).SetDelay(delay);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 材质颜色动画
|
||||
/// </summary>
|
||||
/// <param name="material">材质对象</param>
|
||||
/// <param name="property">属性名称</param>
|
||||
/// <param name="endColor">目标颜色</param>
|
||||
/// <param name="duration">动画时间</param>
|
||||
/// <param name="delay">延迟</param>
|
||||
public static Tweener DoColorAnim(this Material material, string property, Color endColor, float duration = 1f, float delay = 0f)
|
||||
{
|
||||
if (material == null) { return null; }
|
||||
if (!material.HasProperty(property)) { return null; }
|
||||
Color color = material.GetColor(property);
|
||||
return DOTween.To(() => color, (x) => { color = x; material.SetColor(property, color); }, endColor, duration).SetDelay(delay);
|
||||
}
|
||||
|
||||
}
|
||||
11
Assets/Scripts/Anim/AnimExtension.cs.meta
Normal file
11
Assets/Scripts/Anim/AnimExtension.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1483d41b00daaed4abe2a326f5fcc36a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
88
Assets/Scripts/Anim/SpriteAnim.cs
Normal file
88
Assets/Scripts/Anim/SpriteAnim.cs
Normal file
@@ -0,0 +1,88 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class SpriteAnim : MonoBehaviour
|
||||
{
|
||||
public bool isLoop = true;
|
||||
public float timer = 0.1f;
|
||||
public Sprite[] frames;
|
||||
|
||||
private int index = 0;
|
||||
|
||||
private SpriteRenderer spriteRender;
|
||||
private Image image;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
spriteRender = GetComponent<SpriteRenderer>();
|
||||
image = GetComponent<Image>();
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
index = 0;
|
||||
Play();
|
||||
}
|
||||
|
||||
|
||||
public void Play()
|
||||
{
|
||||
CancelInvoke("PlayAnim");
|
||||
InvokeRepeating("PlayAnim", 0f, timer);
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
CancelInvoke("PlayAnim");
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
if (index >= frames.Length)
|
||||
{
|
||||
CancelInvoke("PlayAnim");
|
||||
return;
|
||||
}
|
||||
index = 0;
|
||||
if (spriteRender != null)
|
||||
{
|
||||
spriteRender.sprite = frames[index];
|
||||
}
|
||||
if (image != null)
|
||||
{
|
||||
image.sprite = frames[index];
|
||||
}
|
||||
}
|
||||
|
||||
void PlayAnim()
|
||||
{
|
||||
|
||||
if (index >= frames.Length)
|
||||
{
|
||||
CancelInvoke("PlayAnim");
|
||||
return;
|
||||
}
|
||||
if (spriteRender != null)
|
||||
{
|
||||
spriteRender.sprite = frames[index];
|
||||
}
|
||||
if (image != null)
|
||||
{
|
||||
image.sprite = frames[index];
|
||||
}
|
||||
index++;
|
||||
if (index >= frames.Length)
|
||||
{
|
||||
if (isLoop)
|
||||
{
|
||||
index = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
CancelInvoke("PlayAnim");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Anim/SpriteAnim.cs.meta
Normal file
11
Assets/Scripts/Anim/SpriteAnim.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f79db764f82d97540b4fa307731a557b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
203
Assets/Scripts/Anim/TweenAlpha.cs
Normal file
203
Assets/Scripts/Anim/TweenAlpha.cs
Normal file
@@ -0,0 +1,203 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using DG.Tweening;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class TweenAlpha : MonoBehaviour
|
||||
{
|
||||
[Range(0f, 1f)]
|
||||
public float from = 0f;
|
||||
[Range(0f, 1f)]
|
||||
public float to = 1f;
|
||||
|
||||
public TweenStyle playStyle = TweenStyle.Once;
|
||||
|
||||
public AnimationCurve curve = new AnimationCurve(new Keyframe(0f, 0f, 0f, 1f), new Keyframe(1f, 1f, 1f, 0f));
|
||||
|
||||
public float timer = 1f;
|
||||
|
||||
private Tween tweener = null;
|
||||
|
||||
private SpriteRenderer spriteRender;
|
||||
private Image image;
|
||||
private Text text;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
spriteRender = GetComponent<SpriteRenderer>();
|
||||
image = GetComponent<Image>();
|
||||
text = GetComponent<Text>();
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
PlayForward();
|
||||
}
|
||||
|
||||
public void PlayForward()
|
||||
{
|
||||
ResetToBegining();
|
||||
switch (playStyle)
|
||||
{
|
||||
case TweenStyle.Once:
|
||||
if (spriteRender != null)
|
||||
{
|
||||
tweener = spriteRender.DOFade(to, timer).SetEase(curve);
|
||||
}
|
||||
if (image != null)
|
||||
{
|
||||
tweener = image.DOFade(to, timer).SetEase(curve);
|
||||
}
|
||||
if (text != null)
|
||||
{
|
||||
tweener = text.DOFade(to, timer).SetEase(curve);
|
||||
}
|
||||
break;
|
||||
case TweenStyle.Loop:
|
||||
if (spriteRender != null)
|
||||
{
|
||||
tweener = spriteRender.DOFade(to, timer).SetEase(curve).SetLoops(-1);
|
||||
}
|
||||
if (image != null)
|
||||
{
|
||||
tweener = image.DOFade(to, timer).SetEase(curve).SetLoops(-1);
|
||||
}
|
||||
if (text != null)
|
||||
{
|
||||
tweener = text.DOFade(to, timer).SetEase(curve).SetLoops(-1);
|
||||
}
|
||||
break;
|
||||
case TweenStyle.PingPong:
|
||||
if (spriteRender != null)
|
||||
{
|
||||
tweener = spriteRender.DOFade(to, timer).SetEase(curve).SetLoops(-1, LoopType.Yoyo);
|
||||
}
|
||||
if (image != null)
|
||||
{
|
||||
tweener = image.DOFade(to, timer).SetEase(curve).SetLoops(-1, LoopType.Yoyo);
|
||||
}
|
||||
if (text != null)
|
||||
{
|
||||
tweener = text.DOFade(to, timer).SetEase(curve).SetLoops(-1, LoopType.Yoyo);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void PlayReverse()
|
||||
{
|
||||
ResetToEnding();
|
||||
switch (playStyle)
|
||||
{
|
||||
case TweenStyle.Once:
|
||||
if (spriteRender != null)
|
||||
{
|
||||
tweener = spriteRender.DOFade(from, timer).SetEase(curve);
|
||||
}
|
||||
if (image != null)
|
||||
{
|
||||
tweener = image.DOFade(from, timer).SetEase(curve);
|
||||
}
|
||||
if (text != null)
|
||||
{
|
||||
tweener = text.DOFade(from, timer).SetEase(curve);
|
||||
}
|
||||
break;
|
||||
case TweenStyle.Loop:
|
||||
if (spriteRender != null)
|
||||
{
|
||||
tweener = spriteRender.DOFade(from, timer).SetEase(curve).SetLoops(-1);
|
||||
}
|
||||
if (image != null)
|
||||
{
|
||||
tweener = image.DOFade(from, timer).SetEase(curve).SetLoops(-1);
|
||||
}
|
||||
if (text != null)
|
||||
{
|
||||
tweener = text.DOFade(from, timer).SetEase(curve).SetLoops(-1);
|
||||
}
|
||||
break;
|
||||
case TweenStyle.PingPong:
|
||||
if (spriteRender != null)
|
||||
{
|
||||
tweener = spriteRender.DOFade(from, timer).SetEase(curve).SetLoops(-1, LoopType.Yoyo);
|
||||
}
|
||||
if (image != null)
|
||||
{
|
||||
tweener = image.DOFade(from, timer).SetEase(curve).SetLoops(-1, LoopType.Yoyo);
|
||||
}
|
||||
if (text != null)
|
||||
{
|
||||
tweener = text.DOFade(from, timer).SetEase(curve).SetLoops(-1, LoopType.Yoyo);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
if (tweener != null)
|
||||
{
|
||||
tweener.Kill();
|
||||
}
|
||||
}
|
||||
|
||||
public void Pause()
|
||||
{
|
||||
if (tweener != null)
|
||||
{
|
||||
tweener.Pause();
|
||||
}
|
||||
}
|
||||
|
||||
public void Play()
|
||||
{
|
||||
if (tweener != null)
|
||||
{
|
||||
tweener.Play();
|
||||
}
|
||||
}
|
||||
|
||||
public void ResetToBegining()
|
||||
{
|
||||
if (tweener != null)
|
||||
{
|
||||
tweener.Kill();
|
||||
}
|
||||
if (spriteRender != null)
|
||||
{
|
||||
spriteRender.DOFade(from, 0f);
|
||||
}
|
||||
if (image != null)
|
||||
{
|
||||
image.DOFade(from, 0f);
|
||||
}
|
||||
if (text != null)
|
||||
{
|
||||
text.DOFade(from, 0f);
|
||||
}
|
||||
}
|
||||
|
||||
public void ResetToEnding()
|
||||
{
|
||||
if (tweener != null)
|
||||
{
|
||||
tweener.Kill();
|
||||
}
|
||||
if (spriteRender != null)
|
||||
{
|
||||
spriteRender.DOFade(to, 0f);
|
||||
}
|
||||
if (image != null)
|
||||
{
|
||||
image.DOFade(to, 0f);
|
||||
}
|
||||
if (text != null)
|
||||
{
|
||||
text.DOFade(to, 0f);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
11
Assets/Scripts/Anim/TweenAlpha.cs.meta
Normal file
11
Assets/Scripts/Anim/TweenAlpha.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a50bb6b8f89d76648bff834c0bd96926
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
199
Assets/Scripts/Anim/TweenColor.cs
Normal file
199
Assets/Scripts/Anim/TweenColor.cs
Normal file
@@ -0,0 +1,199 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using DG.Tweening;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class TweenColor : MonoBehaviour
|
||||
{
|
||||
public Color from = Color.white;
|
||||
public Color to = Color.white;
|
||||
|
||||
public TweenStyle playStyle = TweenStyle.Once;
|
||||
|
||||
public AnimationCurve curve = new AnimationCurve(new Keyframe(0f, 0f, 0f, 1f), new Keyframe(1f, 1f, 1f, 0f));
|
||||
|
||||
public float timer = 1f;
|
||||
|
||||
private Tween tweener = null;
|
||||
|
||||
private SpriteRenderer spriteRender;
|
||||
private Image image;
|
||||
private Text text;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
spriteRender = GetComponent<SpriteRenderer>();
|
||||
image = GetComponent<Image>();
|
||||
text = GetComponent<Text>();
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
PlayForward();
|
||||
}
|
||||
|
||||
public void PlayForward()
|
||||
{
|
||||
ResetToBegining();
|
||||
switch (playStyle)
|
||||
{
|
||||
case TweenStyle.Once:
|
||||
if (spriteRender != null)
|
||||
{
|
||||
tweener = spriteRender.DOColor(to, timer).SetEase(curve);
|
||||
}
|
||||
if (image != null)
|
||||
{
|
||||
tweener = image.DOColor(to, timer).SetEase(curve);
|
||||
}
|
||||
if (text != null)
|
||||
{
|
||||
tweener = text.DOColor(to, timer).SetEase(curve);
|
||||
}
|
||||
break;
|
||||
case TweenStyle.Loop:
|
||||
if (spriteRender != null)
|
||||
{
|
||||
tweener = spriteRender.DOColor(to, timer).SetEase(curve).SetLoops(-1);
|
||||
}
|
||||
if (image != null)
|
||||
{
|
||||
tweener = image.DOColor(to, timer).SetEase(curve).SetLoops(-1);
|
||||
}
|
||||
if (text != null)
|
||||
{
|
||||
tweener = text.DOColor(to, timer).SetEase(curve).SetLoops(-1);
|
||||
}
|
||||
break;
|
||||
case TweenStyle.PingPong:
|
||||
if (spriteRender != null)
|
||||
{
|
||||
tweener = spriteRender.DOColor(to, timer).SetEase(curve).SetLoops(-1, LoopType.Yoyo);
|
||||
}
|
||||
if (image != null)
|
||||
{
|
||||
tweener = image.DOColor(to, timer).SetEase(curve).SetLoops(-1, LoopType.Yoyo);
|
||||
}
|
||||
if (text != null)
|
||||
{
|
||||
tweener = text.DOColor(to, timer).SetEase(curve).SetLoops(-1, LoopType.Yoyo);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void PlayReverse()
|
||||
{
|
||||
ResetToEnding();
|
||||
switch (playStyle)
|
||||
{
|
||||
case TweenStyle.Once:
|
||||
if (spriteRender != null)
|
||||
{
|
||||
tweener = spriteRender.DOColor(from, timer).SetEase(curve);
|
||||
}
|
||||
if (image != null)
|
||||
{
|
||||
tweener = image.DOColor(from, timer).SetEase(curve);
|
||||
}
|
||||
if (text != null)
|
||||
{
|
||||
tweener = text.DOColor(from, timer).SetEase(curve);
|
||||
}
|
||||
break;
|
||||
case TweenStyle.Loop:
|
||||
if (spriteRender != null)
|
||||
{
|
||||
tweener = spriteRender.DOColor(from, timer).SetEase(curve).SetLoops(-1);
|
||||
}
|
||||
if (image != null)
|
||||
{
|
||||
tweener = image.DOColor(from, timer).SetEase(curve).SetLoops(-1);
|
||||
}
|
||||
if (text != null)
|
||||
{
|
||||
tweener = text.DOColor(from, timer).SetEase(curve).SetLoops(-1);
|
||||
}
|
||||
break;
|
||||
case TweenStyle.PingPong:
|
||||
if (spriteRender != null)
|
||||
{
|
||||
tweener = spriteRender.DOColor(from, timer).SetEase(curve).SetLoops(-1, LoopType.Yoyo);
|
||||
}
|
||||
if (image != null)
|
||||
{
|
||||
tweener = image.DOColor(from, timer).SetEase(curve).SetLoops(-1, LoopType.Yoyo);
|
||||
}
|
||||
if (text != null)
|
||||
{
|
||||
tweener = text.DOColor(from, timer).SetEase(curve).SetLoops(-1, LoopType.Yoyo);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
if (tweener != null)
|
||||
{
|
||||
tweener.Kill();
|
||||
}
|
||||
}
|
||||
|
||||
public void Pause()
|
||||
{
|
||||
if (tweener != null)
|
||||
{
|
||||
tweener.Pause();
|
||||
}
|
||||
}
|
||||
|
||||
public void Play()
|
||||
{
|
||||
if (tweener != null)
|
||||
{
|
||||
tweener.Play();
|
||||
}
|
||||
}
|
||||
|
||||
public void ResetToBegining()
|
||||
{
|
||||
if (tweener != null)
|
||||
{
|
||||
tweener.Kill();
|
||||
}
|
||||
if (spriteRender != null)
|
||||
{
|
||||
spriteRender.color = from;
|
||||
}
|
||||
if (image != null)
|
||||
{
|
||||
image.color = from;
|
||||
}
|
||||
if (text != null)
|
||||
{
|
||||
text.color = from;
|
||||
}
|
||||
}
|
||||
|
||||
public void ResetToEnding()
|
||||
{
|
||||
if (tweener != null)
|
||||
{
|
||||
tweener.Kill();
|
||||
}
|
||||
if (spriteRender != null)
|
||||
{
|
||||
spriteRender.color = to;
|
||||
}
|
||||
if (image != null)
|
||||
{
|
||||
image.color = to;
|
||||
}
|
||||
if (text != null)
|
||||
{
|
||||
text.color = to;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Anim/TweenColor.cs.meta
Normal file
11
Assets/Scripts/Anim/TweenColor.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c823cb77710c56146b251bac920e7022
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
117
Assets/Scripts/Anim/TweenPosition.cs
Normal file
117
Assets/Scripts/Anim/TweenPosition.cs
Normal file
@@ -0,0 +1,117 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using DG.Tweening;
|
||||
|
||||
public enum TweenStyle
|
||||
{
|
||||
Once,
|
||||
Loop,
|
||||
PingPong,
|
||||
}
|
||||
|
||||
public class TweenPosition : MonoBehaviour
|
||||
{
|
||||
|
||||
#if UNITY_EDITOR
|
||||
private void Reset()
|
||||
{
|
||||
from = transform.localPosition;
|
||||
to = transform.localPosition;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
public Vector3 from;
|
||||
public Vector3 to;
|
||||
|
||||
public TweenStyle playStyle = TweenStyle.Once;
|
||||
|
||||
public AnimationCurve curve = new AnimationCurve(new Keyframe(0f, 0f, 0f, 1f), new Keyframe(1f, 1f, 1f, 0f));
|
||||
|
||||
public float timer = 1f;
|
||||
|
||||
private Tween tweener = null;
|
||||
|
||||
// Use this for initialization
|
||||
void Start()
|
||||
{
|
||||
PlayForward();
|
||||
}
|
||||
|
||||
public void PlayForward()
|
||||
{
|
||||
ResetToBegining();
|
||||
switch (playStyle)
|
||||
{
|
||||
case TweenStyle.Once:
|
||||
tweener = transform.DOLocalMove(to, timer).SetEase(curve);
|
||||
break;
|
||||
case TweenStyle.Loop:
|
||||
tweener = transform.DOLocalMove(to, timer).SetEase(curve).SetLoops(-1);
|
||||
break;
|
||||
case TweenStyle.PingPong:
|
||||
tweener = transform.DOLocalMove(to, timer).SetEase(curve).SetLoops(-1, LoopType.Yoyo);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void PlayReverse()
|
||||
{
|
||||
ResetToEnding();
|
||||
switch (playStyle)
|
||||
{
|
||||
case TweenStyle.Once:
|
||||
tweener = transform.DOLocalMove(from, timer).SetEase(curve);
|
||||
break;
|
||||
case TweenStyle.Loop:
|
||||
tweener = transform.DOLocalMove(from, timer).SetEase(curve).SetLoops(-1);
|
||||
break;
|
||||
case TweenStyle.PingPong:
|
||||
tweener = transform.DOLocalMove(from, timer).SetEase(curve).SetLoops(-1, LoopType.Yoyo);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
if (tweener != null)
|
||||
{
|
||||
tweener.Kill();
|
||||
}
|
||||
}
|
||||
|
||||
public void Pause()
|
||||
{
|
||||
if (tweener != null)
|
||||
{
|
||||
tweener.Pause();
|
||||
}
|
||||
}
|
||||
|
||||
public void Play()
|
||||
{
|
||||
if (tweener != null)
|
||||
{
|
||||
tweener.Play();
|
||||
}
|
||||
}
|
||||
|
||||
public void ResetToBegining()
|
||||
{
|
||||
if (tweener != null)
|
||||
{
|
||||
tweener.Kill();
|
||||
}
|
||||
transform.localPosition = from;
|
||||
}
|
||||
|
||||
public void ResetToEnding()
|
||||
{
|
||||
if (tweener != null)
|
||||
{
|
||||
tweener.Kill();
|
||||
}
|
||||
transform.localPosition = to;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Anim/TweenPosition.cs.meta
Normal file
11
Assets/Scripts/Anim/TweenPosition.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c3b49052cf29a8940b63eb802280c4c8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
109
Assets/Scripts/Anim/TweenRotation.cs
Normal file
109
Assets/Scripts/Anim/TweenRotation.cs
Normal file
@@ -0,0 +1,109 @@
|
||||
using DG.Tweening;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class TweenRotation : MonoBehaviour
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
private void Reset()
|
||||
{
|
||||
from = transform.localEulerAngles;
|
||||
to = transform.localEulerAngles;
|
||||
}
|
||||
#endif
|
||||
|
||||
public Vector3 from = Vector3.zero;
|
||||
public Vector3 to = Vector3.zero;
|
||||
|
||||
public TweenStyle playStyle = TweenStyle.Once;
|
||||
|
||||
public AnimationCurve curve = new AnimationCurve(new Keyframe(0f, 0f, 0f, 1f), new Keyframe(1f, 1f, 1f, 0f));
|
||||
|
||||
public float timer = 1f;
|
||||
|
||||
private Tween tweener = null;
|
||||
|
||||
|
||||
// Use this for initialization
|
||||
void Start()
|
||||
{
|
||||
PlayForward();
|
||||
}
|
||||
|
||||
public void PlayForward()
|
||||
{
|
||||
ResetToBegining();
|
||||
switch (playStyle)
|
||||
{
|
||||
case TweenStyle.Once:
|
||||
tweener = transform.DOLocalRotate(to, timer, RotateMode.FastBeyond360).SetEase(curve);
|
||||
break;
|
||||
case TweenStyle.Loop:
|
||||
tweener = transform.DOLocalRotate(to, timer, RotateMode.FastBeyond360).SetEase(curve).SetLoops(-1);
|
||||
break;
|
||||
case TweenStyle.PingPong:
|
||||
tweener = transform.DOLocalRotate(to, timer, RotateMode.FastBeyond360).SetEase(curve).SetLoops(-1, LoopType.Yoyo);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void PlayReverse()
|
||||
{
|
||||
ResetToEnding();
|
||||
switch (playStyle)
|
||||
{
|
||||
case TweenStyle.Once:
|
||||
tweener = transform.DOLocalRotate(from, timer, RotateMode.FastBeyond360).SetEase(curve);
|
||||
break;
|
||||
case TweenStyle.Loop:
|
||||
tweener = transform.DOLocalRotate(from, timer, RotateMode.FastBeyond360).SetEase(curve).SetLoops(-1);
|
||||
break;
|
||||
case TweenStyle.PingPong:
|
||||
tweener = transform.DOLocalRotate(from, timer, RotateMode.FastBeyond360).SetEase(curve).SetLoops(-1, LoopType.Yoyo);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
if (tweener != null)
|
||||
{
|
||||
tweener.Kill();
|
||||
}
|
||||
}
|
||||
|
||||
public void Pause()
|
||||
{
|
||||
if (tweener != null)
|
||||
{
|
||||
tweener.Pause();
|
||||
}
|
||||
}
|
||||
|
||||
public void Play()
|
||||
{
|
||||
if (tweener != null)
|
||||
{
|
||||
tweener.Play();
|
||||
}
|
||||
}
|
||||
|
||||
public void ResetToBegining()
|
||||
{
|
||||
if (tweener != null)
|
||||
{
|
||||
tweener.Kill();
|
||||
}
|
||||
transform.localEulerAngles = from;
|
||||
}
|
||||
|
||||
public void ResetToEnding()
|
||||
{
|
||||
if (tweener != null)
|
||||
{
|
||||
tweener.Kill();
|
||||
}
|
||||
transform.localEulerAngles = to;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Anim/TweenRotation.cs.meta
Normal file
11
Assets/Scripts/Anim/TweenRotation.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ee5bbb9e760a3c14298e6856bcf949b6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
109
Assets/Scripts/Anim/TweenScale.cs
Normal file
109
Assets/Scripts/Anim/TweenScale.cs
Normal file
@@ -0,0 +1,109 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using DG.Tweening;
|
||||
|
||||
public class TweenScale : MonoBehaviour
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
private void Reset()
|
||||
{
|
||||
from = transform.localScale;
|
||||
to = transform.localScale;
|
||||
}
|
||||
#endif
|
||||
|
||||
public Vector3 from = Vector3.one;
|
||||
public Vector3 to = Vector3.one;
|
||||
|
||||
public TweenStyle playStyle = TweenStyle.Once;
|
||||
|
||||
public AnimationCurve curve = new AnimationCurve(new Keyframe(0f, 0f, 0f, 1f), new Keyframe(1f, 1f, 1f, 0f));
|
||||
|
||||
public float timer = 1f;
|
||||
|
||||
private Tween tweener = null;
|
||||
|
||||
// Use this for initialization
|
||||
void Start()
|
||||
{
|
||||
PlayForward();
|
||||
}
|
||||
|
||||
public void PlayForward()
|
||||
{
|
||||
ResetToBegining();
|
||||
switch (playStyle)
|
||||
{
|
||||
case TweenStyle.Once:
|
||||
tweener = transform.DOScale(to, timer).SetEase(curve);
|
||||
break;
|
||||
case TweenStyle.Loop:
|
||||
tweener = transform.DOScale(to, timer).SetEase(curve).SetLoops(-1);
|
||||
break;
|
||||
case TweenStyle.PingPong:
|
||||
tweener = transform.DOScale(to, timer).SetEase(curve).SetLoops(-1, LoopType.Yoyo);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void PlayReverse()
|
||||
{
|
||||
ResetToEnding();
|
||||
switch (playStyle)
|
||||
{
|
||||
case TweenStyle.Once:
|
||||
tweener = transform.DOScale(from, timer).SetEase(curve);
|
||||
break;
|
||||
case TweenStyle.Loop:
|
||||
tweener = transform.DOScale(from, timer).SetEase(curve).SetLoops(-1);
|
||||
break;
|
||||
case TweenStyle.PingPong:
|
||||
tweener = transform.DOScale(from, timer).SetEase(curve).SetLoops(-1, LoopType.Yoyo);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
if (tweener != null)
|
||||
{
|
||||
tweener.Kill();
|
||||
}
|
||||
}
|
||||
|
||||
public void Pause()
|
||||
{
|
||||
if (tweener != null)
|
||||
{
|
||||
tweener.Pause();
|
||||
}
|
||||
}
|
||||
|
||||
public void Play()
|
||||
{
|
||||
if (tweener != null)
|
||||
{
|
||||
tweener.Play();
|
||||
}
|
||||
}
|
||||
|
||||
public void ResetToBegining()
|
||||
{
|
||||
if (tweener != null)
|
||||
{
|
||||
tweener.Kill();
|
||||
}
|
||||
transform.localScale = from;
|
||||
|
||||
}
|
||||
|
||||
public void ResetToEnding()
|
||||
{
|
||||
if (tweener != null)
|
||||
{
|
||||
tweener.Kill();
|
||||
}
|
||||
transform.localScale = to;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Anim/TweenScale.cs.meta
Normal file
11
Assets/Scripts/Anim/TweenScale.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1c462947f207e664f940b431335486bc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user