20261017
This commit is contained in:
1 parent
caf19faf09
commit
c4b10383f9
18 files changed
+3295
-1524
No files matched your search
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d4fdb1aa5c67c794f8afc4a9916197df
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
|
||||
// StartUI 與 InGame 共用的設定資料,存成 JSON
|
||||
[Serializable]
|
||||
public class GameSettings
|
||||
{
|
||||
// 貢獻者
|
||||
public string contributorID = "Anonymous";
|
||||
|
||||
// 一般設定
|
||||
public float sensitivity = 1.0f;
|
||||
public int fov = 90;
|
||||
|
||||
// 輔助設定 (0 = 無輔助, 1 = 直接移動準心, 2 = 動態靈敏度)
|
||||
public int assistMode = 0;
|
||||
public int assistStrength = 0; // 1~100 (%),無輔助時為 0
|
||||
public bool disableHorizontalAssist = false;
|
||||
public bool disableVerticalAssist = false;
|
||||
|
||||
// 系統資訊
|
||||
public int screenWidth;
|
||||
public int screenHeight;
|
||||
public int refreshRate;
|
||||
public string savedTime; // ISO 8601
|
||||
|
||||
// 檔案位置 : Windows 為 %USERPROFILE%/AppData/LocalLow/<公司>/<產品>/settings.json
|
||||
public static string FilePath => Path.Combine(Application.persistentDataPath, "settings.json");
|
||||
|
||||
public void Save()
|
||||
{
|
||||
File.WriteAllText(FilePath, JsonUtility.ToJson(this, true));
|
||||
}
|
||||
|
||||
// 讀不到檔案就回傳預設值
|
||||
public static GameSettings Load()
|
||||
{
|
||||
if (File.Exists(FilePath))
|
||||
{
|
||||
try
|
||||
{
|
||||
return JsonUtility.FromJson<GameSettings>(File.ReadAllText(FilePath));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogWarning($"讀取設定失敗,改用預設值 : {e.Message}");
|
||||
}
|
||||
}
|
||||
return new GameSettings();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5dff0267e33ca77449f74683ee4cce39
|
||||
@@ -0,0 +1,40 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
|
||||
public class Fov : MonoBehaviour
|
||||
{
|
||||
[Header("UI 參照")]
|
||||
[Tooltip("Slider")]
|
||||
public Slider targetSlider;
|
||||
|
||||
[Tooltip("Text (TMP)")]
|
||||
public TextMeshProUGUI valueDisplayText;
|
||||
|
||||
[Header("預設值")]
|
||||
public int defaultFov = 90;
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (targetSlider != null)
|
||||
{
|
||||
// 與 Apex 相同的範圍
|
||||
targetSlider.minValue = 70f;
|
||||
targetSlider.maxValue = 110f;
|
||||
targetSlider.wholeNumbers = true;
|
||||
targetSlider.value = defaultFov;
|
||||
|
||||
UpdateDisplayText(targetSlider.value);
|
||||
|
||||
targetSlider.onValueChanged.AddListener(UpdateDisplayText);
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateDisplayText(float val)
|
||||
{
|
||||
if (valueDisplayText != null)
|
||||
{
|
||||
valueDisplayText.text = $"FOV : {Mathf.RoundToInt(val)}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c01dc4b4f3335f04a892ab93a70c3e47
|
||||
@@ -0,0 +1,96 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ffe004b22c1ea624694aac6e673483d4
|
||||
@@ -0,0 +1,38 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
// 掛在開始按鈕上 : 按鈕反灰時,滑鼠移上去會顯示提示
|
||||
public class StartButtonHint : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
|
||||
{
|
||||
[Header("UI 參照")]
|
||||
[Tooltip("開始 Button")]
|
||||
public Button targetButton;
|
||||
|
||||
[Tooltip("提示物件 (例如寫著「請閱讀資訊欄並勾選同意書」的 Text 或 Panel)")]
|
||||
public GameObject hintObject;
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (hintObject != null)
|
||||
{
|
||||
hintObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
if (hintObject != null && targetButton != null && !targetButton.interactable)
|
||||
{
|
||||
hintObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
if (hintObject != null)
|
||||
{
|
||||
hintObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4dee269d1934cff4eb46037a8108c44b
|
||||
Reference in new issue
Block a user