(client) feat:实现热重载

This commit is contained in:
m0_75251201
2025-08-20 17:55:22 +08:00
parent d91210a6ff
commit 3e099137a1
20 changed files with 8636 additions and 480 deletions

View File

@ -1,7 +1,9 @@
using System.Collections.Generic;
using System.Linq;
using Base;
using Data;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
namespace UI
@ -22,12 +24,19 @@ namespace UI
private void Init()
{
InitReloadGameButton();
InitEvent();
InitCharacter();
InitMonster();
InitBuilding();
}
private void InitReloadGameButton()
{
var button = InstantiatePrefab(buttonTemplate, menuContent.transform);
button.Label = "热重载Def";
button.AddListener(HotReload);
}
private void InitEvent()
{
@ -162,6 +171,13 @@ namespace UI
entityPlacementUI.snapEnabled = true;
Base.UIInputControl.Instance.Show(entityPlacementUI);
}
private void HotReload()
{
UIInputControl.Instance.HideAll();
Program.Instance.needLoad = true;
SceneManager.LoadScene(0);
}
}
}

View File

@ -1,4 +1,6 @@
using Base;
using UnityEngine;
using UnityEngine.SceneManagement;
namespace UI
{
@ -9,7 +11,7 @@ namespace UI
Base.UIInputControl.Instance.Hide(this);
}
public void ExitButton()
public static void ExitButton()
{
#if UNITY_EDITOR
UnityEditor.EditorApplication.isPlaying = false; // 停止编辑器播放模式
@ -18,9 +20,16 @@ namespace UI
#endif
}
public void SettingsButton()
public static void SettingsButton()
{
UIInputControl.Instance.Show("SettingUI");
}
public static void ReturnMainMenu()
{
if (SceneManager.GetActiveScene().buildIndex == 0)
return;
SceneManager.LoadScene(0);
}
}
}

View File

@ -0,0 +1,72 @@
using System.Globalization;
using Base;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace UI
{
public class SettingUI : UIBase
{
[SerializeField] private Scrollbar globalVolume;
[SerializeField] private Toggle developerMode;
[SerializeField] private Toggle friendlyFire;
[SerializeField] private TMP_Dropdown windowMode;
[SerializeField] private TMP_Dropdown windowResolution;
[SerializeField] private TMP_InputField progressStepDuration;
[SerializeField] private TMP_InputField exitAnimationDuration;
Base.Setting.GameSettings currentSettings;
public override void Show()
{
base.Show();
currentSettings = Base.Setting.Instance.CurrentSettings;
globalVolume.value = currentSettings.globalVolume;
developerMode.isOn = currentSettings.developerMode;
friendlyFire.isOn = currentSettings.friendlyFire;
progressStepDuration.text = currentSettings.progressStepDuration.ToString(CultureInfo.InvariantCulture);
exitAnimationDuration.text = currentSettings.exitAnimationDuration.ToString(CultureInfo.InvariantCulture);
windowResolution.ClearOptions();
var options = new System.Collections.Generic.List<TMP_Dropdown.OptionData>();
foreach (var resolution in Base.Setting.CommonResolutions)
{
options.Add(new TMP_Dropdown.OptionData(resolution.ToString()));
}
windowResolution.AddOptions(options);
if (currentSettings.windowResolution != null)
{
int resolutionIndex = System.Array.FindIndex(Base.Setting.CommonResolutions, r => r == currentSettings.windowResolution);
windowResolution.value = resolutionIndex >= 0 ? resolutionIndex : 0;
}
else
{
windowResolution.value = 0;
}
}
public void CancelSettings()
{
UIInputControl.Instance.Hide(this);
}
public void ApplySettings()
{
currentSettings.globalVolume = globalVolume.value;
currentSettings.developerMode = developerMode.isOn;
currentSettings.friendlyFire = friendlyFire.isOn;
currentSettings.currentWindowMode = (Base.Setting.WindowMode)windowMode.value;
currentSettings.windowResolution = Base.Setting.CommonResolutions[windowResolution.value];
currentSettings.progressStepDuration = float.Parse(progressStepDuration.text, CultureInfo.InvariantCulture);
currentSettings.exitAnimationDuration = float.Parse(exitAnimationDuration.text, CultureInfo.InvariantCulture);
Base.Setting.Instance.CurrentSettings = currentSettings;
Base.Setting.Instance.Apply();
}
public void EnterSetting()
{
ApplySettings();
UIInputControl.Instance.Hide(this);
Base.Setting.Instance.SaveSettings();
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 7f4127efa613491894a9b1a7e9918a26
timeCreated: 1755600172