Added controls for gamepad, changed input & UI
This commit is contained in:
File diff suppressed because one or more lines are too long
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Menu/ControlsMenu.cs.meta
Normal file
11
Assets/Scripts/Menu/ControlsMenu.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ecb843ecde843f11c98ebad43887bfde
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -22,6 +22,7 @@ namespace Assets.Scripts.Menu
|
||||
characterCreation.SetActive(false);
|
||||
mainMenu.SetActive(true);
|
||||
SteamWorksHandler.getStandardAchievement("StartAchievement");
|
||||
EventSystem.current.SetSelectedGameObject(GameObject.Find("btnStart"));
|
||||
}
|
||||
|
||||
public void startGame(SceneHandler sceneHandler)
|
||||
@@ -96,12 +97,14 @@ namespace Assets.Scripts.Menu
|
||||
{
|
||||
characterCreation.SetActive(true);
|
||||
mainMenu.SetActive(false);
|
||||
EventSystem.current.SetSelectedGameObject(GameObject.Find("inName"));
|
||||
}
|
||||
|
||||
public void closeCharacterCreation()
|
||||
{
|
||||
characterCreation.SetActive(false);
|
||||
mainMenu.SetActive(true);
|
||||
EventSystem.current.SetSelectedGameObject(GameObject.Find("btnStart"));
|
||||
}
|
||||
|
||||
public void openOptions()
|
||||
@@ -109,13 +112,15 @@ namespace Assets.Scripts.Menu
|
||||
options.SetActive(true);
|
||||
mainMenu.SetActive(false);
|
||||
FileHandler.loadOptionDisplay();
|
||||
GameObject.Find("ScrollbarOptions").GetComponent<Scrollbar>().value = 1f;
|
||||
EventSystem.current.SetSelectedGameObject(GameObject.Find("btnAudio"));
|
||||
showOptionView("audio");
|
||||
}
|
||||
|
||||
public void closeOptions()
|
||||
{
|
||||
options.SetActive(false);
|
||||
mainMenu.SetActive(true);
|
||||
EventSystem.current.SetSelectedGameObject(GameObject.Find("btnStart"));
|
||||
}
|
||||
|
||||
public string saveVideoSettings(){
|
||||
@@ -181,5 +186,21 @@ namespace Assets.Scripts.Menu
|
||||
PlayerPrefs.SetInt("isLoad", 1);
|
||||
sceneHandler.openGameScene();
|
||||
}
|
||||
|
||||
public bool isCharacterCreation(){
|
||||
return characterCreation.activeSelf;
|
||||
}
|
||||
|
||||
public void showOptionView(string key){
|
||||
GameObject optionContent = GameObject.Find("pnlContent");
|
||||
for(int i = 0; i < optionContent.transform.childCount; i++){
|
||||
if(optionContent.transform.GetChild(i).name.ToLower().Contains(key)){
|
||||
optionContent.transform.GetChild(i).transform.localScale = new Vector3(1,1,1);
|
||||
}
|
||||
else{
|
||||
optionContent.transform.GetChild(i).transform.localScale = new Vector3(0,0,0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user