Merge branch 'main' of https://git.ranaze.com/admin/GGJ2026 into get-tricky

This commit is contained in:
hz
2026-01-31 19:24:32 -06:00
9 changed files with 575 additions and 6 deletions
+86
View File
@@ -1,3 +1,4 @@
using System;
using UnityEngine;
using UnityEngine.InputSystem;
@@ -9,6 +10,8 @@ public class PlayerPickupController : MonoBehaviour
private InputActionAsset runtimeActions;
private InputAction interactAction;
[SerializeField] private string controlSchemeName = "";
[SerializeField] private int gamepadIndex = -1;
private bool deviceFilterEnabled;
[Header("Setup")]
public Transform holdPoint; // Empty GameObject above head
@@ -29,6 +32,9 @@ public class PlayerPickupController : MonoBehaviour
{
runtimeActions.bindingMask = InputBinding.MaskByGroup(controlSchemeName);
}
deviceFilterEnabled = ShouldFilterDevices();
ApplyDeviceFilter();
InputSystem.onDeviceChange += HandleDeviceChange;
var map = runtimeActions.FindActionMap(actionMapName, true);
interactAction = map.FindAction(interactActionName, true);
@@ -53,6 +59,8 @@ public class PlayerPickupController : MonoBehaviour
runtimeActions.Disable();
runtimeActions = null;
}
InputSystem.onDeviceChange -= HandleDeviceChange;
}
private void OnInteractPerformed(InputAction.CallbackContext context)
@@ -122,4 +130,82 @@ public class PlayerPickupController : MonoBehaviour
heldObject.transform.SetParent(null);
heldObject = null;
}
private bool ShouldFilterDevices()
{
return string.Equals(controlSchemeName, "Gamepad", StringComparison.OrdinalIgnoreCase) || gamepadIndex >= 0;
}
private void ApplyDeviceFilter()
{
if (!deviceFilterEnabled || runtimeActions == null)
{
return;
}
var targetIndex = ResolveGamepadIndex();
if (targetIndex < 0)
{
return;
}
if (Gamepad.all.Count <= targetIndex)
{
runtimeActions.devices = Array.Empty<InputDevice>();
return;
}
runtimeActions.devices = new InputDevice[] { Gamepad.all[targetIndex] };
}
private void HandleDeviceChange(InputDevice device, InputDeviceChange change)
{
if (!deviceFilterEnabled)
{
return;
}
if (change == InputDeviceChange.Added || change == InputDeviceChange.Removed || change == InputDeviceChange.Reconnected)
{
ApplyDeviceFilter();
}
}
private int ResolveGamepadIndex()
{
if (gamepadIndex >= 0)
{
return gamepadIndex;
}
if (string.IsNullOrWhiteSpace(actionMapName))
{
return -1;
}
if (string.Equals(actionMapName, "Player", StringComparison.OrdinalIgnoreCase))
{
return 0;
}
var end = actionMapName.Length - 1;
var start = end;
while (start >= 0 && char.IsDigit(actionMapName[start]))
{
start--;
}
start++;
if (start > end)
{
return -1;
}
if (!int.TryParse(actionMapName.Substring(start, end - start + 1), out var parsed))
{
return -1;
}
return parsed > 0 ? parsed - 1 : -1;
}
}
@@ -1,3 +1,4 @@
using System;
using UnityEngine;
using UnityEngine.InputSystem;
@@ -10,6 +11,7 @@ public class PlayerPlatformerController : MonoBehaviour
[SerializeField] private string moveActionName = "Move";
[SerializeField] private string jumpActionName = "Jump";
[SerializeField] private string controlSchemeName = "";
[SerializeField] private int gamepadIndex = -1;
[SerializeField] private float moveSpeed = 6f;
[SerializeField] private float jumpImpulse = 8f;
[SerializeField] private LayerMask groundMask = ~0;
@@ -20,6 +22,7 @@ public class PlayerPlatformerController : MonoBehaviour
private InputActionAsset runtimeActions;
private InputAction moveAction;
private InputAction jumpAction;
private bool deviceFilterEnabled;
private void Awake()
{
@@ -40,6 +43,9 @@ public class PlayerPlatformerController : MonoBehaviour
{
runtimeActions.bindingMask = InputBinding.MaskByGroup(controlSchemeName);
}
deviceFilterEnabled = ShouldFilterDevices();
ApplyDeviceFilter();
InputSystem.onDeviceChange += HandleDeviceChange;
var map = runtimeActions.FindActionMap(actionMapName, true);
moveAction = map.FindAction(moveActionName, true);
@@ -68,6 +74,8 @@ public class PlayerPlatformerController : MonoBehaviour
runtimeActions.Disable();
runtimeActions = null;
}
InputSystem.onDeviceChange -= HandleDeviceChange;
}
private void FixedUpdate()
@@ -96,6 +104,84 @@ public class PlayerPlatformerController : MonoBehaviour
body.AddForce(Vector2.up * jumpImpulse, ForceMode2D.Impulse);
}
private bool ShouldFilterDevices()
{
return string.Equals(controlSchemeName, "Gamepad", StringComparison.OrdinalIgnoreCase) || gamepadIndex >= 0;
}
private void ApplyDeviceFilter()
{
if (!deviceFilterEnabled || runtimeActions == null)
{
return;
}
var targetIndex = ResolveGamepadIndex();
if (targetIndex < 0)
{
return;
}
if (Gamepad.all.Count <= targetIndex)
{
runtimeActions.devices = Array.Empty<InputDevice>();
return;
}
runtimeActions.devices = new InputDevice[] { Gamepad.all[targetIndex] };
}
private void HandleDeviceChange(InputDevice device, InputDeviceChange change)
{
if (!deviceFilterEnabled)
{
return;
}
if (change == InputDeviceChange.Added || change == InputDeviceChange.Removed || change == InputDeviceChange.Reconnected)
{
ApplyDeviceFilter();
}
}
private int ResolveGamepadIndex()
{
if (gamepadIndex >= 0)
{
return gamepadIndex;
}
if (string.IsNullOrWhiteSpace(actionMapName))
{
return -1;
}
if (string.Equals(actionMapName, "Player", StringComparison.OrdinalIgnoreCase))
{
return 0;
}
var end = actionMapName.Length - 1;
var start = end;
while (start >= 0 && char.IsDigit(actionMapName[start]))
{
start--;
}
start++;
if (start > end)
{
return -1;
}
if (!int.TryParse(actionMapName.Substring(start, end - start + 1), out var parsed))
{
return -1;
}
return parsed > 0 ? parsed - 1 : -1;
}
private bool IsGrounded()
{
var bounds = bodyCollider.bounds;