startUI告一段落
This commit is contained in:
1 parent
f8154f92b3
commit
da28b62f7f
34 files changed
+17562
-8231
No files matched your search
@@ -4,6 +4,8 @@ using UnityEngine.UI;
|
||||
using UnityEngine.SceneManagement;
|
||||
using TMPro;
|
||||
|
||||
// 流程 : 勾同意書 → 按開始 → 跳出地圖/武器選擇視窗 → 按確認 → 存 JSON → 切到選擇的地圖場景
|
||||
// 測試 : 按測試 → 用目前設定存 JSON → 直接進測試場景 (不記錄資料,不需勾同意書)
|
||||
public class SettingsSaver : MonoBehaviour
|
||||
{
|
||||
[Header("開始與同意書")]
|
||||
@@ -23,13 +25,46 @@ public class SettingsSaver : MonoBehaviour
|
||||
public Slider assistStrengthSlider;
|
||||
public Toggle disableHorizontalToggle;
|
||||
public Toggle disableVerticalToggle;
|
||||
public Slider assistDelaySlider;
|
||||
public Toggle delayJitterToggle;
|
||||
|
||||
[Header("場景")]
|
||||
[Tooltip("要切換到的場景名稱 (需加入 Build Profiles 的場景清單)")]
|
||||
public string gameSceneName = "InGame";
|
||||
[Header("地圖與武器選擇視窗")]
|
||||
[Tooltip("按開始後跳出的視窗 (Panel)")]
|
||||
public GameObject selectPanel;
|
||||
|
||||
[Tooltip("確認開始 Button")]
|
||||
public Button confirmButton;
|
||||
|
||||
[Tooltip("取消 Button")]
|
||||
public Button cancelButton;
|
||||
|
||||
public TMP_Dropdown mapDropdown;
|
||||
public TMP_Dropdown weaponDropdown;
|
||||
|
||||
[Header("選項名稱 (順序對應 Dropdown 選項)")]
|
||||
[Tooltip("地圖的場景名稱 (需加入 Build Profiles 的場景清單)")]
|
||||
public string[] mapSceneNames = { "Forest", "Basement", "Desert" };
|
||||
|
||||
[Tooltip("武器名稱,會存進 JSON")]
|
||||
public string[] weaponNames = { "M1911", "AK74", "Uzi", "Benelli_M4" };
|
||||
|
||||
[Header("測試")]
|
||||
[Tooltip("測試 Button")]
|
||||
public Button testButton;
|
||||
|
||||
[Tooltip("測試場景名稱 (需加入 Build Profiles 的場景清單)")]
|
||||
public string testSceneName = "Test";
|
||||
|
||||
[Tooltip("測試時使用的武器")]
|
||||
public string testWeapon = "M1911";
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (selectPanel != null)
|
||||
{
|
||||
selectPanel.SetActive(false);
|
||||
}
|
||||
|
||||
if (consentToggle != null)
|
||||
{
|
||||
consentToggle.onValueChanged.AddListener(OnConsentChanged);
|
||||
@@ -40,6 +75,21 @@ public class SettingsSaver : MonoBehaviour
|
||||
{
|
||||
startButton.onClick.AddListener(OnStartClicked);
|
||||
}
|
||||
|
||||
if (confirmButton != null)
|
||||
{
|
||||
confirmButton.onClick.AddListener(OnConfirmClicked);
|
||||
}
|
||||
|
||||
if (cancelButton != null)
|
||||
{
|
||||
cancelButton.onClick.AddListener(OnCancelClicked);
|
||||
}
|
||||
|
||||
if (testButton != null)
|
||||
{
|
||||
testButton.onClick.AddListener(OnTestClicked);
|
||||
}
|
||||
}
|
||||
|
||||
void OnConsentChanged(bool isOn)
|
||||
@@ -54,18 +104,47 @@ public class SettingsSaver : MonoBehaviour
|
||||
{
|
||||
if (consentToggle != null && !consentToggle.isOn) return;
|
||||
|
||||
if (selectPanel != null)
|
||||
{
|
||||
selectPanel.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
void OnCancelClicked()
|
||||
{
|
||||
if (selectPanel != null)
|
||||
{
|
||||
selectPanel.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
void OnConfirmClicked()
|
||||
{
|
||||
SaveAndLoad(CollectSettings());
|
||||
}
|
||||
|
||||
void OnTestClicked()
|
||||
{
|
||||
GameSettings settings = CollectSettings();
|
||||
settings.map = testSceneName;
|
||||
settings.weapon = testWeapon;
|
||||
settings.isTest = true;
|
||||
|
||||
SaveAndLoad(settings);
|
||||
}
|
||||
|
||||
void SaveAndLoad(GameSettings settings)
|
||||
{
|
||||
if (!Application.CanStreamedLevelBeLoaded(settings.map))
|
||||
{
|
||||
Debug.LogError($"找不到場景 \"{settings.map}\",請確認已加入 Build Profiles 的場景清單");
|
||||
return;
|
||||
}
|
||||
|
||||
settings.Save();
|
||||
Debug.Log($"設定已存到 : {GameSettings.FilePath}");
|
||||
|
||||
if (Application.CanStreamedLevelBeLoaded(gameSceneName))
|
||||
{
|
||||
SceneManager.LoadScene(gameSceneName);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"找不到場景 \"{gameSceneName}\",請確認已加入 Build Profiles 的場景清單");
|
||||
}
|
||||
SceneManager.LoadScene(settings.map);
|
||||
}
|
||||
|
||||
GameSettings CollectSettings()
|
||||
@@ -83,9 +162,17 @@ public class SettingsSaver : MonoBehaviour
|
||||
{
|
||||
s.assistStrength = Mathf.RoundToInt(assistStrengthSlider.value);
|
||||
}
|
||||
if (assistDelaySlider != null && s.assistMode != 0)
|
||||
{
|
||||
s.assistDelayMs = Mathf.RoundToInt(assistDelaySlider.value);
|
||||
if (delayJitterToggle != null) s.assistDelayJitter = delayJitterToggle.isOn;
|
||||
}
|
||||
if (disableHorizontalToggle != null) s.disableHorizontalAssist = disableHorizontalToggle.isOn;
|
||||
if (disableVerticalToggle != null) s.disableVerticalAssist = disableVerticalToggle.isOn;
|
||||
|
||||
s.map = PickName(mapSceneNames, mapDropdown);
|
||||
s.weapon = PickName(weaponNames, weaponDropdown);
|
||||
|
||||
s.screenWidth = Screen.width;
|
||||
s.screenHeight = Screen.height;
|
||||
s.refreshRate = Mathf.RoundToInt((float)Screen.currentResolution.refreshRateRatio.value);
|
||||
@@ -93,4 +180,13 @@ public class SettingsSaver : MonoBehaviour
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
// 依 Dropdown 目前的選項取出對應名稱,沒接 Dropdown 就用第一個
|
||||
string PickName(string[] names, TMP_Dropdown dropdown)
|
||||
{
|
||||
if (names == null || names.Length == 0) return "";
|
||||
|
||||
int index = dropdown != null ? dropdown.value : 0;
|
||||
return names[Mathf.Clamp(index, 0, names.Length - 1)];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user