97 lines
2.8 KiB
C#
97 lines
2.8 KiB
C#
using System;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UnityEngine.SceneManagement;
|
|
using TMPro;
|
|
|
|
public class SettingsSaver : MonoBehaviour
|
|
{
|
|
[Header("開始與同意書")]
|
|
[Tooltip("開始 Button")]
|
|
public Button startButton;
|
|
|
|
[Tooltip("同意書 Toggle,不勾就不能開始")]
|
|
public Toggle consentToggle;
|
|
|
|
[Header("一般設定")]
|
|
public IDManager idManager;
|
|
public Slider sensitivitySlider;
|
|
public Slider fovSlider;
|
|
|
|
[Header("輔助設定")]
|
|
public TMP_Dropdown assistDropdown;
|
|
public Slider assistStrengthSlider;
|
|
public Toggle disableHorizontalToggle;
|
|
public Toggle disableVerticalToggle;
|
|
|
|
[Header("場景")]
|
|
[Tooltip("要切換到的場景名稱 (需加入 Build Profiles 的場景清單)")]
|
|
public string gameSceneName = "InGame";
|
|
|
|
void Start()
|
|
{
|
|
if (consentToggle != null)
|
|
{
|
|
consentToggle.onValueChanged.AddListener(OnConsentChanged);
|
|
OnConsentChanged(consentToggle.isOn);
|
|
}
|
|
|
|
if (startButton != null)
|
|
{
|
|
startButton.onClick.AddListener(OnStartClicked);
|
|
}
|
|
}
|
|
|
|
void OnConsentChanged(bool isOn)
|
|
{
|
|
if (startButton != null)
|
|
{
|
|
startButton.interactable = isOn;
|
|
}
|
|
}
|
|
|
|
void OnStartClicked()
|
|
{
|
|
if (consentToggle != null && !consentToggle.isOn) return;
|
|
|
|
GameSettings settings = CollectSettings();
|
|
settings.Save();
|
|
Debug.Log($"設定已存到 : {GameSettings.FilePath}");
|
|
|
|
if (Application.CanStreamedLevelBeLoaded(gameSceneName))
|
|
{
|
|
SceneManager.LoadScene(gameSceneName);
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError($"找不到場景 \"{gameSceneName}\",請確認已加入 Build Profiles 的場景清單");
|
|
}
|
|
}
|
|
|
|
GameSettings CollectSettings()
|
|
{
|
|
GameSettings s = new GameSettings();
|
|
|
|
if (idManager != null) s.contributorID = idManager.GetFinalContributorID();
|
|
|
|
// 與 Sensitivity.cs 相同的 0.1 階梯
|
|
if (sensitivitySlider != null) s.sensitivity = Mathf.Round(sensitivitySlider.value * 10f) / 10f;
|
|
if (fovSlider != null) s.fov = Mathf.RoundToInt(fovSlider.value);
|
|
|
|
if (assistDropdown != null) s.assistMode = assistDropdown.value;
|
|
if (assistStrengthSlider != null && s.assistMode != 0)
|
|
{
|
|
s.assistStrength = Mathf.RoundToInt(assistStrengthSlider.value);
|
|
}
|
|
if (disableHorizontalToggle != null) s.disableHorizontalAssist = disableHorizontalToggle.isOn;
|
|
if (disableVerticalToggle != null) s.disableVerticalAssist = disableVerticalToggle.isOn;
|
|
|
|
s.screenWidth = Screen.width;
|
|
s.screenHeight = Screen.height;
|
|
s.refreshRate = Mathf.RoundToInt((float)Screen.currentResolution.refreshRateRatio.value);
|
|
s.savedTime = DateTime.Now.ToString("o");
|
|
|
|
return s;
|
|
}
|
|
}
|