1
0
Fork 0

implement value-oriented inputs

This commit is contained in:
lightling 2022-07-11 20:09:03 -04:00
parent b517bd6b87
commit 34d927e9e8
Signed by: lightling
GPG key ID: 016F11E0AA296B67
6 changed files with 187 additions and 17 deletions

View file

@ -6,8 +6,8 @@ namespace Goldenwere.GWSU.CTRL.CHAR.Core
public abstract class BaseInputModule : MonoBehaviour
{
public abstract void RegisterModuleAction(BaseModuleAction _action);
public abstract void RegisterModuleAction<T>(BaseModuleAction<T> _action);
public abstract void RegisterModuleAction<T>(BaseModuleAction<T> _action) where T : struct;
public abstract void UnregisterModuleAction(BaseModuleAction _action);
public abstract void UnregisterModuleAction<T>(BaseModuleAction<T> _action);
public abstract void UnregisterModuleAction<T>(BaseModuleAction<T> _action) where T : struct;
}
}

View file

@ -37,6 +37,7 @@ namespace Goldenwere.GWSU.CTRL.CHAR.Core
}
public class BaseModuleAction<T>
where T : struct
{
[SerializeField] private ScriptableObject emitter;
[SerializeField] private Action<T> listener;

View file

@ -74,7 +74,54 @@ namespace Goldenwere.GWSU.CTRL.CHAR.InputSystemModule
{
if (TryGetReference(_action.Emitter, out InputActionReference _reference))
{
Action<InputAction.CallbackContext> canceled = (InputAction.CallbackContext ctx) =>
{
switch (_action.Type)
{
case ModuleActionType.Held:
_action.Listener.Invoke(ctx.ReadValue<T>());
break;
case ModuleActionType.HeldOrPressed:
if (!preferToggledInputs)
{
_action.Listener.Invoke(ctx.ReadValue<T>());
}
break;
}
};
Action<InputAction.CallbackContext> performed = (InputAction.CallbackContext ctx) =>
{
switch (_action.Type)
{
case ModuleActionType.Held:
_action.Listener.Invoke(ctx.ReadValue<T>());
break;
}
};
Action<InputAction.CallbackContext> started = (InputAction.CallbackContext ctx) =>
{
switch (_action.Type)
{
case ModuleActionType.HeldOrPressed:
case ModuleActionType.Pressed:
_action.Listener.Invoke(ctx.ReadValue<T>());
break;
}
};
_reference.action.canceled += canceled;
_reference.action.performed += performed;
_reference.action.started += started;
RegisteredCallbacks.Add
(
_action.GUID,
new Callbacks
{
canceled = canceled,
performed = performed,
started = started,
}
);
}
}

View file

@ -14,30 +14,32 @@ namespace Goldenwere.GWSU.CTRL.CHAR.InputSystemModule.SampleProject
private BaseModuleAction actionOnJump;
private BaseModuleAction<Vector2> actionOnMovement;
private Vector2 valueMovement;
private void Awake()
{
actionOnCrouch = new BaseModuleAction(OnCrouch, emitterOnCrouch, ModuleActionType.HeldOrPressed);
actionOnJump = new BaseModuleAction(OnJump, emitterOnJump, ModuleActionType.Pressed);
actionOnMovement = new BaseModuleAction<Vector2>(OnMovement, emitterOnJump, ModuleActionType.Held);
actionOnMovement = new BaseModuleAction<Vector2>(OnMovement, emitterOnMovement, ModuleActionType.Held);
}
private void OnEnable()
{
module.RegisterModuleAction(actionOnCrouch);
module.RegisterModuleAction(actionOnJump);
//module.RegisterModuleAction(actionOnMovement);
module.RegisterModuleAction(actionOnMovement);
}
private void OnDisable()
{
module.UnregisterModuleAction(actionOnCrouch);
module.UnregisterModuleAction(actionOnJump);
//module.UnregisterModuleAction(actionOnMovement);
module.UnregisterModuleAction(actionOnMovement);
}
private void OnCrouch()
{
Debug.Log($"Crouched");
Debug.Log($"Crouched");
}
private void OnJump()
@ -47,7 +49,16 @@ namespace Goldenwere.GWSU.CTRL.CHAR.InputSystemModule.SampleProject
private void OnMovement(Vector2 value)
{
Debug.Log($"Value was: {value}");
valueMovement = value;
}
private void OnGUI()
{
GUI.Label(
new Rect(10, 10, Screen.width - 10, 64),
$"{valueMovement}",
new GUIStyle { fontSize = 64 }
);
}
}
}

View file

@ -43,7 +43,7 @@ RenderSettings:
--- !u!157 &3
LightmapSettings:
m_ObjectHideFlags: 0
serializedVersion: 12
serializedVersion: 11
m_GIWorkflowMode: 1
m_GISettings:
serializedVersion: 2
@ -98,7 +98,7 @@ LightmapSettings:
m_TrainingDataDestination: TrainingData
m_LightProbeSampleCountMultiplier: 4
m_LightingDataAsset: {fileID: 0}
m_LightingSettings: {fileID: 0}
m_UseShadowmask: 1
--- !u!196 &4
NavMeshSettings:
serializedVersion: 2
@ -118,8 +118,6 @@ NavMeshSettings:
manualTileSize: 0
tileSize: 256
accuratePlacement: 0
maxJobWorkers: 0
preserveTilesOutsideBounds: 0
debug:
m_Flags: 0
m_NavMeshData: {fileID: 0}
@ -155,6 +153,7 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 443109687}
- {fileID: 350861879}
m_Father: {fileID: 0}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@ -189,6 +188,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 2ae55851646730b41a9efe1ad3aa3b5b, type: 3}
m_Name:
m_EditorClassIdentifier:
preferToggledInputs: 0
--- !u!114 &20562263
MonoBehaviour:
m_ObjectHideFlags: 0
@ -217,7 +217,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
m_Actions: {fileID: -944628639613478452, guid: bb0e344ec4e5dad429861af9c6ac5bab,
type: 3}
m_NotificationBehavior: 0
m_NotificationBehavior: 3
m_UIInputModule: {fileID: 0}
m_DeviceLostEvent:
m_PersistentCalls:
@ -265,6 +265,89 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &350861878
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 350861879}
- component: {fileID: 350861881}
- component: {fileID: 350861880}
m_Layer: 0
m_Name: Camera
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &350861879
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 350861878}
m_LocalRotation: {x: 0.2164396, y: 0, z: 0, w: 0.97629607}
m_LocalPosition: {x: 0, y: 3, z: -2.5}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 20562260}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 25, y: 0, z: 0}
--- !u!81 &350861880
AudioListener:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 350861878}
m_Enabled: 1
--- !u!20 &350861881
Camera:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 350861878}
m_Enabled: 1
serializedVersion: 2
m_ClearFlags: 1
m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0}
m_projectionMatrixMode: 1
m_GateFitMode: 2
m_FOVAxisMode: 0
m_SensorSize: {x: 36, y: 24}
m_LensShift: {x: 0, y: 0}
m_FocalLength: 50
m_NormalizedViewPortRect:
serializedVersion: 2
x: 0
y: 0
width: 1
height: 1
near clip plane: 0.3
far clip plane: 1000
field of view: 60
orthographic: 0
orthographic size: 5
m_Depth: 0
m_CullingMask:
serializedVersion: 2
m_Bits: 4294967295
m_RenderingPath: -1
m_TargetTexture: {fileID: 0}
m_TargetDisplay: 0
m_TargetEye: 3
m_HDR: 1
m_AllowMSAA: 1
m_AllowDynamicResolution: 0
m_ForceIntoRT: 0
m_OcclusionCulling: 1
m_StereoConvergence: 10
m_StereoSeparation: 0.022
--- !u!1 &443109686
GameObject:
m_ObjectHideFlags: 0
@ -343,7 +426,6 @@ MeshRenderer:
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RayTraceProcedural: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
@ -368,7 +450,6 @@ MeshRenderer:
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_AdditionalVertexStreams: {fileID: 0}
--- !u!33 &602988447
MeshFilter:
m_ObjectHideFlags: 0
@ -453,7 +534,6 @@ Light:
m_UseColorTemperature: 0
m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0}
m_UseBoundingSphereOverride: 0
m_UseViewFrustumForShadowCasterCull: 1
m_ShadowRadius: 0
m_ShadowAngle: 0
--- !u!4 &863730473
@ -518,7 +598,6 @@ MeshRenderer:
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RayTraceProcedural: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
@ -543,7 +622,6 @@ MeshRenderer:
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_AdditionalVertexStreams: {fileID: 0}
--- !u!33 &1463555310
MeshFilter:
m_ObjectHideFlags: 0

View file

@ -144,6 +144,17 @@
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "",
"id": "c7d6f12e-584e-4cf2-8a7e-dce439e3090d",
"path": "<Gamepad>/leftStick",
"interactions": "",
"processors": "",
"groups": "",
"action": "Movement",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "278ae5dd-3736-406f-84da-7131d6edd649",
@ -155,6 +166,17 @@
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "6f9a5303-598f-4014-83c7-ebd7aec92543",
"path": "<Gamepad>/buttonSouth",
"interactions": "",
"processors": "",
"groups": "",
"action": "Jump",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "ec38fa57-693b-4a36-a820-5d76df95e551",
@ -165,6 +187,17 @@
"action": "Crouch",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "f54cf218-de33-47e3-aaa7-b3703c548fa3",
"path": "<Gamepad>/buttonEast",
"interactions": "",
"processors": "",
"groups": "",
"action": "Crouch",
"isComposite": false,
"isPartOfComposite": false
}
]
}