44 lines
1.4 KiB
C#
44 lines
1.4 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;
|
|
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);
|
|
}
|
|
}
|
|
|
|
private void OnFaceDetected(bool isDetected)
|
|
{
|
|
foreach(var item in _objects)
|
|
item.DOScale(isDetected ? _scales[item.name] : Vector3.zero, Random.Range(.2f, .8f));
|
|
}
|
|
} |