功能:添加启动器场景并更新项目设置
- 调整了启动器场景名(Assets/Launcher.unity)及对应的元数据文件。 - 添加了README.md项目文档,包含安装说明、项目结构、编码规范、测试指南及依赖项。
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 32bf4a12bd0ac2847b19bbb76b7c3dd5
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+1
-1
@@ -5,7 +5,7 @@ using UnityEngine;
|
||||
|
||||
namespace UI
|
||||
{
|
||||
public class GoodsItemViewData
|
||||
public class GoodsItemContext
|
||||
{
|
||||
public string Title;
|
||||
public string Type;
|
||||
@@ -0,0 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace UI
|
||||
{
|
||||
public class LevelUpFormContext
|
||||
{
|
||||
public int Level;
|
||||
public List<LevelUpPropContext> Props;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1874c6c7ef990c04ba726a2581cd23ce
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,14 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace UI
|
||||
{
|
||||
public class LevelUpPropContext
|
||||
{
|
||||
public int PropId;
|
||||
public string Title;
|
||||
public string Type;
|
||||
public Sprite Icon;
|
||||
public string Description;
|
||||
public string IconAssetName;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 424ceeba7cae4fa4faaeef9035f31e31
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,12 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace UI
|
||||
{
|
||||
public class ShopFormContext
|
||||
{
|
||||
public int CurrentLevel;
|
||||
public int RefreshPrice;
|
||||
public int PlayerCoin;
|
||||
public List<GoodsItemContext> GoodsItems;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b0ef5183d2f87a54793b86d848e6524a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7d69a94fcc50f4c4ca1dc45e4338560e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace UI
|
||||
{
|
||||
public interface IFormController<TContext>
|
||||
{
|
||||
int? OpenUI(TContext context);
|
||||
void CloseUI();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 692b282b1ecbf5a44839d5bf4a03a937
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,154 @@
|
||||
using System.Collections.Generic;
|
||||
using CustomEvent;
|
||||
using DataTable;
|
||||
using Definition.Enum;
|
||||
using GameFramework.DataTable;
|
||||
using GameFramework.Event;
|
||||
using UnityEngine;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
namespace UI
|
||||
{
|
||||
public class LevelUpFormController : IFormController<LevelUpFormContext>
|
||||
{
|
||||
private int _currentLevel = 1;
|
||||
private int _buildCount = 4;
|
||||
|
||||
private bool _pendingRefresh;
|
||||
|
||||
private int? _levelUpFormSerialId;
|
||||
private LevelUpForm _levelUpForm;
|
||||
private LevelUpFormContext _context;
|
||||
|
||||
public LevelUpFormController()
|
||||
{
|
||||
GameEntry.Event.Subscribe(OpenUIFormSuccessEventArgs.EventId, OpenUIFormSuccess);
|
||||
GameEntry.Event.Subscribe(CloseUIFormCompleteEventArgs.EventId, CloseUIFormComplete);
|
||||
}
|
||||
|
||||
~LevelUpFormController()
|
||||
{
|
||||
GameEntry.Event.Unsubscribe(OpenUIFormSuccessEventArgs.EventId, OpenUIFormSuccess);
|
||||
GameEntry.Event.Unsubscribe(CloseUIFormCompleteEventArgs.EventId, CloseUIFormComplete);
|
||||
}
|
||||
|
||||
public void ConfigureBuild(int level, int count = 4)
|
||||
{
|
||||
_currentLevel = Mathf.Max(1, level);
|
||||
_buildCount = Mathf.Max(0, count);
|
||||
}
|
||||
|
||||
public int? OpenUI(LevelUpFormContext context)
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
Log.Warning("LevelUpFormController.OpenUI() context is null.");
|
||||
return null;
|
||||
}
|
||||
|
||||
_context = context;
|
||||
|
||||
if (_levelUpForm != null)
|
||||
{
|
||||
_levelUpForm.RefreshUI(_context);
|
||||
return _levelUpFormSerialId;
|
||||
}
|
||||
|
||||
CloseUI();
|
||||
_pendingRefresh = true;
|
||||
_levelUpFormSerialId = GameEntry.UI.OpenUIForm(UIFormType.LevelUpForm, context);
|
||||
return _levelUpFormSerialId;
|
||||
}
|
||||
|
||||
public void CloseUI()
|
||||
{
|
||||
_pendingRefresh = false;
|
||||
|
||||
if (_levelUpFormSerialId.HasValue)
|
||||
{
|
||||
GameEntry.UI.CloseUIForm(_levelUpFormSerialId.Value);
|
||||
return;
|
||||
}
|
||||
|
||||
if (_levelUpForm != null)
|
||||
{
|
||||
_levelUpForm.Close();
|
||||
}
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
_context = null;
|
||||
_levelUpForm = null;
|
||||
_levelUpFormSerialId = null;
|
||||
_pendingRefresh = false;
|
||||
}
|
||||
|
||||
public void OnSelectProp(int propId)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void TryRefreshUI()
|
||||
{
|
||||
if (_context == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_levelUpForm == null)
|
||||
{
|
||||
_pendingRefresh = true;
|
||||
return;
|
||||
}
|
||||
|
||||
_levelUpForm.RefreshUI(_context);
|
||||
_pendingRefresh = false;
|
||||
}
|
||||
|
||||
#region Event Handlers
|
||||
|
||||
private void OpenUIFormSuccess(object sender, GameEventArgs e)
|
||||
{
|
||||
if (!(e is OpenUIFormSuccessEventArgs args)) return;
|
||||
|
||||
if (!_levelUpFormSerialId.HasValue) return;
|
||||
|
||||
if (args.UIForm == null || args.UIForm.SerialId != _levelUpFormSerialId.Value || args.UserData != _context)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_levelUpForm = args.UIForm.Logic as LevelUpForm;
|
||||
|
||||
if (_levelUpForm == null)
|
||||
{
|
||||
Log.Warning("LevelUpFormController open success but form logic is invalid.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (_pendingRefresh)
|
||||
{
|
||||
TryRefreshUI();
|
||||
}
|
||||
}
|
||||
|
||||
private void CloseUIFormComplete(object sender, GameEventArgs e)
|
||||
{
|
||||
if (!(e is CloseUIFormCompleteEventArgs args))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.SerialId != _levelUpFormSerialId)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_levelUpForm = null;
|
||||
_levelUpFormSerialId = null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 89d85bbc4f7cf8c438c7ee693eaf67cf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,133 @@
|
||||
using Definition.Enum;
|
||||
using GameFramework.Event;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
namespace UI
|
||||
{
|
||||
public class ShopFormController : IFormController<ShopFormContext>
|
||||
{
|
||||
#region Property
|
||||
|
||||
private bool _pendingRefresh;
|
||||
|
||||
private int? _shopFormSerialId;
|
||||
|
||||
private ShopForm _shopForm;
|
||||
|
||||
private ShopFormContext _context;
|
||||
|
||||
#endregion
|
||||
|
||||
public ShopFormController()
|
||||
{
|
||||
GameEntry.Event.Subscribe(OpenUIFormSuccessEventArgs.EventId, OpenUIFormSuccess);
|
||||
GameEntry.Event.Subscribe(CloseUIFormCompleteEventArgs.EventId, CloseUIFormComplete);
|
||||
}
|
||||
|
||||
~ShopFormController()
|
||||
{
|
||||
GameEntry.Event.Unsubscribe(OpenUIFormSuccessEventArgs.EventId, OpenUIFormSuccess);
|
||||
GameEntry.Event.Unsubscribe(CloseUIFormCompleteEventArgs.EventId, CloseUIFormComplete);
|
||||
}
|
||||
|
||||
public int? OpenUI(ShopFormContext context)
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
Log.Warning("ShopFormController.OpenUI() context is null.");
|
||||
return null;
|
||||
}
|
||||
|
||||
_context = context;
|
||||
|
||||
if (_shopForm != null)
|
||||
{
|
||||
_shopForm.RefreshUI(_context);
|
||||
return _shopFormSerialId;
|
||||
}
|
||||
|
||||
CloseUI();
|
||||
_pendingRefresh = true;
|
||||
_shopFormSerialId = GameEntry.UI.OpenUIForm(UIFormType.ShopForm, context);
|
||||
return _shopFormSerialId;
|
||||
}
|
||||
|
||||
public void CloseUI()
|
||||
{
|
||||
_pendingRefresh = false;
|
||||
|
||||
if (_shopFormSerialId.HasValue)
|
||||
{
|
||||
GameEntry.UI.CloseUIForm(_shopFormSerialId.Value);
|
||||
return;
|
||||
}
|
||||
|
||||
if (_shopForm != null)
|
||||
{
|
||||
_shopForm.Close();
|
||||
}
|
||||
}
|
||||
|
||||
private void TryRefreshUI()
|
||||
{
|
||||
if (_context == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_shopForm == null)
|
||||
{
|
||||
_pendingRefresh = true;
|
||||
return;
|
||||
}
|
||||
|
||||
_shopForm.RefreshUI(_context);
|
||||
_pendingRefresh = false;
|
||||
}
|
||||
|
||||
#region Event Handlers
|
||||
|
||||
private void OpenUIFormSuccess(object sender, GameEventArgs e)
|
||||
{
|
||||
if (!(e is OpenUIFormSuccessEventArgs args)) return;
|
||||
|
||||
if (!_shopFormSerialId.HasValue) return;
|
||||
|
||||
if (args.UIForm == null || args.UIForm.SerialId != _shopFormSerialId.Value || args.UserData != _context)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_shopForm = args.UIForm.Logic as ShopForm;
|
||||
|
||||
if (_shopForm == null)
|
||||
{
|
||||
Log.Warning("ShopFormController open success but form logic is invalid.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (_pendingRefresh)
|
||||
{
|
||||
TryRefreshUI();
|
||||
}
|
||||
}
|
||||
|
||||
private void CloseUIFormComplete(object sender, GameEventArgs e)
|
||||
{
|
||||
if (!(e is CloseUIFormCompleteEventArgs args))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.SerialId != _shopFormSerialId)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_shopForm = null;
|
||||
_shopFormSerialId = null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: be57ace1e7b07be429632ea49bcab6c5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7af0b9398035e254cb6de37a6c301552
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+7
-7
@@ -1,4 +1,3 @@
|
||||
using Procedure;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
@@ -8,20 +7,21 @@ namespace UI
|
||||
public class GoodsItem : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Image _iconImage;
|
||||
|
||||
[SerializeField] private TMP_Text _titleText;
|
||||
|
||||
[SerializeField] private TMP_Text _typeText;
|
||||
|
||||
[SerializeField] private TMP_Text _descriptionText;
|
||||
|
||||
[SerializeField] private TMP_Text _costText;
|
||||
|
||||
[SerializeField] private CommonButton _purchaseButton;
|
||||
|
||||
private int _cost;
|
||||
private GameStateShop _stateShop;
|
||||
|
||||
#region Init
|
||||
|
||||
public void Init(GameStateShop stateShop, GoodsItemViewData data)
|
||||
public void Init(GoodsItemContext data)
|
||||
{
|
||||
_stateShop = stateShop;
|
||||
_iconImage.sprite = data.Icon;
|
||||
_titleText.text = data.Title;
|
||||
_typeText.text = data.Type;
|
||||
@@ -31,4 +31,4 @@ namespace UI
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
using CustomEvent;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
namespace UI
|
||||
{
|
||||
public class LevelUpForm : UGuiForm
|
||||
{
|
||||
[SerializeField] private TMP_Text _titleText;
|
||||
|
||||
[SerializeField] private LevelUpPropItem[] _propItems;
|
||||
|
||||
private LevelUpFormContext _context;
|
||||
|
||||
public void RefreshUI(LevelUpFormContext context)
|
||||
{
|
||||
_context = context;
|
||||
|
||||
if (_titleText != null)
|
||||
{
|
||||
_titleText.text = $"Level Up (Lv.{_context.Level})";
|
||||
}
|
||||
|
||||
foreach (var propItem in _propItems)
|
||||
{
|
||||
propItem.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
if (_context.Props == null) return;
|
||||
for (int i = 0; i < _propItems.Length; i++)
|
||||
{
|
||||
_propItems[i].gameObject.SetActive(true);
|
||||
_propItems[i].Init(_context.Props[i]);
|
||||
}
|
||||
}
|
||||
|
||||
#region FSM
|
||||
|
||||
protected override void OnOpen(object userData)
|
||||
{
|
||||
base.OnOpen(userData);
|
||||
|
||||
if (userData is LevelUpFormContext context)
|
||||
{
|
||||
RefreshUI(context);
|
||||
return;
|
||||
}
|
||||
|
||||
Log.Warning("LevelUpForm requires LevelUpFormContext as userData.");
|
||||
}
|
||||
|
||||
protected override void OnClose(bool isShutdown, object userData)
|
||||
{
|
||||
_context = null;
|
||||
base.OnClose(isShutdown, userData);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private void OnSelectProp(int index)
|
||||
{
|
||||
GameEntry.Event.Fire(this, LevelUpPropSelectedEventArgs.Create(index));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 73f52c8a6d8b8ec42ad8cd3c00e0254d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.UI;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
namespace UI
|
||||
{
|
||||
public class LevelUpPropItem : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Image _iconImage;
|
||||
|
||||
[SerializeField] private TMP_Text _titleText;
|
||||
|
||||
[SerializeField] private TMP_Text _typeText;
|
||||
|
||||
[SerializeField] private TMP_Text _descriptionText;
|
||||
|
||||
private LevelUpPropContext _context;
|
||||
|
||||
|
||||
public void Init(LevelUpPropContext context)
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
Log.Error("LevelUpPropContext context is invalid.");
|
||||
return;
|
||||
}
|
||||
|
||||
_context = context;
|
||||
|
||||
if (_titleText != null) _titleText.text = context.Title;
|
||||
if (_typeText != null) _typeText.text = context.Type;
|
||||
if (_descriptionText != null) _descriptionText.text = context.Description;
|
||||
if (_iconImage != null) _iconImage.sprite = context.Icon;
|
||||
|
||||
LoadIcon(_context.IconAssetName);
|
||||
}
|
||||
|
||||
private void LoadIcon(string iconAssetName)
|
||||
{
|
||||
if (_iconImage == null) return;
|
||||
|
||||
if (string.IsNullOrEmpty(iconAssetName)) return;
|
||||
|
||||
GameEntry.SpriteCache.GetSprite(iconAssetName, sprite => _iconImage.sprite = sprite);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 237d64392d274c14f9f5c81b54122a93
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+39
-30
@@ -1,6 +1,5 @@
|
||||
using CustomEvent;
|
||||
using GameFramework.Event;
|
||||
using Procedure;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -8,57 +7,61 @@ namespace UI
|
||||
{
|
||||
public class ShopForm : UGuiForm
|
||||
{
|
||||
#region Property
|
||||
|
||||
[SerializeField] private TMP_Text _titleText;
|
||||
|
||||
[SerializeField] private TMP_Text _continueButtonText;
|
||||
|
||||
|
||||
[SerializeField] private TMP_Text _refreshPriceText;
|
||||
|
||||
[SerializeField] private TMP_Text _playerCoinText;
|
||||
private int _currentCoin = 0;
|
||||
private int _currentCoin;
|
||||
|
||||
[SerializeField] private GoodsItem[] _goodsItems;
|
||||
|
||||
private GameStateShop _stateShop;
|
||||
private ShopFormContext _context;
|
||||
|
||||
public void UpdateForm(ShopFormContext context)
|
||||
#endregion
|
||||
|
||||
|
||||
public void RefreshUI(ShopFormContext context)
|
||||
{
|
||||
_stateShop = context.GameStateShop;
|
||||
_context = context;
|
||||
|
||||
_titleText.text = $"商店(第{context.CurrentLevel}波)";
|
||||
_continueButtonText.text = $"继续(第{context.CurrentLevel + 1}波)";
|
||||
_titleText.text = $"商店 (Lv.{context.CurrentLevel})";
|
||||
_continueButtonText.text = $"继续 (Lv.{context.CurrentLevel + 1})";
|
||||
_refreshPriceText.text = $"-{context.RefreshPrice}";
|
||||
_playerCoinText.text = $"{context.PlayerCoin}";
|
||||
_playerCoinText.text = context.PlayerCoin.ToString();
|
||||
|
||||
for (int i = 0; i < _goodsItems.Length; i++)
|
||||
foreach (var item in _goodsItems)
|
||||
{
|
||||
if (i < context.GoodsItems.Count)
|
||||
{
|
||||
_goodsItems[i].Init(context.GameStateShop, context.GoodsItems[i]);
|
||||
_goodsItems[i].gameObject.SetActive(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
_goodsItems[i].gameObject.SetActive(false);
|
||||
}
|
||||
item.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
if (_context.GoodsItems == null) return;
|
||||
for (int i = 0; i < _context.GoodsItems.Count; i++)
|
||||
{
|
||||
_goodsItems[i].Init(context.GoodsItems[i]);
|
||||
_goodsItems[i].gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#region ButtonClick
|
||||
|
||||
public void OnContinueButtonClick()
|
||||
{
|
||||
_stateShop.ShopOver();
|
||||
GameEntry.Event.Fire(this, ShopContinueEventArgs.Create());
|
||||
}
|
||||
|
||||
public void OnPurchaseButtonClick(int index)
|
||||
{
|
||||
_stateShop.PurchaseGoods(index);
|
||||
GameEntry.Event.Fire(this, ShopPurchaseEventArgs.Create(index));
|
||||
}
|
||||
|
||||
public void OnRefreshButtonClick()
|
||||
{
|
||||
_stateShop.RefreshGoods();
|
||||
GameEntry.Event.Fire(this, ShopRefreshEventArgs.Create(_context.RefreshPrice));
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -70,32 +73,38 @@ namespace UI
|
||||
base.OnOpen(userData);
|
||||
|
||||
GameEntry.Event.Subscribe(PlayerCoinChangeEventArgs.EventId, OnPlayerCoinChange);
|
||||
|
||||
ShopFormContext context = (ShopFormContext)userData;
|
||||
UpdateForm(context);
|
||||
|
||||
if (userData is ShopFormContext context)
|
||||
{
|
||||
RefreshUI(context);
|
||||
return;
|
||||
}
|
||||
|
||||
UnityGameFramework.Runtime.Log.Warning("ShopForm requires ShopFormContext as userData.");
|
||||
}
|
||||
|
||||
protected override void OnClose(bool isShutdown, object userData)
|
||||
{
|
||||
_stateShop = null;
|
||||
_context = null;
|
||||
|
||||
GameEntry.Event.Unsubscribe(PlayerCoinChangeEventArgs.EventId, OnPlayerCoinChange);
|
||||
|
||||
|
||||
base.OnClose(isShutdown, userData);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Event Handlers
|
||||
|
||||
private void OnPlayerCoinChange(object sender, GameEventArgs e)
|
||||
{
|
||||
if (!(e is PlayerCoinChangeEventArgs args)) return;
|
||||
if (args.CoinCount == _currentCoin) return;
|
||||
|
||||
|
||||
_currentCoin = args.CoinCount;
|
||||
_playerCoinText.text = _currentCoin.ToString();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user