Merge pull request 'SettingsUI' (#7) from SettingsUI into main
Reviewed-on: Mourning-Ravens/UnityBiz#7
This commit is contained in:
commit
75109d02a1
1740
Assets/Scenes/UISettings.unity
Normal file
1740
Assets/Scenes/UISettings.unity
Normal file
File diff suppressed because it is too large
Load Diff
7
Assets/Scenes/UISettings.unity.meta
Normal file
7
Assets/Scenes/UISettings.unity.meta
Normal file
@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5c832ce820a5cde40b28a8c89706a09b
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/scripts/GUI.meta
Normal file
8
Assets/scripts/GUI.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ce85f0b52a21efd49bb88237eda8b0df
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/scripts/GUI/GameplayUI.meta
Normal file
8
Assets/scripts/GUI/GameplayUI.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 01e2282d61a0bb543be33a312c3c4939
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
137
Assets/scripts/GUI/GameplayUI/KeybindingManager.cs
Normal file
137
Assets/scripts/GUI/GameplayUI/KeybindingManager.cs
Normal file
@ -0,0 +1,137 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
public class KeybindingManager : MonoBehaviour
|
||||
{
|
||||
public Button wKeyButton;
|
||||
public Button aKeyButton;
|
||||
public Button sKeyButton;
|
||||
public Button dKeyButton;
|
||||
|
||||
private Dictionary<string, KeyCode> keyMappings = new Dictionary<string, KeyCode>();
|
||||
private string keyToRebind;
|
||||
private string filePath;
|
||||
private bool awaitingKeyInput;
|
||||
|
||||
[System.Serializable]
|
||||
public class KeyMappingData
|
||||
{
|
||||
public string Forward;
|
||||
public string Left;
|
||||
public string Backward;
|
||||
public string Right;
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
string folderName = "KeybindsSave";
|
||||
string folderPath = Path.Combine(Application.persistentDataPath, folderName);
|
||||
|
||||
if (!Directory.Exists(folderPath))
|
||||
{
|
||||
Directory.CreateDirectory(folderPath);
|
||||
}
|
||||
|
||||
filePath = Path.Combine(folderPath, "keybindings.json");
|
||||
|
||||
Debug.Log("Path to keybindings.json: " + filePath);
|
||||
|
||||
LoadKeyMappings();
|
||||
UpdateButtonTexts();
|
||||
|
||||
wKeyButton.onClick.AddListener(() => StartRebinding("Forward"));
|
||||
aKeyButton.onClick.AddListener(() => StartRebinding("Left"));
|
||||
sKeyButton.onClick.AddListener(() => StartRebinding("Backward"));
|
||||
dKeyButton.onClick.AddListener(() => StartRebinding("Right"));
|
||||
|
||||
wKeyButton.interactable = true;
|
||||
aKeyButton.interactable = true;
|
||||
sKeyButton.interactable = true;
|
||||
dKeyButton.interactable = true;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (awaitingKeyInput)
|
||||
{
|
||||
if (Input.anyKeyDown)
|
||||
{
|
||||
foreach (KeyCode key in System.Enum.GetValues(typeof(KeyCode)))
|
||||
{
|
||||
if (Input.GetKeyDown(key))
|
||||
{
|
||||
if (keyMappings.ContainsKey(keyToRebind))
|
||||
{
|
||||
keyMappings[keyToRebind] = key;
|
||||
SaveKeyMappings();
|
||||
keyToRebind = null;
|
||||
awaitingKeyInput = false;
|
||||
UpdateButtonTexts();
|
||||
Debug.Log("Przypisano nowy klawisz: " + keyToRebind + " -> " + key);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void StartRebinding(string key)
|
||||
{
|
||||
keyToRebind = key;
|
||||
awaitingKeyInput = true;
|
||||
Debug.Log("Naciœnij nowy klawisz dla: " + key);
|
||||
}
|
||||
|
||||
private void UpdateButtonTexts()
|
||||
{
|
||||
if (keyMappings.ContainsKey("Forward"))
|
||||
wKeyButton.GetComponentInChildren<Text>().text = keyMappings["Forward"].ToString();
|
||||
if (keyMappings.ContainsKey("Left"))
|
||||
aKeyButton.GetComponentInChildren<Text>().text = keyMappings["Left"].ToString();
|
||||
if (keyMappings.ContainsKey("Backward"))
|
||||
sKeyButton.GetComponentInChildren<Text>().text = keyMappings["Backward"].ToString();
|
||||
if (keyMappings.ContainsKey("Right"))
|
||||
dKeyButton.GetComponentInChildren<Text>().text = keyMappings["Right"].ToString();
|
||||
}
|
||||
|
||||
private void SaveKeyMappings()
|
||||
{
|
||||
KeyMappingData data = new KeyMappingData
|
||||
{
|
||||
Forward = keyMappings["Forward"].ToString(),
|
||||
Left = keyMappings["Left"].ToString(),
|
||||
Backward = keyMappings["Backward"].ToString(),
|
||||
Right = keyMappings["Right"].ToString()
|
||||
};
|
||||
|
||||
string json = JsonUtility.ToJson(data, true);
|
||||
File.WriteAllText(filePath, json);
|
||||
Debug.Log("Zapisano przypisania klawiszy do pliku: " + filePath);
|
||||
}
|
||||
|
||||
private void LoadKeyMappings()
|
||||
{
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
string json = File.ReadAllText(filePath);
|
||||
KeyMappingData data = JsonUtility.FromJson<KeyMappingData>(json);
|
||||
|
||||
keyMappings["Forward"] = (KeyCode)System.Enum.Parse(typeof(KeyCode), data.Forward);
|
||||
keyMappings["Left"] = (KeyCode)System.Enum.Parse(typeof(KeyCode), data.Left);
|
||||
keyMappings["Backward"] = (KeyCode)System.Enum.Parse(typeof(KeyCode), data.Backward);
|
||||
keyMappings["Right"] = (KeyCode)System.Enum.Parse(typeof(KeyCode), data.Right);
|
||||
|
||||
Debug.Log("Wczytano przypisania klawiszy z pliku: " + filePath);
|
||||
}
|
||||
else
|
||||
{
|
||||
keyMappings["Forward"] = KeyCode.W;
|
||||
keyMappings["Left"] = KeyCode.A;
|
||||
keyMappings["Backward"] = KeyCode.S;
|
||||
keyMappings["Right"] = KeyCode.D;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/scripts/GUI/GameplayUI/KeybindingManager.cs.meta
Normal file
11
Assets/scripts/GUI/GameplayUI/KeybindingManager.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d709acfa31ced444d9303b08bac0e5d4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
25
Assets/scripts/GUI/GameplayUI/MouseSensitivityController.cs
Normal file
25
Assets/scripts/GUI/GameplayUI/MouseSensitivityController.cs
Normal file
@ -0,0 +1,25 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class MouseSensitivityController : MonoBehaviour
|
||||
{
|
||||
public Slider sensitivitySlider;
|
||||
private float mouseSensitivity = 1f;
|
||||
|
||||
void Start()
|
||||
{ sensitivitySlider.value = mouseSensitivity;
|
||||
sensitivitySlider.onValueChanged.AddListener(OnSensitivityChanged);
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity;
|
||||
float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity;
|
||||
}
|
||||
|
||||
public void OnSensitivityChanged(float value)
|
||||
{
|
||||
mouseSensitivity = value;
|
||||
Debug.Log("Czu³oœæ myszy zmieniona na: " + mouseSensitivity);
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6b9a5d2dd94a0bf459d33130af0ceb69
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/scripts/GUI/PlayerSettings.meta
Normal file
8
Assets/scripts/GUI/PlayerSettings.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 050858368fa1f0346bc8dd5dde95eedb
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Reference in New Issue
Block a user