70 lines
3.0 KiB
C#
70 lines
3.0 KiB
C#
|
|
using UnityEngine;
|
|||
|
|
using UnityEngine.UI;
|
|||
|
|
using UVC.UI.Toolbar.Model;
|
|||
|
|
using UVC.UI.ToolBar.View;
|
|||
|
|
|
|||
|
|
namespace UVC.UI.Toolbar.View
|
|||
|
|
{
|
|||
|
|
public class ToolbarRadioButtonViewProcessor : IButtonViewProcessor
|
|||
|
|
{
|
|||
|
|
public GameObject CreateButtonUI(ToolbarButtonBase buttonModel, Transform parentContainer, ToolbarView viewContext)
|
|||
|
|
{
|
|||
|
|
if (viewContext.radioButtonPrefab == null)
|
|||
|
|
{
|
|||
|
|
Debug.LogError("RadioButtonViewProcessor: radioButtonPrefab이 ToolbarView에 할당되지 않았습니다.", viewContext);
|
|||
|
|
return null;
|
|||
|
|
}
|
|||
|
|
return Object.Instantiate(viewContext.radioButtonPrefab, parentContainer);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void SetupButtonInteractions(ToolbarButtonBase buttonModel, GameObject buttonUIObject, ToolbarView viewContext)
|
|||
|
|
{
|
|||
|
|
ToolbarRadioButton radioModel = buttonModel as ToolbarRadioButton;
|
|||
|
|
if (radioModel == null) return;
|
|||
|
|
|
|||
|
|
Toggle toggleComponent = buttonUIObject.GetComponent<Toggle>();
|
|||
|
|
if (toggleComponent != null)
|
|||
|
|
{
|
|||
|
|
ToggleGroup uiToggleGroup = viewContext.GetOrCreateToggleGroup(radioModel.GroupName);
|
|||
|
|
toggleComponent.group = uiToggleGroup;
|
|||
|
|
toggleComponent.SetIsOnWithoutNotify(radioModel.IsSelected);
|
|||
|
|
|
|||
|
|
toggleComponent.onValueChanged.AddListener((isSelected) =>
|
|||
|
|
{
|
|||
|
|
if (isSelected)
|
|||
|
|
{
|
|||
|
|
radioModel.ExecuteClick(true);
|
|||
|
|
}
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
Debug.LogError($"RadioButtonViewProcessor: RadioButton '{radioModel.Text}'의 GameObject에 Toggle 컴포넌트가 없습니다.", buttonUIObject);
|
|||
|
|
}
|
|||
|
|
UpdateCommonButtonVisuals(buttonModel, buttonUIObject, viewContext);
|
|||
|
|
UpdateToggleStateVisuals(radioModel, buttonUIObject, radioModel.IsSelected, viewContext);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void UpdateCommonButtonVisuals(ToolbarButtonBase buttonModel, GameObject buttonUIObject, ToolbarView viewContext)
|
|||
|
|
{
|
|||
|
|
viewContext.InternalUpdateCommonButtonVisuals(buttonModel, buttonUIObject);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void UpdateToggleStateVisuals(ToolbarToggleButton toggleButtonModel, GameObject buttonUIObject, bool isSelected, ToolbarView viewContext)
|
|||
|
|
{
|
|||
|
|
// ToolbarToggleButton 타입으로 캐스팅 시도
|
|||
|
|
ToolbarRadioButton radioModel = toggleButtonModel as ToolbarRadioButton;
|
|||
|
|
if (radioModel == null) return;
|
|||
|
|
|
|||
|
|
Toggle toggleComponent = buttonUIObject.GetComponent<Toggle>();
|
|||
|
|
if (toggleComponent != null)
|
|||
|
|
{
|
|||
|
|
if (toggleComponent.isOn != isSelected)
|
|||
|
|
{
|
|||
|
|
toggleComponent.SetIsOnWithoutNotify(isSelected);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
viewContext.InternalUpdateCommonButtonVisuals(radioModel, buttonUIObject); // 아이콘 업데이트를 위해 호출
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|