1
0
Fork 0

Update FakeControllerModule.cs

documentation and cleanup
This commit is contained in:
lightling 2022-07-11 21:12:31 -04:00
parent 0e8e07bac5
commit 26e70e4fb8
Signed by: lightling
GPG key ID: 016F11E0AA296B67

View file

@ -3,26 +3,41 @@ using Goldenwere.GWSU.CTRL.CHAR.Core;
namespace Goldenwere.GWSU.CTRL.CHAR.InputSystemModule.SampleProject namespace Goldenwere.GWSU.CTRL.CHAR.InputSystemModule.SampleProject
{ {
/// <summary>
/// Fake module to demonstrate the input module with
/// </summary>
public class FakeControllerModule : BaseControllerModule public class FakeControllerModule : BaseControllerModule
{ {
[SerializeField] private BaseInputModule module; [SerializeField] private BaseInputModule module;
[Header("Input Emitters")]
[SerializeField] private ScriptableObject emitterOnCrouch; [SerializeField] private ScriptableObject emitterOnCrouch;
[SerializeField] private ScriptableObject emitterOnJump; [SerializeField] private ScriptableObject emitterOnJump;
[SerializeField] private ScriptableObject emitterOnMovement; [SerializeField] private ScriptableObject emitterOnMovement;
/* actions */
private BaseModuleAction actionOnCrouch; private BaseModuleAction actionOnCrouch;
private BaseModuleAction actionOnJump; private BaseModuleAction actionOnJump;
private BaseModuleAction<Vector2> actionOnMovement; private BaseModuleAction<Vector2> actionOnMovement;
/* state fields */
private Vector2 valueMovement; private Vector2 valueMovement;
private bool valueCrouched;
/// <summary>
/// Initializes the module on Awake
/// </summary>
private void Awake() private void Awake()
{ {
// Set up module actions by assigning emitters to the corresponding actions in the module
actionOnCrouch = new BaseModuleAction(OnCrouch, emitterOnCrouch, ModuleActionType.HeldOrPressed); actionOnCrouch = new BaseModuleAction(OnCrouch, emitterOnCrouch, ModuleActionType.HeldOrPressed);
actionOnJump = new BaseModuleAction(OnJump, emitterOnJump, ModuleActionType.Pressed); actionOnJump = new BaseModuleAction(OnJump, emitterOnJump, ModuleActionType.Pressed);
actionOnMovement = new BaseModuleAction<Vector2>(OnMovement, emitterOnMovement, ModuleActionType.Held); actionOnMovement = new BaseModuleAction<Vector2>(OnMovement, emitterOnMovement, ModuleActionType.Held);
} }
/// <summary>
/// Registers actions on Enable
/// </summary>
private void OnEnable() private void OnEnable()
{ {
module.RegisterModuleAction(actionOnCrouch); module.RegisterModuleAction(actionOnCrouch);
@ -30,6 +45,9 @@ namespace Goldenwere.GWSU.CTRL.CHAR.InputSystemModule.SampleProject
module.RegisterModuleAction(actionOnMovement); module.RegisterModuleAction(actionOnMovement);
} }
/// <summary>
/// Unregisters actions on Disable
/// </summary>
private void OnDisable() private void OnDisable()
{ {
module.UnregisterModuleAction(actionOnCrouch); module.UnregisterModuleAction(actionOnCrouch);
@ -37,27 +55,46 @@ namespace Goldenwere.GWSU.CTRL.CHAR.InputSystemModule.SampleProject
module.UnregisterModuleAction(actionOnMovement); module.UnregisterModuleAction(actionOnMovement);
} }
/// <summary>
/// Handler for the crouch action
/// </summary>
private void OnCrouch() private void OnCrouch()
{ {
Debug.Log($"Crouched"); valueCrouched = !valueCrouched;
} }
/// <summary>
/// Handler for the jump action
/// </summary>
private void OnJump() private void OnJump()
{ {
Debug.Log("Jumped"); Debug.Log("Jumped");
} }
/// <summary>
/// Handler for the movement action
/// </summary>
/// <param name="value">The value of the input</param>
private void OnMovement(Vector2 value) private void OnMovement(Vector2 value)
{ {
valueMovement = value; valueMovement = value;
} }
/// <summary>
/// Displays testing information to the screen
/// </summary>
private void OnGUI() private void OnGUI()
{ {
int size = Screen.height / 32;
GUI.Label( GUI.Label(
new Rect(10, 10, Screen.width - 10, 64), new Rect(10, 10, Screen.width - 10, size),
$"{valueMovement}", $"Movement: {valueMovement}",
new GUIStyle { fontSize = 64 } new GUIStyle { fontSize = size }
);
GUI.Label(
new Rect(10, 10 + size, Screen.width - 10, size),
$"Crouched: {valueCrouched}",
new GUIStyle { fontSize = size }
); );
} }
} }