using System; using Cysharp.Threading.Tasks; using DG.Tweening; using GadGame.Event.Type; using TMPro; using UnityEngine; using UnityEngine.Serialization; using UnityEngine.UI; using UnityEngine.Video; namespace GadGame.Scripts.Coffee { public class CoffeeController : MonoBehaviour { [SerializeField] private VoidEvent _engageReadyEvent; [SerializeField] private StringEvent _generateImageSuccessEvent; [SerializeField] private BoolEvent _playPassByAnimEvent; [SerializeField] private BoolEvent _playVideoEvent; [SerializeField] private FloatEvent _readyCountDownEvent; [SerializeField] private StringEvent _encodeImageEvent; [SerializeField] private VideoPlayer _idleVideo; [SerializeField] private LoadImageEncoded _userImager; [SerializeField] private Image _process; [SerializeField] private TextMeshProUGUI _hintText; [SerializeField] private GameObject _notify; [SerializeField] private GameObject _hint; [SerializeField] private Image _loading; [SerializeField] private float _loadingSpeed = 100; [SerializeField] private string[] _texts; [SerializeField] private string[] _loadingTexts; private int _indexText; private bool _isLoading; private float _timer; private async void Awake() { await P4PGraphqlManager.Instance.JoinPromotion(); await P4PGraphqlManager.Instance.SubmitGameSession(0); _idleVideo.targetCameraAlpha = 1; _loading.transform.DOLocalRotate(new Vector3(0, 0, 360), 10 / _loadingSpeed, RotateMode.FastBeyond360) .SetLoops(-1) .SetRelative(true) .SetEase(Ease.Linear); _notify.SetActive(false); _hint.SetActive(false); } private void OnEnable() { _engageReadyEvent.Register(OnEngageReady); _generateImageSuccessEvent.Register(OnGenerateImageSuccess); _playPassByAnimEvent.Register(Play); _playVideoEvent.Register(SetPlayVideo); _readyCountDownEvent.Register(SetReadyCountDown); _encodeImageEvent.Register(OnGetEncodeImage); } private void OnDisable() { _engageReadyEvent.Unregister(OnEngageReady); _generateImageSuccessEvent.Unregister(OnGenerateImageSuccess); _playPassByAnimEvent.Unregister(Play); _playVideoEvent.Unregister(SetPlayVideo); _readyCountDownEvent.Unregister(SetReadyCountDown); _encodeImageEvent.Unregister(OnGetEncodeImage); } private void Update() { if(!_isLoading) return; _timer += Time.deltaTime; if (_timer >= 3) { _timer = 0; _indexText++; if (_indexText > _loadingTexts.Length - 1) { _indexText = 0; } // _hintText.text = _loadingTexts[_indexText]; } } private void Play(bool engage) { // videoPlayer.gameObject.SetActive(!passBy); // _transform.DOAnchorPosX(engage ? -1000 : 0, 1); // _hintText.text = _texts[0]; } private void OnGenerateImageSuccess(string desc) { _isLoading = false; _loading.DOFade(0, 0.5f); // _hintText.text = desc; _notify.SetActive(false); _hint.SetActive(false); } private void OnGetEncodeImage(string filePath) { _userImager.LoadImage(filePath); _notify.SetActive(true); } private void OnEngageReady() { _process.fillAmount = 0; _isLoading = true; // _hintText.text = _loadingTexts[_indexText]; _loading.DOFade(1, 1f); _hint.SetActive(true); } private async void SetPlayVideo(bool value){ if(value) { while (_idleVideo.targetCameraAlpha < 1) { _idleVideo.targetCameraAlpha += Time.deltaTime * 3; await UniTask.Yield(); } _idleVideo.targetCameraAlpha = 1; } else { while (_idleVideo.targetCameraAlpha > 0) { _idleVideo.targetCameraAlpha -= Time.deltaTime * 3; await UniTask.Yield(); } _idleVideo.targetCameraAlpha = 0; } } private void SetReadyCountDown(float progress){ // _hintText.text = _texts[1]; _process.fillAmount = 1 - progress ; } } }