初始化仓库
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
using Procedure;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
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)
|
||||
{
|
||||
_stateShop = stateShop;
|
||||
_iconImage.sprite = data.Icon;
|
||||
_titleText.text = data.Title;
|
||||
_typeText.text = data.Type;
|
||||
_descriptionText.text = data.Description;
|
||||
_costText.text = data.Price.ToString();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 271f2a0727c521c4280eb2d47fd8de33
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,40 @@
|
||||
using System.Text;
|
||||
using DataTable;
|
||||
using Definition.DataStruct;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UI
|
||||
{
|
||||
public class GoodsItemViewData
|
||||
{
|
||||
public string Title;
|
||||
public string Type;
|
||||
public Sprite Icon;
|
||||
public string Description;
|
||||
public int Price;
|
||||
|
||||
public static string CreateWeaponDescription(DRWeapon drWeapon)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.Append($"伤害:{drWeapon.Attack}\n");
|
||||
sb.Append($"冷却:{drWeapon.Cooldown}\n");
|
||||
sb.Append($"范围:{drWeapon.AttackRange}\n");
|
||||
sb.Append(CreatePropDescription(drWeapon.Modifiers));
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public static string CreatePropDescription(StatModifier[] modifiers)
|
||||
{
|
||||
if (modifiers == null || modifiers.Length == 0) return null;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach (var modifier in modifiers)
|
||||
{
|
||||
sb.Append(modifier.ToString());
|
||||
sb.Append("\n");
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c9d0b321b02be5f41a27cc0a8bf84e34
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,103 @@
|
||||
using Components;
|
||||
using CustomEvent;
|
||||
using Entity;
|
||||
using GameFramework.Event;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace UI
|
||||
{
|
||||
public class HudForm : UGuiForm
|
||||
{
|
||||
[SerializeField] private float _sliderFadeDuration = 0.5f;
|
||||
|
||||
[SerializeField] private Slider _hpSlider;
|
||||
private float _currentHpPercent = 0;
|
||||
private Coroutine _hpSliderFadeCoroutine;
|
||||
|
||||
[SerializeField] private Slider _expSlider;
|
||||
private float _currentExpPercent = 0;
|
||||
private Coroutine _expSliderFadeCoroutine;
|
||||
|
||||
[SerializeField] private TMP_Text _coinText;
|
||||
private int _currentCoin = 0;
|
||||
|
||||
#region FSM
|
||||
|
||||
protected override void OnInit(object userData)
|
||||
{
|
||||
base.OnInit(userData);
|
||||
|
||||
GameEntry.Event.Subscribe(PlayerHealthChangeEventArgs.EventId, OnPlayerHpChange);
|
||||
GameEntry.Event.Subscribe(PlayerExpChangeEventArgs.EventId, OnPlayerExpChange);
|
||||
GameEntry.Event.Subscribe(PlayerCoinChangeEventArgs.EventId, OnPlayerCoinChange);
|
||||
}
|
||||
|
||||
protected override void OnClose(bool isShutdown, object userData)
|
||||
{
|
||||
GameEntry.Event.Unsubscribe(PlayerHealthChangeEventArgs.EventId, OnPlayerHpChange);
|
||||
GameEntry.Event.Unsubscribe(PlayerExpChangeEventArgs.EventId, OnPlayerExpChange);
|
||||
GameEntry.Event.Unsubscribe(PlayerCoinChangeEventArgs.EventId, OnPlayerCoinChange);
|
||||
|
||||
base.OnClose(isShutdown, userData);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Event Handlers
|
||||
|
||||
private void OnPlayerHpChange(object sender, GameEventArgs e)
|
||||
{
|
||||
if (!(e is PlayerHealthChangeEventArgs args)) return;
|
||||
float percent = (float)args.CurrentHealth / args.MaxHealth;
|
||||
if (Mathf.Approximately(_currentHpPercent, percent)) return;
|
||||
|
||||
_currentHpPercent = percent;
|
||||
|
||||
if (_hpSliderFadeCoroutine != null) StopCoroutine(_hpSliderFadeCoroutine);
|
||||
_hpSliderFadeCoroutine = StartCoroutine(_hpSlider.SmoothValue(percent, _sliderFadeDuration));
|
||||
}
|
||||
|
||||
private void OnPlayerExpChange(object sender, GameEventArgs e)
|
||||
{
|
||||
if (!(e is PlayerExpChangeEventArgs args)) return;
|
||||
float percent = (float)args.CurrentExp / args.MaxExp;
|
||||
if (Mathf.Approximately(_currentExpPercent, percent)) return;
|
||||
|
||||
_currentExpPercent = percent;
|
||||
|
||||
if (_expSliderFadeCoroutine != null) StopCoroutine(_expSliderFadeCoroutine);
|
||||
_expSliderFadeCoroutine = StartCoroutine(_expSlider.SmoothValue(percent, _sliderFadeDuration));
|
||||
}
|
||||
|
||||
private void OnPlayerCoinChange(object sender, GameEventArgs e)
|
||||
{
|
||||
if (!(e is PlayerCoinChangeEventArgs args)) return;
|
||||
if (_currentCoin == args.CoinCount) return;
|
||||
|
||||
_coinText.text = args.CoinCount.ToString();
|
||||
_currentCoin = args.CoinCount;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Test
|
||||
|
||||
private Player _player;
|
||||
|
||||
public void CauseDamageToPlayer()
|
||||
{
|
||||
if (_player == null)
|
||||
{
|
||||
_player = FindObjectOfType<Player>();
|
||||
}
|
||||
|
||||
if (_player == null) return;
|
||||
|
||||
_player.GetComponent<HealthComponent>().TakeDamage(2);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bd4c4d6e8d4b0f54c830e2cfef46848e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,101 @@
|
||||
using CustomEvent;
|
||||
using GameFramework.Event;
|
||||
using Procedure;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UI
|
||||
{
|
||||
public class ShopForm : UGuiForm
|
||||
{
|
||||
[SerializeField] private TMP_Text _titleText;
|
||||
|
||||
[SerializeField] private TMP_Text _continueButtonText;
|
||||
|
||||
[SerializeField] private TMP_Text _refreshPriceText;
|
||||
|
||||
[SerializeField] private TMP_Text _playerCoinText;
|
||||
private int _currentCoin = 0;
|
||||
|
||||
[SerializeField] private GoodsItem[] _goodsItems;
|
||||
|
||||
private GameStateShop _stateShop;
|
||||
|
||||
public void UpdateForm(ShopFormContext context)
|
||||
{
|
||||
_stateShop = context.GameStateShop;
|
||||
|
||||
_titleText.text = $"商店(第{context.CurrentLevel}波)";
|
||||
_continueButtonText.text = $"继续(第{context.CurrentLevel + 1}波)";
|
||||
_refreshPriceText.text = $"-{context.RefreshPrice}";
|
||||
_playerCoinText.text = $"{context.PlayerCoin}";
|
||||
|
||||
for (int i = 0; i < _goodsItems.Length; i++)
|
||||
{
|
||||
if (i < context.GoodsItems.Count)
|
||||
{
|
||||
_goodsItems[i].Init(context.GameStateShop, context.GoodsItems[i]);
|
||||
_goodsItems[i].gameObject.SetActive(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
_goodsItems[i].gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#region ButtonClick
|
||||
|
||||
public void OnContinueButtonClick()
|
||||
{
|
||||
_stateShop.ShopOver();
|
||||
}
|
||||
|
||||
public void OnPurchaseButtonClick(int index)
|
||||
{
|
||||
_stateShop.PurchaseGoods(index);
|
||||
}
|
||||
|
||||
public void OnRefreshButtonClick()
|
||||
{
|
||||
_stateShop.RefreshGoods();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region FSM
|
||||
|
||||
protected override void OnOpen(object userData)
|
||||
{
|
||||
base.OnOpen(userData);
|
||||
|
||||
GameEntry.Event.Subscribe(PlayerCoinChangeEventArgs.EventId, OnPlayerCoinChange);
|
||||
|
||||
ShopFormContext context = (ShopFormContext)userData;
|
||||
UpdateForm(context);
|
||||
}
|
||||
|
||||
protected override void OnClose(bool isShutdown, object userData)
|
||||
{
|
||||
_stateShop = 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
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a6f22432e5701804d9a78d0c07f4c334
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user