Moving some things over to the InputData system.

This commit is contained in:
Dan Foster
2026-02-12 00:02:53 +00:00
parent 2abadf0b3e
commit 13ccde8e96
6 changed files with 142 additions and 261 deletions

View File

@@ -9,11 +9,13 @@ GameObject:
serializedVersion: 6
m_Component:
- component: {fileID: 8110894233409421727}
- component: {fileID: 9204028306768623378}
- component: {fileID: 126029702024624554}
- component: {fileID: 3002660132190180648}
- component: {fileID: 4383523072808109851}
- component: {fileID: 3609363995277177833}
- component: {fileID: 5383724707706325514}
- component: {fileID: 7449172431108916039}
m_Layer: 0
m_Name: Player
m_TagString: Untagged
@@ -37,6 +39,18 @@ Transform:
- {fileID: 4867483367381507360}
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &9204028306768623378
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6882903375964528458}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: deeb0d245b10479488cdc39099cb9bab, type: 3}
m_Name:
m_EditorClassIdentifier: Assembly-CSharp::InputHelper
--- !u!143 &126029702024624554
CharacterController:
m_ObjectHideFlags: 0
@@ -112,7 +126,7 @@ MeshRenderer:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6882903375964528458}
m_Enabled: 1
m_CastShadows: 1
m_CastShadows: 0
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_StaticShadowCaster: 0
@@ -129,7 +143,7 @@ MeshRenderer:
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 2100000, guid: 934901a6cc251ea4cb28620f9a14909e, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
@@ -153,6 +167,19 @@ MeshRenderer:
m_SortingOrder: 0
m_MaskInteraction: 0
m_AdditionalVertexStreams: {fileID: 0}
--- !u!114 &7449172431108916039
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6882903375964528458}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f9e99d5848b80d246b6540ad0aabf4d8, type: 3}
m_Name:
m_EditorClassIdentifier: Assembly-CSharp::Player
health: 100
--- !u!1 &8543759782269834926
GameObject:
m_ObjectHideFlags: 0
@@ -165,6 +192,7 @@ GameObject:
- component: {fileID: 2075247097621853228}
- component: {fileID: 6877818284364034329}
- component: {fileID: 8719656586330480197}
- component: {fileID: 8595194069415729003}
m_Layer: 0
m_Name: Camera
m_TagString: Untagged
@@ -259,6 +287,50 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 9ad5c2eb6d6ecad47af3a531cd239ec5, type: 3}
m_Name:
m_EditorClassIdentifier: Assembly-CSharp::CameraShake
--- !u!114 &8595194069415729003
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8543759782269834926}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a79441f348de89743a2939f4d699eac1, type: 3}
m_Name:
m_EditorClassIdentifier: Unity.RenderPipelines.Universal.Runtime::UnityEngine.Rendering.Universal.UniversalAdditionalCameraData
m_RenderShadows: 1
m_RequiresDepthTextureOption: 2
m_RequiresOpaqueTextureOption: 2
m_CameraType: 0
m_Cameras: []
m_RendererIndex: -1
m_VolumeLayerMask:
serializedVersion: 2
m_Bits: 1
m_VolumeTrigger: {fileID: 0}
m_VolumeFrameworkUpdateModeOption: 2
m_RenderPostProcessing: 0
m_Antialiasing: 0
m_AntialiasingQuality: 2
m_StopNaN: 0
m_Dithering: 0
m_ClearDepth: 1
m_AllowXRRendering: 1
m_AllowHDROutput: 1
m_UseScreenCoordOverride: 0
m_ScreenSizeOverride: {x: 0, y: 0, z: 0, w: 0}
m_ScreenCoordScaleBias: {x: 0, y: 0, z: 0, w: 0}
m_RequiresDepthTexture: 0
m_RequiresColorTexture: 0
m_TaaSettings:
m_Quality: 3
m_FrameInfluence: 0.1
m_JitterScale: 1
m_MipBias: 0
m_VarianceClampScale: 0.9
m_ContrastAdaptiveSharpening: 0
m_Version: 2
--- !u!1001 &1420362106600511514
PrefabInstance:
m_ObjectHideFlags: 0
@@ -271,45 +343,57 @@ PrefabInstance:
propertyPath: m_Name
value: Gun Splat
objectReference: {fileID: 0}
- target: {fileID: 3447742079981357586, guid: 4f15ea45bfb5e4f11bc2bce50e39fc10, type: 3}
propertyPath: m_LocalScale.x
value: 1.2387
objectReference: {fileID: 0}
- target: {fileID: 3447742079981357586, guid: 4f15ea45bfb5e4f11bc2bce50e39fc10, type: 3}
propertyPath: m_LocalScale.y
value: 1.2387
objectReference: {fileID: 0}
- target: {fileID: 3447742079981357586, guid: 4f15ea45bfb5e4f11bc2bce50e39fc10, type: 3}
propertyPath: m_LocalScale.z
value: 1.2387
objectReference: {fileID: 0}
- target: {fileID: 3447742079981357586, guid: 4f15ea45bfb5e4f11bc2bce50e39fc10, type: 3}
propertyPath: m_LocalPosition.x
value: -0.05
value: -0.079
objectReference: {fileID: 0}
- target: {fileID: 3447742079981357586, guid: 4f15ea45bfb5e4f11bc2bce50e39fc10, type: 3}
propertyPath: m_LocalPosition.y
value: -0.0791769
value: -0.1367
objectReference: {fileID: 0}
- target: {fileID: 3447742079981357586, guid: 4f15ea45bfb5e4f11bc2bce50e39fc10, type: 3}
propertyPath: m_LocalPosition.z
value: 0.755
value: 0.7986
objectReference: {fileID: 0}
- target: {fileID: 3447742079981357586, guid: 4f15ea45bfb5e4f11bc2bce50e39fc10, type: 3}
propertyPath: m_LocalRotation.w
value: 0.9211828
value: 0.8836397
objectReference: {fileID: 0}
- target: {fileID: 3447742079981357586, guid: 4f15ea45bfb5e4f11bc2bce50e39fc10, type: 3}
propertyPath: m_LocalRotation.x
value: -0.30416393
value: -0.24749401
objectReference: {fileID: 0}
- target: {fileID: 3447742079981357586, guid: 4f15ea45bfb5e4f11bc2bce50e39fc10, type: 3}
propertyPath: m_LocalRotation.y
value: -0.21869422
value: -0.3881987
objectReference: {fileID: 0}
- target: {fileID: 3447742079981357586, guid: 4f15ea45bfb5e4f11bc2bce50e39fc10, type: 3}
propertyPath: m_LocalRotation.z
value: 0.105259016
value: 0.08502574
objectReference: {fileID: 0}
- target: {fileID: 3447742079981357586, guid: 4f15ea45bfb5e4f11bc2bce50e39fc10, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: -30.954
value: -21.801
objectReference: {fileID: 0}
- target: {fileID: 3447742079981357586, guid: 4f15ea45bfb5e4f11bc2bce50e39fc10, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: -32.99
value: -51.649
objectReference: {fileID: 0}
- target: {fileID: 3447742079981357586, guid: 4f15ea45bfb5e4f11bc2bce50e39fc10, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 22.412
value: 21.641
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
@@ -341,7 +425,7 @@ MonoBehaviour:
fireRate: 8
maxAmmo: 30
currentAmmo: 0
isAutomatic: 1
isAutomatic: 0
recoilKickback: 0.08
recoilKickUp: 0.04
recoilRecoverySpeed: 12

View File

@@ -230,70 +230,10 @@ PrefabInstance:
serializedVersion: 3
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 4354687167556866568, guid: 33de4b621d70a49aab5df775f2b826ef, type: 3}
propertyPath: m_LocalScale.x
value: 1.2387
objectReference: {fileID: 0}
- target: {fileID: 4354687167556866568, guid: 33de4b621d70a49aab5df775f2b826ef, type: 3}
propertyPath: m_LocalScale.y
value: 1.2387
objectReference: {fileID: 0}
- target: {fileID: 4354687167556866568, guid: 33de4b621d70a49aab5df775f2b826ef, type: 3}
propertyPath: m_LocalScale.z
value: 1.2387
objectReference: {fileID: 0}
- target: {fileID: 4354687167556866568, guid: 33de4b621d70a49aab5df775f2b826ef, type: 3}
propertyPath: m_LocalPosition.x
value: -0.079
objectReference: {fileID: 0}
- target: {fileID: 4354687167556866568, guid: 33de4b621d70a49aab5df775f2b826ef, type: 3}
propertyPath: m_LocalPosition.y
value: -0.1367
objectReference: {fileID: 0}
- target: {fileID: 4354687167556866568, guid: 33de4b621d70a49aab5df775f2b826ef, type: 3}
propertyPath: m_LocalPosition.z
value: 0.7986
objectReference: {fileID: 0}
- target: {fileID: 4354687167556866568, guid: 33de4b621d70a49aab5df775f2b826ef, type: 3}
propertyPath: m_LocalRotation.w
value: 0.8836397
objectReference: {fileID: 0}
- target: {fileID: 4354687167556866568, guid: 33de4b621d70a49aab5df775f2b826ef, type: 3}
propertyPath: m_LocalRotation.x
value: -0.24749401
objectReference: {fileID: 0}
- target: {fileID: 4354687167556866568, guid: 33de4b621d70a49aab5df775f2b826ef, type: 3}
propertyPath: m_LocalRotation.y
value: -0.3881987
objectReference: {fileID: 0}
- target: {fileID: 4354687167556866568, guid: 33de4b621d70a49aab5df775f2b826ef, type: 3}
propertyPath: m_LocalRotation.z
value: 0.08502574
objectReference: {fileID: 0}
- target: {fileID: 4354687167556866568, guid: 33de4b621d70a49aab5df775f2b826ef, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: -21.801
objectReference: {fileID: 0}
- target: {fileID: 4354687167556866568, guid: 33de4b621d70a49aab5df775f2b826ef, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: -51.649
objectReference: {fileID: 0}
- target: {fileID: 4354687167556866568, guid: 33de4b621d70a49aab5df775f2b826ef, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 21.641
objectReference: {fileID: 0}
- target: {fileID: 5383724707706325514, guid: 33de4b621d70a49aab5df775f2b826ef, type: 3}
propertyPath: m_Enabled
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5383724707706325514, guid: 33de4b621d70a49aab5df775f2b826ef, type: 3}
propertyPath: m_CastShadows
- target: {fileID: 1440475385873073364, guid: 33de4b621d70a49aab5df775f2b826ef, type: 3}
propertyPath: isAutomatic
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5383724707706325514, guid: 33de4b621d70a49aab5df775f2b826ef, type: 3}
propertyPath: 'm_Materials.Array.data[0]'
value:
objectReference: {fileID: 2100000, guid: 934901a6cc251ea4cb28620f9a14909e, type: 2}
- target: {fileID: 6882903375964528458, guid: 33de4b621d70a49aab5df775f2b826ef, type: 3}
propertyPath: m_Name
value: Player
@@ -341,13 +281,7 @@ PrefabInstance:
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents:
- targetCorrespondingSourceObject: {fileID: 6882903375964528458, guid: 33de4b621d70a49aab5df775f2b826ef, type: 3}
insertIndex: -1
addedObject: {fileID: 1221260112}
- targetCorrespondingSourceObject: {fileID: 8543759782269834926, guid: 33de4b621d70a49aab5df775f2b826ef, type: 3}
insertIndex: -1
addedObject: {fileID: 454108990}
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 33de4b621d70a49aab5df775f2b826ef, type: 3}
--- !u!1001 &197010634
PrefabInstance:
@@ -6342,55 +6276,6 @@ Transform:
m_Children: []
m_Father: {fileID: 1716472518}
m_LocalEulerAnglesHint: {x: 0, y: -176, z: 0}
--- !u!1 &454108985 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 8543759782269834926, guid: 33de4b621d70a49aab5df775f2b826ef, type: 3}
m_PrefabInstance: {fileID: 110786869}
m_PrefabAsset: {fileID: 0}
--- !u!114 &454108990
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 454108985}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a79441f348de89743a2939f4d699eac1, type: 3}
m_Name:
m_EditorClassIdentifier: Unity.RenderPipelines.Universal.Runtime::UnityEngine.Rendering.Universal.UniversalAdditionalCameraData
m_RenderShadows: 1
m_RequiresDepthTextureOption: 2
m_RequiresOpaqueTextureOption: 2
m_CameraType: 0
m_Cameras: []
m_RendererIndex: -1
m_VolumeLayerMask:
serializedVersion: 2
m_Bits: 1
m_VolumeTrigger: {fileID: 0}
m_VolumeFrameworkUpdateModeOption: 2
m_RenderPostProcessing: 0
m_Antialiasing: 0
m_AntialiasingQuality: 2
m_StopNaN: 0
m_Dithering: 0
m_ClearDepth: 1
m_AllowXRRendering: 1
m_AllowHDROutput: 1
m_UseScreenCoordOverride: 0
m_ScreenSizeOverride: {x: 0, y: 0, z: 0, w: 0}
m_ScreenCoordScaleBias: {x: 0, y: 0, z: 0, w: 0}
m_RequiresDepthTexture: 0
m_RequiresColorTexture: 0
m_TaaSettings:
m_Quality: 3
m_FrameInfluence: 0.1
m_JitterScale: 1
m_MipBias: 0
m_VarianceClampScale: 0.9
m_ContrastAdaptiveSharpening: 0
m_Version: 2
--- !u!1001 &483729265
PrefabInstance:
m_ObjectHideFlags: 0
@@ -7318,24 +7203,6 @@ Transform:
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1221260105 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 6882903375964528458, guid: 33de4b621d70a49aab5df775f2b826ef, type: 3}
m_PrefabInstance: {fileID: 110786869}
m_PrefabAsset: {fileID: 0}
--- !u!114 &1221260112
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1221260105}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f9e99d5848b80d246b6540ad0aabf4d8, type: 3}
m_Name:
m_EditorClassIdentifier: Assembly-CSharp::Player
health: 100
--- !u!1 &1249073701 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: -8098169881513260187, guid: fa9ce4c3e422d4dfb8c7546b16bc9f33, type: 3}

View File

@@ -20,43 +20,11 @@ public static class InputData
public static MouseButton middleMouseButton;
public static MouseButton rightMouseButton;
public static Button up;
public static Button down;
public static Button debugButton;
public static Button agentDebugButton;
public static Button fireWeapon;
public static Button reload;
public static Button jump;
public static Button rotateLeft;
public static Button rotateRight;
public static Button cancel;
public static Button floorUp;
public static Button floorDown;
public static Button cameraLeft;
public static Button cameraRight;
public static Button cameraUp;
public static Button cameraDown;
public static Button cameraRotateLeft;
public static Button cameraRotateRight;
public static Button cameraSpeedBoost;
public static Button pauseTime;
public static Button pauseGame;
public static Axis cameraHorizontal;
public static Axis cameraVertical;
#if MARKETING_BUILD
public static Axis fovAxis;
public static Axis cameraUpDownAxis;
public static Axis marketingCameraX;
public static Axis marketingCameraY;
#endif
public static Axis horizontalMovement;
private static List<Button> allButtons = new List<Button>();
private static List<Axis> allAxis = new List<Axis>();
@@ -71,85 +39,20 @@ public static class InputData
middleMouseButton = AddButton( new MouseButton( Defines.Input.kMiddleMouseButton ) );
rightMouseButton = AddButton( new MouseButton( Defines.Input.kRightMouseButton ) );
up = AddButton( new KeyboardButton( KeyCode.UpArrow ) );
down = AddButton( new KeyboardButton( KeyCode.DownArrow ) );
rotateLeft = AddButton( new KeyboardButton( Defines.Input.rotateLeftKey ) );
rotateRight = AddButton( new KeyboardButton( Defines.Input.rotateRightKey ) );
cancel = AddButton( new KeyboardButton( Defines.Input.kCancelKeyCode ) );
pauseGame = AddButton( new KeyboardButton( KeyCode.Escape ) );
debugButton = AddButton( new KeyboardButton( KeyCode.Space ) );
agentDebugButton = AddButton( new KeyboardButton( KeyCode.Z ) );
floorUp = AddButton( new MultiButton(
fireWeapon = AddButton( new MultiButton(
new Button[]
{
new KeyboardButton( KeyCode.Alpha2 ),
new KeyboardButton( KeyCode.G )
} ) );
floorDown = AddButton( new MultiButton(
new Button[]
{
new KeyboardButton( KeyCode.Alpha1 ),
new KeyboardButton( KeyCode.F )
new MouseButton( Defines.Input.kLeftMouseButton),
new KeyboardButton( KeyCode.LeftControl ),
} ) );
reload = AddButton( new KeyboardButton( KeyCode.Space ) );
jump = AddButton( new KeyboardButton( KeyCode.Space ) );
cameraLeft = AddButton( new MultiButton(
new Button[]
{
new KeyboardButton( KeyCode.A ),
new KeyboardButton( KeyCode.LeftArrow )
} ) );
cameraRight = AddButton( new MultiButton(
new Button[]
{
new KeyboardButton( KeyCode.D ),
new KeyboardButton( KeyCode.RightArrow )
} ) );
cameraUp = AddButton( new MultiButton(
new Button[]
{
new KeyboardButton( KeyCode.W ),
new KeyboardButton( KeyCode.UpArrow )
} ) );
cameraDown = AddButton( new MultiButton(
new Button[]
{
new KeyboardButton( KeyCode.S ),
new KeyboardButton( KeyCode.DownArrow )
} ) );
cameraRotateLeft = AddButton( new KeyboardButton( KeyCode.Q ) );
cameraRotateRight = AddButton( new KeyboardButton( KeyCode.E ) );
cameraSpeedBoost = AddButton( new KeyboardButton( KeyCode.LeftShift ) );
pauseTime = AddButton( new KeyboardButton( KeyCode.Space ) );
inputConfig.Default.Enable();
cameraHorizontal = AddAxis( new MultiAxis(
horizontalMovement = AddAxis( new MultiAxis(
new Axis[]
{
new InputActionAxis( inputConfig.Default.CameraHorizontal )
new ButtonAxis( new KeyboardButton( KeyCode.A ), new KeyboardButton( KeyCode.D ) )
} ) );
cameraVertical = AddAxis( new MultiAxis(
new Axis[]
{
new InputActionAxis( inputConfig.Default.CameraVertical )
} ) );
#if MARKETING_BUILD
inputConfig.Marketing.Enable();
fovAxis = AddAxis( new InputActionAxis( inputConfig.Marketing.CameraFOV ) );
cameraUpDownAxis = AddAxis( new InputActionAxis( inputConfig.Marketing.CameraUpDown ) );
marketingCameraX = AddAxis( new InputActionAxis( inputConfig.Marketing.CameraRotationX ) );
marketingCameraY = AddAxis( new InputActionAxis( inputConfig.Marketing.CameraRotationY ) );
#endif
}
public static T AddButton<T>( T value ) where T : Button
@@ -331,7 +234,7 @@ public static class InputData
public abstract float GetAxisValue();
public virtual void Update()
public virtual void Update( float unscaledTime)
{
value = GetAxisValue();
}
@@ -406,6 +309,13 @@ public static class InputData
{
return ( positiveButton.down ? 1.0f : 0.0f ) + ( negativeButton.down ? -1.0f : 0.0f );
}
public override void Update( float unscaledTime )
{
positiveButton.Update( unscaledTime );
negativeButton.Update( unscaledTime );
base.Update( unscaledTime );
}
}
public class InputActionAxis : Axis
@@ -458,7 +368,7 @@ public static class InputData
foreach( Axis i in allAxis )
{
i.Update();
i.Update( unscaledTime);
}
#if UNITY_STANDALONE_WIN

View File

@@ -0,0 +1,9 @@
using UnityEngine;
public class InputHelper : MonoBehaviour
{
protected void Update()
{
InputData.Update( Time.unscaledTime );
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: deeb0d245b10479488cdc39099cb9bab
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: -32000
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -94,7 +94,7 @@ public class SimpleGun : MonoBehaviour
void Update()
{
// Shooting
if (isAutomatic ? Input.GetButton("Fire1") : Input.GetButtonDown("Fire1"))
if (isAutomatic ? InputData.leftMouseButton.down : InputData.leftMouseButton.pressed)
{
if (Time.time >= nextTimeToFire)
{
@@ -104,7 +104,7 @@ public class SimpleGun : MonoBehaviour
}
// Reload
if (Input.GetKeyDown(KeyCode.R))
if (InputData.reload.pressed)
Reload();
// Recover from recoil