본문 바로가기
게임개발/게임 UI.UX 프로그래밍

로딩바 만들기

by pudding81 2024. 2. 7.

 

-----------------------------------------------------------------------------------------------

UI 컴포넌트
Blue버튼 누르면 -> 다운로드 매니저 / 스타트 다운로드 (매서드) 
로딩 시작 

다운로드 매니저 /
 스타트 다운로드 (매서드) 코루틴 0~100%       0.1초에 1%씩 
--> 로딩으로

 

------------------------------------------------------------------------------------------------

 

 

 

슬라이더 

 

using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

public class UILoadingBar : MonoBehaviour
{
    [SerializeField] private Slider slider;
    [SerializeField] private TMP_Text progressText;
    [SerializeField] private UIComponents components;
    
    
    private int progress ;

    void Start()
    {
        //컴포넌트 블루버튼을 누르면 
        this.components.bluebutton.onClick.AddListener(() => {

            this.StartCoroutine(this.CoStartDownload()); //코루틴 시작
        });
       
        


    }

    
    IEnumerator CoStartDownload()
    {
       while (true)
        {
           
            //Debug.Log("Loading...");
            this.progress += 1;
            Debug.LogFormat("{0}", this.progress);
            this.UpdateProgressText(); 
            this.UpdateSlider();
            yield return new WaitForSeconds(0.1f);
            if (this.progress == 100f) break;
        }

    }


    private void UpdateProgressText()
    {
        this.progressText.text = string.Format("{0}%", this.progress); // 로딩진행 % 표시
    }

    private void UpdateSlider()
    {
        this.slider.value = this.progress * 0.01f; / 로딩바 슬라이더 채우기
    }
}

 

 

 

 

'게임개발 > 게임 UI.UX 프로그래밍' 카테고리의 다른 글

스킬 버튼 만들기  (0) 2024.02.08
Input 필드 UI만들기  (0) 2024.02.07
스위치버튼, 탭 메뉴 UI 만들기  (0) 2024.02.06
동기 비동기  (0) 2024.02.05
직렬화 & 역직렬화  (1) 2024.02.05