(client) feat:添加设置类,子弹添加敌我识别; chore:修改了右键菜单的初始化方式为独立创建,加载定义报错提供更多信息,动画加载出错也返回默认序列。
This commit is contained in:
@ -5,21 +5,27 @@ using UnityEngine;
|
||||
|
||||
namespace Base
|
||||
{
|
||||
|
||||
public class Launcher : MonoBehaviour
|
||||
{
|
||||
public GameObject loadingUI;
|
||||
public Gradient progressBar; // 渐变色条
|
||||
public TMP_Text describeText; // 描述文本
|
||||
|
||||
|
||||
public float duration = 0.5f; // 过渡时间
|
||||
public float fadeDuration = 2f; // 不透明度渐隐的时间
|
||||
private float _currentProgress = 0f; // 当前进度
|
||||
private float duration = 0.5f; // 过渡时间
|
||||
|
||||
private Color textColor;
|
||||
|
||||
private string[] _loadingSteps =
|
||||
|
||||
private readonly string[] _loadingSteps =
|
||||
{
|
||||
"初始化日志", "正在载入定义", "正在加载图片资源", "正在切割瓦片", "正在加载区分派系",
|
||||
"正在加载物品"
|
||||
};
|
||||
|
||||
public float progress
|
||||
public float Progress
|
||||
{
|
||||
set
|
||||
{
|
||||
@ -33,12 +39,32 @@ namespace Base
|
||||
progressBar.color2 = Color.white;
|
||||
progressBar.color1 = Color.Lerp(Color.black, Color.white, (value - 0.5f) * 2);
|
||||
}
|
||||
|
||||
progressBar.Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
public float Opacity
|
||||
{
|
||||
set
|
||||
{
|
||||
var alpha = (byte)(value * 255);
|
||||
progressBar.color1.a = alpha;
|
||||
progressBar.color2.a = alpha;
|
||||
describeText.color = value > 0.5f ? Color.Lerp(new Color(1, 1, 1, 0), textColor, (value - 0.5f) * 2) : new Color(1, 1, 1, 0);
|
||||
progressBar.Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
Base.Setting.Instance.Init();
|
||||
#if !DEBUG
|
||||
duration = Base.Setting.Instance.progressStepDuration;
|
||||
fadeDuration = Base.Setting.Instance.exitAnimationDuration;
|
||||
#endif
|
||||
loadingUI.SetActive(true);
|
||||
textColor = describeText.color;
|
||||
StartCoroutine(LoadAllManagers());
|
||||
}
|
||||
|
||||
@ -81,7 +107,10 @@ namespace Base
|
||||
|
||||
// 加载完成后的处理
|
||||
describeText.text = "加载完成!";
|
||||
progress = 1f;
|
||||
Progress = 1f;
|
||||
|
||||
// 开始渐隐效果
|
||||
yield return FadeOutProgressBar();
|
||||
}
|
||||
|
||||
private IEnumerator SmoothTransitionTo(float targetProgress)
|
||||
@ -93,12 +122,29 @@ namespace Base
|
||||
{
|
||||
elapsedTime += Time.deltaTime;
|
||||
var t = Mathf.SmoothStep(0f, 1f, elapsedTime / duration); // 使用 SmoothStep 实现平滑过渡
|
||||
progress = Mathf.Lerp(startProgress, targetProgress, t);
|
||||
Progress = Mathf.Lerp(startProgress, targetProgress, t);
|
||||
yield return null;
|
||||
}
|
||||
|
||||
// 确保最终进度达到目标值
|
||||
progress = targetProgress;
|
||||
Progress = targetProgress;
|
||||
}
|
||||
|
||||
private IEnumerator FadeOutProgressBar()
|
||||
{
|
||||
var elapsedTime = 0f;
|
||||
|
||||
while (elapsedTime < fadeDuration)
|
||||
{
|
||||
elapsedTime += Time.deltaTime;
|
||||
var t = Mathf.SmoothStep(0f, 1f, elapsedTime / fadeDuration); // 使用 SmoothStep 实现平滑渐隐
|
||||
Opacity = 1f - t; // 不透明度从 1 到 0
|
||||
yield return null;
|
||||
}
|
||||
|
||||
// 确保最终不透明度为 0
|
||||
Opacity = 0f;
|
||||
loadingUI.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using Prefab;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
namespace Base
|
||||
{
|
||||
public class RightMenu : Utils.MonoSingleton<RightMenu>
|
||||
{
|
||||
public RightMenuPrefab rightMenuPrefab;
|
||||
|
||||
public Vector3 Position
|
||||
{
|
||||
set
|
||||
{
|
||||
rightMenuPrefab.transform.position = value;
|
||||
}
|
||||
get
|
||||
{
|
||||
return rightMenuPrefab.transform.position;
|
||||
}
|
||||
}
|
||||
public void Show()
|
||||
{
|
||||
rightMenuPrefab.Show();
|
||||
}
|
||||
|
||||
public void Hide()
|
||||
{
|
||||
rightMenuPrefab.Hide();
|
||||
}
|
||||
public void Init(List<(string name, UnityAction callback)> buttons)
|
||||
{
|
||||
rightMenuPrefab.Init(buttons);
|
||||
}
|
||||
protected override void OnStart()
|
||||
{
|
||||
Hide();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,2 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7f6fd5ff82ab4ce4aae8dd41118277f8
|
90
Client/Assets/Scripts/Base/Setting.cs
Normal file
90
Client/Assets/Scripts/Base/Setting.cs
Normal file
@ -0,0 +1,90 @@
|
||||
using Newtonsoft.Json;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Base
|
||||
{
|
||||
|
||||
|
||||
public class Setting : Utils.Singleton<Setting>
|
||||
{
|
||||
// 游戏设置数据类(用于序列化)
|
||||
[System.Serializable]
|
||||
public class GameSettings
|
||||
{
|
||||
public float progressStepDuration = 1f;
|
||||
public float exitAnimationDuration = 2f;
|
||||
public bool developerMode = false;
|
||||
public bool friendlyFire = false;
|
||||
public float globalVolume = 1.0f;
|
||||
public WindowMode currentWindowMode = WindowMode.Fullscreen;
|
||||
public Vector2Int windowResolution = new(1920, 1080);
|
||||
}
|
||||
|
||||
// 当前游戏设置
|
||||
public GameSettings CurrentSettings = new();
|
||||
|
||||
// 窗口模式枚举
|
||||
public enum WindowMode { Fullscreen, Windowed, Borderless }
|
||||
|
||||
// 常用分辨率选项
|
||||
public static readonly Vector2Int[] CommonResolutions = new Vector2Int[]
|
||||
{
|
||||
new(800, 600),
|
||||
new(1024, 768),
|
||||
new(1280, 720),
|
||||
new(1366, 768),
|
||||
new(1600, 900),
|
||||
new(1920, 1080),
|
||||
new(2560, 1440),
|
||||
new(3840, 2160)
|
||||
};
|
||||
|
||||
// 初始化加载设置
|
||||
public void Init()
|
||||
{
|
||||
LoadSettings();
|
||||
}
|
||||
|
||||
public void SaveSettings()
|
||||
{
|
||||
string json = JsonConvert.SerializeObject(CurrentSettings);
|
||||
PlayerPrefs.SetString("GameSettings", json);
|
||||
PlayerPrefs.Save();
|
||||
}
|
||||
public void LoadSettings()
|
||||
{
|
||||
if (PlayerPrefs.HasKey("GameSettings"))
|
||||
{
|
||||
string json = PlayerPrefs.GetString("GameSettings");
|
||||
CurrentSettings = JsonConvert.DeserializeObject<GameSettings>(json);
|
||||
}
|
||||
|
||||
// 应用加载的设置
|
||||
ApplyAudioSettings();
|
||||
ApplyWindowSettings();
|
||||
}
|
||||
|
||||
// 应用音频设置
|
||||
private void ApplyAudioSettings()
|
||||
{
|
||||
AudioListener.volume = Mathf.Clamp01(CurrentSettings.globalVolume);
|
||||
}
|
||||
|
||||
// 应用窗口设置
|
||||
private void ApplyWindowSettings()
|
||||
{
|
||||
switch (CurrentSettings.currentWindowMode)
|
||||
{
|
||||
case WindowMode.Fullscreen:
|
||||
Screen.SetResolution(CurrentSettings.windowResolution.x, CurrentSettings.windowResolution.y, FullScreenMode.FullScreenWindow);
|
||||
break;
|
||||
case WindowMode.Windowed:
|
||||
Screen.SetResolution(CurrentSettings.windowResolution.x, CurrentSettings.windowResolution.y, FullScreenMode.Windowed);
|
||||
break;
|
||||
case WindowMode.Borderless:
|
||||
Screen.SetResolution(CurrentSettings.windowResolution.x, CurrentSettings.windowResolution.y, FullScreenMode.MaximizedWindow);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
3
Client/Assets/Scripts/Base/Setting.cs.meta
Normal file
3
Client/Assets/Scripts/Base/Setting.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9eb8b1554550478c85cc87558920ec6b
|
||||
timeCreated: 1755524879
|
Reference in New Issue
Block a user