Commit eb8d3840 authored by Enrique Delgado's avatar Enrique Delgado
Browse files

final change

parent f10fbc1c
No related merge requests found
Showing with 22 additions and 15 deletions
+22 -15
......@@ -8,13 +8,14 @@ public class GameInput : MonoBehaviour
{
private const string PLAYER_PREFS_BINDINGS = "InputBindings";
public static GameInput Instance {get; private set;}
public static GameInput Instance { get; private set; }
public event EventHandler OnInteractAction;
public event EventHandler OnInteractAlternateAction;
public event EventHandler OnPauseAction;
public event EventHandler OnBindingRebind;
public enum Binding {
public enum Binding
{
Move_Up,
Move_Down,
Move_Left,
......@@ -28,15 +29,17 @@ public class GameInput : MonoBehaviour
}
private PlayerInputActions playerInputActions;
private void Awake() {
private void Awake()
{
Instance = this;
playerInputActions = new PlayerInputActions();
// if(PlayerPrefs.HasKey(PLAYER_PREFS_BINDINGS)) {
// playerInputActions.LoadBindingOverridesFromJson(PlayerPrefs.GetString(PLAYER_PREFS_BINDINGS));
// }
if (PlayerPrefs.HasKey(PLAYER_PREFS_BINDINGS))
{
playerInputActions.LoadBindingOverridesFromJson(PlayerPrefs.GetString(PLAYER_PREFS_BINDINGS));
}
playerInputActions.Player.Enable();
playerInputActions.Player.Interact.performed += Interact_performed;
......@@ -44,7 +47,8 @@ public class GameInput : MonoBehaviour
playerInputActions.Player.Pause.performed += Pause_performed;
}
private void OnDestroy() {
private void OnDestroy()
{
// Unsubscribing
playerInputActions.Player.Interact.performed -= Interact_performed;
playerInputActions.Player.InteractAlternate.performed -= InteractAlternate_performed;
......@@ -67,7 +71,7 @@ public class GameInput : MonoBehaviour
{
OnPauseAction?.Invoke(this, EventArgs.Empty);
}
public Vector2 GetMovementVectorNormalized()
{
Vector2 inputVector = playerInputActions.Player.Move.ReadValue<Vector2>();
......@@ -79,7 +83,8 @@ public class GameInput : MonoBehaviour
public string GetBindingText(Binding binding)
{
switch(binding) {
switch (binding)
{
default:
case Binding.Interact:
return playerInputActions.Player.Interact.bindings[0].ToDisplayString();
......@@ -111,9 +116,10 @@ public class GameInput : MonoBehaviour
InputAction inputAction;
int bindingIndex;
switch(binding){
switch (binding)
{
default:
// values should always be assigned
// values should always be assigned
case Binding.Move_Up:
inputAction = playerInputActions.Player.Move;
bindingIndex = 1;
......@@ -157,13 +163,14 @@ public class GameInput : MonoBehaviour
}
inputAction.PerformInteractiveRebinding(bindingIndex)
.OnComplete((callback) => {
.OnComplete((callback) =>
{
callback.Dispose();
playerInputActions.Player.Enable();
onActionRebound();
// PlayerPrefs.SetString(PLAYER_PREFS_BINDINGS, playerInputActions.SaveBindingOverridesAsJson());
// PlayerPrefs.Save();
PlayerPrefs.SetString(PLAYER_PREFS_BINDINGS, playerInputActions.SaveBindingOverridesAsJson());
PlayerPrefs.Save();
OnBindingRebind?.Invoke(this, EventArgs.Empty);
})
......
No preview for this file type
File deleted
File deleted
File deleted
File deleted
File deleted
File deleted
File deleted
File deleted
File deleted
File deleted
File deleted
File deleted
File deleted
File deleted
File deleted
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment