104 lines
3.2 KiB
C#
104 lines
3.2 KiB
C#
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<ContentSelectButton,Button> 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<TextMeshProUGUI>();
|
|
text_Title.SetText(selectButton.Title);
|
|
|
|
//BackGround Set
|
|
if(!string.IsNullOrEmpty(selectButton.BackGroundSpritePath))
|
|
{
|
|
var bgIMG = Resources.Load<Sprite>(selectButton.BackGroundSpritePath);
|
|
btn.image.sprite = bgIMG;
|
|
}
|
|
|
|
//iconSet
|
|
string iconPathToLoad = selectButton.IconSpritePath;
|
|
if (!string.IsNullOrEmpty(iconPathToLoad))
|
|
{
|
|
Image iconImageComponent = btn.transform.Find("Icon")?.GetComponent<Image>() ?? btn.GetComponentInChildren<Image>(true);
|
|
|
|
if (!string.IsNullOrEmpty(iconPathToLoad))
|
|
{
|
|
Sprite iconSprite = Resources.Load<Sprite>(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();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 선택 상태에 따라
|
|
/// </summary>
|
|
/// <param name="btn"></param>
|
|
/// <param name="isSelect"></param>
|
|
private void ChangeBtn(Button btn,bool isSelect)
|
|
{
|
|
var text_Title = btn.GetComponentInChildren<TextMeshProUGUI>();
|
|
Image iconImageComponent = btn.transform.Find("Icon")?.GetComponent<Image>() ?? btn.GetComponentInChildren<Image>(true);
|
|
|
|
if(isSelect)
|
|
{
|
|
text_Title.color = ColorUtil.FromHex("#248BFF");
|
|
}
|
|
else
|
|
{
|
|
text_Title.color = Color.white;
|
|
}
|
|
iconImageComponent.gameObject.SetActive(isSelect);
|
|
}
|
|
}
|
|
|
|
}
|