功能:添加启动器场景并更新项目设置
- 调整了启动器场景名(Assets/Launcher.unity)及对应的元数据文件。 - 添加了README.md项目文档,包含安装说明、项目结构、编码规范、测试指南及依赖项。
This commit is contained in:
@@ -53,5 +53,10 @@ namespace Definition.Enum
|
||||
/// 游戏HUD。
|
||||
/// </summary>
|
||||
HudForm = 203,
|
||||
|
||||
/// <summary>
|
||||
/// 升级选择。
|
||||
/// </summary>
|
||||
LevelUpForm = 204,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,6 +70,8 @@ namespace Entity
|
||||
}
|
||||
}
|
||||
|
||||
public int CurrentLevel => _currentLevel;
|
||||
|
||||
public bool Enable
|
||||
{
|
||||
get => _enable;
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
using GameFramework;
|
||||
using GameFramework.Event;
|
||||
|
||||
namespace CustomEvent
|
||||
{
|
||||
public class LevelUpPropSelectedEventArgs : GameEventArgs
|
||||
{
|
||||
public static readonly int EventId = typeof(LevelUpPropSelectedEventArgs).GetHashCode();
|
||||
|
||||
public override int Id => EventId;
|
||||
|
||||
public int SelectedId { get; private set; }
|
||||
|
||||
public LevelUpPropSelectedEventArgs()
|
||||
{
|
||||
SelectedId = -1;
|
||||
}
|
||||
|
||||
public static LevelUpPropSelectedEventArgs Create(int propId)
|
||||
{
|
||||
var args = ReferencePool.Acquire<LevelUpPropSelectedEventArgs>();
|
||||
args.SelectedId = propId;
|
||||
return args;
|
||||
}
|
||||
|
||||
public override void Clear()
|
||||
{
|
||||
SelectedId = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3183e53376fbf95438a0a938510ce7f1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2540b6786a5c4f3aadd4f57c79b714b9
|
||||
timeCreated: 1770985387
|
||||
@@ -0,0 +1,27 @@
|
||||
using GameFramework;
|
||||
using GameFramework.Event;
|
||||
|
||||
namespace CustomEvent
|
||||
{
|
||||
public class PlayerLevelUpEventArgs : GameEventArgs
|
||||
{
|
||||
public static readonly int EventId = typeof(PlayerLevelUpEventArgs).GetHashCode();
|
||||
|
||||
public override int Id => EventId;
|
||||
|
||||
public PlayerLevelUpEventArgs()
|
||||
{
|
||||
}
|
||||
|
||||
public static PlayerLevelUpEventArgs Create()
|
||||
{
|
||||
var args = ReferencePool.Acquire<PlayerLevelUpEventArgs>();
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
public override void Clear()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 59e602f086ce428396eab715b1277a23
|
||||
timeCreated: 1770989625
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0ce83a125a974b49ad8a9251a8d73359
|
||||
timeCreated: 1770985411
|
||||
@@ -0,0 +1,27 @@
|
||||
using GameFramework;
|
||||
using GameFramework.Event;
|
||||
|
||||
namespace CustomEvent
|
||||
{
|
||||
public class ShopContinueEventArgs : GameEventArgs
|
||||
{
|
||||
public static readonly int EventId = typeof(ShopContinueEventArgs).GetHashCode();
|
||||
|
||||
public override int Id => EventId;
|
||||
|
||||
public ShopContinueEventArgs()
|
||||
{
|
||||
}
|
||||
|
||||
public static ShopContinueEventArgs Create()
|
||||
{
|
||||
var args = ReferencePool.Acquire<ShopContinueEventArgs>();
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
public override void Clear()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b09ad1baac8a41338c0e42baf398beb8
|
||||
timeCreated: 1770986449
|
||||
@@ -0,0 +1,34 @@
|
||||
using GameFramework;
|
||||
using GameFramework.Event;
|
||||
|
||||
namespace CustomEvent
|
||||
{
|
||||
public class ShopPurchaseEventArgs : GameEventArgs
|
||||
{
|
||||
public static readonly int EventId = typeof(ShopPurchaseEventArgs).GetHashCode();
|
||||
|
||||
public override int Id => EventId;
|
||||
|
||||
public int GoodsIndex { get; private set; }
|
||||
|
||||
public ShopPurchaseEventArgs()
|
||||
{
|
||||
GoodsIndex = -1;
|
||||
}
|
||||
|
||||
public static ShopPurchaseEventArgs Create(int index)
|
||||
{
|
||||
var args = ReferencePool.Acquire<ShopPurchaseEventArgs>();
|
||||
|
||||
args.GoodsIndex = index;
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
public override void Clear()
|
||||
{
|
||||
GoodsIndex = -1;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 11c82e4a45804087b1aaf337e38a8836
|
||||
timeCreated: 1770986490
|
||||
@@ -0,0 +1,34 @@
|
||||
using GameFramework;
|
||||
using GameFramework.Event;
|
||||
|
||||
namespace CustomEvent
|
||||
{
|
||||
public class ShopRefreshEventArgs : GameEventArgs
|
||||
{
|
||||
public static readonly int EventId = typeof(ShopRefreshEventArgs).GetHashCode();
|
||||
|
||||
public override int Id => EventId;
|
||||
|
||||
public int Cost { get; private set; }
|
||||
|
||||
public ShopRefreshEventArgs()
|
||||
{
|
||||
Cost = 0;
|
||||
}
|
||||
|
||||
public static ShopRefreshEventArgs Create(int cost)
|
||||
{
|
||||
var args = ReferencePool.Acquire<ShopRefreshEventArgs>();
|
||||
|
||||
args.Cost = cost;
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
public override void Clear()
|
||||
{
|
||||
Cost = 0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7f463ec631b54d9e9feda00be716ae68
|
||||
timeCreated: 1770985436
|
||||
@@ -1,167 +1,209 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using CustomEvent;
|
||||
using DataTable;
|
||||
using Definition.Enum;
|
||||
using Entity;
|
||||
using GameFramework.DataTable;
|
||||
using GameFramework.Event;
|
||||
using GameFramework.Fsm;
|
||||
using GameFramework.Procedure;
|
||||
using UI;
|
||||
using UnityEngine;
|
||||
using UnityGameFramework.Runtime;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
namespace Procedure
|
||||
{
|
||||
public struct ShopFormContext
|
||||
{
|
||||
public GameStateShop GameStateShop;
|
||||
public int CurrentLevel;
|
||||
public int RefreshPrice;
|
||||
public int PlayerCoin;
|
||||
public List<GoodsItemViewData> GoodsItems;
|
||||
}
|
||||
|
||||
public class GameStateShop : GameStateBase
|
||||
{
|
||||
#region Property
|
||||
|
||||
public override GameStateType GameStateType => GameStateType.Shop;
|
||||
|
||||
private ProcedureGame _procedureGame = null;
|
||||
private bool _shopOver = false;
|
||||
private ShopForm _shopForm = null;
|
||||
private ProcedureGame _procedureGame;
|
||||
|
||||
private DRGoods[] _drGoods = null;
|
||||
private IDataTable<DRProp> _propDataTable = null;
|
||||
private IDataTable<DRWeapon> _weaponDataTable = null;
|
||||
private DRGoods[] _drGoods;
|
||||
|
||||
private Player _player = null;
|
||||
private DRProp[] _drProps;
|
||||
private IDataTable<DRProp> _propDataTable;
|
||||
|
||||
private IDataTable<DRWeapon> _weaponDataTable;
|
||||
|
||||
private ShopFormController _shopFormController;
|
||||
private ShopFormContext _shopFormContext;
|
||||
|
||||
public void ShopOver()
|
||||
{
|
||||
if (_shopOver) return;
|
||||
_shopOver = true;
|
||||
}
|
||||
private LevelUpFormController _levelUpFormController;
|
||||
private LevelUpFormContext _levelUpFormContext;
|
||||
|
||||
public void PurchaseGoods(int index)
|
||||
{
|
||||
if (_player.Coin < _shopFormContext.GoodsItems[index].Price) return;
|
||||
_player.Coin -= _shopFormContext.GoodsItems[index].Price;
|
||||
//TODO:OnGoodsPurchased
|
||||
}
|
||||
private int _shopRefreshTime = 0;
|
||||
|
||||
public void RefreshGoods()
|
||||
private Player _player => _procedureGame.Player;
|
||||
|
||||
private bool _shopOver = false;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
#region LevelUp
|
||||
|
||||
private LevelUpFormContext BuildLevelUpFormContext(int count = 4)
|
||||
{
|
||||
if (_player.Coin < _shopFormContext.RefreshPrice) return;
|
||||
_player.Coin -= _shopFormContext.RefreshPrice;
|
||||
_shopFormContext = new ShopFormContext()
|
||||
List<LevelUpPropContext> props = new List<LevelUpPropContext>();
|
||||
int total = _drProps.Length;
|
||||
if (total <= 0)
|
||||
{
|
||||
GameStateShop = this,
|
||||
CurrentLevel = _procedureGame.CurrentLevel,
|
||||
RefreshPrice = _shopFormContext.RefreshPrice + _procedureGame.CurrentLevel,
|
||||
Log.Error("GameStateShop::BuildLevelUpFormContext(): _drProps == null");
|
||||
return null;
|
||||
}
|
||||
|
||||
count = Mathf.Min(count, total);
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
int index = Random.Range(0, total);
|
||||
DRProp drProp = _drProps[index];
|
||||
props.Add(new LevelUpPropContext
|
||||
{
|
||||
PropId = drProp.Id,
|
||||
Title = drProp.Title,
|
||||
Type = "Prop",
|
||||
Icon = null,
|
||||
Description = GoodsItemContext.CreatePropDescription(drProp.Modifiers),
|
||||
IconAssetName = drProp.IconAssetName
|
||||
});
|
||||
}
|
||||
|
||||
return new LevelUpFormContext
|
||||
{
|
||||
Level = _player.CurrentLevel,
|
||||
Props = props
|
||||
};
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Shop
|
||||
|
||||
private void RefreshGoodsItems()
|
||||
{
|
||||
_shopFormContext = BuildShopFormContext();
|
||||
_shopFormContext.RefreshPrice = (_shopRefreshTime + 1) * _procedureGame.CurrentLevel;
|
||||
_shopRefreshTime++;
|
||||
_shopFormController.OpenUI(_shopFormContext);
|
||||
}
|
||||
|
||||
private ShopFormContext BuildShopFormContext()
|
||||
{
|
||||
int currentLevel = _procedureGame.CurrentLevel;
|
||||
var context = new ShopFormContext
|
||||
{
|
||||
CurrentLevel = currentLevel,
|
||||
RefreshPrice = currentLevel,
|
||||
PlayerCoin = _player.Coin,
|
||||
GoodsItems = InitRandomGoodsItems()
|
||||
};
|
||||
_shopForm.UpdateForm(_shopFormContext);
|
||||
return context;
|
||||
}
|
||||
|
||||
private List<GoodsItemViewData> InitRandomGoodsItems()
|
||||
private List<GoodsItemContext> InitRandomGoodsItems(int count = -1)
|
||||
{
|
||||
// 1. 随机生成商店商品数量
|
||||
int count = Random.Range(4, 6);
|
||||
if (_drGoods == null || _drGoods.Length == 0)
|
||||
{
|
||||
Log.Error("GameStateShop::InitRandomGoodsItems(): _drGoods == null");
|
||||
return null;
|
||||
}
|
||||
|
||||
// 2. 获取数据表中配置的商品总数
|
||||
count = Mathf.Max(count, Random.Range(4, 6));
|
||||
int totalCount = _drGoods.Length;
|
||||
List<GoodsItemContext> items = new List<GoodsItemContext>(count);
|
||||
if (totalCount <= 0) return items;
|
||||
count = Mathf.Min(count, totalCount);
|
||||
|
||||
// 3. 创建要返回的商品列表
|
||||
List<GoodsItemViewData> items = new List<GoodsItemViewData>(count);
|
||||
|
||||
// 4. 填充商品列表
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
// 4.1 获取要添加的商品Id
|
||||
int index = Random.Range(0, totalCount);
|
||||
|
||||
// 4.2 从数据表中获取商品数据
|
||||
var drGoods = _drGoods[index];
|
||||
|
||||
// 4.3 构建商品数据类
|
||||
var goodsItem = new GoodsItemViewData();
|
||||
|
||||
// 4.4 填充商品数据(价格、名字、类型、图标、描述)
|
||||
goodsItem.Price = Random.Range(drGoods.MinPrice, drGoods.MaxPrice);
|
||||
DRGoods drGoods = _drGoods[index];
|
||||
GoodsItemContext goodsItem = new GoodsItemContext
|
||||
{
|
||||
Price = Random.Range(drGoods.MinPrice, drGoods.MaxPrice)
|
||||
};
|
||||
|
||||
if (drGoods.GoodsType == GoodsType.Prop)
|
||||
{
|
||||
DRProp drProp = _propDataTable.GetDataRow(drGoods.GoodsTypeId);
|
||||
|
||||
goodsItem.Title = drProp.Title;
|
||||
goodsItem.Type = "道具";
|
||||
goodsItem.Type = "Prop";
|
||||
GameEntry.SpriteCache.GetSprite(drProp.IconAssetName, sprite => goodsItem.Icon = sprite);
|
||||
goodsItem.Description = GoodsItemViewData.CreatePropDescription(drProp.Modifiers);
|
||||
goodsItem.Description = GoodsItemContext.CreatePropDescription(drProp.Modifiers);
|
||||
}
|
||||
else if (drGoods.GoodsType is GoodsType.Weapon)
|
||||
else if (drGoods.GoodsType == GoodsType.Weapon)
|
||||
{
|
||||
DRWeapon drWeapon = _weaponDataTable.GetDataRow(drGoods.GoodsTypeId);
|
||||
|
||||
goodsItem.Title = drWeapon.Title;
|
||||
goodsItem.Type = "武器";
|
||||
goodsItem.Type = "Weapon";
|
||||
GameEntry.SpriteCache.GetSprite(drWeapon.IconAssetName, sprite => goodsItem.Icon = sprite);
|
||||
goodsItem.Description = GoodsItemViewData.CreateWeaponDescription(drWeapon);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Warning("Goods type not supported.");
|
||||
goodsItem.Description = GoodsItemContext.CreateWeaponDescription(drWeapon);
|
||||
}
|
||||
|
||||
// 4.5 添加到商品列表
|
||||
items.Add(goodsItem);
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region FSM
|
||||
|
||||
public override void OnInit(ProcedureGame master)
|
||||
{
|
||||
Log.Debug("GameStateShop::OnInit");
|
||||
_procedureGame = master;
|
||||
_shopOver = false;
|
||||
|
||||
_levelUpFormController = new LevelUpFormController();
|
||||
_shopFormController = new ShopFormController();
|
||||
|
||||
_drGoods = GameEntry.DataTable.GetDataTable<DRGoods>().ToArray();
|
||||
_propDataTable = GameEntry.DataTable.GetDataTable<DRProp>();
|
||||
_drProps = _propDataTable.ToArray();
|
||||
_weaponDataTable = GameEntry.DataTable.GetDataTable<DRWeapon>();
|
||||
|
||||
_shopOver = false;
|
||||
}
|
||||
|
||||
public override void OnEnter(IFsm<IProcedureManager> procedureOwner)
|
||||
{
|
||||
Log.Debug("GameStateShop::OnEnter");
|
||||
|
||||
GameEntry.Event.Subscribe(OpenUIFormSuccessEventArgs.EventId, OpenUIFormSuccess);
|
||||
GameEntry.Event.Subscribe(ShopRefreshEventArgs.EventId, ShopRefresh);
|
||||
GameEntry.Event.Subscribe(ShopPurchaseEventArgs.EventId, ShopPurchase);
|
||||
GameEntry.Event.Subscribe(ShopContinueEventArgs.EventId, ShopContinue);
|
||||
GameEntry.Event.Subscribe(CloseUIFormCompleteEventArgs.EventId, CloseUIFormComplete);
|
||||
|
||||
_shopOver = false;
|
||||
_player = _procedureGame.Player;
|
||||
|
||||
_shopFormContext = new ShopFormContext()
|
||||
if (_procedureGame.PlayerPendingLevel != 0)
|
||||
{
|
||||
GameStateShop = this,
|
||||
CurrentLevel = _procedureGame.CurrentLevel,
|
||||
RefreshPrice = _procedureGame.CurrentLevel,
|
||||
PlayerCoin = _player.Coin,
|
||||
GoodsItems = InitRandomGoodsItems()
|
||||
};
|
||||
GameEntry.UI.OpenUIForm(UIFormType.ShopForm, _shopFormContext);
|
||||
_levelUpFormContext = BuildLevelUpFormContext();
|
||||
_levelUpFormController.OpenUI(_levelUpFormContext);
|
||||
}
|
||||
else
|
||||
{
|
||||
_shopFormContext = BuildShopFormContext();
|
||||
_shopFormController.OpenUI(_shopFormContext);
|
||||
}
|
||||
|
||||
_shopOver = false;
|
||||
}
|
||||
|
||||
public override void OnUpdate(IFsm<IProcedureManager> procedureOwner, float elapseSeconds,
|
||||
float realElapseSeconds)
|
||||
{
|
||||
Log.Debug("GameStateShop::OnUpdate");
|
||||
|
||||
if (_shopOver)
|
||||
{
|
||||
_shopForm.Close();
|
||||
_shopFormController?.CloseUI();
|
||||
_procedureGame.ShopToBattle();
|
||||
}
|
||||
}
|
||||
@@ -170,14 +212,29 @@ namespace Procedure
|
||||
{
|
||||
Log.Debug("GameStateShop::OnLeave");
|
||||
|
||||
_shopForm = null;
|
||||
_shopFormContext = null;
|
||||
_shopFormController.CloseUI();
|
||||
_shopFormController = null;
|
||||
|
||||
GameEntry.Event.Unsubscribe(OpenUIFormSuccessEventArgs.EventId, OpenUIFormSuccess);
|
||||
_levelUpFormContext = null;
|
||||
_levelUpFormController.CloseUI();
|
||||
_levelUpFormController = null;
|
||||
|
||||
GameEntry.Event.Unsubscribe(CloseUIFormCompleteEventArgs.EventId, CloseUIFormComplete);
|
||||
GameEntry.Event.Unsubscribe(ShopRefreshEventArgs.EventId, ShopRefresh);
|
||||
GameEntry.Event.Unsubscribe(ShopPurchaseEventArgs.EventId, ShopPurchase);
|
||||
GameEntry.Event.Unsubscribe(ShopContinueEventArgs.EventId, ShopContinue);
|
||||
}
|
||||
|
||||
public override void OnDestroy(IFsm<IProcedureManager> procedureOwner)
|
||||
{
|
||||
_procedureGame = null;
|
||||
_shopFormController = null;
|
||||
_shopFormContext = null;
|
||||
|
||||
_levelUpFormController = null;
|
||||
_levelUpFormContext = null;
|
||||
|
||||
_drGoods = null;
|
||||
_propDataTable = null;
|
||||
_weaponDataTable = null;
|
||||
@@ -189,16 +246,62 @@ namespace Procedure
|
||||
|
||||
#region Event Handlers
|
||||
|
||||
private void OpenUIFormSuccess(object sender, GameEventArgs e)
|
||||
private void ShopRefresh(object sender, EventArgs e)
|
||||
{
|
||||
if (!(e is OpenUIFormSuccessEventArgs args)) return;
|
||||
if (!(args.UserData is ShopFormContext data)) return;
|
||||
if (data.GameStateShop == this)
|
||||
{
|
||||
_shopForm = args.UIForm.Logic as ShopForm;
|
||||
}
|
||||
if (!(e is ShopRefreshEventArgs args)) return;
|
||||
|
||||
if (_player.Coin < args.Cost) return;
|
||||
_player.Coin -= args.Cost;
|
||||
RefreshGoodsItems();
|
||||
}
|
||||
|
||||
|
||||
private void ShopPurchase(object sender, EventArgs e)
|
||||
{
|
||||
if (!(e is ShopPurchaseEventArgs args)) return;
|
||||
|
||||
int index = args.GoodsIndex;
|
||||
|
||||
if (index < 0 && index >= _shopFormContext.GoodsItems.Count)
|
||||
{
|
||||
Log.Warning("GameStateShop::ShopPurchase: Invalid index");
|
||||
return;
|
||||
}
|
||||
|
||||
if (_player.Coin < _shopFormContext.GoodsItems[index].Price) return;
|
||||
_player.Coin -= _shopFormContext.GoodsItems[index].Price;
|
||||
_shopFormContext.GoodsItems.RemoveAt(index);
|
||||
_shopFormController.OpenUI(_shopFormContext);
|
||||
// TODO: OnGoodsPurchased
|
||||
}
|
||||
|
||||
private void ShopContinue(object sender, EventArgs e)
|
||||
{
|
||||
if (!(e is ShopContinueEventArgs)) return;
|
||||
|
||||
_shopOver = true;
|
||||
}
|
||||
|
||||
private void CloseUIFormComplete(object sender, EventArgs e)
|
||||
{
|
||||
if (!(e is CloseUIFormCompleteEventArgs args)) return;
|
||||
|
||||
if (args.UIFormAssetName == nameof(UIFormType.LevelUpForm))
|
||||
{
|
||||
|
||||
if (--_procedureGame.PlayerPendingLevel != 0)
|
||||
{
|
||||
_levelUpFormContext = BuildLevelUpFormContext();
|
||||
_levelUpFormController.OpenUI(_levelUpFormContext);
|
||||
}
|
||||
else
|
||||
{
|
||||
_levelUpFormContext = BuildLevelUpFormContext();
|
||||
_levelUpFormController.OpenUI(_levelUpFormContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -36,6 +36,11 @@ namespace Procedure
|
||||
private Dictionary<GameStateType, GameStateBase> _gameStates;
|
||||
public Player Player;
|
||||
|
||||
/// <summary>
|
||||
/// 玩家升级可分配点数
|
||||
/// </summary>
|
||||
public int PlayerPendingLevel = 0;
|
||||
|
||||
private void InitGameState()
|
||||
{
|
||||
_gameStates = new Dictionary<GameStateType, GameStateBase>
|
||||
@@ -76,8 +81,9 @@ namespace Procedure
|
||||
|
||||
_procedureOwner = procedureOwner;
|
||||
|
||||
GameEntry.Event.Subscribe(OpenUIFormSuccessEventArgs.EventId, OnOpenUIFormSuccess);
|
||||
GameEntry.Event.Subscribe(ShowEntitySuccessEventArgs.EventId, OnShowEntitySuccess);
|
||||
GameEntry.Event.Subscribe(OpenUIFormSuccessEventArgs.EventId, OpenUIFormSuccess);
|
||||
GameEntry.Event.Subscribe(ShowEntitySuccessEventArgs.EventId, ShowEntitySuccess);
|
||||
GameEntry.Event.Subscribe(PlayerLevelUpEventArgs.EventId, PlayerLevelUp);
|
||||
|
||||
CurrentLevel = 1;
|
||||
_currentPlayerData = new PlayerData(-1, 1001);
|
||||
@@ -120,8 +126,9 @@ namespace Procedure
|
||||
Player = null;
|
||||
_procedureOwner = null;
|
||||
|
||||
GameEntry.Event.Unsubscribe(OpenUIFormSuccessEventArgs.EventId, OnOpenUIFormSuccess);
|
||||
GameEntry.Event.Unsubscribe(ShowEntitySuccessEventArgs.EventId, OnShowEntitySuccess);
|
||||
GameEntry.Event.Unsubscribe(PlayerLevelUpEventArgs.EventId, PlayerLevelUp);
|
||||
GameEntry.Event.Unsubscribe(OpenUIFormSuccessEventArgs.EventId, OpenUIFormSuccess);
|
||||
GameEntry.Event.Unsubscribe(ShowEntitySuccessEventArgs.EventId, ShowEntitySuccess);
|
||||
|
||||
base.OnLeave(procedureOwner, isShutdown);
|
||||
}
|
||||
@@ -130,7 +137,7 @@ namespace Procedure
|
||||
|
||||
#region Event Handler
|
||||
|
||||
private void OnOpenUIFormSuccess(object sender, GameEventArgs e)
|
||||
private void OpenUIFormSuccess(object sender, GameEventArgs e)
|
||||
{
|
||||
if (!(e is OpenUIFormSuccessEventArgs args)) return;
|
||||
|
||||
@@ -140,7 +147,7 @@ namespace Procedure
|
||||
}
|
||||
}
|
||||
|
||||
private void OnShowEntitySuccess(object sender, GameEventArgs e)
|
||||
private void ShowEntitySuccess(object sender, GameEventArgs e)
|
||||
{
|
||||
if (!(e is ShowEntitySuccessEventArgs args)) return;
|
||||
|
||||
@@ -150,6 +157,13 @@ namespace Procedure
|
||||
}
|
||||
}
|
||||
|
||||
private void PlayerLevelUp(object sender, GameEventArgs e)
|
||||
{
|
||||
if (!(e is PlayerLevelUpEventArgs)) return;
|
||||
|
||||
//PlayerPendingLevel++;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -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