private void HandleMovementDirection(AxisEventData data) { CustomButton overrideSelection = null; bool performNavigation = true; switch (data.moveDir) { case MoveDirection.Left: { if (Selected.Slot.Pos.Y == 0 && Selected.Slot.Pos.X == 0) { if (PreviousRow()) { overrideSelection = Grid[LastY][LastX].Slot; } else { overrideSelection = Grid[0][LastX].Slot; } } break; } case MoveDirection.Right: { if (Selected.Slot.Pos.Y == LastY && Selected.Slot.Pos.X == LastX) { if (NextRow()) { overrideSelection = Grid[0][0].Slot; } else { overrideSelection = Grid[LastY][0].Slot; } } break; } case MoveDirection.Up: { if (Selected.Slot.Pos.Y == 0 && data.moveDir == MoveDirection.Up) { performNavigation = PreviousRow(); } break; } case MoveDirection.Down: { if (Selected.Slot.Pos.Y == LastY && data.moveDir == MoveDirection.Down) { performNavigation = NextRow(); } break; } } // Change selection, we moved from edge if (performNavigation) { // Check if slot we want to move to is enabled if (overrideSelection && (UnityEngine.Object)overrideSelection != (UnityEngine.Object)null) { // If it's not enabled, recursively find first enabled slot on left (there is always at least one) if (!overrideSelection.IsActive()) { data.selectedObject = overrideSelection.GetNavigationTarget(MoveDirection.Left); } else { data.selectedObject = overrideSelection.gameObject; } } else { Selected.Slot.Slot.DoMove(data); } } // No selection change, but slot can be disabled now else if (!Selected.Slot.Slot.enabled) { // recursively find first enabled slot on left (there is always at least one) data.selectedObject = Selected.Slot.Slot.GetNavigationTarget(MoveDirection.Left); } }