Merge pull request 'SettingsUI' (#7) from SettingsUI into main

Reviewed-on: Mourning-Ravens/UnityBiz#7
This commit is contained in:
Nukie 2024-09-17 22:56:44 +00:00
commit 75109d02a1
9 changed files with 1955 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 5c832ce820a5cde40b28a8c89706a09b
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

8
Assets/scripts/GUI.meta Normal file
View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ce85f0b52a21efd49bb88237eda8b0df
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 01e2282d61a0bb543be33a312c3c4939
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View 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;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d709acfa31ced444d9303b08bac0e5d4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View 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);
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6b9a5d2dd94a0bf459d33130af0ceb69
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 050858368fa1f0346bc8dd5dde95eedb
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: