티스토리 뷰
#1.Button 구조=>SettingMain->UISettingDirector->UIsettingButtons
#2.버튼 구현하기
*onclick이벤트가 발생하면 type을 debug한다(type은 enum으로 정의)
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.Slide 구조=>SettingMain->UISettingDirector->UIList
#slid구현하기(onValueChanged를 이용해 value값 출력, max=10)
#text 타입의 value,maxValue는 현재 value 와 최대 maxValue를 보여줌
#게임 시작시 Init메서드를 통해 value값을 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
}
}
#icon의 활성/비활성은 구현했으나 색으로 표현하고싶었다
#활성 상태의 색은 string onColor = "#FAB037"; / 비활성 상태는 this.musicSlider.value = val;
#Color가 모호한 참조라는 오류가 발생하여 구현 실패, API를 조금 더 참고해야 겠다
#UIPopupID에서 입력받은 Text를 UISettingButtons에서 debug하기
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class UIPopupID : MonoBehaviour
{
public TMP_Text txtInputField;
public Button btnOk;
void Start()
{
this.txtInputField.text = string.Format("{0}",this.txtInputField);
this.btnOk.onClick.AddListener(() => {
Debug.LogFormat("ID:{0}", this.txtInputField.text);
this.gameObject.SetActive(false);
});
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.VisualScripting;
public class UISettingDirector : MonoBehaviour
{
public UISettingButtons uiSettingButtons;
public UISettingList uiSettingList;
public UIPopupID uiPopupID;
void Start()
{
this.uiSettingButtons.onClick = (x) =>
{
Debug.Log(x);
if (x == UISettingButtons.eSettingButtonType.Logout)
{
Debug.LogFormat("<color=red>{0}</color>",this.uiSettingButtons.btnType);
this.LogOut();
}
};
this.uiSettingList.Init(0); //vale=0
}
public void LogOut()
{
Debug.LogFormat("Logout ID:{0}", this.uiPopupID.txtInputField.text);
}
}
'게임클라이언트 프로그래밍 > Unity' 카테고리의 다른 글
3D 캐릭터 이동 연습 (0) | 2023.02.26 |
---|---|
VRCity (0) | 2023.02.23 |
2D Shooting 복습 (0) | 2023.02.19 |
UIDailyReward (0) | 2023.02.17 |
UIMission (0) | 2023.02.15 |