ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [UIUXSamples(2)] UIManager 스크립트
    Unity(유니티) 2022. 4. 12. 10:01
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    using UnityEngine.UI;
    
    // UI 관리자
    public class UIManager : MonoBehaviour
    {
        public Character character; // 캐릭터 참조
    
        public GameObject toastMessagePopup; // 토스트 팝업 참조
        public float toastMessageTime; // 토스트 메시지 출력 시간
    
        public AudioSource bgmAudioSource; // BGM 재생기
    
        public Material[] colorMats; // 색상 머리티얼들 참조
        public Renderer characterRenderer; // 캐릭터(큐브) 렌더러
    
        // 색상 변경
        public void ChangeColor(int index)
        {
            // 캐릭터의 재질을 변경
            characterRenderer.material = colorMats[index];
        }
    
        // 배경 음악 볼륨값 변경
        public void ChangeBGMVolume(float volume)
        {
            // 오디오 소스에 BGM 볼륨값 설정
            bgmAudioSource.volume = volume;
        }
    
        // 캐릭터 회전 상태 설정
        public void CharacterRotation(bool isRotation)
        {
            // 캐릭터 회전 상태 설정
            character.SetIsRotation(isRotation);
        }
    
        // 팝업 열기
        public void OpenPopupButtonClick(GameObject popup)
        {
            popup.SetActive(true);
        }
    
        // 팝업 닫기
        public void ClosePopupButtonClick(GameObject popup)
        {
            popup.SetActive(false);
        }
    
        // 로그인 수행 토스트 메시지 출력
        public void ShowToastMessage(string msg, GameObject popup)
        {
            Debug.Log(msg);
            popup.SetActive(false);
    
            StopAllCoroutines(); // 이전에 실행된 코루틴을 종료함
            StartCoroutine("ToastMessageCroutine", msg);
        }
    
        // 토스트 메시지 출력
        IEnumerator ToastMessageCroutine(string msg)
        {
            // 토스트 메시지창 활성화
            toastMessagePopup.SetActive(true);
    
            // 메시지 출력
            UIToastMessage toast = toastMessagePopup.GetComponent<UIToastMessage>();
            if (toast != null)
            {
                toast.PrintToastMessage(msg);
            }
    
            // 토스트 메시지 오픈 시간
            yield return new WaitForSeconds(toastMessageTime);
    
            // 토스트 메시지창 비활성화
            toastMessagePopup.SetActive(false);
        }
    
    }

     

Designed by Tistory.