78 lines
2.3 KiB
C#
78 lines
2.3 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[] _objects;
|
|
[SerializeField] private Transform[] _points;
|
|
[Inject] private Visualizer _visualizer;
|
|
|
|
private Dictionary<string, Vector3> _scales;
|
|
private Vector3 _baseScale;
|
|
|
|
private void Start()
|
|
{
|
|
_scales = new Dictionary<string, Vector3>();
|
|
|
|
_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);
|
|
_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 + .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);
|
|
}
|
|
}
|
|
|
|
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)));
|
|
|
|
sq.Play();
|
|
}
|
|
else
|
|
{
|
|
if(sq.IsPlaying()) sq.Kill();
|
|
|
|
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));
|
|
}
|
|
} |