Import assets from store
This commit is contained in:
1 parent
a05f2e47a2
commit
376e52e323
875 files changed
+128037
No files matched your search
@@ -0,0 +1,290 @@
|
||||
{
|
||||
"version": 1,
|
||||
"name": "Controls",
|
||||
"maps": [
|
||||
{
|
||||
"name": "Control",
|
||||
"id": "55a13aec-5a6d-4b4c-bb6a-90718753e458",
|
||||
"actions": [
|
||||
{
|
||||
"name": "Move",
|
||||
"type": "Value",
|
||||
"id": "07044d6a-8693-4677-b81e-65664ca92bf9",
|
||||
"expectedControlType": "Vector2",
|
||||
"processors": "",
|
||||
"interactions": "",
|
||||
"initialStateCheck": true
|
||||
},
|
||||
{
|
||||
"name": "Look",
|
||||
"type": "Value",
|
||||
"id": "c4a37b2b-f58e-4bed-bad7-b9b5233fc94f",
|
||||
"expectedControlType": "Vector2",
|
||||
"processors": "",
|
||||
"interactions": "",
|
||||
"initialStateCheck": true
|
||||
},
|
||||
{
|
||||
"name": "Jump",
|
||||
"type": "Button",
|
||||
"id": "4b64d549-fdcd-4bb9-8dfa-9a6e619309b9",
|
||||
"expectedControlType": "Button",
|
||||
"processors": "",
|
||||
"interactions": "",
|
||||
"initialStateCheck": false
|
||||
},
|
||||
{
|
||||
"name": "Crouch",
|
||||
"type": "Button",
|
||||
"id": "28cc9761-81ca-495b-a15a-20944b18d14b",
|
||||
"expectedControlType": "Button",
|
||||
"processors": "",
|
||||
"interactions": "",
|
||||
"initialStateCheck": false
|
||||
},
|
||||
{
|
||||
"name": "Dash",
|
||||
"type": "Button",
|
||||
"id": "e5bc0705-bbf1-49a5-9dfb-acd0f513a635",
|
||||
"expectedControlType": "",
|
||||
"processors": "",
|
||||
"interactions": "",
|
||||
"initialStateCheck": false
|
||||
},
|
||||
{
|
||||
"name": "Walk",
|
||||
"type": "Button",
|
||||
"id": "4274c722-fc7a-4609-8cf7-03c31c001825",
|
||||
"expectedControlType": "Button",
|
||||
"processors": "",
|
||||
"interactions": "",
|
||||
"initialStateCheck": false
|
||||
},
|
||||
{
|
||||
"name": "Sprint",
|
||||
"type": "Button",
|
||||
"id": "866d7580-8041-4c95-927c-940e7bbc1ea8",
|
||||
"expectedControlType": "Button",
|
||||
"processors": "",
|
||||
"interactions": "",
|
||||
"initialStateCheck": false
|
||||
},
|
||||
{
|
||||
"name": "Prone",
|
||||
"type": "Button",
|
||||
"id": "451e2596-de3a-453e-a751-3eb2f4ae07b9",
|
||||
"expectedControlType": "Button",
|
||||
"processors": "",
|
||||
"interactions": "",
|
||||
"initialStateCheck": false
|
||||
}
|
||||
],
|
||||
"bindings": [
|
||||
{
|
||||
"name": "2D Vector",
|
||||
"id": "845d4d91-41e0-4345-aa9e-98cc0b8af61a",
|
||||
"path": "2DVector",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Move",
|
||||
"isComposite": true,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "up",
|
||||
"id": "9f529ebc-378b-44db-9977-60b2b4281eeb",
|
||||
"path": "<Keyboard>/w",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Move",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": true
|
||||
},
|
||||
{
|
||||
"name": "down",
|
||||
"id": "5a72236d-4580-4a5b-9400-3ec5c41b9c7c",
|
||||
"path": "<Keyboard>/s",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Move",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": true
|
||||
},
|
||||
{
|
||||
"name": "left",
|
||||
"id": "fc6ecc3f-7d0e-4c08-8c3e-4cad523c3bfd",
|
||||
"path": "<Keyboard>/a",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Move",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": true
|
||||
},
|
||||
{
|
||||
"name": "right",
|
||||
"id": "2ed21813-ed53-4f7d-8025-80e5d764fe1b",
|
||||
"path": "<Keyboard>/d",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Move",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": true
|
||||
},
|
||||
{
|
||||
"name": "up",
|
||||
"id": "352bac99-3185-463f-8879-2c95737e69c7",
|
||||
"path": "<Keyboard>/upArrow",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Move",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": true
|
||||
},
|
||||
{
|
||||
"name": "down",
|
||||
"id": "61ffb665-6f37-4256-868a-926b41477af0",
|
||||
"path": "<Keyboard>/downArrow",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Move",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": true
|
||||
},
|
||||
{
|
||||
"name": "left",
|
||||
"id": "d50c7c2f-d5a9-4029-9790-83a42d023aa3",
|
||||
"path": "<Keyboard>/leftArrow",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Move",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": true
|
||||
},
|
||||
{
|
||||
"name": "right",
|
||||
"id": "e42c406b-d211-4420-98ff-6fe5dfb3624e",
|
||||
"path": "<Keyboard>/rightArrow",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Move",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": true
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "280a58c7-f0a0-4f79-a5ff-09974f3a5355",
|
||||
"path": "<Keyboard>/space",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Jump",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "32270217-c493-45d1-8f18-6d7e8d0fb7f3",
|
||||
"path": "<Keyboard>/ctrl",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Crouch",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "ced9c90c-08df-4b20-ba32-f4c686b44ccf",
|
||||
"path": "<Keyboard>/alt",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Walk",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "5c805672-37b0-4261-9c70-26362812f512",
|
||||
"path": "<Pointer>/delta",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Look",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "0f99c2bc-e04b-4a63-b080-d763509c083e",
|
||||
"path": "<Keyboard>/shift",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Sprint",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "bad6d415-4fa0-44cb-9a06-539092539fd3",
|
||||
"path": "<Keyboard>/e",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Dash",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "fbd3ef64-32ce-49e9-bbe8-55347f75254e",
|
||||
"path": "<Keyboard>/z",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Prone",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"controlSchemes": [
|
||||
{
|
||||
"name": "New control scheme",
|
||||
"bindingGroup": "New control scheme",
|
||||
"devices": [
|
||||
{
|
||||
"devicePath": "<Keyboard>",
|
||||
"isOptional": false,
|
||||
"isOR": false
|
||||
},
|
||||
{
|
||||
"devicePath": "<Gamepad>",
|
||||
"isOptional": false,
|
||||
"isOR": false
|
||||
},
|
||||
{
|
||||
"devicePath": "<Joystick>",
|
||||
"isOptional": false,
|
||||
"isOR": false
|
||||
},
|
||||
{
|
||||
"devicePath": "<Mouse>",
|
||||
"isOptional": false,
|
||||
"isOR": false
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6da0542b9a9ab794f861de14633db34c
|
||||
ScriptedImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
script: {fileID: 11500000, guid: 8404be70184654265930450def6a9037, type: 3}
|
||||
generateWrapperCode: 0
|
||||
wrapperCodePath:
|
||||
wrapperClassName:
|
||||
wrapperCodeNamespace: CharacterMovement
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 367142
|
||||
packageName: "MotionCore \u2013 Physics Character Controller"
|
||||
packageVersion: 1.2
|
||||
assetPath: Assets/Character Controller/Core/Scripts/Input/Controls.inputactions
|
||||
uploadId: 997018
|
||||
@@ -0,0 +1,78 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace CharacterMovement
|
||||
{
|
||||
/// <summary>
|
||||
/// Everything the character motor needs to know about player intent.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Locomotion reads intent through this interface and never touches key bindings or the Input
|
||||
/// System directly, so a project can drive the same controller from an AI brain, a replay, a
|
||||
/// network stream, or its own input stack by supplying a different implementation to
|
||||
/// <see cref="PlayerController.SetInputSource"/>.
|
||||
/// <para>
|
||||
/// The shipped implementation is <see cref="InputHandler"/>, which binds these values to a Unity
|
||||
/// Input System action map.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
/// <example>
|
||||
/// <code>
|
||||
/// // Driving the controller from code instead of from a device.
|
||||
/// public sealed class ScriptedInput : MonoBehaviour, ICharacterInputSource
|
||||
/// {
|
||||
/// public Vector2 MoveDirection { get; set; }
|
||||
/// public bool IsMoving => MoveDirection.sqrMagnitude > 0.0001f;
|
||||
/// public bool IsSprinting { get; set; }
|
||||
/// public bool IsWalking => false;
|
||||
/// public bool IsCrouching { get; set; }
|
||||
/// public bool IsProne => false;
|
||||
///
|
||||
/// public event Action JumpPerformed;
|
||||
/// public event Action DashPerformed;
|
||||
/// public event Action CrouchPerformed;
|
||||
/// public event Action PronePerformed;
|
||||
///
|
||||
/// public void Jump() => JumpPerformed?.Invoke();
|
||||
/// }
|
||||
/// </code>
|
||||
/// </example>
|
||||
public interface ICharacterInputSource
|
||||
{
|
||||
/// <summary>Planar movement intent, where y is forward. Magnitudes above 1 are clamped.</summary>
|
||||
Vector2 MoveDirection { get; }
|
||||
|
||||
/// <summary>True while <see cref="MoveDirection"/> is non-zero.</summary>
|
||||
bool IsMoving { get; }
|
||||
|
||||
/// <summary>True while the sprint modifier is held.</summary>
|
||||
bool IsSprinting { get; }
|
||||
|
||||
/// <summary>True while the walk modifier is held.</summary>
|
||||
bool IsWalking { get; }
|
||||
|
||||
/// <summary>True while the crouch input is held.</summary>
|
||||
bool IsCrouching { get; }
|
||||
|
||||
/// <summary>True while prone is toggled on.</summary>
|
||||
bool IsProne { get; }
|
||||
|
||||
/// <summary>
|
||||
/// True while the jump input is held down. Drives variable jump height; an implementation
|
||||
/// that only pulses <see cref="JumpPerformed"/> can return false and jumps stay full height.
|
||||
/// </summary>
|
||||
bool IsJumpHeld { get; }
|
||||
|
||||
/// <summary>Raised once when the jump input is pressed.</summary>
|
||||
event Action JumpPerformed;
|
||||
|
||||
/// <summary>Raised once when the dash input is pressed.</summary>
|
||||
event Action DashPerformed;
|
||||
|
||||
/// <summary>Raised once when the crouch input is pressed.</summary>
|
||||
event Action CrouchPerformed;
|
||||
|
||||
/// <summary>Raised once when the prone input is pressed.</summary>
|
||||
event Action PronePerformed;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6637cbbb64914e32be1abbc4852424c0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 367142
|
||||
packageName: "MotionCore \u2013 Physics Character Controller"
|
||||
packageVersion: 1.2
|
||||
assetPath: Assets/Character Controller/Core/Scripts/Input/ICharacterInputSource.cs
|
||||
uploadId: 997018
|
||||
@@ -0,0 +1,67 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace CharacterMovement
|
||||
{
|
||||
public abstract class InputExtensionModule : MonoBehaviour
|
||||
{
|
||||
protected InputActionAsset[] InputAssets { get; private set; }
|
||||
|
||||
internal void EnableActions(InputActionAsset[] assets)
|
||||
{
|
||||
InputAssets = assets;
|
||||
OnActionsEnabled();
|
||||
}
|
||||
|
||||
internal void DisableActions()
|
||||
{
|
||||
OnActionsDisabled();
|
||||
}
|
||||
|
||||
internal void Suspend()
|
||||
{
|
||||
OnActionsSuspended();
|
||||
}
|
||||
|
||||
internal void Resume()
|
||||
{
|
||||
OnActionsResumed();
|
||||
}
|
||||
|
||||
protected InputActionMap FindMap(string mapName)
|
||||
{
|
||||
if (InputAssets == null)
|
||||
return null;
|
||||
|
||||
InputActionMap firstMatch = null;
|
||||
int matchCount = 0;
|
||||
|
||||
foreach (InputActionAsset asset in InputAssets)
|
||||
{
|
||||
InputActionMap map = asset?.FindActionMap(mapName, throwIfNotFound: false);
|
||||
if (map == null)
|
||||
continue;
|
||||
|
||||
matchCount++;
|
||||
if (firstMatch == null)
|
||||
{
|
||||
firstMatch = map;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (matchCount == 2)
|
||||
Debug.LogWarning($"[{GetType().Name}] Multiple action maps named '{mapName}' were found. Using the first match.");
|
||||
}
|
||||
|
||||
if (firstMatch == null)
|
||||
Debug.LogWarning($"[{GetType().Name}] Action map '{mapName}' not found.");
|
||||
|
||||
return firstMatch;
|
||||
}
|
||||
|
||||
protected abstract void OnActionsEnabled();
|
||||
protected abstract void OnActionsDisabled();
|
||||
protected virtual void OnActionsSuspended() { }
|
||||
protected virtual void OnActionsResumed() { }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 27804f1084fd8fc449e2a6394afcd402
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 367142
|
||||
packageName: "MotionCore \u2013 Physics Character Controller"
|
||||
packageVersion: 1.2
|
||||
assetPath: Assets/Character Controller/Core/Scripts/Input/InputExtensionModule.cs
|
||||
uploadId: 997018
|
||||
@@ -0,0 +1,364 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
namespace CharacterMovement
|
||||
{
|
||||
/// <summary>
|
||||
/// Binds Unity Input System actions to the character motor's <see cref="ICharacterInputSource"/>
|
||||
/// contract. Replaceable: see <see cref="PlayerController.SetInputSource"/>.
|
||||
/// </summary>
|
||||
public class InputHandler : MonoBehaviour, ICharacterInputSource
|
||||
{
|
||||
[FormerlySerializedAs("_coreAsset")]
|
||||
[Tooltip("Input Action asset holding the movement action map.")]
|
||||
[SerializeField] private InputActionAsset movementActionsAsset;
|
||||
|
||||
[FormerlySerializedAs("_coreMapName")]
|
||||
[Tooltip("Name of the action map inside the asset that holds the movement actions. Must match "
|
||||
+ "exactly.")]
|
||||
[SerializeField] private string movementActionMapName = "Control";
|
||||
|
||||
[FormerlySerializedAs("_extraAssets")]
|
||||
[SerializeField]
|
||||
[Tooltip("Extra action assets made available to InputExtensionModule components, such as the "
|
||||
+ "FPS add-on's weapon actions.")]
|
||||
private InputActionAsset[] extensionActionAssets = Array.Empty<InputActionAsset>();
|
||||
|
||||
[Header("Action Names")]
|
||||
[SerializeField]
|
||||
[Tooltip("Name of the 2D movement action in the map above. Required.")]
|
||||
private string moveActionName = "Move";
|
||||
|
||||
[SerializeField]
|
||||
[Tooltip("Name of the jump button action. Clear the field to disable jumping input.")]
|
||||
private string jumpActionName = "Jump";
|
||||
|
||||
[SerializeField]
|
||||
[Tooltip("Name of the sprint modifier action. Clear the field to disable sprinting input.")]
|
||||
private string sprintActionName = "Sprint";
|
||||
|
||||
[SerializeField]
|
||||
[Tooltip("Name of the walk modifier action. Clear the field to disable walking input.")]
|
||||
private string walkActionName = "Walk";
|
||||
|
||||
[SerializeField]
|
||||
[Tooltip("Name of the crouch action. Clear the field to disable crouching input.")]
|
||||
private string crouchActionName = "Crouch";
|
||||
|
||||
[SerializeField]
|
||||
[Tooltip("Name of the prone toggle action. Clear the field to disable prone input.")]
|
||||
private string proneActionName = "Prone";
|
||||
|
||||
[SerializeField]
|
||||
[Tooltip("Name of the dash action. Clear the field to disable dashing input.")]
|
||||
private string dashActionName = "Dash";
|
||||
|
||||
[SerializeField]
|
||||
[Tooltip("Logs a warning when a named action is missing from the map. Turn off if you "
|
||||
+ "deliberately ship maps without some of these actions.")]
|
||||
private bool warnOnMissingActions = true;
|
||||
|
||||
public InputActionAsset CoreAsset => movementActionsAsset;
|
||||
public InputActionAsset[] AllAssets { get; private set; }
|
||||
|
||||
public Vector2 MoveDirection { get; private set; }
|
||||
public bool IsCrouching { get; private set; }
|
||||
public bool IsProne { get; private set; }
|
||||
public bool IsSprinting { get; private set; }
|
||||
public bool IsWalking { get; private set; }
|
||||
public bool IsMoving { get; private set; }
|
||||
public bool IsJumpHeld { get; private set; }
|
||||
|
||||
public event Action JumpEvent;
|
||||
public event Action DashEvent;
|
||||
public event Action CrouchEvent;
|
||||
public event Action ProneEvent;
|
||||
|
||||
// The interface names are the stable contract; the *Event names above are kept so existing
|
||||
// projects that subscribe to them keep compiling.
|
||||
event Action ICharacterInputSource.JumpPerformed
|
||||
{
|
||||
add => JumpEvent += value;
|
||||
remove => JumpEvent -= value;
|
||||
}
|
||||
|
||||
event Action ICharacterInputSource.DashPerformed
|
||||
{
|
||||
add => DashEvent += value;
|
||||
remove => DashEvent -= value;
|
||||
}
|
||||
|
||||
event Action ICharacterInputSource.CrouchPerformed
|
||||
{
|
||||
add => CrouchEvent += value;
|
||||
remove => CrouchEvent -= value;
|
||||
}
|
||||
|
||||
event Action ICharacterInputSource.PronePerformed
|
||||
{
|
||||
add => ProneEvent += value;
|
||||
remove => ProneEvent -= value;
|
||||
}
|
||||
|
||||
private InputActionMap _movementActionMap;
|
||||
private InputExtensionModule[] _extensionModules;
|
||||
|
||||
private readonly Dictionary<InputAction, List<Action<InputAction.CallbackContext>>> _callbackRegistry =
|
||||
new Dictionary<InputAction, List<Action<InputAction.CallbackContext>>>();
|
||||
|
||||
private readonly Stack<InputMode> _inputModeStack = new Stack<InputMode>();
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if (!movementActionsAsset)
|
||||
{
|
||||
Debug.LogError("[InputHandler] Movement action asset is not assigned.");
|
||||
return;
|
||||
}
|
||||
|
||||
List<InputActionAsset> allAssets = new List<InputActionAsset> { movementActionsAsset };
|
||||
if (extensionActionAssets != null)
|
||||
{
|
||||
foreach (InputActionAsset asset in extensionActionAssets)
|
||||
{
|
||||
if (asset != null)
|
||||
allAssets.Add(asset);
|
||||
}
|
||||
}
|
||||
|
||||
AllAssets = allAssets.ToArray();
|
||||
|
||||
_movementActionMap = movementActionsAsset.FindActionMap(movementActionMapName, throwIfNotFound: false);
|
||||
if (_movementActionMap == null)
|
||||
{
|
||||
Debug.LogError($"[InputHandler] Action map '{movementActionMapName}' not found in '{movementActionsAsset.name}'.");
|
||||
return;
|
||||
}
|
||||
|
||||
RegisterActionCallbacks();
|
||||
_movementActionMap.Enable();
|
||||
|
||||
_extensionModules = GetComponents<InputExtensionModule>();
|
||||
foreach (InputExtensionModule module in _extensionModules)
|
||||
module.EnableActions(AllAssets);
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
foreach (KeyValuePair<InputAction, List<Action<InputAction.CallbackContext>>> entry in _callbackRegistry)
|
||||
{
|
||||
InputAction action = entry.Key;
|
||||
foreach (Action<InputAction.CallbackContext> callback in entry.Value)
|
||||
{
|
||||
action.started -= callback;
|
||||
action.performed -= callback;
|
||||
action.canceled -= callback;
|
||||
}
|
||||
}
|
||||
|
||||
_movementActionMap?.Disable();
|
||||
ResetMovementState();
|
||||
|
||||
if (_extensionModules == null)
|
||||
return;
|
||||
|
||||
foreach (InputExtensionModule module in _extensionModules)
|
||||
module.DisableActions();
|
||||
}
|
||||
|
||||
public void PushInputMode(InputMode mode)
|
||||
{
|
||||
if (mode == null)
|
||||
return;
|
||||
|
||||
if (_inputModeStack.Count == 0)
|
||||
SuspendExtensions();
|
||||
|
||||
_inputModeStack.Push(mode);
|
||||
mode.Activate(AllAssets ?? Array.Empty<InputActionAsset>());
|
||||
SyncCoreMovementSuspension();
|
||||
}
|
||||
|
||||
public void PopInputMode(InputMode mode)
|
||||
{
|
||||
if (mode == null)
|
||||
{
|
||||
Debug.LogWarning("[InputHandler] PopInputMode called with null mode.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (_inputModeStack.Count == 0)
|
||||
{
|
||||
Debug.LogWarning($"[InputHandler] PopInputMode '{mode.ModeName}' but stack is empty.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (_inputModeStack.Peek() != mode)
|
||||
{
|
||||
Debug.LogWarning($"[InputHandler] PopInputMode '{mode.ModeName}' but top is '{_inputModeStack.Peek().ModeName}'.");
|
||||
return;
|
||||
}
|
||||
|
||||
_inputModeStack.Pop();
|
||||
mode.Deactivate();
|
||||
SyncCoreMovementSuspension();
|
||||
|
||||
if (_inputModeStack.Count == 0)
|
||||
ResumeExtensions();
|
||||
}
|
||||
|
||||
private void SyncCoreMovementSuspension()
|
||||
{
|
||||
if (_movementActionMap == null)
|
||||
return;
|
||||
|
||||
bool shouldSuspend = false;
|
||||
foreach (InputMode mode in _inputModeStack)
|
||||
{
|
||||
if (mode.SuspendsCoreMovement)
|
||||
{
|
||||
shouldSuspend = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (shouldSuspend && _movementActionMap.enabled)
|
||||
{
|
||||
_movementActionMap.Disable();
|
||||
ResetMovementState();
|
||||
}
|
||||
else if (!shouldSuspend && !_movementActionMap.enabled)
|
||||
_movementActionMap.Enable();
|
||||
}
|
||||
|
||||
private void RegisterActionCallbacks()
|
||||
{
|
||||
BindAll(moveActionName, context =>
|
||||
{
|
||||
MoveDirection = context.ReadValue<Vector2>();
|
||||
IsMoving = MoveDirection.sqrMagnitude > 0.0001f;
|
||||
});
|
||||
|
||||
BindAll(jumpActionName, context =>
|
||||
{
|
||||
if (context.started)
|
||||
IsJumpHeld = true;
|
||||
else if (context.canceled)
|
||||
IsJumpHeld = false;
|
||||
|
||||
if (context.performed)
|
||||
JumpEvent?.Invoke();
|
||||
});
|
||||
|
||||
BindAll(crouchActionName, context =>
|
||||
{
|
||||
if (context.started)
|
||||
{
|
||||
IsCrouching = true;
|
||||
CrouchEvent?.Invoke();
|
||||
}
|
||||
else if (context.canceled)
|
||||
{
|
||||
IsCrouching = false;
|
||||
}
|
||||
});
|
||||
|
||||
BindAll(proneActionName, context =>
|
||||
{
|
||||
if (!context.performed)
|
||||
return;
|
||||
|
||||
IsProne = !IsProne;
|
||||
ProneEvent?.Invoke();
|
||||
});
|
||||
|
||||
BindAll(dashActionName, context =>
|
||||
{
|
||||
if (context.performed)
|
||||
DashEvent?.Invoke();
|
||||
});
|
||||
|
||||
BindAll(walkActionName, context =>
|
||||
{
|
||||
if (context.started)
|
||||
IsWalking = true;
|
||||
else if (context.canceled)
|
||||
IsWalking = false;
|
||||
});
|
||||
|
||||
BindAll(sprintActionName, context =>
|
||||
{
|
||||
if (context.started)
|
||||
IsSprinting = true;
|
||||
else if (context.canceled)
|
||||
IsSprinting = false;
|
||||
});
|
||||
}
|
||||
|
||||
private void SuspendExtensions()
|
||||
{
|
||||
if (_extensionModules == null)
|
||||
return;
|
||||
|
||||
foreach (InputExtensionModule module in _extensionModules)
|
||||
module.Suspend();
|
||||
}
|
||||
|
||||
private void ResumeExtensions()
|
||||
{
|
||||
if (_extensionModules == null)
|
||||
return;
|
||||
|
||||
foreach (InputExtensionModule module in _extensionModules)
|
||||
module.Resume();
|
||||
}
|
||||
|
||||
private void BindAll(string actionName, Action<InputAction.CallbackContext> callback)
|
||||
{
|
||||
// An empty name means the project deliberately does not use that action.
|
||||
if (string.IsNullOrWhiteSpace(actionName))
|
||||
return;
|
||||
|
||||
InputAction action = _movementActionMap.FindAction(actionName, throwIfNotFound: false);
|
||||
if (action == null)
|
||||
{
|
||||
if (warnOnMissingActions)
|
||||
{
|
||||
Debug.LogWarning(
|
||||
$"[InputHandler] Action '{actionName}' was not found in map "
|
||||
+ $"'{movementActionMapName}'. That input will do nothing. Rename it under "
|
||||
+ "Action Names, clear the field to disable it, or turn off "
|
||||
+ "Warn On Missing Actions.",
|
||||
this);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
action.started += callback;
|
||||
action.performed += callback;
|
||||
action.canceled += callback;
|
||||
|
||||
if (!_callbackRegistry.TryGetValue(action, out List<Action<InputAction.CallbackContext>> callbacks))
|
||||
{
|
||||
callbacks = new List<Action<InputAction.CallbackContext>>();
|
||||
_callbackRegistry[action] = callbacks;
|
||||
}
|
||||
|
||||
callbacks.Add(callback);
|
||||
}
|
||||
|
||||
private void ResetMovementState()
|
||||
{
|
||||
MoveDirection = Vector2.zero;
|
||||
IsMoving = false;
|
||||
IsJumpHeld = false;
|
||||
IsCrouching = false;
|
||||
IsSprinting = false;
|
||||
IsWalking = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c28644d793744314bf329a2c98da20fc
|
||||
timeCreated: 1701815180
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 367142
|
||||
packageName: "MotionCore \u2013 Physics Character Controller"
|
||||
packageVersion: 1.2
|
||||
assetPath: Assets/Character Controller/Core/Scripts/Input/InputHandler.cs
|
||||
uploadId: 997018
|
||||
@@ -0,0 +1,44 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace CharacterMovement
|
||||
{
|
||||
public abstract class InputMode
|
||||
{
|
||||
public abstract string ModeName { get; }
|
||||
|
||||
public virtual bool SuspendsCoreMovement => false;
|
||||
|
||||
protected InputActionAsset[] InputAssets { get; private set; }
|
||||
|
||||
internal void Activate(InputActionAsset[] assets)
|
||||
{
|
||||
InputAssets = assets;
|
||||
OnActivate();
|
||||
}
|
||||
|
||||
internal void Deactivate()
|
||||
{
|
||||
OnDeactivate();
|
||||
}
|
||||
|
||||
protected virtual void OnActivate() { }
|
||||
protected virtual void OnDeactivate() { }
|
||||
|
||||
protected InputActionMap FindMap(string mapName)
|
||||
{
|
||||
if (InputAssets == null)
|
||||
return null;
|
||||
|
||||
foreach (InputActionAsset asset in InputAssets)
|
||||
{
|
||||
InputActionMap map = asset?.FindActionMap(mapName, throwIfNotFound: false);
|
||||
if (map != null)
|
||||
return map;
|
||||
}
|
||||
|
||||
Debug.LogWarning($"[{GetType().Name}] Action map '{mapName}' not found.");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cd3e40818edc3af45840159f25008f47
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 367142
|
||||
packageName: "MotionCore \u2013 Physics Character Controller"
|
||||
packageVersion: 1.2
|
||||
assetPath: Assets/Character Controller/Core/Scripts/Input/InputMode.cs
|
||||
uploadId: 997018
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,21 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e3f4aa7e8e1b435086a1e379ecefbe5b
|
||||
ScriptedImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
script: {fileID: 11500000, guid: 8404be70184654265930450def6a9037, type: 3}
|
||||
generateWrapperCode: 0
|
||||
wrapperCodePath:
|
||||
wrapperClassName:
|
||||
wrapperCodeNamespace:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 367142
|
||||
packageName: "MotionCore \u2013 Physics Character Controller"
|
||||
packageVersion: 1.2
|
||||
assetPath: Assets/Character Controller/Core/Scripts/Input/InputSystem_Actions.inputactions
|
||||
uploadId: 997018
|
||||
@@ -0,0 +1,17 @@
|
||||
namespace CharacterMovement
|
||||
{
|
||||
/// <summary>
|
||||
/// How the sprint input is interpreted.
|
||||
/// </summary>
|
||||
public enum SprintActivationMode
|
||||
{
|
||||
/// <summary>Sprint only while the input is held. The common default for action games.</summary>
|
||||
Hold = 0,
|
||||
|
||||
/// <summary>
|
||||
/// A press switches sprinting on and off. Releasing the movement input also ends it, so the
|
||||
/// character does not silently sprint again the next time the player moves.
|
||||
/// </summary>
|
||||
Toggle = 1
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cf9219a641ec43319c0d263da75dec2f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 367142
|
||||
packageName: "MotionCore \u2013 Physics Character Controller"
|
||||
packageVersion: 1.2
|
||||
assetPath: Assets/Character Controller/Core/Scripts/Input/SprintActivationMode.cs
|
||||
uploadId: 997018
|
||||
Reference in new issue
Block a user