using Carousel; using LightJSON; using Network; using UnityEngine; namespace ConsoleConnection { [RequireComponent(typeof(Carousel.Carousel))] public class ConsoleCarouselController : MonoBehaviour { private Carousel.Carousel carousel; // console-side focus state private int consoleFocusedRow; private int consoleFocusedItem; private int consoleFocusedAction; private void Awake() { carousel = GetComponent(); carousel.OnRowFocused += OnRowFocused; carousel.OnItemFocused += OnItemFocused; carousel.OnActionFocused += OnActionFocused; carousel.OnActionTriggered += OnActionTriggered; } public void OnRowFocused(RowModel model, int index) { if (index == consoleFocusedRow) return; var changeRowCommand = JSONParseHelper.GetChangeRowCommand(index); //Debug.LogFormat("ChangeRowCommand: {0}", index); ConsoleNetworkManager.Instance.Send(changeRowCommand); } public void OnItemFocused(ItemModel model, int index) { var rowIndex = carousel.Model.FocusedRow; if (rowIndex == consoleFocusedRow && index == consoleFocusedItem) return; consoleFocusedRow = rowIndex; consoleFocusedItem = index; consoleFocusedAction = 0; //Debug.LogFormat("ChangeItemCommand: {0}, {1}", rowIndex, index); ConsoleNetworkManager.Instance.Send(JSONParseHelper.GetChangeItemCommand(rowIndex, index)); } public void OnActionFocused(ActionModel model, int index) { if (index == consoleFocusedAction) return; consoleFocusedAction = index; var command = (JSON)model.UserData; //Debug.LogFormat("ChangeActionCommand: {0}", index); ConsoleNetworkManager.Instance.Send(JSONParseHelper.GetChangeActionCommand(command)); } public void OnActionTriggered(ActionModel model, int index) { var command = (JSON)model.UserData; ConsoleNetworkManager.Instance.Send(command); } public void OnConsoleFocusMessage(int rowIndex, int itemIndex, int actionIndex) { //Debug.LogFormat("OnConsoleFocusMessage: {0}, {1}, {2}", rowIndex, itemIndex, actionIndex); consoleFocusedRow = rowIndex; consoleFocusedItem = itemIndex; consoleFocusedAction = actionIndex; carousel.SetupFocus(rowIndex, itemIndex, actionIndex); } } }