Add background color setting

This commit is contained in:
2025-06-16 14:42:25 -07:00
parent b37db5231e
commit 1abe2ac064
4 changed files with 2935 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -42,6 +42,20 @@ public class GamePlayer : MonoBehaviour
void Awake()
{
var backgroundColor = PlayerPrefs.GetString("BackgroundColor", "58;58;58").Split(";");
try
{
Camera.main.backgroundColor = new Color(
int.Parse(backgroundColor[0])/255f,
int.Parse(backgroundColor[1])/255f,
int.Parse(backgroundColor[2])/255f
);
}
catch
{
Debug.LogError("Invalid BackgroundColor format");
}
lastMoveTime = Time.time;
UnityEngine.InputSystem.EnhancedTouch.EnhancedTouchSupport.Enable();
instance = this;

View File

@@ -0,0 +1,62 @@
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class SettingsMenuBgColorPanel : MonoBehaviour
{
public Slider rSlider;
public Slider gSlider;
public Slider bSlider;
public TMP_InputField hexValue;
public Image previewImage;
public Button resetButton;
void Awake()
{
var backgroundColor = PlayerPrefs.GetString("BackgroundColor", "58;58;58").Split(";");
try
{
rSlider.value = int.Parse(backgroundColor[0]);
gSlider.value = int.Parse(backgroundColor[1]);
bSlider.value = int.Parse(backgroundColor[2]);
}
catch
{
Debug.LogError("Invalid BackgroundColor format");
rSlider.value = 58; gSlider.value = 58; bSlider.value = 58;
}
SlidersChanged();
rSlider.onValueChanged.AddListener(_ => SlidersChanged());
gSlider.onValueChanged.AddListener(_ => SlidersChanged());
bSlider.onValueChanged.AddListener(_ => SlidersChanged());
hexValue.onValueChanged.AddListener(value =>
{
var v = value.StartsWith("#") ? value[1..] : value;
if (v.Length == 6 && ColorUtility.TryParseHtmlString("#" + v, out var col))
{
rSlider.SetValueWithoutNotify(col.r * 255f);
gSlider.SetValueWithoutNotify(col.g * 255f);
bSlider.SetValueWithoutNotify(col.b * 255f);
previewImage.color = col;
PlayerPrefs.SetString("BackgroundColor", $"{(int)(col.r * 255)};{(int)(col.g * 255)};{(int)(col.b * 255)}");
PlayerPrefs.Save();
}
});
resetButton.onClick.AddListener(() =>
{
hexValue.text = "#3a3a3a";
});
}
void SlidersChanged()
{
var col = new Color(rSlider.value/255f, gSlider.value/255f, bSlider.value/255f);
previewImage.color = col;
hexValue.SetTextWithoutNotify($"#{ColorUtility.ToHtmlStringRGB(col)}");
PlayerPrefs.SetString("BackgroundColor", $"{(int)rSlider.value};{(int)gSlider.value};{(int)bSlider.value}");
PlayerPrefs.Save();
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 851d6819986698659a53cdf0cb057649