move duplicate code to own method

This commit is contained in:
minenice55 2022-07-25 12:49:43 -04:00
parent 9054015342
commit 379ad6163b

View file

@ -40,6 +40,50 @@ namespace HeavenStudio.Editor
{
InputController lastController = PlayerInput.GetInputController(1);
InputController newController = PlayerInput.GetInputControllers()[controllersDropdown.value];
AssignController(newController, lastController);
});
}
private void Update() {
if (isAutoSearching) {
var controllers = PlayerInput.GetInputControllers();
foreach (var controller in controllers) {
if (controller.GetLastButtonDown() > 0 || controller.GetLastKeyDown() > 0) {
InputController lastController = PlayerInput.GetInputController(1);
isAutoSearching = false;
autoSearchLabel.SetActive(false);
controllersDropdown.value = PlayerInput.GetInputControllerId(1);
AssignController(controller, lastController);
}
}
}
else if (isPairSearching) {
var controllers = PlayerInput.GetInputControllers();
InputController.InputFeatures lrFlag = pairSelectLR ? InputController.InputFeatures.Extra_SplitControllerLeft : InputController.InputFeatures.Extra_SplitControllerRight;
foreach (var controller in controllers) {
if (controller == PlayerInput.GetInputController(1)) continue;
InputController.InputFeatures features = controller.GetFeatures();
if (!features.HasFlag(lrFlag)) continue;
if (controller.GetLastButtonDown() > 0 || controller.GetLastKeyDown() > 0) {
InputJoyshock con = (InputJoyshock) PlayerInput.GetInputController(1);
con.AssignOtherHalf((InputJoyshock) controller);
isPairSearching = false;
pairSearchLabel.SetActive(false);
currentControllerLabel.text = "Current Controller: " + controller.GetDeviceName();
pairingLabel.text = "Joy-Con (L / R) Selected\nPairing Successful!";
ShowControllerIcon(controller);
StartCoroutine(SelectionVibrate(con));
StartCoroutine(SelectionVibrate((InputJoyshock) controller));
}
}
}
}
void AssignController(InputController newController, InputController lastController)
{
lastController.SetPlayer(-1);
newController.SetPlayer(1);
@ -66,74 +110,8 @@ namespace HeavenStudio.Editor
}
else
{
pairSearchItem.SetActive(false);
CancelPairSearch();
}
});
}
private void Update() {
if (isAutoSearching) {
var controllers = PlayerInput.GetInputControllers();
foreach (var controller in controllers) {
if (controller.GetLastButtonDown() > 0 || controller.GetLastKeyDown() > 0) {
InputController lastController = PlayerInput.GetInputController(1);
lastController.SetPlayer(-1);
controller.SetPlayer(1);
isAutoSearching = false;
autoSearchLabel.SetActive(false);
controllersDropdown.value = PlayerInput.GetInputControllerId(1);
if (typeof(InputJoyshock) == lastController.GetType()) {
((InputJoyshock)lastController).UnAssignOtherHalf();
}
if (typeof(InputJoyshock) == controller.GetType()) {
InputJoyshock con = (InputJoyshock) controller;
StartCoroutine(SelectionVibrate(con));
con.UnAssignOtherHalf();
}
currentControllerLabel.text = "Current Controller: " + controller.GetDeviceName();
ShowControllerIcon(controller);
InputController.InputFeatures features = controller.GetFeatures();
if (features.HasFlag(InputController.InputFeatures.Extra_SplitControllerLeft) || features.HasFlag(InputController.InputFeatures.Extra_SplitControllerRight))
{
pairSelectLR = !features.HasFlag(InputController.InputFeatures.Extra_SplitControllerLeft);
pairSearchItem.SetActive(true);
StartPairSearch();
}
else
{
pairSearchItem.SetActive(false);
CancelPairSearch();
}
}
}
}
else if (isPairSearching) {
var controllers = PlayerInput.GetInputControllers();
InputController.InputFeatures lrFlag = pairSelectLR ? InputController.InputFeatures.Extra_SplitControllerLeft : InputController.InputFeatures.Extra_SplitControllerRight;
foreach (var controller in controllers) {
if (controller == PlayerInput.GetInputController(1)) continue;
InputController.InputFeatures features = controller.GetFeatures();
if (!features.HasFlag(lrFlag)) continue;
if (controller.GetLastButtonDown() > 0 || controller.GetLastKeyDown() > 0) {
InputJoyshock con = (InputJoyshock) PlayerInput.GetInputController(1);
con.AssignOtherHalf((InputJoyshock) controller);
isPairSearching = false;
pairSearchLabel.SetActive(false);
currentControllerLabel.text = "Current Controller: " + controller.GetDeviceName();
pairingLabel.text = "Joy-Con (L / R) Selected\nPairing Successful!";
ShowControllerIcon(controller);
StartCoroutine(SelectionVibrate(con));
StartCoroutine(SelectionVibrate((InputJoyshock) controller));
}
}
}
}