1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
| using System;
using System.Collections;
using System.Collections.Genhttps://www.youtube.com/watch?v=5N2tPBTyHO4eric;
using UnityEngine;
using UnityEngine.Events;
public class CollectEffects : MonoBehaviour
{
[SerializeField] private GameObject targetObject;
[SerializeField] private List<ParticleSystem> ParticleSystems;
[SerializeField] private List<AnimationData> _animationsList;
public enum Animations
{
BOUNCE,
SHRINK,
SPIN
}
//private FXTools fx;
private Tweener twn;
public void StartAnimation(UnityAction action)
{
StartCoroutine(animation((() => action?.Invoke())));
}
private IEnumerator animation(Action action)
{
foreach (var data in _animationsList)
{
foreach (var fx in data.FX)
{
FXTools.RunCommand(fx);
}
if (!data.skip)
{
yield return StartCoroutine(Tween(targetObject, data));
}
}
action?.Invoke();
}
private IEnumerator Tween(GameObject obj,AnimationData data)
{
//var
float elapsedTime = 0f;
//Vector3 endScale = new Vector3(data., end, end);
Quaternion currentRot = obj.transform.localRotation;
Vector3 startScale = obj.transform.localScale;
Vector3 startPosition = obj.transform.localPosition;
var lerp = 0f;
while (elapsedTime < data.Duration)
{
if (data.spinable)
{
transform.Rotate(0, data.spinValue * Time.deltaTime, 0);
}
else
{
obj.transform.localRotation = Quaternion.Lerp(currentRot,Quaternion.Euler(data.targetRotation), Time.deltaTime/data.Duration );
}
obj.transform.localPosition = Vector3.Lerp(startPosition, data.targetLocalPosition, (elapsedTime / data.Duration));
obj.transform.localScale = Vector3.Lerp(startScale, data.targetScale, (elapsedTime / data.Duration));
elapsedTime += Time.deltaTime;
yield return null; // yield one frame
}
//action?.Invoke();
}
[System.Serializable]
public class AnimationData
{
public Vector3 targetScale, targetRotation, targetLocalPosition;
public float spinValue;
public bool spinable,skip;
public float Duration;
public List<FXTools.FXCommand> FX;
}
}
|