105 lines
2.8 KiB
C#
105 lines
2.8 KiB
C#
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;
|
|
|
|
void Awake()
|
|
{
|
|
if(instance != null){
|
|
Destroy(gameObject);
|
|
return;
|
|
}
|
|
canvasGroup = GetComponent<CanvasGroup>();
|
|
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);
|
|
}
|
|
|
|
|
|
public void SetupMatchMade(Team myTeam, string opponentName, string myName, string myL10, string opponentL10){
|
|
matchmadeUI.SetActive(true);
|
|
|
|
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 = myName;
|
|
p2_name.text = opponentName;
|
|
p1_l10.text = myL10;
|
|
p2_l10.text = opponentL10;
|
|
}
|
|
}
|