#1.버튼 구조=>SettingMain->UISettingDirector->UIsettingButtons
#2. 버튼 구현
*onclick 이벤트 발생시 디버그 타입 (타입은 열거형으로 정의)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class UISettingButtons : MonoBehaviour
{
public enum eSettingButtonType
{
Languge,
ID,
Like,
Rate,
About,
OtherGame,
DeleteAcoount,
ConnectFacebook,
ConnectGameCneter,
Logout
}
public Button() arrBtns;
public System.Action<eSettingButtonType> onClick;
void Start()
{
for(int i=0; i<arrBtns.Length; i++) //enum으로 정의해논 type 할당
{
int idx = i; //변수캡쳐 사용(event)
this.arrBtns(idx).onClick.AddListener(() => {
Debug.Log("Click");
this.onClick((eSettingButtonType)idx);
});
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UISettingDirector : MonoBehaviour
{
public UISettingButtons UISettingButtons;
void Start()
{
this.UISettingButtons.onClick = (x) =>
{
Debug.Log(x);
};
}
}
#2.슬라이드 구조=>SettingMain->UISettingDirector->UIList
#슬라이드 구현(onValueChanged를 사용하여 값 출력, 최대=10)
#text type value,maxValue는 현재 값과 최대값 maxValue를 표시합니다.
# 게임이 시작되면 Init 메소드를 통해 값을 0으로 초기화합니다.
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class UISettingList : MonoBehaviour
{
//slider
//soundFx
public Slider soundFxSlider;
public TMP_Text soundFxTxtValue;
public Image iconSoundFx;
//music
public Slider musicSlider;
public TMP_Text musicTxtValue;
public Image iconMusic;
public System.Action<float> onValueChanged;
public void Init(int val)
{
this.soundFxSlider.value = val;
this.musicSlider.value = val;
}
void Start()
{
//Slider(soundFx,Music)
//color
string onColor = "#FAB037";
string offColor = "#76617D";
//Color color1;
//Color color1;
//if (ColorUtility.TryParseHtmlString(onColor, out color1))
//{
// this.iconSoundFx.color = color1;
//}
this.soundFxSlider.onValueChanged.AddListener((val) => {
Debug.Log(val);
this.soundFxTxtValue.text = string.Format("{0}",(int)val);
if(val>0)
{
this.iconSoundFx.gameObject.SetActive(true);
//this.iconSoundFx.color=Color.red;
}
else
{
this.iconSoundFx.gameObject.SetActive(false);
}
});
this.musicSlider.onValueChanged.AddListener((val) => {
Debug.Log(val);
this.musicTxtValue.text=string.Format("{0}",(int)val);
if(val>0)
{
this.iconMusic.gameObject.SetActive(true);
}
else
{
this.iconMusic.gameObject.SetActive(false);
}
});
//switch(Alram,Vibration)
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UISettingDirector : MonoBehaviour
{
public UISettingButtons uiSettingButtons;
public UISettingList uiSettingList;
void Start()
{
this.uiSettingButtons.onClick = (x) =>
{
Debug.Log(x);
};
this.uiSettingList.Init(0); //vale=0
}
}
#아이콘 활성화/비활성화는 되었지만 색상으로 표현하고 싶습니다.
#활성 색상은 string onColor = “#FAB037″입니다./ 비활성 this.musicSlider.value = val;
#Color is an ambiguous reference 오류로 구현 실패, API를 더 참조해야 합니다.
