finished portal fundimentals
This commit is contained in:
34
Assets/Scripts/GUI/ControlCard.cs
Normal file
34
Assets/Scripts/GUI/ControlCard.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class ControlCard : MonoBehaviour
|
||||
{
|
||||
|
||||
public Command MyCommand;
|
||||
|
||||
[SerializeField] private Text description;
|
||||
[SerializeField] private Text key;
|
||||
|
||||
private RebindMenu rebindMenu;
|
||||
|
||||
public void Populate(Command command, RebindMenu rebindMenu)
|
||||
{
|
||||
this.rebindMenu = rebindMenu;
|
||||
MyCommand = command;
|
||||
Refresh();
|
||||
}
|
||||
|
||||
public void Rebind()
|
||||
{
|
||||
rebindMenu.Open(this);
|
||||
}
|
||||
|
||||
public void Refresh()
|
||||
{
|
||||
description.text = MyCommand.Description;
|
||||
key.text = MyCommand.Key.ToString();
|
||||
}
|
||||
|
||||
}
|
||||
11
Assets/Scripts/GUI/ControlCard.cs.meta
Normal file
11
Assets/Scripts/GUI/ControlCard.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8940b9c7b5c3e474fb41c133c6d5921b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
48
Assets/Scripts/GUI/ControlsMenu.cs
Normal file
48
Assets/Scripts/GUI/ControlsMenu.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class ControlsMenu : MonoBehaviour
|
||||
{
|
||||
|
||||
[Header("Widgets")]
|
||||
[SerializeField] private GameObject mainPanel;
|
||||
[SerializeField] private GameObject scrollContent;
|
||||
[SerializeField] private RebindMenu rebindMenu;
|
||||
|
||||
[Header("Prefabs")]
|
||||
[SerializeField] private ControlCard controlCardPrefab;
|
||||
|
||||
private InputHandler inputHandler;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
inputHandler = FindObjectOfType<InputHandler>();
|
||||
if (inputHandler == null)
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
return;
|
||||
}
|
||||
foreach (Command command in inputHandler.Keymap)
|
||||
{
|
||||
ControlCard card = Instantiate(controlCardPrefab, scrollContent.transform);
|
||||
card.Populate(command, rebindMenu);
|
||||
}
|
||||
Close();
|
||||
}
|
||||
|
||||
public void Open()
|
||||
{
|
||||
mainPanel.SetActive(true);
|
||||
inputHandler.enabled = false;
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
mainPanel.SetActive(false);
|
||||
rebindMenu.Close();
|
||||
inputHandler.enabled = true;
|
||||
}
|
||||
|
||||
}
|
||||
11
Assets/Scripts/GUI/ControlsMenu.cs.meta
Normal file
11
Assets/Scripts/GUI/ControlsMenu.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2a01ec157fbb2184ba9fe507120720d7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
37
Assets/Scripts/GUI/RebindMenu.cs
Normal file
37
Assets/Scripts/GUI/RebindMenu.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class RebindMenu : MonoBehaviour
|
||||
{
|
||||
|
||||
[SerializeField] private Text instruction;
|
||||
|
||||
private ControlCard controlCard;
|
||||
|
||||
public void Open(ControlCard keybindCard)
|
||||
{
|
||||
controlCard = keybindCard;
|
||||
instruction.text = $"Enter new key for\n" +
|
||||
$"{controlCard.MyCommand.Description}";
|
||||
gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
//On GUI provides a convenient method to get keycodes through Event data
|
||||
void OnGUI()
|
||||
{
|
||||
if(!(Event.current.isKey && Input.anyKeyDown))
|
||||
return;
|
||||
|
||||
controlCard.MyCommand.Key = Event.current.keyCode;
|
||||
controlCard.Refresh();
|
||||
Close();
|
||||
}
|
||||
|
||||
}
|
||||
11
Assets/Scripts/GUI/RebindMenu.cs.meta
Normal file
11
Assets/Scripts/GUI/RebindMenu.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bd6df0aacf9fc0649996299244764e42
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user