UITitle
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
using UnityEngine.SceneManagement;
public class UITitle : MonoBehaviour
{
public Slider loadSlider;
public TMP_Text txtVersion;
private int maxData = 1304;
private int data = 0;
private System.Action toNextScene;
public void Init(string nowVersion)
{
this.txtVersion.text = nowVersion;
}
void Start()
{
StartCoroutine(UILoading());
this.toNextScene = () =>
{
AsyncOperation oper = SceneManager.LoadSceneAsync("TitleTouchScene");
oper.completed += (obj) =>
{
App app = GameObject.FindObjectOfType<App>();
UITitleTouch uiTitleTouch = GameObject.FindObjectOfType<UITitleTouch>();
uiTitleTouch.Init(app.version);
};
};
}
IEnumerator UILoading()
{
while (this.maxData >= this.data)
{
if(this.maxData == this.data)
{
this.toNextScene();
}
if (this.data == 330) yield return new WaitForSeconds(0.5f);
if (this.data == 770) yield return new WaitForSeconds(1.7f);
if (this.data == 1070) yield return new WaitForSeconds(0.7f);
if (this.data == 50) this.data += 230;
if (this.data == 546) this.data += 100;
this.data += 2;
Debug.Log(this.data);
this.loadSlider.value = this.data;
var txtGO = this.loadSlider.transform.Find("Text (TMP)").GetComponent<TMP_Text>();
txtGO.text = string.Format("<color=#C6AC34>Downloading...</color> {0:#,###}/{1:#,###}", this.data, this.maxData);
yield return null;
}
}
}
- 슬라이더의 밸류값에 접근하여 코루틴으로 매 프레임 일정 값을 더해주는 식으로 로딩화면을 구현, 로딩이 끝나면 다음 씬으로 넘어간다.
UITitleTouch
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
using UnityEngine.SceneManagement;
public class UITitleTouch : MonoBehaviour
{
public TMP_Text txtVersion;
public WifiZone wifiZone;
public GameObject popupNetworkError;
public Button[] btns;
public void Init(string nowVersion)
{
this.txtVersion.text = nowVersion;
this.wifiZone.isOn = false;
}
void Start()
{
for(int i = 0; i < btns.Length; i++)
{
int idx = i;
btns[idx].onClick.AddListener(() =>
{
if (this.wifiZone.isOn == false) Instantiate(this.popupNetworkError);
else SceneManager.LoadScene("LobbyScene");
});
}
}
}
- 처음 화면을 터치하면 네트워크 에러가 발생하고 와이파이를 켜고 화면을 터치하면 다음 씬으로 넘어가도록 구현

'C# > 수업 과제' 카테고리의 다른 글
원형 큐에 대해 (0) | 2023.02.18 |
---|---|
SpaceShooter2D (0) | 2023.02.12 |
Unity) [유니티 UI] 로그인 UI 구현 (2) | 2023.02.10 |
이진트리 구현과 순회 (0) | 2023.02.09 |
재귀함수를 통한 팩토리얼, 피보나치수열 구현 (0) | 2023.02.08 |