반응형
SMALL
톤앤 매너를 변경하였고 공지사항과 도움말 그리고 타이틀화면 버튼과 버전을 추가하였다.
공지사항과 도움말 버튼은 실제 게임 안에서 클릭시 게임의 공식 블로그로 이동시킬 예정
(현재는 내 블로그로 되어있다 ㅎㅎ;;)
타이틀 화면의 경우 씬 매니저가 만들어지면 해당 씬 매니저에게 액션을 보내주는 형식으로 사용.
버전의 경우 게임의 버전으로 그대로 가져올 예정이고 버전 규칙은 아래와 같이 하면 어떨지 싶다.
Major.Minor.Patch
UISettingDirector 스크립트
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class UISettingDirector : MonoBehaviour
{
public AudioManager audioManager; // AudioManager 컴포넌트
public Button BtnUISettingPopupInTitle; //게임 시작 메뉴 팝업 버튼
public Button BtnUISettingPopupInGame; //인게임 팝업 버튼
public Button UISettingBG; //팝업 배경 (팝업 종료)
public GameObject UISettingPopup; //팝업창
public Slider backgroundMusicSlider; // 배경음악 볼륨 조절 슬라이더
public Slider soundEffectSlider; // 효과음 볼륨 조절 슬라이더
public Toggle vibrationToggle; // 진동 On/Off 토글
public Button BtnAnnouncement; // 공지사항 버튼
public Button BtnHelp; // 도움말 버튼
public Button BtnBackToTitle; // 타이틀화면으로 버튼
public Text txtVersion;
public Action toTileScreen;
void Awake()
{
// 초기값 설정
this.backgroundMusicSlider.value = this.audioManager.backgroundMusicVolume;
this.soundEffectSlider.value = this.audioManager.soundEffectVolume;
this.vibrationToggle.isOn = this.audioManager.isVibrationOn;
//ver info : Major.Minor.Patch
this.txtVersion.text = string.Format("Ver.{0}",Application.version);
//팝업창 키는 버튼 두종류 (타이틀 , 인게임)
this.BtnUISettingPopupInTitle.onClick.AddListener(() => {
this.UISettingPopup.SetActive(true);
});
this.BtnUISettingPopupInGame.onClick.AddListener(() => {
this.UISettingPopup.SetActive(true);
});
//팝업 창 끄는 버튼(타이틀 ,인게임 동일)
this.UISettingBG.onClick.AddListener(() => {
this.UISettingPopup.SetActive(false);
});
//팝업 메뉴 내 버튼 기능
this.backgroundMusicSlider.onValueChanged.AddListener((x) =>
{
this.OnBackgroundMusicSliderValueChanged(x);
});
this.soundEffectSlider.onValueChanged.AddListener((x) =>
{
this.OnSoundEffectSliderValueChanged(x);
});
this.vibrationToggle.onValueChanged.AddListener((x) => {
this.OnVibrationToggleValueChanged(x);
});
// 임시로 제 블로그를사용했습니다. 나중에 저희 게임 블로그로 변경하면 됩니다.
this.BtnAnnouncement.onClick.AddListener(() => {
Application.OpenURL("https://bueong-e.tistory.com/");
});
this.BtnHelp.onClick.AddListener(() => {
Application.OpenURL("https://bueong-e.tistory.com/");
});
this.BtnBackToTitle.onClick.AddListener(() => {
//타이틀 씬으로 전환 용 액션 (나중에 씬 매니저에서 사용하심 됩니다.)
this.toTileScreen();
Debug.Log("타이틀 씬 로드");
});
// 초기값 : 팝업창 SetOFF
this.UISettingPopup.SetActive(false);
}
// 배경음악 볼륨 조절 슬라이더 값 변경시 호출되는 메소드
public void OnBackgroundMusicSliderValueChanged(float value)
{
this.audioManager.SetBackgroundMusicVolume(value);
}
// 효과음 볼륨 조절 슬라이더 값 변경시 호출되는 메소드
public void OnSoundEffectSliderValueChanged(float value)
{
this.audioManager.SetSoundEffectVolume(value);
}
// 진동 On/Off 토글 값 변경시 호출되는 메소드
public void OnVibrationToggleValueChanged(bool value)
{
this.audioManager.SetVibrationOnOff(value);
}
}
AudioManager 스크립트
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AudioManager : MonoBehaviour
{
public float backgroundMusicVolume = 1f; // 배경음악 볼륨
public float soundEffectVolume = 1f; // 효과음 볼륨
public bool isVibrationOn = true; // 진동 On/Off
private AudioSource audioSource;
public GameObject deathSound;
void Start()
{
// 초기화
this.audioSource = this.GetComponent<AudioSource>();
}
// 배경음악 볼륨 설정
public void SetBackgroundMusicVolume(float value)
{
this.backgroundMusicVolume = value;
this.audioSource.volume = value;
}
// 효과음 볼륨 설정
public void SetSoundEffectVolume(float value)
{
this.soundEffectVolume = value;
this.PlaySfx();
}
// 진동 On/Off 설정
public void SetVibrationOnOff(bool value)
{
this.isVibrationOn = value;
string state = value ? "on" : "off";
Debug.LogFormat("viberation : {0}", state);
}
public void PlaySfx()
{
var go = GameObject.Instantiate(this.deathSound);
go.GetComponent<AudioSource>().volume = this.soundEffectVolume;
this.StartCoroutine(this.DestoySFX(go));
}
private IEnumerator DestoySFX(GameObject go)
{
yield return new WaitForSeconds(2f);
GameObject.Destroy(go);
}
}
반응형
LIST
'프로젝트 > 건즈앤 레이첼스' 카테고리의 다른 글
[유니티 프로젝트] A* 알고리즘을 이용한 맵 생성 (로직 변경) (0) | 2023.04.05 |
---|---|
[유니티 프로젝트] 옵션 UI .3 (0) | 2023.04.03 |
[유니티 프로젝트] 옵션 UI (0) | 2023.04.01 |
[유니티 프로젝트] 드래그 앤 드롭 인벤토리 구현 .1 (0) | 2023.03.30 |
[랜덤 맵 생성] A* 알고리즘을 이용한 절차적 맵 제작 방법 정리 (0) | 2023.03.30 |