using Code.DI; using Code.Gameplay.Enemies; using Code.Gameplay.Player; using Code.Input; using TMPro; using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UI; using DG.Tweening; namespace Code.UI { public class GameplayControllerSecond : MonoBehaviour { [SerializeField] private Image deathScreen; [SerializeField] private Image winScreen; [SerializeField] private TMP_Text deathText; [SerializeField] private TMP_Text winText; [SerializeField] private Button exitButton; [SerializeField] private Button returnButton; [SerializeField] private PlayerHealth playerHealth; [SerializeField] private AudioSource audioSource; [SerializeField] private BoxCollider2D blockBorder; private IInputService _inputService; private void Start() { _inputService = FindFirstObjectByType().Resolve(); _inputService.EnableMap(ActionMapping.Gameplay); FindFirstObjectByType().Construct(_inputService); exitButton.onClick.AddListener(OnExitButtonPressed); returnButton.onClick.AddListener(OnReturnButtonPressed); playerHealth.OnDied += HandleDeath; deathScreen.gameObject.SetActive(false); winScreen.gameObject.SetActive(false); } private void HandleDeath() { var clip = Resources.Load("Audio/SFX/DeathSFX"); audioSource.PlayOneShot(clip); _inputService.DisableMap(ActionMapping.Gameplay); deathScreen.gameObject.SetActive(true); deathScreen.rectTransform.localScale = Vector3.zero; deathScreen.rectTransform.DOScale(1f, 0.3f) .SetEase(Ease.OutBack); var color = deathText.color; color.a = 0; deathText.color = color; deathText.DOFade(1f, 0.6f) .OnComplete(() => { deathText.DOFade(0.8f, 0.5f) .SetLoops(-1, LoopType.Yoyo) .SetEase(Ease.InOutSine); }); } public void OnBossDefeated() { var clip = Resources.Load("Audio/SFX/WinSFX"); audioSource.PlayOneShot(clip); _inputService.DisableMap(ActionMapping.Gameplay); winScreen.gameObject.SetActive(true); winScreen.rectTransform.localScale = Vector3.zero; winScreen.rectTransform.DOScale(1f, 0.3f) .SetEase(Ease.OutBack); var color = winText.color; color.a = 0; winText.color = color; winText.DOFade(1f, 0.6f) .OnComplete(() => { deathText.DOFade(0.8f, 0.5f) .SetLoops(-1, LoopType.Yoyo) .SetEase(Ease.InOutSine); }); } private void OnExitButtonPressed() { DOTween.Kill(deathScreen.rectTransform); DOTween.Kill(deathText); exitButton.onClick.RemoveAllListeners(); returnButton.onClick.RemoveAllListeners(); SceneManager.LoadScene("MainMenu"); } private void OnReturnButtonPressed() { DOTween.Kill(winScreen.rectTransform); DOTween.Kill(winText); exitButton.onClick.RemoveAllListeners(); returnButton.onClick.RemoveAllListeners(); SceneManager.LoadScene("MainMenu"); } } }