gpt-3.5-turbo-0613· openai
Suzhen/CodeChat
мне нужно вынести логику Update в другой класс так как он теперь не MonoBehaviour public…
- User
мне нужно вынести логику Update в другой класс так как он теперь не MonoBehaviour public class UINavigator { public event Action OnNextScreen; public event Action OnPreviousScreen;
private PopupItem currentPanel = null; private int selectedPopupIndex = 0; private bool isEmptyScreen = false; private int selectedCurrentPopupIndex = 0; private IInputService inputService; public UINavigator() { inputService = new InputService(); } public void SetCurrentPopup(PopupItem panelItem) { currentPanel = panelItem; if (currentPanel.Popup.Length != 0) { ResetPopupSelection(); EventSystem.current.SetSelectedGameObject(currentPanel.Popup[currentPanel.SelectedPopupIndex].gameObject); currentPanel.Popup[currentPanel.SelectedPopupIndex].Highlight(); selectedCurrentPopupIndex = currentPanel.SelectedPopupIndex; } else { isEmptyScreen = true; } } private void Update() { if (isEmptyScreen) { HandleEmptyScreenInput(); } else { HandlePopupInput(); } } private void HandleEmptyScreenInput() { if (currentPanel.NextItemName == NamePopupItem.None) { if (inputService.GetLeftArrowKeyDown()) { OnPreviousScreen?.Invoke(); } } else { if (inputService.GetRightArrowKeyDown()) { OnNextScreen?.Invoke(currentPanel.NextItemName); } if (inputService.GetLeftArrowKeyDown()) { OnPreviousScreen?.Invoke(); } } } private void HandlePopupInput() { if (EventSystem.current.currentSelectedGameObject == null) { EventSystem.current.SetSelectedGameObject(currentPanel.Popup[selectedPopupIndex].gameObject); } if (inputService.GetUpArrowKeyDown()) { selectedPopupIndex = selectedCurrentPopupIndex; SelectFocus(-1); } if (inputService.GetDownArrowKeyDown()) { selectedPopupIndex = selectedCurrentPopupIndex; SelectFocus(1); } if (inputService.GetLeftArrowKeyDown()) { OnPreviousScreen?.Invoke(); } if (inputService.GetRightArrowKeyDown()) { selectedPopupIndex = selectedCurrentPopupIndex; currentPanel.Popup[selectedPopupIndex].Select(); currentPanel.SelectedPopupIndex = selectedPopupIndex; OnNextScreen?.Invoke(currentPanel.Popup[selectedPopupIndex].ScreenItem); } } private void SelectFocus(int direction) { EventSystem.current.SetSelectedGameObject(null); ResetPopupSelection(); selectedPopupIndex = (selectedPopupIndex + direction + currentPanel.Popup.Length) % currentPanel.Popup.Length; EventSystem.current.SetSelectedGameObject(currentPanel.Popup[selectedPopupIndex].gameObject); currentPanel.Popup[selectedPopupIndex].Highlight(); selectedCurrentPopupIndex = selectedPopupIndex; } private void ResetPopupSelection() { isEmptyScreen = false; EventSystem.current.SetSelectedGameObject(null); foreach (var item in currentPanel.Popup) { item.Deselect(); } } } - Assistant