using NUnit.Framework; using System.Collections.Generic; using TMPro; using UnityEngine; using UnityEngine.UI; using UVC.Util; using UVC.UI.Toolbar.Model; namespace EnglewoodLAB.UI.Controller { public class ContentButtonController { private Dictionary btnTable = new(); private ContentSelectButton prevSelectBtn; public void AddItem(ContentSelectButton selectButton, Button btn) { btnTable.Add(selectButton,btn); SetItem(btn, selectButton); } public void SetItem(Button btn, ContentSelectButton selectButton) { var text_Title = btn.GetComponentInChildren(); text_Title.SetText(selectButton.Title); //BackGround Set if(!string.IsNullOrEmpty(selectButton.BackGroundSpritePath)) { var bgIMG = Resources.Load(selectButton.BackGroundSpritePath); btn.image.sprite = bgIMG; } //iconSet string iconPathToLoad = selectButton.IconSpritePath; if (!string.IsNullOrEmpty(iconPathToLoad)) { Image iconImageComponent = btn.transform.Find("Icon")?.GetComponent() ?? btn.GetComponentInChildren(true); if (!string.IsNullOrEmpty(iconPathToLoad)) { Sprite iconSprite = Resources.Load(iconPathToLoad); iconImageComponent.sprite = iconSprite; iconImageComponent.enabled = (iconSprite != null); } else { iconImageComponent.sprite = null; iconImageComponent.enabled = false; } iconImageComponent.gameObject.SetActive(false); } } public void OnClickBtn(ContentSelectButton selectItem) { Reset(); selectItem.ExCuteClick(); ChangeBtn(btnTable[selectItem], true); prevSelectBtn = selectItem; } public void Reset() { if (prevSelectBtn != null) { //ÇØ´ç ¹öưÀÇ ¾ÆÀÌÄÜ ºñȰ¼ºÈ­ prevSelectBtn.ExCuteClick(); if (btnTable.ContainsKey(prevSelectBtn)) ChangeBtn(btnTable[prevSelectBtn], false); } prevSelectBtn = null; } public void Clear() { btnTable.Clear(); } /// /// ¼±Åà »óÅ¿¡ µû¶ó /// /// /// private void ChangeBtn(Button btn,bool isSelect) { var text_Title = btn.GetComponentInChildren(); Image iconImageComponent = btn.transform.Find("Icon")?.GetComponent() ?? btn.GetComponentInChildren(true); if(isSelect) { text_Title.color = ColorUtil.FromHex("#248BFF"); } else { text_Title.color = Color.white; } iconImageComponent.gameObject.SetActive(isSelect); } } }