浏览代码

Merge branch 'simple-menu-controls' into pr-bash

# Conflicts:
#	UOP1_Project/Assets/Scenes/TestingGround.unity
#	UOP1_Project/Assets/Scripts/Input/GameInput.cs
/devlogs-3-input
Ciro Continisio 4 年前
当前提交
0f81c55a
共有 20 个文件被更改,包括 1780 次插入318 次删除
  1. 656
      UOP1_Project/Assets/Scripts/Input/GameInput.cs
  2. 64
      UOP1_Project/Assets/Scripts/Input/InputReader.cs
  3. 102
      UOP1_Project/Assets/Settings/Input/GameInput.inputactions
  4. 2
      UOP1_Project/Packages/packages-lock.json
  5. 8
      UOP1_Project/Assets/Prefabs/Menu.meta
  6. 3
      UOP1_Project/Assets/Scripts/Menu.meta
  7. 7
      UOP1_Project/Assets/Prefabs/Menu/DebugMenu.prefab.meta
  8. 1001
      UOP1_Project/Assets/Prefabs/Menu/DebugMenu.prefab
  9. 12
      UOP1_Project/Assets/Scripts/Menu/SelectableUIElement.cs.meta
  10. 22
      UOP1_Project/Assets/Scripts/Menu/README.md
  11. 3
      UOP1_Project/Assets/Scripts/Menu/README.md.meta
  12. 3
      UOP1_Project/Assets/Scripts/Menu/CC_Button.cs.meta
  13. 35
      UOP1_Project/Assets/Scripts/Menu/CC_Button.cs
  14. 29
      UOP1_Project/Assets/Scripts/Menu/SelectableUIElement.cs
  15. 12
      UOP1_Project/Assets/Scripts/Menu/MenuSelectionHandler.cs.meta
  16. 3
      UOP1_Project/Assets/Scripts/Menu/MenuController.cs.meta
  17. 34
      UOP1_Project/Assets/Scripts/Menu/MenuController.cs
  18. 102
      UOP1_Project/Assets/Scripts/Menu/MenuSelectionHandler.cs

656
UOP1_Project/Assets/Scripts/Input/GameInput.cs


public class @GameInput : IInputActionCollection, IDisposable
{
public InputActionAsset asset { get; }
public @GameInput()
{
asset = InputActionAsset.FromJson(@"{
public InputActionAsset asset { get; }
public @GameInput()
{
asset = InputActionAsset.FromJson(@"{
""name"": ""GameInput"",
""maps"": [
{

""id"": ""a6b0dc37-2ef3-420d-990a-eef5df26ae21"",
""actions"": [
{
""name"": ""MoveSelection"",
""name"": ""MoveMenuSelection"",
""type"": ""Value"",
""id"": ""ca8fee63-58a3-49c0-9b34-e74351e25113"",
""expectedControlType"": ""Vector2"",

""name"": ""Cancel"",
""type"": ""Button"",
""id"": ""c0e250d4-50a1-4b32-a5e6-f4d8a75bdcd7"",
""expectedControlType"": ""Button"",
""processors"": """",
""interactions"": """"
},
{
""name"": ""MouseMove"",
""type"": ""PassThrough"",
""id"": ""df62b304-145b-43af-9a21-8cfd14f72fdb"",
""expectedControlType"": ""Vector2"",
""processors"": """",
""interactions"": """"
},
{
""name"": ""Unpause"",
""type"": ""Button"",
""id"": ""a33f8309-65f3-4f8a-8671-c7cb90ef798e"",
""expectedControlType"": ""Button"",
""processors"": """",
""interactions"": """"

""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""b03f649e-d5ec-4fad-8614-6a69620c5345"",
""path"": ""<Mouse>/leftButton"",
""interactions"": """",
""processors"": """",
""groups"": ""KeyboardOrGamepad"",
""action"": ""Confirm"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": ""Gamepad Left Stick"",
""id"": ""abfca31e-4360-48f9-89ac-897570e32b3c"",
""path"": ""2DVector(mode=1)"",

""action"": ""MoveSelection"",
""action"": ""MoveMenuSelection"",
""isComposite"": true,
""isPartOfComposite"": false
},

""interactions"": """",
""processors"": """",
""groups"": ""KeyboardOrGamepad"",
""action"": ""MoveSelection"",
""action"": ""MoveMenuSelection"",
""isComposite"": false,
""isPartOfComposite"": true
},

""interactions"": """",
""processors"": """",
""groups"": ""KeyboardOrGamepad"",
""action"": ""MoveSelection"",
""action"": ""MoveMenuSelection"",
""isComposite"": false,
""isPartOfComposite"": true
},

""interactions"": """",
""processors"": """",
""groups"": ""KeyboardOrGamepad"",
""action"": ""MoveSelection"",
""action"": ""MoveMenuSelection"",
""isComposite"": false,
""isPartOfComposite"": true
},

""interactions"": """",
""processors"": """",
""groups"": ""KeyboardOrGamepad"",
""action"": ""MoveSelection"",
""action"": ""MoveMenuSelection"",
""isComposite"": false,
""isPartOfComposite"": true
},

""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""MoveSelection"",
""action"": ""MoveMenuSelection"",
""isComposite"": true,
""isPartOfComposite"": false
},

""interactions"": """",
""processors"": """",
""groups"": ""KeyboardOrGamepad"",
""action"": ""MoveSelection"",
""action"": ""MoveMenuSelection"",
""isComposite"": false,
""isPartOfComposite"": true
},

""interactions"": """",
""processors"": """",
""groups"": ""KeyboardOrGamepad"",
""action"": ""MoveSelection"",
""action"": ""MoveMenuSelection"",
""isComposite"": false,
""isPartOfComposite"": true
},

""interactions"": """",
""processors"": """",
""groups"": ""KeyboardOrGamepad"",
""action"": ""MoveSelection"",
""action"": ""MoveMenuSelection"",
""isComposite"": false,
""isPartOfComposite"": true
},

""interactions"": """",
""processors"": """",
""groups"": ""KeyboardOrGamepad"",
""action"": ""MoveSelection"",
""action"": ""MoveMenuSelection"",
""isComposite"": false,
""isPartOfComposite"": true
},

""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""MoveSelection"",
""action"": ""MoveMenuSelection"",
""isComposite"": true,
""isPartOfComposite"": false
},

""interactions"": """",
""processors"": """",
""groups"": ""KeyboardOrGamepad"",
""action"": ""MoveSelection"",
""action"": ""MoveMenuSelection"",
""isComposite"": false,
""isPartOfComposite"": true
},

""interactions"": """",
""processors"": """",
""groups"": ""KeyboardOrGamepad"",
""action"": ""MoveSelection"",
""action"": ""MoveMenuSelection"",
""isComposite"": false,
""isPartOfComposite"": true
},

""interactions"": """",
""processors"": """",
""groups"": ""KeyboardOrGamepad"",
""action"": ""MoveSelection"",
""action"": ""MoveMenuSelection"",
""isComposite"": false,
""isPartOfComposite"": true
},

""interactions"": """",
""processors"": """",
""groups"": ""KeyboardOrGamepad"",
""action"": ""MoveSelection"",
""action"": ""MoveMenuSelection"",
""isComposite"": false,
""isPartOfComposite"": true
},

""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""MoveSelection"",
""action"": ""MoveMenuSelection"",
""isComposite"": true,
""isPartOfComposite"": false
},

""interactions"": """",
""processors"": """",
""groups"": ""KeyboardOrGamepad"",
""action"": ""MoveSelection"",
""action"": ""MoveMenuSelection"",
""isComposite"": false,
""isPartOfComposite"": true
},

""interactions"": """",
""processors"": """",
""groups"": ""KeyboardOrGamepad"",
""action"": ""MoveSelection"",
""action"": ""MoveMenuSelection"",
""isComposite"": false,
""isPartOfComposite"": true
},

""interactions"": """",
""processors"": """",
""groups"": ""KeyboardOrGamepad"",
""action"": ""MoveSelection"",
""action"": ""MoveMenuSelection"",
""isComposite"": false,
""isPartOfComposite"": true
},

""interactions"": """",
""processors"": """",
""groups"": ""KeyboardOrGamepad"",
""action"": ""MoveSelection"",
""action"": ""MoveMenuSelection"",
""isComposite"": false,
""isPartOfComposite"": true
},

""action"": ""Cancel"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""10a96123-fa2f-43f5-b596-4ed4c93fd4b3"",
""path"": ""<Gamepad>/start"",
""interactions"": """",
""processors"": """",
""groups"": ""KeyboardOrGamepad"",
""action"": ""Unpause"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""b8857ec1-9a5c-4cd2-af29-276683c9151e"",
""path"": ""<Keyboard>/escape"",
""interactions"": """",
""processors"": """",
""groups"": ""KeyboardOrGamepad"",
""action"": ""Unpause"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""23583bb1-6dd5-4287-94bd-3028199fc088"",
""path"": ""<Mouse>/position"",
""interactions"": """",
""processors"": """",
""groups"": ""Keyboard&Mouse;KeyboardOrGamepad"",
""action"": ""MouseMove"",
""isComposite"": false,
""isPartOfComposite"": false
}
]
},

}
]
}");
// Gameplay
m_Gameplay = asset.FindActionMap("Gameplay", throwIfNotFound: true);
m_Gameplay_Move = m_Gameplay.FindAction("Move", throwIfNotFound: true);
m_Gameplay_Jump = m_Gameplay.FindAction("Jump", throwIfNotFound: true);
m_Gameplay_Attack = m_Gameplay.FindAction("Attack", throwIfNotFound: true);
m_Gameplay_Interact = m_Gameplay.FindAction("Interact", throwIfNotFound: true);
m_Gameplay_Pause = m_Gameplay.FindAction("Pause", throwIfNotFound: true);
m_Gameplay_ExtraAction = m_Gameplay.FindAction("ExtraAction", throwIfNotFound: true);
m_Gameplay_RotateCamera = m_Gameplay.FindAction("RotateCamera", throwIfNotFound: true);
m_Gameplay_MouseControlCamera = m_Gameplay.FindAction("MouseControlCamera", throwIfNotFound: true);
// Gameplay
m_Gameplay = asset.FindActionMap("Gameplay", throwIfNotFound: true);
m_Gameplay_Move = m_Gameplay.FindAction("Move", throwIfNotFound: true);
m_Gameplay_Jump = m_Gameplay.FindAction("Jump", throwIfNotFound: true);
m_Gameplay_Attack = m_Gameplay.FindAction("Attack", throwIfNotFound: true);
m_Gameplay_Interact = m_Gameplay.FindAction("Interact", throwIfNotFound: true);
m_Gameplay_Pause = m_Gameplay.FindAction("Pause", throwIfNotFound: true);
m_Gameplay_ExtraAction = m_Gameplay.FindAction("ExtraAction", throwIfNotFound: true);
m_Gameplay_RotateCamera = m_Gameplay.FindAction("RotateCamera", throwIfNotFound: true);
m_Gameplay_MouseControlCamera = m_Gameplay.FindAction("MouseControlCamera", throwIfNotFound: true);
// Menus
m_Menus = asset.FindActionMap("Menus", throwIfNotFound: true);
m_Menus_MoveSelection = m_Menus.FindAction("MoveSelection", throwIfNotFound: true);
m_Menus_Confirm = m_Menus.FindAction("Confirm", throwIfNotFound: true);
m_Menus_Cancel = m_Menus.FindAction("Cancel", throwIfNotFound: true);
// Dialogues
m_Dialogues = asset.FindActionMap("Dialogues", throwIfNotFound: true);
m_Dialogues_MoveSelection = m_Dialogues.FindAction("MoveSelection", throwIfNotFound: true);
m_Dialogues_AdvanceDialogue = m_Dialogues.FindAction("AdvanceDialogue", throwIfNotFound: true);
}
// Menus
m_Menus = asset.FindActionMap("Menus", throwIfNotFound: true);
m_Menus_MoveMenuSelection = m_Menus.FindAction("MoveMenuSelection", throwIfNotFound: true);
m_Menus_Confirm = m_Menus.FindAction("Confirm", throwIfNotFound: true);
m_Menus_Cancel = m_Menus.FindAction("Cancel", throwIfNotFound: true);
m_Menus_MouseMove = m_Menus.FindAction("MouseMove", throwIfNotFound: true);
m_Menus_Unpause = m_Menus.FindAction("Unpause", throwIfNotFound: true);
// Dialogues
m_Dialogues = asset.FindActionMap("Dialogues", throwIfNotFound: true);
m_Dialogues_MoveSelection = m_Dialogues.FindAction("MoveSelection", throwIfNotFound: true);
m_Dialogues_AdvanceDialogue = m_Dialogues.FindAction("AdvanceDialogue", throwIfNotFound: true);
}
public void Dispose()
{
UnityEngine.Object.Destroy(asset);
}
public void Dispose()
{
UnityEngine.Object.Destroy(asset);
}
public InputBinding? bindingMask
{
get => asset.bindingMask;
set => asset.bindingMask = value;
}
public InputBinding? bindingMask
{
get => asset.bindingMask;
set => asset.bindingMask = value;
}
public ReadOnlyArray<InputDevice>? devices
{
get => asset.devices;
set => asset.devices = value;
}
public ReadOnlyArray<InputDevice>? devices
{
get => asset.devices;
set => asset.devices = value;
}
public ReadOnlyArray<InputControlScheme> controlSchemes => asset.controlSchemes;
public ReadOnlyArray<InputControlScheme> controlSchemes => asset.controlSchemes;
public bool Contains(InputAction action)
{
return asset.Contains(action);
}
public bool Contains(InputAction action)
{
return asset.Contains(action);
}
public IEnumerator<InputAction> GetEnumerator()
{
return asset.GetEnumerator();
}
public IEnumerator<InputAction> GetEnumerator()
{
return asset.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
public void Enable()
{
asset.Enable();
}
public void Enable()
{
asset.Enable();
}
public void Disable()
{
asset.Disable();
}
public void Disable()
{
asset.Disable();
}
// Gameplay
private readonly InputActionMap m_Gameplay;
private IGameplayActions m_GameplayActionsCallbackInterface;
private readonly InputAction m_Gameplay_Move;
private readonly InputAction m_Gameplay_Jump;
private readonly InputAction m_Gameplay_Attack;
private readonly InputAction m_Gameplay_Interact;
private readonly InputAction m_Gameplay_Pause;
private readonly InputAction m_Gameplay_ExtraAction;
private readonly InputAction m_Gameplay_RotateCamera;
private readonly InputAction m_Gameplay_MouseControlCamera;
// Gameplay
private readonly InputActionMap m_Gameplay;
private IGameplayActions m_GameplayActionsCallbackInterface;
private readonly InputAction m_Gameplay_Move;
private readonly InputAction m_Gameplay_Jump;
private readonly InputAction m_Gameplay_Pause;
private readonly InputAction m_Gameplay_ExtraAction;
private readonly InputAction m_Gameplay_RotateCamera;
private readonly InputAction m_Gameplay_MouseControlCamera;
public struct GameplayActions
{
private @GameInput m_Wrapper;
public GameplayActions(@GameInput wrapper) { m_Wrapper = wrapper; }
public InputAction @Move => m_Wrapper.m_Gameplay_Move;
public InputAction @Jump => m_Wrapper.m_Gameplay_Jump;
public InputAction @Attack => m_Wrapper.m_Gameplay_Attack;
public InputAction @Interact => m_Wrapper.m_Gameplay_Interact;
public InputAction @Pause => m_Wrapper.m_Gameplay_Pause;
public InputAction @ExtraAction => m_Wrapper.m_Gameplay_ExtraAction;
public InputAction @RotateCamera => m_Wrapper.m_Gameplay_RotateCamera;
public InputAction @MouseControlCamera => m_Wrapper.m_Gameplay_MouseControlCamera;
public struct GameplayActions
{
private @GameInput m_Wrapper;
public GameplayActions(@GameInput wrapper) { m_Wrapper = wrapper; }
public InputAction @Move => m_Wrapper.m_Gameplay_Move;
public InputAction @Jump => m_Wrapper.m_Gameplay_Jump;
public InputAction @Attack => m_Wrapper.m_Gameplay_Attack;
public InputAction @Interact => m_Wrapper.m_Gameplay_Interact;
public InputAction @Pause => m_Wrapper.m_Gameplay_Pause;
public InputAction @ExtraAction => m_Wrapper.m_Gameplay_ExtraAction;
public InputAction @RotateCamera => m_Wrapper.m_Gameplay_RotateCamera;
public InputAction @MouseControlCamera => m_Wrapper.m_Gameplay_MouseControlCamera;
public InputActionMap Get() { return m_Wrapper.m_Gameplay; }
public void Enable() { Get().Enable(); }
public void Disable() { Get().Disable(); }
public bool enabled => Get().enabled;
public static implicit operator InputActionMap(GameplayActions set) { return set.Get(); }
public void SetCallbacks(IGameplayActions instance)
{
if (m_Wrapper.m_GameplayActionsCallbackInterface != null)
{
@Move.started -= m_Wrapper.m_GameplayActionsCallbackInterface.OnMove;
@Move.performed -= m_Wrapper.m_GameplayActionsCallbackInterface.OnMove;
@Move.canceled -= m_Wrapper.m_GameplayActionsCallbackInterface.OnMove;
@Jump.started -= m_Wrapper.m_GameplayActionsCallbackInterface.OnJump;
@Jump.performed -= m_Wrapper.m_GameplayActionsCallbackInterface.OnJump;
@Jump.canceled -= m_Wrapper.m_GameplayActionsCallbackInterface.OnJump;
@Attack.started -= m_Wrapper.m_GameplayActionsCallbackInterface.OnAttack;
@Attack.performed -= m_Wrapper.m_GameplayActionsCallbackInterface.OnAttack;
@Attack.canceled -= m_Wrapper.m_GameplayActionsCallbackInterface.OnAttack;
@Interact.started -= m_Wrapper.m_GameplayActionsCallbackInterface.OnInteract;
@Interact.performed -= m_Wrapper.m_GameplayActionsCallbackInterface.OnInteract;
@Interact.canceled -= m_Wrapper.m_GameplayActionsCallbackInterface.OnInteract;
@Pause.started -= m_Wrapper.m_GameplayActionsCallbackInterface.OnPause;
@Pause.performed -= m_Wrapper.m_GameplayActionsCallbackInterface.OnPause;
@Pause.canceled -= m_Wrapper.m_GameplayActionsCallbackInterface.OnPause;
@ExtraAction.started -= m_Wrapper.m_GameplayActionsCallbackInterface.OnExtraAction;
@ExtraAction.performed -= m_Wrapper.m_GameplayActionsCallbackInterface.OnExtraAction;
@ExtraAction.canceled -= m_Wrapper.m_GameplayActionsCallbackInterface.OnExtraAction;
@RotateCamera.started -= m_Wrapper.m_GameplayActionsCallbackInterface.OnRotateCamera;
@RotateCamera.performed -= m_Wrapper.m_GameplayActionsCallbackInterface.OnRotateCamera;
@RotateCamera.canceled -= m_Wrapper.m_GameplayActionsCallbackInterface.OnRotateCamera;
@MouseControlCamera.started -= m_Wrapper.m_GameplayActionsCallbackInterface.OnMouseControlCamera;
@MouseControlCamera.performed -= m_Wrapper.m_GameplayActionsCallbackInterface.OnMouseControlCamera;
@MouseControlCamera.canceled -= m_Wrapper.m_GameplayActionsCallbackInterface.OnMouseControlCamera;
public InputActionMap Get() { return m_Wrapper.m_Gameplay; }
public void Enable() { Get().Enable(); }
public void Disable() { Get().Disable(); }
public bool enabled => Get().enabled;
public static implicit operator InputActionMap(GameplayActions set) { return set.Get(); }
public void SetCallbacks(IGameplayActions instance)
{
if (m_Wrapper.m_GameplayActionsCallbackInterface != null)
{
@Move.started -= m_Wrapper.m_GameplayActionsCallbackInterface.OnMove;
@Move.performed -= m_Wrapper.m_GameplayActionsCallbackInterface.OnMove;
@Move.canceled -= m_Wrapper.m_GameplayActionsCallbackInterface.OnMove;
@Jump.started -= m_Wrapper.m_GameplayActionsCallbackInterface.OnJump;
@Jump.performed -= m_Wrapper.m_GameplayActionsCallbackInterface.OnJump;
@Jump.canceled -= m_Wrapper.m_GameplayActionsCallbackInterface.OnJump;
@Attack.started -= m_Wrapper.m_GameplayActionsCallbackInterface.OnAttack;
@Attack.performed -= m_Wrapper.m_GameplayActionsCallbackInterface.OnAttack;
@Attack.canceled -= m_Wrapper.m_GameplayActionsCallbackInterface.OnAttack;
@Interact.started -= m_Wrapper.m_GameplayActionsCallbackInterface.OnInteract;
@Interact.performed -= m_Wrapper.m_GameplayActionsCallbackInterface.OnInteract;
@Interact.canceled -= m_Wrapper.m_GameplayActionsCallbackInterface.OnInteract;
@Pause.started -= m_Wrapper.m_GameplayActionsCallbackInterface.OnPause;
@Pause.performed -= m_Wrapper.m_GameplayActionsCallbackInterface.OnPause;
@Pause.canceled -= m_Wrapper.m_GameplayActionsCallbackInterface.OnPause;
@ExtraAction.started -= m_Wrapper.m_GameplayActionsCallbackInterface.OnExtraAction;
@ExtraAction.performed -= m_Wrapper.m_GameplayActionsCallbackInterface.OnExtraAction;
@ExtraAction.canceled -= m_Wrapper.m_GameplayActionsCallbackInterface.OnExtraAction;
@RotateCamera.started -= m_Wrapper.m_GameplayActionsCallbackInterface.OnRotateCamera;
@RotateCamera.performed -= m_Wrapper.m_GameplayActionsCallbackInterface.OnRotateCamera;
@RotateCamera.canceled -= m_Wrapper.m_GameplayActionsCallbackInterface.OnRotateCamera;
@MouseControlCamera.started -= m_Wrapper.m_GameplayActionsCallbackInterface.OnMouseControlCamera;
@MouseControlCamera.performed -= m_Wrapper.m_GameplayActionsCallbackInterface.OnMouseControlCamera;
@MouseControlCamera.canceled -= m_Wrapper.m_GameplayActionsCallbackInterface.OnMouseControlCamera;
}
m_Wrapper.m_GameplayActionsCallbackInterface = instance;
if (instance != null)
{
@Move.started += instance.OnMove;
@Move.performed += instance.OnMove;
@Move.canceled += instance.OnMove;
@Jump.started += instance.OnJump;
@Jump.performed += instance.OnJump;
@Jump.canceled += instance.OnJump;
@Attack.started += instance.OnAttack;
@Attack.performed += instance.OnAttack;
@Attack.canceled += instance.OnAttack;
@Interact.started += instance.OnInteract;
@Interact.performed += instance.OnInteract;
@Interact.canceled += instance.OnInteract;
@Pause.started += instance.OnPause;
@Pause.performed += instance.OnPause;
@Pause.canceled += instance.OnPause;
@ExtraAction.started += instance.OnExtraAction;
@ExtraAction.performed += instance.OnExtraAction;
@ExtraAction.canceled += instance.OnExtraAction;
@RotateCamera.started += instance.OnRotateCamera;
@RotateCamera.performed += instance.OnRotateCamera;
@RotateCamera.canceled += instance.OnRotateCamera;
@MouseControlCamera.started += instance.OnMouseControlCamera;
@MouseControlCamera.performed += instance.OnMouseControlCamera;
@MouseControlCamera.canceled += instance.OnMouseControlCamera;
}
m_Wrapper.m_GameplayActionsCallbackInterface = instance;
if (instance != null)
{
@Move.started += instance.OnMove;
@Move.performed += instance.OnMove;
@Move.canceled += instance.OnMove;
@Jump.started += instance.OnJump;
@Jump.performed += instance.OnJump;
@Jump.canceled += instance.OnJump;
@Attack.started += instance.OnAttack;
@Attack.performed += instance.OnAttack;
@Attack.canceled += instance.OnAttack;
@Interact.started += instance.OnInteract;
@Interact.performed += instance.OnInteract;
@Interact.canceled += instance.OnInteract;
@Pause.started += instance.OnPause;
@Pause.performed += instance.OnPause;
@Pause.canceled += instance.OnPause;
@ExtraAction.started += instance.OnExtraAction;
@ExtraAction.performed += instance.OnExtraAction;
@ExtraAction.canceled += instance.OnExtraAction;
@RotateCamera.started += instance.OnRotateCamera;
@RotateCamera.performed += instance.OnRotateCamera;
@RotateCamera.canceled += instance.OnRotateCamera;
@MouseControlCamera.started += instance.OnMouseControlCamera;
@MouseControlCamera.performed += instance.OnMouseControlCamera;
@MouseControlCamera.canceled += instance.OnMouseControlCamera;
}
}
}
public GameplayActions @Gameplay => new GameplayActions(this);
}
}
}
private readonly InputAction m_Gameplay_Interact;
private readonly InputAction m_Gameplay_Attack;
public GameplayActions @Gameplay => new GameplayActions(this);
// Menus
private readonly InputActionMap m_Menus;
private IMenusActions m_MenusActionsCallbackInterface;
private readonly InputAction m_Menus_MoveSelection;
private readonly InputAction m_Menus_Confirm;
private readonly InputAction m_Menus_Cancel;
public struct MenusActions
{
private @GameInput m_Wrapper;
public MenusActions(@GameInput wrapper) { m_Wrapper = wrapper; }
public InputAction @MoveSelection => m_Wrapper.m_Menus_MoveSelection;
public InputAction @Confirm => m_Wrapper.m_Menus_Confirm;
public InputAction @Cancel => m_Wrapper.m_Menus_Cancel;
public InputActionMap Get() { return m_Wrapper.m_Menus; }
public void Enable() { Get().Enable(); }
public void Disable() { Get().Disable(); }
public bool enabled => Get().enabled;
public static implicit operator InputActionMap(MenusActions set) { return set.Get(); }
public void SetCallbacks(IMenusActions instance)
{
if (m_Wrapper.m_MenusActionsCallbackInterface != null)
{
@MoveSelection.started -= m_Wrapper.m_MenusActionsCallbackInterface.OnMoveSelection;
@MoveSelection.performed -= m_Wrapper.m_MenusActionsCallbackInterface.OnMoveSelection;
@MoveSelection.canceled -= m_Wrapper.m_MenusActionsCallbackInterface.OnMoveSelection;
@Confirm.started -= m_Wrapper.m_MenusActionsCallbackInterface.OnConfirm;
@Confirm.performed -= m_Wrapper.m_MenusActionsCallbackInterface.OnConfirm;
@Confirm.canceled -= m_Wrapper.m_MenusActionsCallbackInterface.OnConfirm;
@Cancel.started -= m_Wrapper.m_MenusActionsCallbackInterface.OnCancel;
@Cancel.performed -= m_Wrapper.m_MenusActionsCallbackInterface.OnCancel;
@Cancel.canceled -= m_Wrapper.m_MenusActionsCallbackInterface.OnCancel;
}
m_Wrapper.m_MenusActionsCallbackInterface = instance;
if (instance != null)
{
@MoveSelection.started += instance.OnMoveSelection;
@MoveSelection.performed += instance.OnMoveSelection;
@MoveSelection.canceled += instance.OnMoveSelection;
@Confirm.started += instance.OnConfirm;
@Confirm.performed += instance.OnConfirm;
@Confirm.canceled += instance.OnConfirm;
@Cancel.started += instance.OnCancel;
@Cancel.performed += instance.OnCancel;
@Cancel.canceled += instance.OnCancel;
}
}
}
public MenusActions @Menus => new MenusActions(this);
// Menus
private readonly InputActionMap m_Menus;
private IMenusActions m_MenusActionsCallbackInterface;
private readonly InputAction m_Menus_MoveMenuSelection;
private readonly InputAction m_Menus_Confirm;
private readonly InputAction m_Menus_Cancel;
private readonly InputAction m_Menus_MouseMove;
private readonly InputAction m_Menus_Unpause;
public struct MenusActions
{
private @GameInput m_Wrapper;
public MenusActions(@GameInput wrapper) { m_Wrapper = wrapper; }
public InputAction @MoveMenuSelection => m_Wrapper.m_Menus_MoveMenuSelection;
public InputAction @Confirm => m_Wrapper.m_Menus_Confirm;
public InputAction @Cancel => m_Wrapper.m_Menus_Cancel;
public InputAction @MouseMove => m_Wrapper.m_Menus_MouseMove;
public InputAction @Unpause => m_Wrapper.m_Menus_Unpause;
public InputActionMap Get() { return m_Wrapper.m_Menus; }
public void Enable() { Get().Enable(); }
public void Disable() { Get().Disable(); }
public bool enabled => Get().enabled;
public static implicit operator InputActionMap(MenusActions set) { return set.Get(); }
public void SetCallbacks(IMenusActions instance)
{
if (m_Wrapper.m_MenusActionsCallbackInterface != null)
{
@MoveMenuSelection.started -= m_Wrapper.m_MenusActionsCallbackInterface.OnMoveMenuSelection;
@MoveMenuSelection.performed -= m_Wrapper.m_MenusActionsCallbackInterface.OnMoveMenuSelection;
@MoveMenuSelection.canceled -= m_Wrapper.m_MenusActionsCallbackInterface.OnMoveMenuSelection;
@Confirm.started -= m_Wrapper.m_MenusActionsCallbackInterface.OnConfirm;
@Confirm.performed -= m_Wrapper.m_MenusActionsCallbackInterface.OnConfirm;
@Confirm.canceled -= m_Wrapper.m_MenusActionsCallbackInterface.OnConfirm;
@Cancel.started -= m_Wrapper.m_MenusActionsCallbackInterface.OnCancel;
@Cancel.performed -= m_Wrapper.m_MenusActionsCallbackInterface.OnCancel;
@Cancel.canceled -= m_Wrapper.m_MenusActionsCallbackInterface.OnCancel;
@MouseMove.started -= m_Wrapper.m_MenusActionsCallbackInterface.OnMouseMove;
@MouseMove.performed -= m_Wrapper.m_MenusActionsCallbackInterface.OnMouseMove;
@MouseMove.canceled -= m_Wrapper.m_MenusActionsCallbackInterface.OnMouseMove;
@Unpause.started -= m_Wrapper.m_MenusActionsCallbackInterface.OnUnpause;
@Unpause.performed -= m_Wrapper.m_MenusActionsCallbackInterface.OnUnpause;
@Unpause.canceled -= m_Wrapper.m_MenusActionsCallbackInterface.OnUnpause;
}
m_Wrapper.m_MenusActionsCallbackInterface = instance;
if (instance != null)
{
@MoveMenuSelection.started += instance.OnMoveMenuSelection;
@MoveMenuSelection.performed += instance.OnMoveMenuSelection;
@MoveMenuSelection.canceled += instance.OnMoveMenuSelection;
@Confirm.started += instance.OnConfirm;
@Confirm.performed += instance.OnConfirm;
@Confirm.canceled += instance.OnConfirm;
@Cancel.started += instance.OnCancel;
@Cancel.performed += instance.OnCancel;
@Cancel.canceled += instance.OnCancel;
@MouseMove.started += instance.OnMouseMove;
@MouseMove.performed += instance.OnMouseMove;
@MouseMove.canceled += instance.OnMouseMove;
@Unpause.started += instance.OnUnpause;
@Unpause.performed += instance.OnUnpause;
@Unpause.canceled += instance.OnUnpause;
}
}
}
public MenusActions @Menus => new MenusActions(this);
// Dialogues
private readonly InputActionMap m_Dialogues;
private IDialoguesActions m_DialoguesActionsCallbackInterface;
private readonly InputAction m_Dialogues_MoveSelection;
private readonly InputAction m_Dialogues_AdvanceDialogue;
public struct DialoguesActions
{
private @GameInput m_Wrapper;
public DialoguesActions(@GameInput wrapper) { m_Wrapper = wrapper; }
public InputAction @MoveSelection => m_Wrapper.m_Dialogues_MoveSelection;
public InputAction @AdvanceDialogue => m_Wrapper.m_Dialogues_AdvanceDialogue;
public InputActionMap Get() { return m_Wrapper.m_Dialogues; }
public void Enable() { Get().Enable(); }
public void Disable() { Get().Disable(); }
public bool enabled => Get().enabled;
public static implicit operator InputActionMap(DialoguesActions set) { return set.Get(); }
public void SetCallbacks(IDialoguesActions instance)
{
if (m_Wrapper.m_DialoguesActionsCallbackInterface != null)
{
@MoveSelection.started -= m_Wrapper.m_DialoguesActionsCallbackInterface.OnMoveSelection;
@MoveSelection.performed -= m_Wrapper.m_DialoguesActionsCallbackInterface.OnMoveSelection;
@MoveSelection.canceled -= m_Wrapper.m_DialoguesActionsCallbackInterface.OnMoveSelection;
@AdvanceDialogue.started -= m_Wrapper.m_DialoguesActionsCallbackInterface.OnAdvanceDialogue;
@AdvanceDialogue.performed -= m_Wrapper.m_DialoguesActionsCallbackInterface.OnAdvanceDialogue;
@AdvanceDialogue.canceled -= m_Wrapper.m_DialoguesActionsCallbackInterface.OnAdvanceDialogue;
}
m_Wrapper.m_DialoguesActionsCallbackInterface = instance;
if (instance != null)
{
@MoveSelection.started += instance.OnMoveSelection;
@MoveSelection.performed += instance.OnMoveSelection;
@MoveSelection.canceled += instance.OnMoveSelection;
@AdvanceDialogue.started += instance.OnAdvanceDialogue;
@AdvanceDialogue.performed += instance.OnAdvanceDialogue;
@AdvanceDialogue.canceled += instance.OnAdvanceDialogue;
}
}
}
public DialoguesActions @Dialogues => new DialoguesActions(this);
private int m_KeyboardOrGamepadSchemeIndex = -1;
public InputControlScheme KeyboardOrGamepadScheme
{
get
{
if (m_KeyboardOrGamepadSchemeIndex == -1)
m_KeyboardOrGamepadSchemeIndex = asset.FindControlSchemeIndex("KeyboardOrGamepad");
return asset.controlSchemes[m_KeyboardOrGamepadSchemeIndex];
}
}
public interface IGameplayActions
{
void OnMove(InputAction.CallbackContext context);
void OnJump(InputAction.CallbackContext context);
void OnAttack(InputAction.CallbackContext context);
void OnInteract(InputAction.CallbackContext context);
void OnPause(InputAction.CallbackContext context);
void OnExtraAction(InputAction.CallbackContext context);
void OnRotateCamera(InputAction.CallbackContext context);
void OnMouseControlCamera(InputAction.CallbackContext context);
void OnRun(InputAction.CallbackContext context);
}
public interface IMenusActions
{
void OnMoveSelection(InputAction.CallbackContext context);
void OnConfirm(InputAction.CallbackContext context);
void OnCancel(InputAction.CallbackContext context);
}
public interface IDialoguesActions
{
void OnMoveSelection(InputAction.CallbackContext context);
void OnAdvanceDialogue(InputAction.CallbackContext context);
}
// Dialogues
private readonly InputActionMap m_Dialogues;
private IDialoguesActions m_DialoguesActionsCallbackInterface;
private readonly InputAction m_Dialogues_MoveSelection;
private readonly InputAction m_Dialogues_AdvanceDialogue;
public struct DialoguesActions
{
private @GameInput m_Wrapper;
public DialoguesActions(@GameInput wrapper) { m_Wrapper = wrapper; }
public InputAction @MoveSelection => m_Wrapper.m_Dialogues_MoveSelection;
public InputAction @AdvanceDialogue => m_Wrapper.m_Dialogues_AdvanceDialogue;
public InputActionMap Get() { return m_Wrapper.m_Dialogues; }
public void Enable() { Get().Enable(); }
public void Disable() { Get().Disable(); }
public bool enabled => Get().enabled;
public static implicit operator InputActionMap(DialoguesActions set) { return set.Get(); }
public void SetCallbacks(IDialoguesActions instance)
{
if (m_Wrapper.m_DialoguesActionsCallbackInterface != null)
{
@MoveSelection.started -= m_Wrapper.m_DialoguesActionsCallbackInterface.OnMoveSelection;
@MoveSelection.performed -= m_Wrapper.m_DialoguesActionsCallbackInterface.OnMoveSelection;
@MoveSelection.canceled -= m_Wrapper.m_DialoguesActionsCallbackInterface.OnMoveSelection;
@AdvanceDialogue.started -= m_Wrapper.m_DialoguesActionsCallbackInterface.OnAdvanceDialogue;
@AdvanceDialogue.performed -= m_Wrapper.m_DialoguesActionsCallbackInterface.OnAdvanceDialogue;
@AdvanceDialogue.canceled -= m_Wrapper.m_DialoguesActionsCallbackInterface.OnAdvanceDialogue;
}
m_Wrapper.m_DialoguesActionsCallbackInterface = instance;
if (instance != null)
{
@MoveSelection.started += instance.OnMoveSelection;
@MoveSelection.performed += instance.OnMoveSelection;
@MoveSelection.canceled += instance.OnMoveSelection;
@AdvanceDialogue.started += instance.OnAdvanceDialogue;
@AdvanceDialogue.performed += instance.OnAdvanceDialogue;
@AdvanceDialogue.canceled += instance.OnAdvanceDialogue;
}
}
}
public DialoguesActions @Dialogues => new DialoguesActions(this);
private int m_KeyboardOrGamepadSchemeIndex = -1;
public InputControlScheme KeyboardOrGamepadScheme
{
get
{
if (m_KeyboardOrGamepadSchemeIndex == -1) m_KeyboardOrGamepadSchemeIndex = asset.FindControlSchemeIndex("KeyboardOrGamepad");
return asset.controlSchemes[m_KeyboardOrGamepadSchemeIndex];
}
}
public interface IGameplayActions
{
void OnMove(InputAction.CallbackContext context);
void OnJump(InputAction.CallbackContext context);
void OnAttack(InputAction.CallbackContext context);
void OnInteract(InputAction.CallbackContext context);
void OnPause(InputAction.CallbackContext context);
void OnExtraAction(InputAction.CallbackContext context);
void OnRotateCamera(InputAction.CallbackContext context);
void OnMouseControlCamera(InputAction.CallbackContext context);
}
public interface IMenusActions
{
void OnMoveMenuSelection(InputAction.CallbackContext context);
void OnConfirm(InputAction.CallbackContext context);
void OnCancel(InputAction.CallbackContext context);
void OnMouseMove(InputAction.CallbackContext context);
void OnUnpause(InputAction.CallbackContext context);
}
public interface IDialoguesActions
{
void OnMoveSelection(InputAction.CallbackContext context);
void OnAdvanceDialogue(InputAction.CallbackContext context);
}
}

64
UOP1_Project/Assets/Scripts/Input/InputReader.cs


using UnityEngine.Events;
[CreateAssetMenu(fileName = "InputReader", menuName = "Game/Input Reader")]
public class InputReader : ScriptableObject, GameInput.IGameplayActions, GameInput.IDialoguesActions
public class InputReader : ScriptableObject, GameInput.IGameplayActions, GameInput.IDialoguesActions, GameInput.IMenusActions
{
// Gameplay
public event UnityAction jumpEvent;

public event UnityAction advanceDialogueEvent;
public event UnityAction onMoveSelectionEvent;
// MenuEvents
public event UnityAction MoveSelectionMenuEvent = delegate { };
public event UnityAction MouseMoveMenuEvent = delegate { };
public event UnityAction ConfirmMenuEvent = delegate { };
public event UnityAction CancelMenuEvent = delegate { };
public event UnityAction UnpauseMenuEvent = delegate { };
private GameInput gameInput;
private void OnEnable()

gameInput = new GameInput();
gameInput.Menus.SetCallbacks(this);
gameInput.Gameplay.SetCallbacks(this);
gameInput.Dialogues.SetCallbacks(this);
}

public void OnAttack(InputAction.CallbackContext context)
{
if (attackEvent != null
&& context.phase == InputActionPhase.Performed)
&& context.phase == InputActionPhase.Performed)
attackEvent.Invoke();
}

&& context.phase == InputActionPhase.Performed)
&& context.phase == InputActionPhase.Performed)
extraActionEvent.Invoke();
}

&& context.phase == InputActionPhase.Performed)
&& context.phase == InputActionPhase.Performed)
interactEvent.Invoke();
}

&& context.phase == InputActionPhase.Performed)
&& context.phase == InputActionPhase.Performed)
&& context.phase == InputActionPhase.Canceled)
&& context.phase == InputActionPhase.Canceled)
jumpCanceledEvent.Invoke();
}

public void OnPause(InputAction.CallbackContext context)
{
if (pauseEvent != null
&& context.phase == InputActionPhase.Performed)
&& context.phase == InputActionPhase.Performed)
pauseEvent.Invoke();
}

advanceDialogueEvent();
}
public void OnMoveMenuSelection(InputAction.CallbackContext context)
{
if (context.phase == InputActionPhase.Performed)
MoveSelectionMenuEvent();
}
public void OnConfirm(InputAction.CallbackContext context)
{
if (context.phase == InputActionPhase.Performed)
ConfirmMenuEvent();
}
public void OnCancel(InputAction.CallbackContext context)
{
if (context.phase == InputActionPhase.Performed)
CancelMenuEvent();
}
public void OnMouseMove(InputAction.CallbackContext context)
{
if (context.phase == InputActionPhase.Performed)
MouseMoveMenuEvent();
}
public void OnUnpause(InputAction.CallbackContext context)
{
if (context.phase == InputActionPhase.Performed)
UnpauseMenuEvent();
}
gameInput.Menus.Disable();
gameInput.Gameplay.Disable();
gameInput.Menus.Disable();
}

gameInput.Gameplay.Enable();
gameInput.Menus.Disable();
gameInput.Dialogues.Disable();
gameInput.Menus.Disable();
}

public void DisableAllInput()
{
gameInput.Gameplay.Disable();
gameInput.Menus.Disable();
public void EnableMenuInput()
{
gameInput.Dialogues.Disable();
gameInput.Gameplay.Disable();
gameInput.Menus.Enable();
}
public bool LeftMouseDown() => Mouse.current.leftButton.isPressed;
}

102
UOP1_Project/Assets/Settings/Input/GameInput.inputactions


"id": "a6b0dc37-2ef3-420d-990a-eef5df26ae21",
"actions": [
{
"name": "MoveSelection",
"name": "MoveMenuSelection",
"type": "Value",
"id": "ca8fee63-58a3-49c0-9b34-e74351e25113",
"expectedControlType": "Vector2",

"name": "Cancel",
"type": "Button",
"id": "c0e250d4-50a1-4b32-a5e6-f4d8a75bdcd7",
"expectedControlType": "Button",
"processors": "",
"interactions": ""
},
{
"name": "MouseMove",
"type": "PassThrough",
"id": "df62b304-145b-43af-9a21-8cfd14f72fdb",
"expectedControlType": "Vector2",
"processors": "",
"interactions": ""
},
{
"name": "Unpause",
"type": "Button",
"id": "a33f8309-65f3-4f8a-8671-c7cb90ef798e",
"expectedControlType": "Button",
"processors": "",
"interactions": ""

"isPartOfComposite": false
},
{
"name": "",
"id": "b03f649e-d5ec-4fad-8614-6a69620c5345",
"path": "<Mouse>/leftButton",
"interactions": "",
"processors": "",
"groups": "KeyboardOrGamepad",
"action": "Confirm",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "Gamepad Left Stick",
"id": "abfca31e-4360-48f9-89ac-897570e32b3c",
"path": "2DVector(mode=1)",

"action": "MoveSelection",
"action": "MoveMenuSelection",
"isComposite": true,
"isPartOfComposite": false
},

"interactions": "",
"processors": "",
"groups": "KeyboardOrGamepad",
"action": "MoveSelection",
"action": "MoveMenuSelection",
"isComposite": false,
"isPartOfComposite": true
},

"interactions": "",
"processors": "",
"groups": "KeyboardOrGamepad",
"action": "MoveSelection",
"action": "MoveMenuSelection",
"isComposite": false,
"isPartOfComposite": true
},

"interactions": "",
"processors": "",
"groups": "KeyboardOrGamepad",
"action": "MoveSelection",
"action": "MoveMenuSelection",
"isComposite": false,
"isPartOfComposite": true
},

"interactions": "",
"processors": "",
"groups": "KeyboardOrGamepad",
"action": "MoveSelection",
"action": "MoveMenuSelection",
"isComposite": false,
"isPartOfComposite": true
},

"interactions": "",
"processors": "",
"groups": "",
"action": "MoveSelection",
"action": "MoveMenuSelection",
"isComposite": true,
"isPartOfComposite": false
},

"interactions": "",
"processors": "",
"groups": "KeyboardOrGamepad",
"action": "MoveSelection",
"action": "MoveMenuSelection",
"isComposite": false,
"isPartOfComposite": true
},

"interactions": "",
"processors": "",
"groups": "KeyboardOrGamepad",
"action": "MoveSelection",
"action": "MoveMenuSelection",
"isComposite": false,
"isPartOfComposite": true
},

"interactions": "",
"processors": "",
"groups": "KeyboardOrGamepad",
"action": "MoveSelection",
"action": "MoveMenuSelection",
"isComposite": false,
"isPartOfComposite": true
},

"interactions": "",
"processors": "",
"groups": "KeyboardOrGamepad",
"action": "MoveSelection",
"action": "MoveMenuSelection",
"isComposite": false,
"isPartOfComposite": true
},

"interactions": "",
"processors": "",
"groups": "",
"action": "MoveSelection",
"action": "MoveMenuSelection",
"isComposite": true,
"isPartOfComposite": false
},

"interactions": "",
"processors": "",
"groups": "KeyboardOrGamepad",
"action": "MoveSelection",
"action": "MoveMenuSelection",
"isComposite": false,
"isPartOfComposite": true
},

"interactions": "",
"processors": "",
"groups": "KeyboardOrGamepad",
"action": "MoveSelection",
"action": "MoveMenuSelection",
"isComposite": false,
"isPartOfComposite": true
},

"interactions": "",
"processors": "",
"groups": "KeyboardOrGamepad",
"action": "MoveSelection",
"action": "MoveMenuSelection",
"isComposite": false,
"isPartOfComposite": true
},

"interactions": "",
"processors": "",
"groups": "KeyboardOrGamepad",
"action": "MoveSelection",
"action": "MoveMenuSelection",
"isComposite": false,
"isPartOfComposite": true
},

"interactions": "",
"processors": "",
"groups": "",
"action": "MoveSelection",
"action": "MoveMenuSelection",
"isComposite": true,
"isPartOfComposite": false
},

"interactions": "",
"processors": "",
"groups": "KeyboardOrGamepad",
"action": "MoveSelection",
"action": "MoveMenuSelection",
"isComposite": false,
"isPartOfComposite": true
},

"interactions": "",
"processors": "",
"groups": "KeyboardOrGamepad",
"action": "MoveSelection",
"action": "MoveMenuSelection",
"isComposite": false,
"isPartOfComposite": true
},

"interactions": "",
"processors": "",
"groups": "KeyboardOrGamepad",
"action": "MoveSelection",
"action": "MoveMenuSelection",
"isComposite": false,
"isPartOfComposite": true
},

"interactions": "",
"processors": "",
"groups": "KeyboardOrGamepad",
"action": "MoveSelection",
"action": "MoveMenuSelection",
"isComposite": false,
"isPartOfComposite": true
},

"processors": "",
"groups": "KeyboardOrGamepad",
"action": "Cancel",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "10a96123-fa2f-43f5-b596-4ed4c93fd4b3",
"path": "<Gamepad>/start",
"interactions": "",
"processors": "",
"groups": "KeyboardOrGamepad",
"action": "Unpause",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "b8857ec1-9a5c-4cd2-af29-276683c9151e",
"path": "<Keyboard>/escape",
"interactions": "",
"processors": "",
"groups": "KeyboardOrGamepad",
"action": "Unpause",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "23583bb1-6dd5-4287-94bd-3028199fc088",
"path": "<Mouse>/position",
"interactions": "",
"processors": "",
"groups": "Keyboard&Mouse;KeyboardOrGamepad",
"action": "MouseMove",
"isComposite": false,
"isPartOfComposite": false
}

2
UOP1_Project/Packages/packages-lock.json


"url": "https://packages.unity.com"
},
"com.unity.test-framework": {
"version": "1.1.18",
"version": "1.1.16",
"depth": 1,
"source": "registry",
"dependencies": {

8
UOP1_Project/Assets/Prefabs/Menu.meta


fileFormatVersion: 2
guid: 2511b99d5e527884599f3f6931c9ca20
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

3
UOP1_Project/Assets/Scripts/Menu.meta


fileFormatVersion: 2
guid: 16765aec59254aecb85652a16fe5e108
timeCreated: 1604981499

7
UOP1_Project/Assets/Prefabs/Menu/DebugMenu.prefab.meta


fileFormatVersion: 2
guid: 0913fb2fbf6c4cb4aa9d88e5feaece97
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

1001
UOP1_Project/Assets/Prefabs/Menu/DebugMenu.prefab
文件差异内容过多而无法显示
查看文件

12
UOP1_Project/Assets/Scripts/Menu/SelectableUIElement.cs.meta


fileFormatVersion: 2
guid: 83c0f9e51d2b4ff7bc0b46c5ed82b408
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences:
- _inputReader: {fileID: 11400000, guid: 945ec0365077176418488737deed54be, type: 2}
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

22
UOP1_Project/Assets/Scripts/Menu/README.md


#Overview
Menu Controller class consumes input from inputreader
- opens / closes menu
MenuSelectionHandler class acts as manager UI selection logic
- it consumes events provided by the InputReader class
- adds custom selection and component caching behaviour
- must be present on the same transform as the SelectableUI or CC_Button components it controls
SelectableUIELement send messages to the MenuSelectionHandler when a mouse is over them or selection has been moved onto them
- they have events for mouse enter and exit
- they have events for on selection
- they find the MenuSelectionHandler component by checking the root transform for children with the MenuSelectionHandler class (can be refactored later)
- does not handle submit events (must use CC_Button if you'd like submit behaviour)
CC_Button (chop chop button) implements the same methods as SelectableUIElement, however it also inherits from UnityEngine.UI.Button implements an OnSubmitMethod which queries whether it should call base.OnSubmit() or stop the interaction early. Used for our custom menu input handling to prevent an edgecase where mouse clicks can call submit on the wrong UI element.
## Setup
- add MenuSystem prefab to scene if not already present
- assign references if they are not assigned
- hit escape to open and close menu

3
UOP1_Project/Assets/Scripts/Menu/README.md.meta


fileFormatVersion: 2
guid: 5096bddc202247e391d5c512f42e6bad
timeCreated: 1605316809

3
UOP1_Project/Assets/Scripts/Menu/CC_Button.cs.meta


fileFormatVersion: 2
guid: 77b26c7a54d143a7b78bcba222262814
timeCreated: 1605334203

35
UOP1_Project/Assets/Scripts/Menu/CC_Button.cs


using UnityEngine.EventSystems;
using UnityEngine.UI;
// Chop Chop button
public class CC_Button : Button
{
private MenuSelectionHandler _menuSelectionHandler;
private void Awake()
{
_menuSelectionHandler = transform.root.gameObject.GetComponentInChildren<MenuSelectionHandler>();
}
public override void OnPointerEnter(PointerEventData eventData)
{
_menuSelectionHandler.HandleMouseEnter(gameObject);
}
public override void OnPointerExit(PointerEventData eventData)
{
_menuSelectionHandler.HandleMouseExit(gameObject);
}
public override void OnSelect(BaseEventData eventData)
{
_menuSelectionHandler.UpdateSelection(gameObject);
base.OnSelect(eventData);
}
public override void OnSubmit(BaseEventData eventData)
{
if (_menuSelectionHandler.AllowsSubmitOccurance())
base.OnSubmit(eventData);
}
}

29
UOP1_Project/Assets/Scripts/Menu/SelectableUIElement.cs


using System;
using UnityEngine;
using UnityEngine.EventSystems;
[AddComponentMenu("UI/SelectableUIElement")]
public class SelectableUIElement : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, ISelectHandler
{
private MenuSelectionHandler _menuInput;
private void Awake()
{
_menuInput = transform.root.gameObject.GetComponentInChildren<MenuSelectionHandler>();
}
public void OnPointerEnter(PointerEventData eventData)
{
_menuInput.HandleMouseEnter(gameObject);
}
public void OnPointerExit(PointerEventData eventData)
{
_menuInput.HandleMouseExit(gameObject);
}
public void OnSelect(BaseEventData eventData)
{
_menuInput.UpdateSelection(gameObject);
}
}

12
UOP1_Project/Assets/Scripts/Menu/MenuSelectionHandler.cs.meta


fileFormatVersion: 2
guid: af38c0740d43a4f419a21ea970c9cf53
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences:
- _inputReader: {fileID: 11400000, guid: 945ec0365077176418488737deed54be, type: 2}
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

3
UOP1_Project/Assets/Scripts/Menu/MenuController.cs.meta


fileFormatVersion: 2
guid: bfb8a0b36800464dab759d2f75a1b6a0
timeCreated: 1605314932

34
UOP1_Project/Assets/Scripts/Menu/MenuController.cs


using System;
using UnityEngine;
public class MenuController : MonoBehaviour
{
[SerializeField] private InputReader _inputReader;
[SerializeField] private GameObject _menuPrefab;
private GameObject _menuInstance;
private void OnEnable()
{
_inputReader.pauseEvent += OpenMenu;
_inputReader.UnpauseMenuEvent += UnpauseMenu;
}
private void OnDisable()
{
_inputReader.pauseEvent -= OpenMenu;
_inputReader.UnpauseMenuEvent -= UnpauseMenu;
}
private void OpenMenu()
{
if (_menuInstance == null) _menuInstance = Instantiate(_menuPrefab);
_menuInstance.SetActive(true);
_inputReader.EnableMenuInput();
}
private void UnpauseMenu()
{
_menuInstance.SetActive(false);
_inputReader.EnableGameplayInput();
}
}

102
UOP1_Project/Assets/Scripts/Menu/MenuSelectionHandler.cs


using System;
using System.Collections;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.InputSystem;
public class MenuSelectionHandler : MonoBehaviour
{
[SerializeField] private InputReader _inputReader;
[SerializeField] private GameObject _defaultSelection;
public GameObject _currentSelection;
public GameObject _mouseSelection;
private void OnEnable()
{
_inputReader.MouseMoveMenuEvent += HandleMoveCursor;
_inputReader.MoveSelectionMenuEvent += HandleMoveSelection;
StartCoroutine(SelectDefault());
}
private void OnDisable()
{
_inputReader.MouseMoveMenuEvent -= HandleMoveCursor;
_inputReader.MoveSelectionMenuEvent -= HandleMoveSelection;
}
/// <summary>
/// Highlights the default element
/// </summary>
private IEnumerator SelectDefault()
{
yield return new WaitForSeconds(.03f); // Necessary wait otherwise the highlight won't show up
if (_defaultSelection != null)
EventSystem.current.SetSelectedGameObject(_defaultSelection);
}
/// <summary>
/// Fired by keyboard and gamepad inputs. Current selected UI element will be the ui Element that was selected
/// when the event was fired. The _currentSelection is updated later on, after the EventSystem moves to the
/// desired UI element, the UI element will call into UpdateSelection()
/// </summary>
private void HandleMoveSelection()
{
Cursor.visible = false;
// Handle case where no UI element is selected because mouse left selectable bounds
if (EventSystem.current.currentSelectedGameObject == null)
EventSystem.current.SetSelectedGameObject(_currentSelection);
}
private void HandleMoveCursor()
{
if (_mouseSelection != null)
{
EventSystem.current.SetSelectedGameObject(_mouseSelection);
}
Cursor.visible = true;
}
public void HandleMouseEnter(GameObject uiElement)
{
_mouseSelection = uiElement;
EventSystem.current.SetSelectedGameObject(uiElement);
}
public void HandleMouseExit(GameObject uiElement)
{
if (EventSystem.current.currentSelectedGameObject != uiElement) return;
// deselect UI element if mouse moves away from it
_mouseSelection = null;
EventSystem.current.SetSelectedGameObject(null);
}
/// <summary>
/// Method interactable UI elements should call on Submit interaction to determine whether to continue or not.
/// </summary>
/// <returns></returns>
public bool AllowsSubmitOccurance()
{
// if LMB is not down, there is no edge case to handle, allow the event to continue
return !_inputReader.LeftMouseDown()
// if we know mouse & keyboard are on different elements, do not allow interaction to continue
|| _mouseSelection != null && _mouseSelection == _currentSelection;
}
/// <summary>
/// Fired by gamepad or keyboard navigation inputs
/// </summary>
/// <param name="uiElement"></param>
public void UpdateSelection(GameObject uiElement) => _currentSelection = uiElement;
// debug
// private void OnGUI()
// {
// GUILayout.Box($"_currentSelection: {(_currentSelection != null ? _currentSelection.name : "null")}");
// GUILayout.Box($"_mouseSelection: {(_mouseSelection != null ? _mouseSelection.name : "null")}");
// }
}
正在加载...
取消
保存