60 lines
2.6 KiB
C#
60 lines
2.6 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UVC.UI.Toolbar.Model;
|
|
using UVC.UI.ToolBar.View;
|
|
|
|
namespace UVC.UI.Toolbar.View
|
|
{
|
|
public class ToolbarToggleButtonViewProcessor : IButtonViewProcessor
|
|
{
|
|
public GameObject CreateButtonUI(ToolbarButtonBase buttonModel, Transform parentContainer, ToolbarView viewContext)
|
|
{
|
|
if (viewContext.toggleButtonPrefab == null)
|
|
{
|
|
Debug.LogError("ToggleButtonViewProcessor: toggleButtonPrefab이 ToolbarView에 할당되지 않았습니다.", viewContext);
|
|
return null;
|
|
}
|
|
return Object.Instantiate(viewContext.toggleButtonPrefab, parentContainer);
|
|
}
|
|
|
|
public void SetupButtonInteractions(ToolbarButtonBase buttonModel, GameObject buttonUIObject, ToolbarView viewContext)
|
|
{
|
|
ToolbarToggleButton toggleModel = buttonModel as ToolbarToggleButton;
|
|
if (toggleModel == null) return;
|
|
|
|
Toggle toggleComponent = buttonUIObject.GetComponent<Toggle>();
|
|
if (toggleComponent != null)
|
|
{
|
|
toggleComponent.SetIsOnWithoutNotify(toggleModel.IsSelected);
|
|
toggleComponent.onValueChanged.AddListener((isSelected) =>
|
|
{
|
|
toggleModel.ExecuteClick();
|
|
});
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError($"ToggleButtonViewProcessor: ToggleButton '{toggleModel.Text}'의 GameObject에 Toggle 컴포넌트가 없습니다.", buttonUIObject);
|
|
}
|
|
UpdateCommonButtonVisuals(buttonModel, buttonUIObject, viewContext);
|
|
UpdateToggleStateVisuals(toggleModel, buttonUIObject, toggleModel.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)
|
|
{
|
|
Toggle toggleComponent = buttonUIObject.GetComponent<Toggle>();
|
|
if (toggleComponent != null)
|
|
{
|
|
if (toggleComponent.isOn != isSelected)
|
|
{
|
|
toggleComponent.SetIsOnWithoutNotify(isSelected);
|
|
}
|
|
}
|
|
viewContext.InternalUpdateCommonButtonVisuals(toggleButtonModel, buttonUIObject); // 아이콘 업데이트를 위해 호출
|
|
}
|
|
}
|
|
} |