디자인 적용
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
@@ -23,21 +24,30 @@ namespace UVC.UI.Util
|
||||
[SerializeField]
|
||||
private Color disabledColor = Color.gray; // 비활성화 시 컬러
|
||||
[SerializeField]
|
||||
private Image targetImage; // 컬러를 변경할 이미지 컴포넌트
|
||||
private Image[] targetImages; // 컬러를 변경할 이미지 컴포넌트
|
||||
[SerializeField]
|
||||
private TextMeshProUGUI[] targetTexts; // 컬러를 변경할 이미지 컴포넌트
|
||||
[SerializeField]
|
||||
private Selectable button; // 버튼 컴포넌트
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (targetImage == null)
|
||||
if (targetImages == null)
|
||||
{
|
||||
targetImage = GetComponent<UnityEngine.UI.Image>();
|
||||
var img = GetComponent<Image>();
|
||||
if(img != null) targetImages = new Image[] { img };
|
||||
}
|
||||
if (targetImage != null)
|
||||
|
||||
if (targetTexts == null)
|
||||
{
|
||||
targetImage.color = originalColor; // 초기 컬러 설정
|
||||
targetImage.color = enabled ? originalColor : disabledColor;
|
||||
var txt = GetComponent<TextMeshProUGUI>();
|
||||
if(txt != null) targetTexts = new TextMeshProUGUI[] { txt };
|
||||
}
|
||||
|
||||
ChangeColor(enabled ? originalColor : disabledColor);
|
||||
|
||||
|
||||
|
||||
if (button == null)
|
||||
{
|
||||
button = GetComponent<Button>();
|
||||
@@ -59,16 +69,31 @@ namespace UVC.UI.Util
|
||||
toggle.onValueChanged.AddListener(onValueChangedToggle);
|
||||
}
|
||||
|
||||
if (targetImage != null) targetImage.color = color;
|
||||
ChangeColor(color);
|
||||
}
|
||||
}
|
||||
|
||||
private void ChangeColor(Color color)
|
||||
{
|
||||
if (targetImages != null)
|
||||
{
|
||||
foreach (var img in targetImages)
|
||||
{
|
||||
img.color = color;
|
||||
}
|
||||
}
|
||||
if (targetTexts != null)
|
||||
{
|
||||
foreach (var txt in targetTexts)
|
||||
{
|
||||
txt.color = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void onValueChangedToggle(bool isOn)
|
||||
{
|
||||
if (targetImage != null)
|
||||
{
|
||||
targetImage.color = isOn ? clickColor : originalColor; // 토글 상태에 따라 컬러 변경
|
||||
}
|
||||
ChangeColor(isOn ? clickColor : originalColor); // 토글 상태에 따라 컬러 변경
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
@@ -83,17 +108,11 @@ namespace UVC.UI.Util
|
||||
{
|
||||
if ((button != null && button.interactable) || (button == null && enabled))
|
||||
{
|
||||
if (targetImage != null)
|
||||
{
|
||||
targetImage.color = clickColor; // 클릭 시 컬러 변경
|
||||
}
|
||||
ChangeColor(clickColor); // 클릭 시 컬러 변경
|
||||
}
|
||||
else
|
||||
{
|
||||
if (targetImage != null)
|
||||
{
|
||||
targetImage.color = disabledColor; // 비활성화 시 컬러 변경
|
||||
}
|
||||
ChangeColor(disabledColor); // 비활성화 상태일 때 컬러 변경
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,10 +120,7 @@ namespace UVC.UI.Util
|
||||
{
|
||||
if ((button != null && button.interactable) || (button == null && enabled))
|
||||
{
|
||||
if (targetImage != null)
|
||||
{
|
||||
targetImage.color = hoverColor; // 마우스 오버 시 컬러 변경
|
||||
}
|
||||
ChangeColor(hoverColor); // 마우스 오버 시 컬러 변경
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,23 +130,16 @@ namespace UVC.UI.Util
|
||||
{
|
||||
if (button != null && button is Toggle toggle)
|
||||
{
|
||||
if (targetImage != null)
|
||||
targetImage.color = toggle.isOn ? clickColor : originalColor; // 토글 상태에 따라 컬러 변경
|
||||
ChangeColor(toggle.isOn ? clickColor : originalColor); // 토글 상태에 따라 컬러 변경
|
||||
}
|
||||
else
|
||||
{
|
||||
if (targetImage != null)
|
||||
{
|
||||
targetImage.color = originalColor; // 마우스가 벗어날 때 원래 컬러로 변경
|
||||
}
|
||||
ChangeColor(originalColor); // 마우스가 벗어날 때 원래 컬러로 변경
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (targetImage != null)
|
||||
{
|
||||
targetImage.color = disabledColor; // 비활성화 상태일 때 컬러 변경
|
||||
}
|
||||
ChangeColor(disabledColor); // 비활성화 상태일 때 컬러 변경
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,17 +147,11 @@ namespace UVC.UI.Util
|
||||
{
|
||||
if ((button != null && button.interactable) || (button == null && enabled))
|
||||
{
|
||||
if (targetImage != null)
|
||||
{
|
||||
targetImage.color = hoverColor; // 클릭 후 원래 컬러로 변경
|
||||
}
|
||||
ChangeColor(hoverColor); // 클릭 후 원래 컬러로 변경
|
||||
}
|
||||
else
|
||||
{
|
||||
if (targetImage != null)
|
||||
{
|
||||
targetImage.color = disabledColor; // 비활성화 상태일 때 컬러 변경
|
||||
}
|
||||
ChangeColor(disabledColor); // 비활성화 상태일 때 컬러 변경
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user