버튼 UI
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UITabMenu : MonoBehaviour
{
public UIMenu[] arrUIMenu; //UiTabMenu 엑세스
private UIMenu selectedUIMenu; //UIMenu 맴버 Button btn
void Start()
{
foreach (UIMenu uiMenu in this.arrUIMenu)
{
uiMenu.btn.onClick.AddListener(() =>
{
if (this.selectedUIMenu != null) {
this.selectedUIMenu.FocusOff(); //arrUIMenu 의 메서드 FocusOff호출
}
this.selectedUIMenu = uiMenu;
this.selectedUIMenu.FocusOn();//arrUIMenu 의 메서드 FocusOn호출
});
uiMenu.onClick = (menuType) => //uiMenu의 맴버 Action대리자 onClick호출
{
Debug.LogFormat("-----> {0}", menuType);
};
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class UIMenu : MonoBehaviour
{
public enum eMenuType
{
Shop, Item
}
public Button btn;
public TMP_Text txtName; //메뉴 명
public GameObject focusGo; //포커스 이미지
public eMenuType menuType;
public System.Action<eMenuType> onClick;
private void Start()
{
this.btn.onClick.AddListener(() =>
{
this.onClick(this.menuType);
});
}
public void FocusOn()
{
//글자 색 변경
//F4DE9E
string htmlString = "#F4DE9E";
Color color;
if (ColorUtility.TryParseHtmlString(htmlString, out color)) //out으로 변수를 Color color에 다시 할당
{
this.txtName.color = color;
}
//포커스 이미지 활성화
this.focusGo.SetActive(true);
}
public void FocusOff()
{
//글자 색 변경
//FFFFFF
string htmlString = "#FFFFFF";
Color color;
if (ColorUtility.TryParseHtmlString(htmlString, out color)) //out으로 변수를 Color color에 다시 할당
{
this.txtName.color = color;
}
//포커스 이미지 비활성화
this.focusGo.SetActive(false);
}
}
https://docs.unity3d.com/ScriptReference/Events.UnityEvent.AddListener.html
Unity - Scripting API: Events.UnityEvent.AddListener
Success! Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable. Close
docs.unity3d.com
#Action대리자의 사용빈도가 높다 빨리 익숙해지자
#처음 구조가 중요! 누가 누구를 관리하고 어디에 연결되어있는지!
https://docs.unity3d.com/ScriptReference/UIElements.Button-onClick.html
Unity - Scripting API: UIElements.Button.onClick
Success! Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable. Close
docs.unity3d.com
https://docs.unity3d.com/ScriptReference/ColorUtility.html
Unity - Scripting API: ColorUtility
Success! Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable. Close
docs.unity3d.com
https://docs.unity3d.com/ScriptReference/ColorUtility.TryParseHtmlString.html
Unity - Scripting API: ColorUtility.TryParseHtmlString
Strings that begin with '#' will be parsed as hexadecimal in the following way: #RGB (becomes RRGGBB) #RRGGBB #RGBA (becomes RRGGBBAA) #RRGGBBAA When not specified alpha will default to FF. Strings that do not begin with '#' will be parsed as literal color
docs.unity3d.com
# out 형식?
https://learn.microsoft.com/ko-kr/dotnet/csharp/language-reference/keywords/out-parameter-modifier
out 매개 변수 한정자 - C# 참조
out 매개 변수 한정자(C# 참조) 아티클 10/05/2022 읽는 데 7분 걸림 기여자 14명 피드백 이 문서의 내용 --> out 키워드를 사용하면 참조를 통해 인수를 전달할 수 있습니다. 이 키워드는 정식 매개 변수
learn.microsoft.com
#드디어 보인다 ... 빨리 람다와 친해지자