smart-interactive-display/Assets/GadGame/Scripts/PassByAnimation.cs

67 lines
2.2 KiB
C#
Raw Normal View History

2024-06-19 02:32:17 -07:00
using System;
2024-04-25 04:54:33 -07:00
using Cysharp.Threading.Tasks;
2024-04-22 02:10:49 -07:00
using DG.Tweening;
2024-06-19 02:32:17 -07:00
using GadGame.Event.Type;
2024-04-23 02:44:22 -07:00
using TMPro;
2024-04-22 02:10:49 -07:00
using UnityEngine;
2024-06-19 02:32:17 -07:00
using UnityEngine.Serialization;
2024-04-23 02:44:22 -07:00
using UnityEngine.UI;
2024-04-25 04:54:33 -07:00
using UnityEngine.Video;
2024-04-22 02:10:49 -07:00
namespace GadGame.State.MainFlowState
{
2024-06-19 02:32:17 -07:00
public class PassByAnimation : MonoBehaviour
2024-04-22 02:10:49 -07:00
{
2024-06-19 02:32:17 -07:00
[SerializeField] private Animator _passBy;
2024-04-22 02:10:49 -07:00
[SerializeField] private RectTransform _transform;
2024-04-25 04:54:33 -07:00
// [SerializeField] private RectTransform _videoIdleTransform;
[SerializeField] private Image CircleImg;
2024-04-23 02:44:22 -07:00
[SerializeField] private TextMeshProUGUI txtProgress;
2024-04-25 04:54:33 -07:00
[SerializeField] private VideoPlayer videoPlayer;
2024-06-19 02:32:17 -07:00
[SerializeField] private BoolEvent _playPassByAnimEvent;
[SerializeField] private BoolEvent _playVideoEvent;
[SerializeField] private FloatEvent _readyCountDownEvent;
2024-04-22 02:10:49 -07:00
2024-06-19 02:32:17 -07:00
private void OnEnable()
{
_playPassByAnimEvent.Register(Play);
_playVideoEvent.Register(SetPlayVideo);
_readyCountDownEvent.Register(SetReadyCountDown);
}
private void OnDisable()
{
_playPassByAnimEvent.Unregister(Play);
_playVideoEvent.Unregister(SetPlayVideo);
_readyCountDownEvent.Unregister(SetReadyCountDown);
}
private void Play(bool engage) {
2024-04-25 04:54:33 -07:00
// videoPlayer.gameObject.SetActive(!passBy);
_transform.DOAnchorPosX(engage ? -1000 : 0, 1);
2024-04-22 02:10:49 -07:00
}
2024-04-23 02:44:22 -07:00
2024-06-19 02:32:17 -07:00
private async void SetPlayVideo(bool value){
2024-04-25 04:54:33 -07:00
if(value) {
2024-06-19 04:29:32 -07:00
while (videoPlayer.targetCameraAlpha < 1)
2024-04-25 04:54:33 -07:00
{
videoPlayer.targetCameraAlpha += Time.deltaTime * 3;
await UniTask.Yield();
}
videoPlayer.targetCameraAlpha = 1;
} else {
while (videoPlayer.targetCameraAlpha > 0)
{
videoPlayer.targetCameraAlpha -= Time.deltaTime * 3;
await UniTask.Yield();
}
videoPlayer.targetCameraAlpha = 0;
}
}
2024-06-19 02:32:17 -07:00
private void SetReadyCountDown(float progress){
2024-04-23 02:44:22 -07:00
CircleImg.fillAmount = progress ;
txtProgress.text = Mathf.Floor(progress * 3).ToString();
}
2024-04-22 02:10:49 -07:00
}
}