mirror of
https://github.com/Leahnaya/TheKingsRace.git
synced 2026-08-20 17:37:08 -05:00
Merge branch 'bindKeys' into main
This commit is contained in:
39
Assets/Scripts/UI/ControlsMenuScript.cs
Normal file
39
Assets/Scripts/UI/ControlsMenuScript.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class ControlsMenuScript : MonoBehaviour
|
||||
{
|
||||
public GameObject keyboardControlsMenu;
|
||||
public GameObject gamePadControlsMenu;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
//if vertical input from right analog
|
||||
if (Input.GetAxis("KingVerticalMouseMove") != 0 || Input.GetAxis("KingHorizontalMouseMove") != 0)
|
||||
{
|
||||
//if off, turn it on
|
||||
if(gamePadControlsMenu.activeInHierarchy == false)
|
||||
{
|
||||
keyboardControlsMenu.SetActive(false);
|
||||
gamePadControlsMenu.SetActive(true);
|
||||
}
|
||||
}
|
||||
//check if mouse movement if so (turn off pointer)
|
||||
if (Input.GetAxis("Mouse X") != 0 || Input.GetAxis("Mouse Y") != 0)
|
||||
{
|
||||
if (keyboardControlsMenu.activeInHierarchy == false)
|
||||
{
|
||||
keyboardControlsMenu.SetActive(true);
|
||||
gamePadControlsMenu.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/UI/ControlsMenuScript.cs.meta
Normal file
11
Assets/Scripts/UI/ControlsMenuScript.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9de3cdadb48fc5443bf46a58d7e6bd9b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
59
Assets/Scripts/UI/GameManager.cs
Normal file
59
Assets/Scripts/UI/GameManager.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class GameManager : MonoBehaviour
|
||||
{
|
||||
public static GameManager GM;
|
||||
|
||||
//values for runner
|
||||
//probably shouldn't rebind this
|
||||
//public KeyCode glide;
|
||||
[SerializeField]
|
||||
public Dictionary<string,KeyCode> bindableActions = new Dictionary<string, KeyCode>();
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (GM == null)
|
||||
{
|
||||
DontDestroyOnLoad(gameObject);
|
||||
GM = this;
|
||||
}
|
||||
else if (GM != this)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
|
||||
|
||||
//for keyboard
|
||||
/* walkForward = (KeyCode)System.Enum.Parse(typeof(KeyCode), PlayerPrefs.GetString("walkForwardKey", "W"));
|
||||
walkBackward = (KeyCode)System.Enum.Parse(typeof(KeyCode), PlayerPrefs.GetString("walkBackwardKey", "S"));
|
||||
walkLeft = (KeyCode)System.Enum.Parse(typeof(KeyCode), PlayerPrefs.GetString("walkLeftKey", "A"));
|
||||
walkRight = (KeyCode)System.Enum.Parse(typeof(KeyCode), PlayerPrefs.GetString("walkRightKey", "D"));*/
|
||||
KeyCode jump = (KeyCode)System.Enum.Parse(typeof(KeyCode), PlayerPrefs.GetString("jumpKey", "Space"));
|
||||
KeyCode kick = (KeyCode)System.Enum.Parse(typeof(KeyCode), PlayerPrefs.GetString("kickKey", "F"));
|
||||
KeyCode slide = (KeyCode)System.Enum.Parse(typeof(KeyCode), PlayerPrefs.GetString("slideKey", "Q"));
|
||||
KeyCode dash = (KeyCode)System.Enum.Parse(typeof(KeyCode), PlayerPrefs.GetString("dashKey", "R"));
|
||||
KeyCode nitro = (KeyCode)System.Enum.Parse(typeof(KeyCode), PlayerPrefs.GetString("nitroKey", "LeftShift"));
|
||||
KeyCode grapple = (KeyCode)System.Enum.Parse(typeof(KeyCode), PlayerPrefs.GetString("grappleKey", "E"));
|
||||
|
||||
|
||||
bindableActions.Add("jumpKey", jump);
|
||||
bindableActions.Add("kickKey", kick);
|
||||
bindableActions.Add("slideKey", slide);
|
||||
bindableActions.Add("dashKey", dash);
|
||||
bindableActions.Add("nitroKey", nitro);
|
||||
bindableActions.Add("grappleKey", grapple);
|
||||
}
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/UI/GameManager.cs.meta
Normal file
11
Assets/Scripts/UI/GameManager.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5df0ae8b0ae70844496f4608ba6d6747
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -47,4 +47,8 @@ public class OptionsMenu : MonoBehaviour {
|
||||
public void OnReturnToTitleClicked() {
|
||||
SceneManager.LoadScene("TitleScene");
|
||||
}
|
||||
public void GoToControls()
|
||||
{
|
||||
SceneManager.LoadScene("Controls");
|
||||
}
|
||||
}
|
||||
|
||||
171
Assets/Scripts/UI/RebindManager.cs
Normal file
171
Assets/Scripts/UI/RebindManager.cs
Normal file
@@ -0,0 +1,171 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class RebindManager : MonoBehaviour
|
||||
{
|
||||
Event keyEvent;
|
||||
KeyCode newKey;
|
||||
GameObject currentButtonObject;
|
||||
//const array of valid input
|
||||
readonly KeyCode[] valildKeys = {KeyCode.Q, KeyCode.E, KeyCode.R, KeyCode.F, KeyCode.LeftShift, KeyCode.Space};
|
||||
|
||||
|
||||
//currently waiting for input from user
|
||||
bool waitingForKey;
|
||||
bool hasPressedValidKey = false;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
waitingForKey = false;
|
||||
//go through all buttons and set correct image
|
||||
//for
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
void OnGUI()
|
||||
{
|
||||
keyEvent = Event.current;
|
||||
//if is a key event
|
||||
if (keyEvent.isKey)
|
||||
{
|
||||
//if waiting for a key and the key entered is valid
|
||||
if (waitingForKey && isValidKey(keyEvent.keyCode))
|
||||
{
|
||||
newKey = keyEvent.keyCode;
|
||||
waitingForKey = false;
|
||||
hasPressedValidKey = true;
|
||||
//Debug.Log("right key");
|
||||
}
|
||||
}
|
||||
}
|
||||
public void SendCurrentButton(GameObject gameObject)
|
||||
{
|
||||
currentButtonObject = gameObject;
|
||||
}
|
||||
public void StartAssignment(string keyName)
|
||||
{
|
||||
if (!waitingForKey)
|
||||
{
|
||||
StartCoroutine(AssignKey(keyName));
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
IEnumerator waitForKey()
|
||||
{
|
||||
//if it gets past here it has a keycode, but we also want to double check if it is one of the 10 keys we
|
||||
//TO-DO add controller keys
|
||||
//Debug.Log("waiting");
|
||||
while (hasPressedValidKey == false)
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
public bool isValidKey(KeyCode keycode)
|
||||
{
|
||||
bool hasValue = false;
|
||||
for(int i =0; i < valildKeys.Length; i++) {
|
||||
if(valildKeys[i] == keycode)
|
||||
{
|
||||
hasValue = true;
|
||||
}
|
||||
}
|
||||
return hasValue;
|
||||
}
|
||||
public bool areThereDuplicates()
|
||||
{
|
||||
bool duplicateExists = false;
|
||||
List<KeyCode> tHolder = new List<KeyCode>();
|
||||
foreach (var item in GameManager.GM.bindableActions)
|
||||
{
|
||||
tHolder.Add(item.Value);
|
||||
}
|
||||
|
||||
/* foreach (var item in tHolder)
|
||||
{
|
||||
Debug.Log(item);
|
||||
}*/
|
||||
|
||||
for(int i=0; i < tHolder.Count - 1; i++)
|
||||
{
|
||||
for(int j=i+1; j < tHolder.Count; j++)
|
||||
{
|
||||
if(tHolder[i] == tHolder[j])
|
||||
{
|
||||
|
||||
duplicateExists = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return duplicateExists;
|
||||
}
|
||||
public IEnumerator AssignKey(string keyName)
|
||||
{
|
||||
waitingForKey = true;
|
||||
yield return waitForKey();
|
||||
|
||||
//could be a bit more dyanmic, but it is sufficeint solution for goal
|
||||
switch (keyName)
|
||||
{
|
||||
//player prefs are used to keep key binds after game has closed (won't do anything until then). They are commented out for now for SGX
|
||||
case "jump":
|
||||
GameManager.GM.bindableActions["jumpKey"] = newKey;
|
||||
//replace image of button
|
||||
//currentButtonObject.GetComponent<Image>().sprite =
|
||||
//PlayerPrefs.SetString("jumpKey", GameManager.GM.bindableActions["jumpKey"].ToString());
|
||||
//revert flag
|
||||
hasPressedValidKey = false;
|
||||
break;
|
||||
case "kick":
|
||||
GameManager.GM.bindableActions["kickKey"] = newKey;
|
||||
//replace image of button
|
||||
//currentButtonObject.GetComponent<Image>().sprite =
|
||||
//PlayerPrefs.SetString("kickKey", GameManager.GM.bindableActions["kickKey"].ToString());
|
||||
//revert flag
|
||||
hasPressedValidKey = false;
|
||||
break;
|
||||
case "slide":
|
||||
GameManager.GM.bindableActions["slideKey"] = newKey;
|
||||
//replace image of button
|
||||
//currentButtonObject.GetComponent<Image>().sprite =
|
||||
//PlayerPrefs.SetString("slideKey", GameManager.GM.bindableActions["slideKey"].ToString());
|
||||
//revert flag
|
||||
hasPressedValidKey = false;
|
||||
break;
|
||||
case "dash":
|
||||
GameManager.GM.bindableActions["dashKey"] = newKey;
|
||||
//replace image of button
|
||||
//currentButtonObject.GetComponent<Image>().sprite =
|
||||
//PlayerPrefs.SetString("dashKey", GameManager.GM.bindableActions["dashKey"].ToString());
|
||||
//revert flag
|
||||
hasPressedValidKey = false;
|
||||
break;
|
||||
case "nitro":
|
||||
GameManager.GM.bindableActions["nitroKey"] = newKey;
|
||||
//replace image of button
|
||||
//currentButtonObject.GetComponent<Image>().sprite =
|
||||
//PlayerPrefs.SetString("nitroKey", GameManager.GM.bindableActions["nitroKey"].ToString());
|
||||
//revert flag
|
||||
hasPressedValidKey = false;
|
||||
break;
|
||||
case "grapple":
|
||||
GameManager.GM.bindableActions["grappleKey"] = newKey;
|
||||
//replace image of button
|
||||
//currentButtonObject.GetComponent<Image>().sprite =
|
||||
//PlayerPrefs.SetString("grappleKey", GameManager.GM.bindableActions["grappleKey"].ToString());
|
||||
//revert flag
|
||||
hasPressedValidKey = false;
|
||||
break;
|
||||
}
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/UI/RebindManager.cs.meta
Normal file
11
Assets/Scripts/UI/RebindManager.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ad99f686b83c15c40a0741b75afb37a2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -5,7 +5,7 @@ using UnityEngine.SceneManagement;
|
||||
|
||||
public class ReturnToTitle : MonoBehaviour
|
||||
{
|
||||
public void backToTitle(){
|
||||
SceneManager.LoadScene("TitleScene");
|
||||
public void backToSettings(){
|
||||
SceneManager.LoadScene("Options");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user