HPMP变化事件

This commit is contained in:
sin365 2023-01-11 23:42:41 +08:00
parent 0581bf8548
commit 89a2460de1
4 changed files with 62 additions and 0 deletions

View File

@ -100,6 +100,8 @@ namespace Game
UnderAttack.BaseData.life.curHP -= DamageHP; UnderAttack.BaseData.life.curHP -= DamageHP;
UnderAttack.BaseData.life.curHP = Math.Max(UnderAttack.BaseData.life.curHP, 0); UnderAttack.BaseData.life.curHP = Math.Max(UnderAttack.BaseData.life.curHP, 0);
AppEntry.Event.Fire(null, HPMPChangeEventArgs.Create(UnderAttack.RoleType, UnderAttack.RoleID));
if (UnderAttack.BaseData.life.curHP > 0) if (UnderAttack.BaseData.life.curHP > 0)
UnderAttack.Anime.PlayHit(); UnderAttack.Anime.PlayHit();
else else

View File

@ -0,0 +1,32 @@
using Axibug;
using Axibug.Event;
namespace Game
{
public class HPMPChangeEventArgs : LogicEventArgs
{
public static readonly int EventId = typeof(HPMPChangeEventArgs).GetHashCode();
public E_NODE_TYPE roleType = E_NODE_TYPE.N_FREE;
public int RoleID = 0;
/// <summary>
/// 获取加载数据表成功事件编号。
/// </summary>
public override int Id { get { return EventId; } }
public static HPMPChangeEventArgs Create(E_NODE_TYPE type,int roleID)
{
HPMPChangeEventArgs s = ReferencePool.Acquire<HPMPChangeEventArgs>();
s.RoleID = roleID;
s.roleType = type;
return s;
}
public override void Clear()
{
roleType = E_NODE_TYPE.N_FREE;
RoleID = 0;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a03fb589092408848b244a23325483ad
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -10,6 +10,8 @@ using UnityEngine.UI;
using Game; using Game;
using TMPro; using TMPro;
using Axibug.Runtime; using Axibug.Runtime;
using Axibug.Event;
using Axibug;
namespace Game namespace Game
{ {
@ -43,6 +45,7 @@ namespace Game
//UIAutoBuild_EventReg //UIAutoBuild_EventReg
//UIAutoBuild_EventReg //UIAutoBuild_EventReg
Reflush(); Reflush();
AppEntry.Event.Subscribe(HPMPChangeEventArgs.EventId, OnHPMPChangeEventArgs);
} }
void OnDisable() void OnDisable()
@ -55,6 +58,20 @@ namespace Game
{ {
} }
#region
private void OnHPMPChangeEventArgs(object sender, LogicEventArgs e)
{
HPMPChangeEventArgs msg = (HPMPChangeEventArgs)e;
if (msg == null) throw new GameException("OnHPMPChangeEventArgs is null");
if (msg.RoleID == GamePlayEntry.MainPlayer.Player.RoleID)
{
Reflush();
}
}
#endregion
// 每次显示都执行, 可定义参数 // 每次显示都执行, 可定义参数
public override void Show(params object[] _params) public override void Show(params object[] _params)
{ {