Added controls for gamepad, changed input & UI
This commit is contained in:
87
Assets/Scripts/Menu/ControlsMenu.cs
Normal file
87
Assets/Scripts/Menu/ControlsMenu.cs
Normal file
@@ -0,0 +1,87 @@
|
||||
using Assets.Scripts;
|
||||
using Assets.Scripts.Menu;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class ControlsMenu : MonoBehaviour
|
||||
{
|
||||
UIHandlerMenu uihandler;
|
||||
MoveDirection direction;
|
||||
PlayerInput playerInput;
|
||||
|
||||
|
||||
void Start()
|
||||
{
|
||||
uihandler = GameObject.Find("UIHandler").GetComponent<UIHandlerMenu>();
|
||||
direction = MoveDirection.None;
|
||||
playerInput = GetComponent<PlayerInput>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
changeNameInput();
|
||||
if(playerInput.currentControlScheme == "Controller"){
|
||||
if(EventSystem.current.currentSelectedGameObject == null){
|
||||
EventSystem.current.SetSelectedGameObject(FindFirstObjectByType<Button>().gameObject);
|
||||
}
|
||||
if(Cursor.lockState != CursorLockMode.Locked){
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
}
|
||||
if(playerInput.currentActionMap.name != "Menu"){
|
||||
playerInput.SwitchCurrentActionMap("Menu");
|
||||
}
|
||||
}
|
||||
else{
|
||||
if(Cursor.lockState != CursorLockMode.Confined){
|
||||
Cursor.lockState = CursorLockMode.Confined;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void FixedUpdate(){
|
||||
if(direction != MoveDirection.None){
|
||||
AxisEventData data = new AxisEventData(EventSystem.current);
|
||||
data.moveDir = direction;
|
||||
data.selectedObject = EventSystem.current.currentSelectedGameObject;
|
||||
ExecuteEvents.Execute(data.selectedObject, data, ExecuteEvents.moveHandler);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnMovement(InputValue value){
|
||||
if(value.Get<Vector2>().x < 0){
|
||||
direction = MoveDirection.Left;
|
||||
}
|
||||
else if(value.Get<Vector2>().x > 0){
|
||||
direction = MoveDirection.Right;
|
||||
}
|
||||
else if(value.Get<Vector2>().y < 0){
|
||||
direction = MoveDirection.Down;
|
||||
}
|
||||
else if(value.Get<Vector2>().y > 0){
|
||||
direction = MoveDirection.Up;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnBack(){
|
||||
|
||||
}
|
||||
|
||||
public void changeNameInput(){
|
||||
if(uihandler.isCharacterCreation()){
|
||||
if(playerInput.currentControlScheme == "Controller"){
|
||||
if(EventSystem.current.currentSelectedGameObject == null || EventSystem.current.currentSelectedGameObject == GameObject.Find("inName")){
|
||||
EventSystem.current.SetSelectedGameObject(GameObject.Find("btnRandomName"));
|
||||
}
|
||||
GameObject.Find("inName").GetComponent<InputField>().interactable = false;
|
||||
}
|
||||
else{
|
||||
GameObject.Find("inName").GetComponent<InputField>().interactable = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user