- 完善设置面板的具体功能,全局性的设置项已经可以发挥作用了

- 调整部分项目结构和AB包设置,打包测试设置面板的功能
This commit is contained in:
SepComet
2026-02-11 14:58:05 +08:00
parent 13583354f9
commit deb2c01d01
64 changed files with 536 additions and 1536 deletions
@@ -1,17 +1,4 @@
//------------------------------------------------------------
// Game Framework
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
// Homepage: https://gameframework.cn/
// Feedback: mailto:ellan@gameframework.cn
//------------------------------------------------------------
// 此文件由工具自动生成,请勿直接修改。
// 生成时间:2021-06-16 21:54:35.591
//------------------------------------------------------------
using GameFramework;
using System;
using System.Collections.Generic;
using System.IO;
using System.IO;
using System.Text;
using UnityEngine;
using UnityGameFramework.Runtime;
@@ -21,7 +8,7 @@ namespace DataTable
/// <summary>
/// 音乐配置表。
/// </summary>
public class DRMusic : DataRowBase
public class DRBGM : DataRowBase
{
private int m_Id = 0;
@@ -1,7 +1,4 @@
using GameFramework;
using System;
using System.Collections.Generic;
using System.IO;
using System.IO;
using System.Text;
using UnityEngine;
using UnityGameFramework.Runtime;
@@ -11,7 +8,7 @@ namespace DataTable
/// <summary>
/// 声音配置表。
/// </summary>
public class DRUISound : DataRowBase
public class DRSE : DataRowBase
{
private int m_Id = 0;
@@ -1,127 +0,0 @@
using System.IO;
using System.Text;
using UnityGameFramework.Runtime;
namespace DataTable
{
/// <summary>
/// 声音配置表。
/// </summary>
public class DRSound : DataRowBase
{
private int m_Id = 0;
/// <summary>
/// 获取声音编号。
/// </summary>
public override int Id
{
get
{
return m_Id;
}
}
/// <summary>
/// 获取资源名称。
/// </summary>
public string AssetName
{
get;
private set;
}
/// <summary>
/// 获取优先级(默认0,128最高,-128最低)。
/// </summary>
public int Priority
{
get;
private set;
}
/// <summary>
/// 获取是否循环。
/// </summary>
public bool Loop
{
get;
private set;
}
/// <summary>
/// 获取音量(0~1)。
/// </summary>
public float Volume
{
get;
private set;
}
/// <summary>
/// 获取声音空间混合量(0为2D,1为3D,中间值混合效果)。
/// </summary>
public float SpatialBlend
{
get;
private set;
}
/// <summary>
/// 获取声音最大距离。
/// </summary>
public float MaxDistance
{
get;
private set;
}
public override bool ParseDataRow(string dataRowString, object userData)
{
string[] columnStrings = dataRowString.Split(DataTableExtension.DataSplitSeparators);
for (int i = 0; i < columnStrings.Length; i++)
{
columnStrings[i] = columnStrings[i].Trim(DataTableExtension.DataTrimSeparators);
}
int index = 0;
index++;
m_Id = int.Parse(columnStrings[index++]);
index++;
AssetName = columnStrings[index++];
Priority = int.Parse(columnStrings[index++]);
Loop = bool.Parse(columnStrings[index++]);
Volume = float.Parse(columnStrings[index++]);
SpatialBlend = float.Parse(columnStrings[index++]);
MaxDistance = float.Parse(columnStrings[index++]);
GeneratePropertyArray();
return true;
}
public override bool ParseDataRow(byte[] dataRowBytes, int startIndex, int length, object userData)
{
using (MemoryStream memoryStream = new MemoryStream(dataRowBytes, startIndex, length, false))
{
using (BinaryReader binaryReader = new BinaryReader(memoryStream, Encoding.UTF8))
{
m_Id = binaryReader.Read7BitEncodedInt32();
AssetName = binaryReader.ReadString();
Priority = binaryReader.Read7BitEncodedInt32();
Loop = binaryReader.ReadBoolean();
Volume = binaryReader.ReadSingle();
SpatialBlend = binaryReader.ReadSingle();
MaxDistance = binaryReader.ReadSingle();
}
}
GeneratePropertyArray();
return true;
}
private void GeneratePropertyArray()
{
}
}
}
@@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: fc0abcc42a26c844d91d422da22eb94d
timeCreated: 1528026147
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
-9
View File
@@ -1,9 +0,0 @@
fileFormatVersion: 2
guid: 5479812568543994bbbcdbee6c42fce1
folderAsset: yes
timeCreated: 1528026148
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
@@ -1,86 +0,0 @@
//------------------------------------------------------------
// Game Framework
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
// Homepage: https://gameframework.cn/
// Feedback: mailto:ellan@gameframework.cn
//------------------------------------------------------------
using Definition;
using GameFramework.Debugger;
using GameFramework.Localization;
using UnityEngine;
using UnityGameFramework.Runtime;
namespace StarForce
{
public class ChangeLanguageDebuggerWindow : IDebuggerWindow
{
private Vector2 m_ScrollPosition = Vector2.zero;
private bool m_NeedRestart = false;
public void Initialize(params object[] args)
{
}
public void Shutdown()
{
}
public void OnEnter()
{
}
public void OnLeave()
{
}
public void OnUpdate(float elapseSeconds, float realElapseSeconds)
{
if (m_NeedRestart)
{
m_NeedRestart = false;
UnityGameFramework.Runtime.GameEntry.Shutdown(ShutdownType.Restart);
}
}
public void OnDraw()
{
m_ScrollPosition = GUILayout.BeginScrollView(m_ScrollPosition);
{
DrawSectionChangeLanguage();
}
GUILayout.EndScrollView();
}
private void DrawSectionChangeLanguage()
{
GUILayout.Label("<b>Change Language</b>");
GUILayout.BeginHorizontal("box");
{
if (GUILayout.Button("Chinese Simplified", GUILayout.Height(30)))
{
GameEntry.Localization.Language = Language.ChineseSimplified;
SaveLanguage();
}
if (GUILayout.Button("Chinese Traditional", GUILayout.Height(30)))
{
GameEntry.Localization.Language = Language.ChineseTraditional;
SaveLanguage();
}
if (GUILayout.Button("English", GUILayout.Height(30)))
{
GameEntry.Localization.Language = Language.English;
SaveLanguage();
}
}
GUILayout.EndHorizontal();
}
private void SaveLanguage()
{
GameEntry.Setting.SetString(Constant.Setting.Language, GameEntry.Localization.Language.ToString());
GameEntry.Setting.Save();
m_NeedRestart = true;
}
}
}
@@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: 278a7992e66d1ea4081597614f912f3d
timeCreated: 1528026148
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -11,15 +11,18 @@ namespace Definition
{
public static class Setting
{
public const string Language = "Setting.Language";
public const string SoundGroupMuted = "Setting.{0}Muted";
public const string SoundGroupVolume = "Setting.{0}Volume";
public const string MusicMuted = "Setting.MusicMuted";
public const string MusicVolume = "Setting.MusicVolume";
public const string SoundMuted = "Setting.SoundMuted";
public const string SoundVolume = "Setting.SoundVolume";
public const string UISoundMuted = "Setting.UISoundMuted";
public const string UISoundVolume = "Setting.UISoundVolume";
public const string BGMVolume = "Setting.BGMVolume";
public const string SEVolume = "Setting.SEVolume";
public const string AllowShake = "Setting.AllowShake";
public const string AllowBlink = "Setting.AllowBlink";
public const string DialogWindowAlpha = "Setting.DialogWindowAlpha";
public const string DialogPlayingSpeed = "Setting.PlayingSpeed";
public const string ScreenSolution = "Setting.ScreenSolution";
public const string ScreenWindow = "Setting.ScreenWindow";
public const string VSync = "Setting.VSync";
public const string AntiAliasing = "Setting.AntiAliasing";
}
}
}
@@ -38,7 +38,7 @@ namespace Definition.DataStruct
/// <summary>
/// 对话播放速度
/// </summary>
public DialogPlayingSpeed PlayingSpeed { get; set; }
public DialogPlayingSpeed DialogPlayingSpeed { get; set; }
#endregion
@@ -47,7 +47,7 @@ namespace Definition.DataStruct
/// <summary>
/// 屏幕分辨率
/// </summary>
public ScreenSolutionType ScreenSolution { get; set; }
public ScreenResolutionType ScreenResolution { get; set; }
/// <summary>
/// 屏幕窗口模式
@@ -15,14 +15,20 @@ namespace Definition.Enum
High
}
public enum ScreenSolutionType : byte
public enum ScreenResolutionType : byte
{
_1280x720,
_1366x768,
_1600x900,
_1920x1080,
_2560x1440,
_2560x1600
}
public enum ScreenWindowType : byte
{
NoneBoard,
Window,
FullScreen
Borderless,
FullScreen,
Windowed,
}
}
@@ -11,7 +11,7 @@ namespace Event
public override int Id => EventId;
public GameSetting? GameSettings;
public GameSetting GameSettings;
public SettingSaveEventArgs()
{
@@ -26,7 +26,7 @@ namespace Event
public override void Clear()
{
GameSettings = null;
GameSettings = new GameSetting();
}
}
}
@@ -4,7 +4,7 @@ using Definition;
using Definition.Enum;
using GameFramework.DataTable;
using GameFramework.Event;
using StarForce;
using Sound;
using UnityGameFramework.Runtime;
using ProcedureOwner = GameFramework.Fsm.IFsm<GameFramework.Procedure.IProcedureManager>;
@@ -57,7 +57,8 @@ namespace Procedure
return;
}
GameEntry.Scene.LoadScene(AssetUtility.GetSceneAsset(drScene.AssetName), Constant.AssetPriority.SceneAsset, this);
GameEntry.Scene.LoadScene(AssetUtility.GetSceneAsset(drScene.AssetName), Constant.AssetPriority.SceneAsset,
this);
_backgroundMusicId = drScene.BackgroundMusicId;
}
@@ -83,6 +84,9 @@ namespace Procedure
SceneId sceneId = (SceneId)_nextSceneId;
switch (sceneId)
{
case SceneId.Menu:
ChangeState<ProcedureMenu>(procedureOwner);
break;
case SceneId.GameplayA:
ChangeState<ProcedureCombine>(procedureOwner);
break;
@@ -105,7 +109,7 @@ namespace Procedure
if (_backgroundMusicId > 0)
{
GameEntry.Sound.PlayMusic(_backgroundMusicId);
GameEntry.Sound.PlayBGM(_backgroundMusicId);
}
_isChangeSceneComplete = true;
@@ -141,7 +145,8 @@ namespace Procedure
return;
}
Log.Info("Load scene '{0}' dependency asset '{1}', count '{2}/{3}'.", ne.SceneAssetName, ne.DependencyAssetName, ne.LoadedCount.ToString(), ne.TotalCount.ToString());
Log.Info("Load scene '{0}' dependency asset '{1}', count '{2}/{3}'.", ne.SceneAssetName,
ne.DependencyAssetName, ne.LoadedCount.ToString(), ne.TotalCount.ToString());
}
}
}
}
@@ -1,7 +1,5 @@
using GameFramework.Localization;
using System;
using Definition;
using StarForce;
using Definition;
using Sound;
using UnityGameFramework.Runtime;
using ProcedureOwner = GameFramework.Fsm.IFsm<GameFramework.Procedure.IProcedureManager>;
@@ -17,19 +15,10 @@ namespace Procedure
// 构建信息:发布版本时,把一些数据以 Json 的格式写入 Assets/GameMain/Configs/BuildInfo.txt,供游戏逻辑读取
GameEntry.BuiltinData.InitBuildInfo();
// 语言配置:设置当前使用的语言,如果不设置,则默认使用操作系统语言
InitLanguageSettings();
// 变体配置:根据使用的语言,通知底层加载对应的资源变体
InitCurrentVariant();
// 声音配置:根据用户配置数据,设置即将使用的声音选项
InitSoundSettings();
// 默认字典:加载默认字典文件 Assets/GameMain/Configs/DefaultDictionary.xml
// 此字典文件记录了资源更新前使用的各种语言的字符串,会随 App 一起发布,故不可更新
GameEntry.BuiltinData.InitDefaultDictionary();
// GameEntry.BuiltinData.InitDefaultDictionary();
}
protected override void OnUpdate(ProcedureOwner procedureOwner, float elapseSeconds, float realElapseSeconds)
@@ -39,89 +28,5 @@ namespace Procedure
// 运行一帧即切换到 Splash 展示流程
ChangeState<ProcedureSplash>(procedureOwner);
}
private void InitLanguageSettings()
{
if (GameEntry.Base.EditorResourceMode && GameEntry.Base.EditorLanguage != Language.Unspecified)
{
// 编辑器资源模式直接使用 Inspector 上设置的语言
return;
}
Language language = GameEntry.Localization.Language;
if (GameEntry.Setting.HasSetting(Constant.Setting.Language))
{
try
{
string languageString = GameEntry.Setting.GetString(Constant.Setting.Language);
language = (Language)Enum.Parse(typeof(Language), languageString);
}
catch
{
}
}
if (language != Language.English
&& language != Language.ChineseSimplified
&& language != Language.ChineseTraditional
&& language != Language.Korean)
{
// 若是暂不支持的语言,则使用英语
language = Language.English;
GameEntry.Setting.SetString(Constant.Setting.Language, language.ToString());
GameEntry.Setting.Save();
}
GameEntry.Localization.Language = language;
Log.Info("Init language settings complete, current language is '{0}'.", language.ToString());
}
private void InitCurrentVariant()
{
if (GameEntry.Base.EditorResourceMode)
{
// 编辑器资源模式不使用 AssetBundle,也就没有变体了
return;
}
string currentVariant = null;
switch (GameEntry.Localization.Language)
{
case Language.English:
currentVariant = "en-us";
break;
case Language.ChineseSimplified:
currentVariant = "zh-cn";
break;
case Language.ChineseTraditional:
currentVariant = "zh-tw";
break;
case Language.Korean:
currentVariant = "ko-kr";
break;
default:
currentVariant = "zh-cn";
break;
}
GameEntry.Resource.SetCurrentVariant(currentVariant);
Log.Info("Init current variant complete.");
}
private void InitSoundSettings()
{
GameEntry.Sound.Mute("Music", GameEntry.Setting.GetBool(Constant.Setting.MusicMuted, false));
GameEntry.Sound.SetVolume("Music", GameEntry.Setting.GetFloat(Constant.Setting.MusicVolume, 0.3f));
GameEntry.Sound.Mute("Sound", GameEntry.Setting.GetBool(Constant.Setting.SoundMuted, false));
GameEntry.Sound.SetVolume("Sound", GameEntry.Setting.GetFloat(Constant.Setting.SoundVolume, 1f));
GameEntry.Sound.Mute("UISound", GameEntry.Setting.GetBool(Constant.Setting.UISoundMuted, false));
GameEntry.Sound.SetVolume("UISound", GameEntry.Setting.GetFloat(Constant.Setting.UISoundVolume, 1f));
Log.Info("Init sound settings complete.");
}
}
}
@@ -1,14 +1,19 @@
using GameFramework;
using System;
using GameFramework;
using GameFramework.Event;
using GameFramework.Resource;
using System.Collections.Generic;
using System.Linq;
using CustomUtility;
using DataTable;
using Definition;
using Definition.Enum;
using Setting;
using Sound;
using TMPro;
using UI;
using UnityEngine;
using UnityEngine.Rendering;
using UnityGameFramework.Runtime;
using ProcedureOwner = GameFramework.Fsm.IFsm<GameFramework.Procedure.IProcedureManager>;
@@ -19,11 +24,10 @@ namespace Procedure
public static readonly string[] DataTableNames = new string[]
{
"Entity",
"Music",
"BGM",
"Scene",
"Sound",
"UIForm",
"UISound",
"SE",
"Dialog",
"DialogLine"
};
@@ -72,15 +76,12 @@ namespace Procedure
}
}
procedureOwner.SetData<VarInt32>("NextSceneId", (int)SceneId.Main);
procedureOwner.SetData<VarInt32>("NextSceneId", (int)SceneId.Menu);
ChangeState<ProcedureChangeScene>(procedureOwner);
}
private void PreloadResources()
{
// Preload configs
LoadConfig("DefaultConfig");
// Preload data tables
foreach (string dataTableName in DataTableNames)
{
@@ -88,18 +89,13 @@ namespace Procedure
}
// Preload dictionaries
LoadDictionary("Default");
// LoadDictionary("Default");
// Preload fonts
LoadFont("MainFont");
LoadTMPFont("MainTMPFont");
}
private void LoadConfig(string configName)
{
string configAssetName = AssetUtility.GetConfigAsset(configName, false);
_loadedFlag.Add(configAssetName, false);
GameEntry.Config.ReadData(configAssetName, this);
LoadSetting();
}
private void LoadDataTable(string dataTableName)
@@ -152,6 +148,81 @@ namespace Procedure
}));
}
private void LoadSetting()
{
var setting = GameEntry.Setting.GetGameSetting();
GameEntry.Sound.SetVolume("BGM", setting.BGMVolume);
GameEntry.Sound.SetVolume("SE", setting.SEVolume);
ScreenResolutionType resolution = setting.ScreenResolution;
int width = 0, height = 0;
switch (resolution)
{
case ScreenResolutionType._1280x720:
width = 1280;
height = 720;
break;
case ScreenResolutionType._1366x768:
width = 1366;
height = 768;
break;
case ScreenResolutionType._1600x900:
width = 1600;
height = 900;
break;
case ScreenResolutionType._1920x1080:
width = 1920;
height = 1080;
break;
case ScreenResolutionType._2560x1440:
width = 2560;
height = 1440;
break;
case ScreenResolutionType._2560x1600:
width = 2560;
height = 1600;
break;
default:
throw new ArgumentOutOfRangeException();
}
ScreenWindowType resolutionWindow = setting.ScreenWindow;
switch (resolutionWindow)
{
case ScreenWindowType.FullScreen:
Screen.SetResolution(width, height, FullScreenMode.ExclusiveFullScreen);
break;
case ScreenWindowType.Borderless:
Screen.SetResolution(width, height, FullScreenMode.FullScreenWindow);
break;
case ScreenWindowType.Windowed:
Screen.SetResolution(width, height, FullScreenMode.Windowed);
break;
default:
throw new ArgumentOutOfRangeException();
}
Application.targetFrameRate = -1;
QualitySettings.vSyncCount = setting.VSync ? 1 : 0;
if (setting.AntiAliasing)
{
foreach (var asset in GraphicsSettings.allConfiguredRenderPipelines)
{
if (asset.name == "URP-AntiAliasing") GraphicsSettings.renderPipelineAsset = asset;
}
}
else
{
foreach (var asset in GraphicsSettings.allConfiguredRenderPipelines)
{
if (asset.name == "URP-Normal") GraphicsSettings.renderPipelineAsset = asset;
}
}
}
#region Event Hanlders
private void OnLoadConfigSuccess(object sender, GameEventArgs e)
{
LoadConfigSuccessEventArgs ne = (LoadConfigSuccessEventArgs)e;
@@ -223,5 +294,7 @@ namespace Procedure
Log.Error("Can not load dictionary '{0}' from '{1}' with error message '{2}'.", ne.DictionaryAssetName,
ne.DictionaryAssetName, ne.ErrorMessage);
}
#endregion
}
}
@@ -1,6 +1,15 @@
using System;
using Definition.DataStruct;
using Definition.Enum;
using Event;
using GameFramework.Event;
using GameFramework.Fsm;
using GameFramework.Procedure;
using Setting;
using Sound;
using UI;
using UnityEngine;
using UnityEngine.Rendering;
namespace Procedure
@@ -11,18 +20,64 @@ namespace Procedure
private MenuFormController _menuFormController;
private SettingFormController _settingFormController;
private const string SettingPrefix = "Setting.";
private void StartGame()
{
}
private void LoadGame()
{
}
private void OpenSettingForm()
{
if (_settingFormController == null)
{
_settingFormController = new SettingFormController();
}
var settingContext = new SettingFormContext
{
Setting = GameEntry.Setting.GetGameSetting()
};
_settingFormController.OpenUI(settingContext);
}
private void ExitGame()
{
Application.Quit();
}
#region FSM
protected override void OnEnter(IFsm<IProcedureManager> procedureOwner)
{
base.OnEnter(procedureOwner);
var e = GameEntry.Event;
e.Subscribe(MenuStartEventArgs.EventId, MenuStart);
e.Subscribe(MenuContinueEventArgs.EventId, MenuContinue);
e.Subscribe(MenuSettingEventArgs.EventId, MenuSetting);
e.Subscribe(MenuExitEventArgs.EventId, MenuExit);
e.Subscribe(SettingSaveEventArgs.EventId, SettingSave);
_menuFormController = new MenuFormController();
_menuFormController.OpenUI(new MenuFormContext());
}
protected override void OnLeave(IFsm<IProcedureManager> procedureOwner, bool isShutdown)
{
var e = GameEntry.Event;
e.Unsubscribe(MenuStartEventArgs.EventId, MenuStart);
e.Unsubscribe(MenuContinueEventArgs.EventId, MenuContinue);
e.Unsubscribe(MenuSettingEventArgs.EventId, MenuSetting);
e.Unsubscribe(MenuExitEventArgs.EventId, MenuExit);
e.Unsubscribe(SettingSaveEventArgs.EventId, SettingSave);
base.OnLeave(procedureOwner, isShutdown);
}
@@ -33,5 +88,107 @@ namespace Procedure
}
#endregion
#region Event Handlers
private void MenuStart(object sender, GameEventArgs e)
{
if (!(e is MenuStartEventArgs)) return;
}
private void MenuContinue(object sender, GameEventArgs e)
{
if (!(e is MenuContinueEventArgs)) return;
}
private void MenuSetting(object sender, GameEventArgs e)
{
if (!(e is MenuSettingEventArgs)) return;
OpenSettingForm();
}
private void MenuExit(object sender, GameEventArgs e)
{
if (!(e is MenuExitEventArgs)) return;
ExitGame();
}
private void SettingSave(object sender, GameEventArgs e)
{
if (!(e is SettingSaveEventArgs args)) return;
GameEntry.Sound.SetVolume("BGM", args.GameSettings.BGMVolume);
GameEntry.Sound.SetVolume("SE", args.GameSettings.SEVolume);
ScreenResolutionType resolution = args.GameSettings.ScreenResolution;
int width = 0, height = 0;
switch (resolution)
{
case ScreenResolutionType._1280x720:
width = 1280;
height = 720;
break;
case ScreenResolutionType._1366x768:
width = 1366;
height = 768;
break;
case ScreenResolutionType._1600x900:
width = 1600;
height = 900;
break;
case ScreenResolutionType._1920x1080:
width = 1920;
height = 1080;
break;
case ScreenResolutionType._2560x1440:
width = 2560;
height = 1440;
break;
case ScreenResolutionType._2560x1600:
width = 2560;
height = 1600;
break;
default:
throw new ArgumentOutOfRangeException();
}
ScreenWindowType resolutionWindow = args.GameSettings.ScreenWindow;
switch (resolutionWindow)
{
case ScreenWindowType.FullScreen:
Screen.SetResolution(width, height, FullScreenMode.ExclusiveFullScreen);
break;
case ScreenWindowType.Borderless:
Screen.SetResolution(width, height, FullScreenMode.FullScreenWindow);
break;
case ScreenWindowType.Windowed:
Screen.SetResolution(width, height, FullScreenMode.Windowed);
break;
default:
throw new ArgumentOutOfRangeException();
}
if (args.GameSettings.AntiAliasing)
{
foreach (var asset in GraphicsSettings.allConfiguredRenderPipelines)
{
if (asset.name == "URP-AntiAliasing") GraphicsSettings.renderPipelineAsset = asset;
}
}
else
{
foreach (var asset in GraphicsSettings.allConfiguredRenderPipelines)
{
if (asset.name == "URP-Normal") GraphicsSettings.renderPipelineAsset = asset;
}
}
Application.targetFrameRate = -1;
QualitySettings.vSyncCount = args.GameSettings.VSync ? 1 : 0;
GameEntry.Setting.SaveSetting(args.GameSettings);
}
#endregion
}
}
+15 -78
View File
@@ -1,33 +1,25 @@
//------------------------------------------------------------
// Game Framework
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
// Homepage: https://gameframework.cn/
// Feedback: mailto:ellan@gameframework.cn
//------------------------------------------------------------
using CustomUtility;
using CustomUtility;
using DataTable;
using Definition;
using Entity;
using GameFramework;
using GameFramework.DataTable;
using GameFramework.Sound;
using UnityGameFramework.Runtime;
namespace StarForce
namespace Sound
{
public static class SoundExtension
{
private const float FadeVolumeDuration = 1f;
private static int? s_MusicSerialId = null;
public static int? PlayMusic(this SoundComponent soundComponent, int musicId, object userData = null)
public static int? PlayBGM(this SoundComponent soundComponent, int musicId, object userData = null)
{
soundComponent.StopMusic();
IDataTable<DRMusic> dtMusic = GameEntry.DataTable.GetDataTable<DRMusic>();
DRMusic drMusic = dtMusic.GetDataRow(musicId);
if (drMusic == null)
IDataTable<DRBGM> dtMusic = GameEntry.DataTable.GetDataTable<DRBGM>();
DRBGM drBgm = dtMusic.GetDataRow(musicId);
if (drBgm == null)
{
Log.Warning("Can not load music '{0}' from data table.", musicId.ToString());
return null;
@@ -39,7 +31,8 @@ namespace StarForce
playSoundParams.VolumeInSoundGroup = 1f;
playSoundParams.FadeInSeconds = FadeVolumeDuration;
playSoundParams.SpatialBlend = 0f;
s_MusicSerialId = soundComponent.PlaySound(AssetUtility.GetMusicAsset(drMusic.AssetName), "Music", Constant.AssetPriority.MusicAsset, playSoundParams, null, userData);
s_MusicSerialId = soundComponent.PlaySound(AssetUtility.GetMusicAsset(drBgm.AssetName), "BGM",
Constant.AssetPriority.MusicAsset, playSoundParams, null, userData);
return s_MusicSerialId;
}
@@ -54,28 +47,10 @@ namespace StarForce
s_MusicSerialId = null;
}
public static int? PlaySound(this SoundComponent soundComponent, int soundId, EntityBase bindingEntity = null, object userData = null)
public static int? PlaySE(this SoundComponent soundComponent, int uiSoundId, object userData = null)
{
IDataTable<DRSound> dtSound = GameEntry.DataTable.GetDataTable<DRSound>();
DRSound drSound = dtSound.GetDataRow(soundId);
if (drSound == null)
{
Log.Warning("Can not load sound '{0}' from data table.", soundId.ToString());
return null;
}
PlaySoundParams playSoundParams = PlaySoundParams.Create();
playSoundParams.Priority = drSound.Priority;
playSoundParams.Loop = drSound.Loop;
playSoundParams.VolumeInSoundGroup = drSound.Volume;
playSoundParams.SpatialBlend = drSound.SpatialBlend;
return soundComponent.PlaySound(AssetUtility.GetSoundAsset(drSound.AssetName), "Sound", Constant.AssetPriority.SoundAsset, playSoundParams, bindingEntity != null ? bindingEntity.Entity : null, userData);
}
public static int? PlayUISound(this SoundComponent soundComponent, int uiSoundId, object userData = null)
{
IDataTable<DRUISound> dtUISound = GameEntry.DataTable.GetDataTable<DRUISound>();
DRUISound drUISound = dtUISound.GetDataRow(uiSoundId);
IDataTable<DRSE> dtUISound = GameEntry.DataTable.GetDataTable<DRSE>();
DRSE drUISound = dtUISound.GetDataRow(uiSoundId);
if (drUISound == null)
{
Log.Warning("Can not load UI sound '{0}' from data table.", uiSoundId.ToString());
@@ -87,46 +62,8 @@ namespace StarForce
playSoundParams.Loop = false;
playSoundParams.VolumeInSoundGroup = drUISound.Volume;
playSoundParams.SpatialBlend = 0f;
return soundComponent.PlaySound(AssetUtility.GetUISoundAsset(drUISound.AssetName), "UISound", Constant.AssetPriority.UISoundAsset, playSoundParams, userData);
}
public static bool IsMuted(this SoundComponent soundComponent, string soundGroupName)
{
if (string.IsNullOrEmpty(soundGroupName))
{
Log.Warning("Sound group is invalid.");
return true;
}
ISoundGroup soundGroup = soundComponent.GetSoundGroup(soundGroupName);
if (soundGroup == null)
{
Log.Warning("Sound group '{0}' is invalid.", soundGroupName);
return true;
}
return soundGroup.Mute;
}
public static void Mute(this SoundComponent soundComponent, string soundGroupName, bool mute)
{
if (string.IsNullOrEmpty(soundGroupName))
{
Log.Warning("Sound group is invalid.");
return;
}
ISoundGroup soundGroup = soundComponent.GetSoundGroup(soundGroupName);
if (soundGroup == null)
{
Log.Warning("Sound group '{0}' is invalid.", soundGroupName);
return;
}
soundGroup.Mute = mute;
GameEntry.Setting.SetBool(Utility.Text.Format(Constant.Setting.SoundGroupMuted, soundGroupName), mute);
GameEntry.Setting.Save();
return soundComponent.PlaySound(AssetUtility.GetUISoundAsset(drUISound.AssetName), "SE",
Constant.AssetPriority.UISoundAsset, playSoundParams, userData);
}
public static float GetVolume(this SoundComponent soundComponent, string soundGroupName)
@@ -164,8 +101,8 @@ namespace StarForce
soundGroup.Volume = volume;
GameEntry.Setting.SetFloat(Utility.Text.Format(Constant.Setting.SoundGroupVolume, soundGroupName), volume);
GameEntry.Setting.SetFloat($"Setting.{soundGroup}Volume", volume);
GameEntry.Setting.Save();
}
}
}
}
@@ -25,6 +25,7 @@ namespace UI
return null;
}
context.Controller = this;
_context = context;
if (_settingForm != null)
+3 -18
View File
@@ -1,13 +1,6 @@
//------------------------------------------------------------
// Game Framework
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
// Homepage: https://gameframework.cn/
// Feedback: mailto:ellan@gameframework.cn
//------------------------------------------------------------
using System.Collections;
using System.Collections;
using System.Collections.Generic;
using StarForce;
using Sound;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
@@ -51,7 +44,7 @@ namespace UI
public void PlayUISound(int uiSoundId)
{
GameEntry.Sound.PlayUISound(uiSoundId);
GameEntry.Sound.PlaySE(uiSoundId);
}
public static void SetMainFont(Font mainFont)
@@ -108,10 +101,6 @@ namespace UI
foreach (var text in tmp_texts)
{
text.font = _mainTMPFont;
if (!string.IsNullOrEmpty(text.text))
{
text.text = GameEntry.Localization.GetString(text.text);
}
}
}
@@ -125,10 +114,6 @@ namespace UI
foreach (var text in texts)
{
text.font = _mainFont;
if (!string.IsNullOrEmpty(text.text))
{
text.text = GameEntry.Localization.GetString(text.text);
}
}
}
}
@@ -46,15 +46,15 @@ namespace UI
var setting = context.Setting;
_bgmVolumeSlider.value = setting.BGMVolume;
_seVolumeSlider.value = setting.SEVolume;
_bgmVolumeSlider.value = setting.BGMVolume * 4;
_seVolumeSlider.value = setting.SEVolume * 4;
_allowBlinkGroup.SetValue(setting.AllowBlink);
_allowShakeGroup.SetValue(setting.AllowShake);
_dialogWindowAlpha.SetValue((int)setting.DialogWindowAlpha);
_playingSpeed.SetValue((int)setting.PlayingSpeed);
_playingSpeed.SetValue((int)setting.DialogPlayingSpeed);
_screenSolution.SetValue((int)setting.ScreenSolution);
_screenSolution.SetValue((int)setting.ScreenResolution);
_screenWindow.SetValue((int)setting.ScreenWindow);
_vSyncGroup.SetValue(setting.VSync);
_antiAliasingGroup.SetValue(setting.AntiAliasing);
@@ -77,15 +77,15 @@ namespace UI
{
var setting = new GameSetting
{
BGMVolume = _bgmVolumeSlider.value,
SEVolume = _seVolumeSlider.value,
BGMVolume = _bgmVolumeSlider.value / 4,
SEVolume = _seVolumeSlider.value / 4,
AllowShake = _allowShakeGroup.GetBoolValue(),
AllowBlink = _allowBlinkGroup.GetBoolValue(),
DialogWindowAlpha = (DialogWindowAlpha)_dialogWindowAlpha.GetIntValue(),
PlayingSpeed = (DialogPlayingSpeed)_playingSpeed.GetIntValue(),
DialogPlayingSpeed = (DialogPlayingSpeed)_playingSpeed.GetIntValue(),
ScreenSolution = (ScreenSolutionType)_screenSolution.GetIntValue(),
ScreenResolution = (ScreenResolutionType)_screenSolution.GetIntValue(),
ScreenWindow = (ScreenWindowType)_screenWindow.GetIntValue(),
VSync = _vSyncGroup.GetBoolValue(),
AntiAliasing = _antiAliasingGroup.GetBoolValue()
@@ -129,6 +129,7 @@ namespace UI
{
var setting = CollectSetting();
GameEntry.Event.Fire(this, SettingSaveEventArgs.Create(setting));
_controller.CloseUI();
}
}
}