引入 UISerializationRoot 和 Item
- 完成 MenuForm 和 SelectRoleForm 的迁移
This commit is contained in:
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 88a351268ca28c14fb18659fe3d042d3
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,80 +0,0 @@
|
||||
using SepCore.Definition;
|
||||
using SepCore.Event;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
namespace SepCore.UI
|
||||
{
|
||||
public class MenuForm : UGuiForm
|
||||
{
|
||||
[SerializeField] private GameObject _defaultButton;
|
||||
|
||||
public void RefreshUI(MenuContext context)
|
||||
{
|
||||
if (EventSystem.current.currentSelectedGameObject != _defaultButton)
|
||||
{
|
||||
EventSystem.current.SetSelectedGameObject(this._defaultButton);
|
||||
}
|
||||
}
|
||||
|
||||
#region Lifecycle
|
||||
|
||||
protected override void OnOpen(object userData)
|
||||
{
|
||||
base.OnOpen(userData);
|
||||
|
||||
if (userData is MenuContext context)
|
||||
{
|
||||
RefreshUI(context);
|
||||
return;
|
||||
}
|
||||
|
||||
Log.Warning("MenuForm requires MenuFormContext as userData.");
|
||||
}
|
||||
|
||||
protected override void OnClose(bool isShutdown, object userData)
|
||||
{
|
||||
base.OnClose(isShutdown, userData);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
// 以下方法被 MenuForm.prefab 中的 Button.onClick 通过名称反射绑定。
|
||||
// 重命名前需同步修改 prefab 中的 m_MethodName 引用。
|
||||
public void OnStartButtonClick()
|
||||
{
|
||||
FireButtonClick(MenuButtonId.StartGame);
|
||||
}
|
||||
|
||||
public void OnFileButtonClick()
|
||||
{
|
||||
FireButtonClick(MenuButtonId.File);
|
||||
}
|
||||
|
||||
public void OnGuideButtonClick()
|
||||
{
|
||||
FireButtonClick(MenuButtonId.Guide);
|
||||
}
|
||||
|
||||
public void OnSettingButtonClick()
|
||||
{
|
||||
FireButtonClick(MenuButtonId.Setting);
|
||||
}
|
||||
|
||||
public void OnQuitButtonClick()
|
||||
{
|
||||
FireButtonClick(MenuButtonId.Quit);
|
||||
}
|
||||
|
||||
public void OnAboutButtonClick()
|
||||
{
|
||||
FireButtonClick(MenuButtonId.About);
|
||||
}
|
||||
|
||||
private void FireButtonClick(MenuButtonId button)
|
||||
{
|
||||
GameEntry.Event.Fire(this, MenuButtonClickEventArgs.Create(button));
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -34,7 +34,7 @@ namespace SepCore.UI
|
||||
{
|
||||
if (userData != null)
|
||||
{
|
||||
Log.Warning("MenuController.OpenUIAsync() userData type is invalid.");
|
||||
Log.Error("MenuController.OpenUIAsync() userData type is invalid.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
using SepCore.Definition;
|
||||
using SepCore.Event;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
namespace SepCore.UI
|
||||
{
|
||||
public partial class MenuForm
|
||||
{
|
||||
private bool _listenersBound;
|
||||
|
||||
public void RefreshUI(MenuContext context)
|
||||
{
|
||||
EnsureButtonListeners();
|
||||
|
||||
if (EventSystem.current.currentSelectedGameObject != View.startButton.gameObject)
|
||||
{
|
||||
EventSystem.current.SetSelectedGameObject(View.startButton.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
#region Lifecycle
|
||||
|
||||
protected override void OnOpen(object userData)
|
||||
{
|
||||
base.OnOpen(userData);
|
||||
|
||||
if (userData is not MenuContext context)
|
||||
{
|
||||
Log.Error("MenuForm requires MenuContext as userData.");
|
||||
return;
|
||||
}
|
||||
|
||||
RefreshUI(context);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private void EnsureButtonListeners()
|
||||
{
|
||||
if (_listenersBound)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_listenersBound = true;
|
||||
|
||||
View.startButton.onClick.AddListener(OnStartButtonClick);
|
||||
View.fileButton.onClick.AddListener(OnFileButtonClick);
|
||||
View.guideButton.onClick.AddListener(OnGuideButtonClick);
|
||||
View.settingButton.onClick.AddListener(OnSettingButtonClick);
|
||||
View.quitButton.onClick.AddListener(OnQuitButtonClick);
|
||||
View.aboutButton.onClick.AddListener(OnAboutButtonClick);
|
||||
}
|
||||
|
||||
private void OnStartButtonClick()
|
||||
{
|
||||
FireButtonClick(MenuButtonId.StartGame);
|
||||
}
|
||||
|
||||
private void OnFileButtonClick()
|
||||
{
|
||||
FireButtonClick(MenuButtonId.File);
|
||||
}
|
||||
|
||||
private void OnGuideButtonClick()
|
||||
{
|
||||
FireButtonClick(MenuButtonId.Guide);
|
||||
}
|
||||
|
||||
private void OnSettingButtonClick()
|
||||
{
|
||||
FireButtonClick(MenuButtonId.Setting);
|
||||
}
|
||||
|
||||
private void OnQuitButtonClick()
|
||||
{
|
||||
FireButtonClick(MenuButtonId.Quit);
|
||||
}
|
||||
|
||||
private void OnAboutButtonClick()
|
||||
{
|
||||
FireButtonClick(MenuButtonId.About);
|
||||
}
|
||||
|
||||
private void FireButtonClick(MenuButtonId button)
|
||||
{
|
||||
GameEntry.Event.Fire(this, MenuButtonClickEventArgs.Create(button));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// <auto-generated />
|
||||
using UnityEngine;
|
||||
|
||||
namespace SepCore.UI
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
public partial class MenuForm : UGuiForm
|
||||
{
|
||||
[SerializeField] private MenuView _view = null;
|
||||
|
||||
public MenuView View => _view;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e82dc413a4cd277429ec1e3f2de69434
|
||||
guid: 8b02c5e7bddd2ab418026de1527b5e25
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -0,0 +1,16 @@
|
||||
// <auto-generated />
|
||||
using UnityEngine;
|
||||
|
||||
namespace SepCore.UI
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
public partial class MenuView : MonoBehaviour
|
||||
{
|
||||
[SerializeField] public global::SepCore.UI.CommonButton startButton;
|
||||
[SerializeField] public global::SepCore.UI.CommonButton fileButton;
|
||||
[SerializeField] public global::SepCore.UI.CommonButton guideButton;
|
||||
[SerializeField] public global::SepCore.UI.CommonButton settingButton;
|
||||
[SerializeField] public global::SepCore.UI.CommonButton quitButton;
|
||||
[SerializeField] public global::SepCore.UI.CommonButton aboutButton;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 35de2974f065de547952f8d5cbb9f6fe
|
||||
guid: 47c8b7ced811ef448ad8b07d5cafdfc7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 77da285af8f83814084722c2bbda3198
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,46 +0,0 @@
|
||||
using Cysharp.Threading.Tasks;
|
||||
using SepCore.AsyncTask;
|
||||
using SepCore.Event;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace SepCore.UI
|
||||
{
|
||||
public class RoleItem : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Image _roleImage = null;
|
||||
|
||||
private RoleItemContext _context = null;
|
||||
|
||||
public async UniTaskVoid OnInit(RoleItemContext context)
|
||||
{
|
||||
_context = context;
|
||||
if (_context == null || string.IsNullOrEmpty(_context.IconName))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_roleImage.sprite = await SpriteLoader.LoadSpriteByKeyAsync(_context.IconName);
|
||||
}
|
||||
|
||||
public void OnReset()
|
||||
{
|
||||
_context = null;
|
||||
}
|
||||
|
||||
public void OnHoverEnter()
|
||||
{
|
||||
if (_context == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
GameEntry.Event.Fire(this, SelectRoleHoverEventArgs.Create(_context.RoleName));
|
||||
}
|
||||
|
||||
public void OnConfirmRoleClick()
|
||||
{
|
||||
GameEntry.Event.Fire(this, SelectRoleConfirmEventArgs.Create());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
namespace SepCore.UI
|
||||
{
|
||||
public class RoleItemContext : UIContext
|
||||
{
|
||||
public string RoleName;
|
||||
public string IconName;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0337fd9faf4a5b44eb95858bff44c015
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,37 +0,0 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace SepCore.UI
|
||||
{
|
||||
public class RolePropertyArea : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private TMP_Text _roleNameText;
|
||||
|
||||
[SerializeField] private RawImage _roleAvatar;
|
||||
|
||||
[SerializeField] private TMP_Text _roleInitialPropertyText;
|
||||
|
||||
[SerializeField] private Transform _roleInitialItemParent;
|
||||
|
||||
private RolePropertyAreaContext _context;
|
||||
|
||||
public void OnInit(RolePropertyAreaContext context)
|
||||
{
|
||||
_context = context;
|
||||
if (_context == null)
|
||||
{
|
||||
OnReset();
|
||||
return;
|
||||
}
|
||||
|
||||
_roleNameText.text = _context.RoleName;
|
||||
_roleInitialPropertyText.text = _context.InitialPropertyText;
|
||||
}
|
||||
|
||||
public void OnReset(object userData = null)
|
||||
{
|
||||
_context = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
namespace SepCore.UI
|
||||
{
|
||||
public class RolePropertyAreaContext : UIContext
|
||||
{
|
||||
public string RoleName;
|
||||
public string InitialPropertyText;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8f37335b27f20c647a0a6175226c0b45
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,9 +0,0 @@
|
||||
namespace SepCore.UI
|
||||
{
|
||||
public class SelectRoleContext : UIContext
|
||||
{
|
||||
public RoleItemContext[] RoleItemContexts;
|
||||
public RolePropertyAreaContext RolePropertyAreaContext;
|
||||
public bool ShowRoleProperty;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6c34d5aa87925ee41b70887958e7611c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,223 +0,0 @@
|
||||
using Cysharp.Threading.Tasks;
|
||||
using SepCore.Event;
|
||||
using SepCore.Definition;
|
||||
using SepCore.CustomUtility;
|
||||
using GameFramework.Event;
|
||||
using UnityEngine;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
namespace SepCore.UI
|
||||
{
|
||||
public class SelectRoleController : UIControllerBase<SelectRoleContext, SelectRoleForm>
|
||||
{
|
||||
private SelectRoleUseCase _useCase;
|
||||
|
||||
protected override UIFormType UIFormType => UIFormType.SelectRoleForm;
|
||||
|
||||
protected override void RefreshUI(SelectRoleForm form, SelectRoleContext context)
|
||||
{
|
||||
form.RefreshUI(context);
|
||||
}
|
||||
|
||||
protected override void SubscribeCustomEvents()
|
||||
{
|
||||
GameEntry.Event.Subscribe(SelectRoleReturnEventArgs.EventId, OnSelectRoleReturn);
|
||||
GameEntry.Event.Subscribe(SelectRoleHoverEventArgs.EventId, OnSelectRoleHover);
|
||||
GameEntry.Event.Subscribe(SelectRoleClearEventArgs.EventId, OnSelectRoleClear);
|
||||
GameEntry.Event.Subscribe(SelectRoleConfirmEventArgs.EventId, OnSelectRoleConfirm);
|
||||
}
|
||||
|
||||
protected override void UnsubscribeCustomEvents()
|
||||
{
|
||||
GameEntry.Event.Unsubscribe(SelectRoleReturnEventArgs.EventId, OnSelectRoleReturn);
|
||||
GameEntry.Event.Unsubscribe(SelectRoleHoverEventArgs.EventId, OnSelectRoleHover);
|
||||
GameEntry.Event.Unsubscribe(SelectRoleClearEventArgs.EventId, OnSelectRoleClear);
|
||||
GameEntry.Event.Unsubscribe(SelectRoleConfirmEventArgs.EventId, OnSelectRoleConfirm);
|
||||
}
|
||||
|
||||
private static SelectRoleContext BuildContext(SelectRoleRawData rawData)
|
||||
{
|
||||
if (rawData == null)
|
||||
{
|
||||
Log.Error("SelectRoleController.BuildContext() rawData is null.");
|
||||
return null;
|
||||
}
|
||||
|
||||
int count = rawData.RoleItems?.Length ?? 0;
|
||||
RoleItemContext[] roleItems = new RoleItemContext[count];
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
RoleItemRawData itemRawData = rawData.RoleItems[i];
|
||||
roleItems[i] = new RoleItemContext
|
||||
{
|
||||
RoleName = itemRawData.RoleName,
|
||||
IconName = itemRawData.IconName
|
||||
};
|
||||
}
|
||||
|
||||
RolePropertyAreaContext propertyContext = null;
|
||||
if (rawData.SelectedRole != null)
|
||||
{
|
||||
propertyContext = new RolePropertyAreaContext
|
||||
{
|
||||
RoleName = rawData.SelectedRole.Name,
|
||||
InitialPropertyText = ItemDescUtility.CreatePropDescription(rawData.SelectedRole.InitialProperties)
|
||||
?? string.Empty
|
||||
};
|
||||
}
|
||||
|
||||
return new SelectRoleContext
|
||||
{
|
||||
RoleItemContexts = roleItems,
|
||||
RolePropertyAreaContext = propertyContext,
|
||||
ShowRoleProperty = propertyContext != null
|
||||
};
|
||||
}
|
||||
|
||||
public override async UniTask OpenUIAsync(object userData = null, float timeout = 30f)
|
||||
{
|
||||
if (userData is SelectRoleRawData rawData)
|
||||
{
|
||||
await OpenUIAsync(rawData, timeout);
|
||||
return;
|
||||
}
|
||||
|
||||
if (userData != null)
|
||||
{
|
||||
Log.Warning("SelectRoleController.OpenUIAsync() userData type is invalid.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (_useCase == null)
|
||||
{
|
||||
Log.Error("SelectRoleController.OpenUIAsync() useCase is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
SelectRoleRawData initialRawData = _useCase.CreateModel();
|
||||
await OpenUIAsync(initialRawData, timeout);
|
||||
}
|
||||
|
||||
public async UniTask OpenUIAsync(SelectRoleRawData rawData, float timeout = 30f)
|
||||
{
|
||||
SelectRoleContext context = BuildContext(rawData);
|
||||
await OpenFormAsync(context, timeout);
|
||||
}
|
||||
|
||||
public override void BindUseCase(IUIUseCase useCase)
|
||||
{
|
||||
if (useCase is not SelectRoleUseCase selectRoleUseCase)
|
||||
{
|
||||
Log.Error("SelectRoleController.BindUseCase() useCase is invalid.");
|
||||
return;
|
||||
}
|
||||
|
||||
_useCase = selectRoleUseCase;
|
||||
}
|
||||
|
||||
private bool IsCurrentFormEventSender(object sender)
|
||||
{
|
||||
if (sender is SelectRoleForm selectRoleForm)
|
||||
{
|
||||
return selectRoleForm == Form;
|
||||
}
|
||||
|
||||
if (sender is Component component && Form != null)
|
||||
{
|
||||
return component.transform.IsChildOf(Form.transform);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void OnSelectRoleReturn(object sender, GameEventArgs e)
|
||||
{
|
||||
if (e is not SelectRoleReturnEventArgs)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!IsCurrentFormEventSender(sender))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
CloseUIAsync().Forget();
|
||||
}
|
||||
|
||||
private void OnSelectRoleHover(object sender, GameEventArgs e)
|
||||
{
|
||||
if (e is not SelectRoleHoverEventArgs args)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!IsCurrentFormEventSender(sender))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
OnSelectRoleHoverAsync(args).Forget();
|
||||
}
|
||||
|
||||
private async UniTaskVoid OnSelectRoleHoverAsync(SelectRoleHoverEventArgs args)
|
||||
{
|
||||
if (_useCase == null)
|
||||
{
|
||||
Log.Error("SelectRoleController.OnSelectRoleHoverAsync() useCase is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
SelectRoleRawData rawData = _useCase.SelectRole(args.RoleName);
|
||||
await OpenUIAsync(rawData);
|
||||
}
|
||||
|
||||
private void OnSelectRoleClear(object sender, GameEventArgs e)
|
||||
{
|
||||
if (e is not SelectRoleClearEventArgs)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!IsCurrentFormEventSender(sender))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
OnSelectRoleClearAsync().Forget();
|
||||
}
|
||||
|
||||
private async UniTaskVoid OnSelectRoleClearAsync()
|
||||
{
|
||||
if (_useCase == null)
|
||||
{
|
||||
Log.Error("SelectRoleController.OnSelectRoleClearAsync() useCase is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
SelectRoleRawData rawData = _useCase.ClearSelection();
|
||||
await OpenUIAsync(rawData);
|
||||
}
|
||||
|
||||
private void OnSelectRoleConfirm(object sender, GameEventArgs e)
|
||||
{
|
||||
if (e is not SelectRoleConfirmEventArgs)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!IsCurrentFormEventSender(sender))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_useCase == null)
|
||||
{
|
||||
Log.Error("SelectRoleController.OnSelectRoleConfirm() useCase is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
_useCase.ConfirmSelectedRole();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ff46cd6b508b0304a801223cbae79419
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,107 +0,0 @@
|
||||
using SepCore.Event;
|
||||
using UnityEngine;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
namespace SepCore.UI
|
||||
{
|
||||
public class SelectRoleForm : UGuiForm
|
||||
{
|
||||
[SerializeField] private GameObject _randomRoleCard = null;
|
||||
|
||||
[SerializeField] private GameObject _roleCard = null;
|
||||
|
||||
[SerializeField] private RolePropertyArea _propertyArea = null;
|
||||
|
||||
private SelectRoleContext _context = null;
|
||||
|
||||
private RoleItem[] _roleItems = null;
|
||||
|
||||
public void RefreshUI(SelectRoleContext context)
|
||||
{
|
||||
_context = context;
|
||||
|
||||
RoleItemContext[] roleContexts = _context.RoleItemContexts;
|
||||
for (int i = 0; i < _roleItems.Length; i++)
|
||||
{
|
||||
RoleItem item = _roleItems[i];
|
||||
if (i < roleContexts.Length)
|
||||
{
|
||||
item.OnInit(roleContexts[i]).Forget();
|
||||
item.gameObject.SetActive(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
item.OnReset();
|
||||
item.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
UpdateShowRole(_context.ShowRoleProperty, _context.RolePropertyAreaContext);
|
||||
}
|
||||
|
||||
#region FSM
|
||||
|
||||
protected override void OnInit(object userData)
|
||||
{
|
||||
base.OnInit(userData);
|
||||
_roleItems = this.transform.GetComponentsInChildren<RoleItem>();
|
||||
}
|
||||
|
||||
protected override void OnOpen(object userData)
|
||||
{
|
||||
base.OnOpen(userData);
|
||||
|
||||
if (userData is SelectRoleContext context)
|
||||
{
|
||||
RefreshUI(context);
|
||||
return;
|
||||
}
|
||||
|
||||
Log.Warning("SelectRoleForm requires SelectRoleFormContext as userData.");
|
||||
}
|
||||
|
||||
protected override void OnClose(bool isShutdown, object userData)
|
||||
{
|
||||
base.OnClose(isShutdown, userData);
|
||||
|
||||
_context = null;
|
||||
foreach (var item in _roleItems)
|
||||
{
|
||||
item.OnReset();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private void UpdateShowRole(bool showRoleProperty, RolePropertyAreaContext propertyAreaContext)
|
||||
{
|
||||
if (!showRoleProperty)
|
||||
{
|
||||
_randomRoleCard.SetActive(true);
|
||||
_roleCard.SetActive(false);
|
||||
_propertyArea.OnReset();
|
||||
}
|
||||
else
|
||||
{
|
||||
_randomRoleCard.SetActive(false);
|
||||
_propertyArea.OnInit(propertyAreaContext);
|
||||
_roleCard.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnReturnButtonClick()
|
||||
{
|
||||
GameEntry.Event.Fire(this, SelectRoleReturnEventArgs.Create());
|
||||
}
|
||||
|
||||
public void OnRandomConfirmClick()
|
||||
{
|
||||
GameEntry.Event.Fire(this, SelectRoleConfirmEventArgs.Create());
|
||||
}
|
||||
|
||||
public void OnRandomHoverEnter()
|
||||
{
|
||||
GameEntry.Event.Fire(this, SelectRoleClearEventArgs.Create());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 665710bc9ed5c5547a40f0cc2d92ba2e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4f719ae636cc2724b94a834ae2407353
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,189 +0,0 @@
|
||||
//------------------------------------------------------------
|
||||
// Game Framework
|
||||
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
|
||||
// Homepage: https://gameframework.cn/
|
||||
// Feedback: mailto:ellan@gameframework.cn
|
||||
//------------------------------------------------------------
|
||||
|
||||
using SepCore.Definition;
|
||||
using GameFramework.Localization;
|
||||
using SepCore.Sound;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
namespace SepCore.UI
|
||||
{
|
||||
public class SettingForm : UGuiForm
|
||||
{
|
||||
[SerializeField] private Toggle _musicMuteToggle = null;
|
||||
[SerializeField] private Slider _musicVolumeSlider = null;
|
||||
|
||||
[SerializeField] private Toggle _soundMuteToggle = null;
|
||||
[SerializeField] private Slider _soundVolumeSlider = null;
|
||||
|
||||
[SerializeField] private Toggle _uiSoundMuteToggle = null;
|
||||
[SerializeField] private Slider _uiSoundVolumeSlider = null;
|
||||
|
||||
[SerializeField] private CanvasGroup _languageTipsCanvasGroup = null;
|
||||
|
||||
[SerializeField] private Toggle _englishToggle = null;
|
||||
[SerializeField] private Toggle _chineseSimplifiedToggle = null;
|
||||
[SerializeField] private Toggle _chineseTraditionalToggle = null;
|
||||
[SerializeField] private Toggle _koreanToggle = null;
|
||||
|
||||
private Language _selectedLanguage = Language.Unspecified;
|
||||
|
||||
public void OnMusicMuteChanged(bool isOn)
|
||||
{
|
||||
GameEntry.Sound.Mute("Music", !isOn);
|
||||
_musicVolumeSlider.gameObject.SetActive(isOn);
|
||||
}
|
||||
|
||||
public void OnMusicVolumeChanged(float volume)
|
||||
{
|
||||
GameEntry.Sound.SetVolume("Music", volume);
|
||||
}
|
||||
|
||||
public void OnSoundMuteChanged(bool isOn)
|
||||
{
|
||||
GameEntry.Sound.Mute("Sound", !isOn);
|
||||
_soundVolumeSlider.gameObject.SetActive(isOn);
|
||||
}
|
||||
|
||||
public void OnSoundVolumeChanged(float volume)
|
||||
{
|
||||
GameEntry.Sound.SetVolume("Sound", volume);
|
||||
}
|
||||
|
||||
public void OnUISoundMuteChanged(bool isOn)
|
||||
{
|
||||
GameEntry.Sound.Mute("UISound", !isOn);
|
||||
_uiSoundVolumeSlider.gameObject.SetActive(isOn);
|
||||
}
|
||||
|
||||
public void OnUISoundVolumeChanged(float volume)
|
||||
{
|
||||
GameEntry.Sound.SetVolume("UISound", volume);
|
||||
}
|
||||
|
||||
public void OnEnglishSelected(bool isOn)
|
||||
{
|
||||
if (!isOn)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_selectedLanguage = Language.English;
|
||||
RefreshLanguageTips();
|
||||
}
|
||||
|
||||
public void OnChineseSimplifiedSelected(bool isOn)
|
||||
{
|
||||
if (!isOn)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_selectedLanguage = Language.ChineseSimplified;
|
||||
RefreshLanguageTips();
|
||||
}
|
||||
|
||||
public void OnChineseTraditionalSelected(bool isOn)
|
||||
{
|
||||
if (!isOn)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_selectedLanguage = Language.ChineseTraditional;
|
||||
RefreshLanguageTips();
|
||||
}
|
||||
|
||||
public void OnKoreanSelected(bool isOn)
|
||||
{
|
||||
if (!isOn)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_selectedLanguage = Language.Korean;
|
||||
RefreshLanguageTips();
|
||||
}
|
||||
|
||||
public void OnSubmitButtonClick()
|
||||
{
|
||||
if (_selectedLanguage == GameEntry.Localization.Language)
|
||||
{
|
||||
Close();
|
||||
return;
|
||||
}
|
||||
|
||||
GameEntry.Setting.SetString(Constant.Setting.Language, _selectedLanguage.ToString());
|
||||
GameEntry.Setting.Save();
|
||||
|
||||
GameEntry.Sound.StopMusic();
|
||||
UnityGameFramework.Runtime.GameEntry.Shutdown(ShutdownType.Restart);
|
||||
}
|
||||
|
||||
#if UNITY_2017_3_OR_NEWER
|
||||
protected override void OnOpen(object userData)
|
||||
#else
|
||||
protected internal override void OnOpen(object userData)
|
||||
#endif
|
||||
{
|
||||
base.OnOpen(userData);
|
||||
|
||||
_musicMuteToggle.isOn = !GameEntry.Sound.IsMuted("Music");
|
||||
_musicVolumeSlider.value = GameEntry.Sound.GetVolume("Music");
|
||||
|
||||
_soundMuteToggle.isOn = !GameEntry.Sound.IsMuted("Sound");
|
||||
_soundVolumeSlider.value = GameEntry.Sound.GetVolume("Sound");
|
||||
|
||||
_uiSoundMuteToggle.isOn = !GameEntry.Sound.IsMuted("UISound");
|
||||
_uiSoundVolumeSlider.value = GameEntry.Sound.GetVolume("UISound");
|
||||
|
||||
_selectedLanguage = GameEntry.Localization.Language;
|
||||
switch (_selectedLanguage)
|
||||
{
|
||||
case Language.English:
|
||||
_englishToggle.isOn = true;
|
||||
break;
|
||||
|
||||
case Language.ChineseSimplified:
|
||||
_chineseSimplifiedToggle.isOn = true;
|
||||
break;
|
||||
|
||||
case Language.ChineseTraditional:
|
||||
_chineseTraditionalToggle.isOn = true;
|
||||
break;
|
||||
|
||||
case Language.Korean:
|
||||
_koreanToggle.isOn = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_2017_3_OR_NEWER
|
||||
protected override void OnUpdate(float elapseSeconds, float realElapseSeconds)
|
||||
#else
|
||||
protected internal override void OnUpdate(float elapseSeconds, float realElapseSeconds)
|
||||
#endif
|
||||
{
|
||||
base.OnUpdate(elapseSeconds, realElapseSeconds);
|
||||
|
||||
if (_languageTipsCanvasGroup.gameObject.activeSelf)
|
||||
{
|
||||
_languageTipsCanvasGroup.alpha = 0.5f + 0.5f * Mathf.Sin(Mathf.PI * Time.time);
|
||||
}
|
||||
}
|
||||
|
||||
private void RefreshLanguageTips()
|
||||
{
|
||||
_languageTipsCanvasGroup.gameObject.SetActive(_selectedLanguage != GameEntry.Localization.Language);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 02bbd1c1f00c17842b1449ae2b66a932
|
||||
timeCreated: 1528026161
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user