添加 BgForm

This commit is contained in:
SepComet
2026-04-18 20:27:12 +08:00
parent fbb9120a42
commit cc5d8edec4
23 changed files with 1128 additions and 166 deletions
@@ -19,6 +19,8 @@ namespace UI
/// </summary>
DialogForm = 1,
BgForm = 2,
/// <summary>
/// 主菜单。
/// </summary>
@@ -53,7 +55,7 @@ namespace UI
/// 气泡剧情对话界面。
/// </summary>
BubbleDialogForm = 106,
MainOverlayForm = 107,
AIChatForm = 108,
@@ -87,6 +87,9 @@ namespace Procedure
case SceneId.Menu:
ChangeState<ProcedureMenu>(procedureOwner);
break;
case SceneId.Main:
ChangeState<ProcedureMain>(procedureOwner);
break;
case SceneId.GameplayA:
ChangeState<ProcedureCombine>(procedureOwner);
break;
@@ -149,4 +152,4 @@ namespace Procedure
ne.DependencyAssetName, ne.LoadedCount.ToString(), ne.TotalCount.ToString());
}
}
}
}
@@ -1,18 +1,21 @@
using System.Collections;
using System.Collections.Generic;
using GameFramework.Fsm;
using GameFramework.Procedure;
using UnityEngine;
public class ProcedureMain : MonoBehaviour
namespace Procedure
{
// Start is called before the first frame update
void Start()
public class ProcedureMain : ProcedureBase
{
}
public override bool UseNativeDialog => false;
// Update is called once per frame
void Update()
{
protected override void OnEnter(IFsm<IProcedureManager> procedureOwner)
{
base.OnEnter(procedureOwner);
GameEntry.Dialog.Init(1);
GameEntry.Dialog.StartDialog(1001);
}
}
}
@@ -24,7 +24,7 @@ namespace Procedure
private SettingFormController _settingFormController;
private const string SettingPrefix = "Setting.";
private bool _gameStarted = false;
private void StartGame()
@@ -78,7 +78,7 @@ namespace Procedure
{
_menuFormController?.CloseUI();
_settingFormController?.CloseUI();
var e = GameEntry.Event;
e.Unsubscribe(MenuStartEventArgs.EventId, MenuStart);
e.Unsubscribe(MenuContinueEventArgs.EventId, MenuContinue);
@@ -96,7 +96,7 @@ namespace Procedure
if (_gameStarted)
{
procedureOwner.SetData<VarInt32>("NextSceneId", (int)SceneId.GameplayA);
procedureOwner.SetData<VarInt32>("NextSceneId", (int)SceneId.Main);
ChangeState<ProcedureChangeScene>(procedureOwner);
}
}
@@ -132,10 +132,10 @@ namespace Procedure
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)
@@ -183,7 +183,7 @@ namespace Procedure
default:
throw new ArgumentOutOfRangeException();
}
if (args.GameSettings.AntiAliasing)
{
foreach (var asset in GraphicsSettings.allConfiguredRenderPipelines)
@@ -201,10 +201,10 @@ namespace Procedure
Application.targetFrameRate = -1;
QualitySettings.vSyncCount = args.GameSettings.VSync ? 1 : 0;
GameEntry.Setting.SaveSetting(args.GameSettings);
}
#endregion
}
}
}
@@ -0,0 +1,11 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace UI
{
public class BgFormContext : UIContext
{
public Sprite Sprite;
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 35695e29b2219844fa8bf1bae0c2bb3e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,127 @@
using GameFramework.Event;
using UnityGameFramework.Runtime;
namespace UI
{
public class BgFormController : IFormController<BgFormContext>
{
private BgFormContext _context;
private BgForm _bgForm;
private int? _formSerialId;
private bool _pendingRefresh;
public BgFormController()
{
GameEntry.Event.Subscribe(OpenUIFormSuccessEventArgs.EventId, OnOpenUIFormSuccess);
GameEntry.Event.Subscribe(CloseUIFormCompleteEventArgs.EventId, OnCloseUIFormComplete);
}
public int? OpenUI(BgFormContext context)
{
if (context == null)
{
Log.Warning("BgFormController open failed. context is null.");
return null;
}
_context = context;
if (_bgForm != null)
{
_bgForm.RefreshUI(_context);
return _formSerialId;
}
CloseUI();
_pendingRefresh = true;
_formSerialId = GameEntry.UI.OpenUIForm(UIFormId.BgForm, context);
return _formSerialId;
}
public void CloseUI()
{
_pendingRefresh = false;
if (_formSerialId.HasValue)
{
GameEntry.UI.CloseUIForm(_formSerialId.Value);
return;
}
if (_bgForm != null)
{
_bgForm.Close();
}
}
~BgFormController()
{
GameEntry.Event.Unsubscribe(OpenUIFormSuccessEventArgs.EventId, OnOpenUIFormSuccess);
GameEntry.Event.Unsubscribe(CloseUIFormCompleteEventArgs.EventId, OnCloseUIFormComplete);
}
private void TryRefreshUI()
{
if (_context == null)
{
return;
}
if (_bgForm == null)
{
_pendingRefresh = true;
return;
}
_bgForm.RefreshUI(_context);
_pendingRefresh = false;
}
private void OnOpenUIFormSuccess(object sender, GameEventArgs e)
{
if (!(e is OpenUIFormSuccessEventArgs args))
{
return;
}
if (!_formSerialId.HasValue)
{
return;
}
if (args.UIForm == null || args.UIForm.SerialId != _formSerialId.Value || args.UserData != _context)
{
return;
}
_bgForm = args.UIForm.Logic as BgForm;
if (_bgForm == null)
{
Log.Warning("AIChatFormController open success but form logic is invalid.");
return;
}
if (_pendingRefresh)
{
TryRefreshUI();
}
}
private void OnCloseUIFormComplete(object sender, GameEventArgs e)
{
if (!(e is CloseUIFormCompleteEventArgs args))
{
return;
}
if (args.SerialId != _formSerialId)
{
return;
}
_bgForm = null;
_formSerialId = null;
_pendingRefresh = false;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5676b59e53ae51b449044f870ba39daa
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+42
View File
@@ -0,0 +1,42 @@
using UnityEngine;
using UnityEngine.UI;
using UnityGameFramework.Runtime;
namespace UI
{
public class BgForm : UGuiForm
{
[SerializeField] private Image _bgImage;
private Sprite _currentSprite;
protected override void OnOpen(object userData)
{
base.OnOpen(userData);
if (!(userData is BgFormContext context))
{
Log.Error("BgFormContext is invalid.");
return;
}
RefreshUI(context);
}
protected override void OnClose(bool isShutdown, object userData)
{
_currentSprite = null;
_bgImage.sprite = null;
base.OnClose(isShutdown, userData);
}
public void RefreshUI(BgFormContext context)
{
if (this._currentSprite == context.Sprite) return;
this._currentSprite = context.Sprite;
_bgImage.sprite = context.Sprite;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 956fafaa81c7caa4c840171e4e4488cd
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: