add some effects
This commit is contained in:
@@ -7,72 +7,92 @@ using UltraFace;
|
||||
|
||||
public class AnimationHandler : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Transform[] _objects;
|
||||
[SerializeField] private Transform[] _points;
|
||||
[SerializeField] private Transform _sberText;
|
||||
[SerializeField] private List<Transform> _objects = new List<Transform>();
|
||||
[SerializeField] private List<ParticleSystem> _effects = new List<ParticleSystem>();
|
||||
[Inject] private Visualizer _visualizer;
|
||||
|
||||
private Dictionary<string, Vector3> _scales;
|
||||
private Dictionary<string, ParticleSystem> _effectDict;
|
||||
private Vector3 _baseScale;
|
||||
|
||||
private List<Tween> _rotationAnimations = new List<Tween>();
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_sberText.DOLocalMoveY(_sberText.localPosition.y - .25f, 2.5f)
|
||||
.SetEase(Ease.InOutSine)
|
||||
.SetLoops(-1, LoopType.Yoyo);
|
||||
|
||||
_scales = new Dictionary<string, Vector3>();
|
||||
|
||||
_effectDict = new Dictionary<string, ParticleSystem>();
|
||||
_visualizer.OnDetectionStatusChanged += OnFaceDetected;
|
||||
|
||||
// transform.DOLocalRotate(new Vector3(0, -360f, 0), 15f, RotateMode.FastBeyond360)
|
||||
// .SetLoops(-1, LoopType.Restart)
|
||||
// .SetRelative()
|
||||
// .SetEase(Ease.Linear);
|
||||
|
||||
foreach(var item in _objects)
|
||||
{
|
||||
int rotateDir = Random.Range(-4, 5);
|
||||
int index = _objects.IndexOf(item);
|
||||
|
||||
_scales.Add(item.name, item.localScale);
|
||||
item.DOScale(Vector3.zero, 0);
|
||||
|
||||
item.DOLocalRotate(new Vector3(0, rotateDir > 0 ? 360f : -360f, 0), Random.Range(5f, 10f), RotateMode.FastBeyond360)
|
||||
.SetLoops(-1, LoopType.Restart)
|
||||
.SetRelative()
|
||||
.SetEase(Ease.Linear);
|
||||
item.DOLocalMoveY(item.localPosition.y + (index == _objects.Count - 1 ? .2f : .5f), Random.Range(2f, 5f))
|
||||
.SetEase(Ease.InOutSine)
|
||||
.SetLoops(-1, LoopType.Yoyo);
|
||||
}
|
||||
|
||||
item.DOLocalMoveY(item.localPosition.y + .5f, Random.Range(.5f, 5f))
|
||||
.SetEase(Ease.InOutSine)
|
||||
.SetLoops(-1, LoopType.Yoyo);
|
||||
|
||||
item.DOLocalMoveZ(item.localPosition.z + 1.5f, Random.Range(1f, 5f))
|
||||
.SetEase(Ease.InOutSine)
|
||||
.SetLoops(-1, LoopType.Yoyo);
|
||||
for(int i = 0; i < _objects.Count; i++)
|
||||
_effectDict.Add(_objects[i].name, _effects[i]);
|
||||
|
||||
foreach(var effect in _effects)
|
||||
{
|
||||
var emission = effect.emission;
|
||||
emission.enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnFaceDetected(bool isDetected)
|
||||
{
|
||||
Sequence sq = DOTween.Sequence();
|
||||
if(isDetected)
|
||||
{
|
||||
foreach(var item in _objects)
|
||||
sq.Append(item.DOScale(_scales[item.name], Random.Range(.2f, .4f)));
|
||||
foreach(var tween in _rotationAnimations)
|
||||
tween.Kill();
|
||||
|
||||
sq.Play();
|
||||
_rotationAnimations = new List<Tween>();
|
||||
|
||||
foreach(var item in _objects)
|
||||
{
|
||||
int index = _objects.IndexOf(item);
|
||||
|
||||
if(index != _objects.Count - 1 || index % 2 == 0)
|
||||
item.DOLocalRotate(Vector3.up * 360 * 2, Random.Range(1f, 2f))
|
||||
.SetRelative()
|
||||
.SetEase(Ease.InOutSine)
|
||||
.OnComplete(() =>
|
||||
{
|
||||
_rotationAnimations.Add(item.DOLocalRotate(new Vector3(0, index % 2 == 0 ? 360f : 0, 0), Random.Range(10f, 14f))
|
||||
.SetLoops(-1, LoopType.Yoyo)
|
||||
.SetRelative()
|
||||
.SetEase(Ease.InOutSine));
|
||||
});
|
||||
|
||||
item.DOScale(_scales[item.name], 1f)
|
||||
.OnComplete(() =>
|
||||
{
|
||||
var emission = _effectDict[item.name].emission;
|
||||
emission.enabled = true;
|
||||
});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(sq.IsPlaying()) sq.Kill();
|
||||
|
||||
foreach(var effect in _effects)
|
||||
{
|
||||
var emission = effect.emission;
|
||||
emission.enabled = false;
|
||||
}
|
||||
|
||||
foreach(var item in _objects)
|
||||
item.DOScale(Vector3.zero, .2f);
|
||||
}
|
||||
}
|
||||
|
||||
private void ChangeScale(int index)
|
||||
{
|
||||
if (index == _objects.Length)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_objects[index].DOScale(_scales[_objects[index].name], Random.Range(.2f, .4f))
|
||||
.OnComplete(() => ChangeScale(++index));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user