98 lines
3.2 KiB
C#
98 lines
3.2 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using DG.Tweening;
|
|
using Zenject;
|
|
using UltraFace;
|
|
|
|
public class AnimationHandler : MonoBehaviour
|
|
{
|
|
[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;
|
|
|
|
foreach(var item in _objects)
|
|
{
|
|
int index = _objects.IndexOf(item);
|
|
|
|
_scales.Add(item.name, item.localScale);
|
|
item.DOScale(Vector3.zero, 0);
|
|
|
|
item.DOLocalMoveY(item.localPosition.y + (index == _objects.Count - 1 ? .2f : .5f), Random.Range(2f, 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)
|
|
{
|
|
if(isDetected)
|
|
{
|
|
foreach(var tween in _rotationAnimations)
|
|
tween.Kill();
|
|
|
|
_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
|
|
{
|
|
foreach(var effect in _effects)
|
|
{
|
|
var emission = effect.emission;
|
|
emission.enabled = false;
|
|
}
|
|
|
|
foreach(var item in _objects)
|
|
item.DOScale(Vector3.zero, .2f);
|
|
}
|
|
}
|
|
} |