728x90
1. 버튼 추가
Canvas 아래 ConfigButton 추가
2. 배경음악 추가
Asset Store -> Music Tracks for Your Games 다운
UIManager Audio Source 컴포넌트 추가
3.
4.
RotationTitleText -> Toggle Group 컴포넌트 추가
토글그룹 연결
5.
C# Script
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 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(); //StopCoroutine("ToastMessageCroutine"); 써도됨(이전에 실행된 코루틴을 종료함)
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);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Character : MonoBehaviour
{
public bool isRotation = true;
// Update is called once per frame
void Update()
{
if (isRotation)
{
transform.Rotate(Vector3.up * 90f * Time.deltaTime);
}
}
//캐릭터의 회전 여부 설정
public void SetIsRotation(bool isRotation)
{
this.isRotation = isRotation;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class UIConfig : MonoBehaviour
{
public UIManager uiManager;
public void RotationConfig(Toggle onToggle)
{
//회전 on 상태값 추출
bool isRotation = onToggle.isOn;
//캐릭터 회전 상태 설정 요청
uiManager.CharacterRotation(isRotation);
}
}
6. 볼륨조절
슬라이더 추가
7.
드롭다운
8. 색 선택한것에 따라 큐브 색상 변경
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;
public Renderer characterRenderer;
public Material[] colorMats; //색상 재료 참조
public void ChangeColor(int index)
{
//캐릭터의 재질을 변경
characterRenderer.material = colorMats[index];
}
//배경 음악 볼륨값 변경
public void ChagneBGMVolume(float volume)
{
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(); //StopCoroutine("ToastMessageCroutine"); 써도됨(이전에 실행된 코루틴을 종료함)
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);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class UIColor : MonoBehaviour
{
public UIManager uiManager;
//색상 선택 드롭다운 선택 이벤트 메소드
public void ChangeColor(Dropdown dd)
{
int index = dd.value;
Debug.Log("선택된 드롭다운 인덱스 : " + dd.value);
uiManager.ChangeColor(index);
}
}
스크롤뷰
Asset Store -> Animal Pack Redux다운 -> Texture Type
Mask 컴포넌트 추가
CellButton
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class UICell : MonoBehaviour
{
public void OnCellButtonClick(int index)
{
Debug.Log("선택한 스크롤뷰 셀 인덱스는 " + index);
}
}
'Unity' 카테고리의 다른 글
[유니티] 3D 슈팅게임 만들기 (0) | 2021.05.21 |
---|---|
[유니티] 네이게이션 (0) | 2021.05.20 |
[유니티] UI/UX Samples (0) | 2021.05.18 |
[유니티] 조이패드 (0) | 2021.05.18 |
[유니티] 조명설정하기 (0) | 2021.05.14 |
댓글