using UnityEngine; using UnityEngine.UI; using DG.Tweening; using UnityEngine.SceneManagement; using System.Collections; using TMPro; public class LevelLoadManager : MonoBehaviour { public static LevelLoadManager instance; public Image contentImage; public float transitionDuration = 0.5f; CanvasGroup canvasGroup; public bool isShowing => canvasGroup.alpha == 1; [Header("Matchmade UI")] public GameObject matchmadeUI; public GameObject p1_red,p2_red,p1_blue,p2_blue; public Image p1_icon, p2_icon; public TMP_Text p1_name, p2_name; public TMP_Text p1_l10, p2_l10; public Sprite redIcon, blueIcon; public TMP_Text txtMiddle; public TMP_Text txtRcPrize; [Header("Game Over UI")] public GameObject p1_winner; public GameObject p2_winner; void Awake() { if(instance != null){ Destroy(gameObject); return; } canvasGroup = GetComponent(); instance = this; DontDestroyOnLoad(gameObject); Hide(); matchmadeUI.SetActive(false); } public static void LoadLevel(string levelName){ instance.loadLevel(levelName); } void loadLevel(string levelName){ StartCoroutine(CoroutineLoadLevel(levelName)); } IEnumerator CoroutineLoadLevel(string levelName){ instance.Show(); yield return new WaitForSeconds(transitionDuration); if(matchmadeUI.activeSelf){ yield return new WaitForSeconds(3f); } yield return SceneManager.LoadSceneAsync(levelName); instance.Hide(); } public void Show(){ canvasGroup.blocksRaycasts=true; canvasGroup.interactable=true; contentImage.fillOrigin = 0; canvasGroup.DOFade(1, transitionDuration).SetEase(Ease.OutSine); contentImage.DOFillAmount(1, transitionDuration).SetEase(Ease.OutSine); } public void Hide(){ canvasGroup.blocksRaycasts=false; canvasGroup.interactable=false; contentImage.fillOrigin = 1; canvasGroup.DOFade(0, transitionDuration).SetEase(Ease.InSine); contentImage.DOFillAmount(0, transitionDuration).SetEase(Ease.InSine).OnComplete(() => { if(gameOver){ gameOver = false; matchmadeUI.SetActive(false); } }); } Team myTeam = Team.Red; public void SetupMatchMade(Team myTeam_, string opponentName, string myName, string myL10, string opponentL10, string rcPrize){ myTeam = myTeam_; matchmadeUI.SetActive(true); p1_winner.SetActive(false); p2_winner.SetActive(false); txtMiddle.text = "VS"; if(myTeam == Team.Red){ p1_red.SetActive(true); p1_blue.SetActive(false); p2_red.SetActive(false); p2_blue.SetActive(true); p1_icon.sprite = redIcon; p2_icon.sprite = blueIcon; }else{ p1_red.SetActive(false); p1_blue.SetActive(true); p2_red.SetActive(true); p2_blue.SetActive(false); p1_icon.sprite = blueIcon; p2_icon.sprite = redIcon; } p1_name.text = opponentName; p2_name.text = myName; p1_l10.text = myL10; p2_l10.text = opponentL10; txtRcPrize.text = rcPrize; } public static MatchmadePlayer myPlayer; public static MatchmadePlayer opponentPlayer; public void SetupMatchMade(Team myTeam_, MatchmadePlayer myPlayer_, MatchmadePlayer opponentPlayer_, string rcPrize){ myTeam = myTeam_; myPlayer = myPlayer_; opponentPlayer = opponentPlayer_; string opponentName = opponentPlayer_.Name; string myName = myPlayer_.Name; string myL10 = $"L10 {myPlayer.l10_wins} -{myPlayer.l10_losses}"; string opponentL10 = $"L10 {opponentPlayer.l10_wins} -{opponentPlayer.l10_losses}"; SetupMatchMade(myTeam, myName, opponentName, myL10, opponentL10, rcPrize); } bool gameOver = false; public void SetupGameOver(Team winningTeam, int redScore, int blueScore){ gameOver = true; txtMiddle.text = $"{(myTeam == Team.Red ? redScore : blueScore)} FINAL {(myTeam == Team.Red ? blueScore : redScore)}"; if(myTeam == winningTeam){ p1_winner.SetActive(true); p2_winner.SetActive(false); }else{ p1_winner.SetActive(false); p2_winner.SetActive(true); } p1_l10.text = $"L10 {myPlayer.l10_wins}-{myPlayer.l10_losses}"; p2_l10.text = $"L10 {opponentPlayer.l10_wins}-{opponentPlayer.l10_losses}"; } }