Print Friendly and PDF

유니티/게임 제작

[디펜스 게임] 로딩 UI 및 기능

나는야 개발자 2025. 7. 17. 07:01
반응형

이번 시간엔 로딩UI와 기능에 대해 제작해보려 합니다.

 

만든는 이유?

- 추후에 패치서버나 어드레서블이 들어가게 되면 비동기식으로 불러오기 때문에 로딩이 필수적으로 필요하게 됩니다. 그걸 미리 만들어 적용할 예정입니다.

 

로딩UI 제작

 

 

로딩 코드

using TMPro;
using UnityEngine;
using UnityEngine.UI;

public class UI_Loading : MonoBehaviour
{
    [SerializeField] Image _gagebar;
    [SerializeField] TextMeshProUGUI _gagetext;
    [SerializeField] GameObject _loginpanel;
    float _currentgage = 0;
    float _updategage = 0;

    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Start()
    {
        _gagebar.fillAmount = 0;
        _gagetext.text = "0%";
        _updategage = 0;
        _currentgage = 0;
    }

    // Update is called once per frame
    void Update()
    {
        if (_currentgage <= 0)
        {
            return;
        }

        _updategage += Time.deltaTime;
        if (_updategage >= _currentgage)
        {
            _updategage = _currentgage;
        }
        _gagebar.fillAmount = _updategage;
        _gagetext.text = (_updategage * 100).ToString("F1") + "%";
        //로딩 완료시점
        if (_updategage < 1)
        {
            return;
        }
        _loginpanel.SetActive(true);
        this.gameObject.SetActive(false);
    }

    public void UpdateGage(float gage)
    {
        _currentgage += gage;
    }
}

- 로딩이 끝나면 로그인 패널이 나오도록 해두었습니다.

 

using UnityEngine;

public class UI_Title : MonoBehaviour
{
    [SerializeField] UI_Loading _loading;

    void Start()
    {
        //TODO 추후에 풀링이나, DataManager에 있는거 어드레서블로 가져올때 로딩하기
        _loading.UpdateGage(1);
    }
}

- 그리고 이 로딩을 타이틀 UI에서 하나하나 로딩하여 채우는 방식으로 할 예정입니다.

 

결과

 

 


20250717 06:30 ~ 07:00 로딩 UI 제작/로딩 코드 추가/ UI_Title 코드 추가

반응형