mycj_demo/mycj/Assets/Game/Scripts/Application/Object/FBRole.cs
2024-12-02 09:37:47 +08:00

122 lines
2.6 KiB
C#
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Felix-BangFBRole
//   へ     /|
//  /7    ∠_/
//  / │    
//  Z _,    /`ヽ
// │     ヽ   /  〉
//  Y     `  /  /
// イ● 、 ●  ⊂⊃〈  /
// ()  へ    | \〈
//  >ー 、_  ィ  │
//  / へ   / ノ<|
//  ヽ_ノ  (_  │//
//  7       |
//  ―r ̄ ̄`ー―_
// Describe角色色基类
// Createtime2018/10/15
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using FBFramework;
using System;
namespace FBApplication
{
public abstract class FBRole : FBReusableObject, IFBReusable
{
#region
#endregion
#region
public event Action<int, int> HPChangedAction; //血量变化事件
public event Action<FBRole> DeadAction; //死亡事件
#endregion
#region
int f_hp;
int f_maxHp;
#endregion
#region
public int HP
{
get { return f_hp; }
set
{
value = Mathf.Clamp(value, 0, f_maxHp);
if (value == f_hp)
return;
f_hp = value;
if (HPChangedAction != null)
HPChangedAction(f_hp, f_maxHp);
if (f_hp == 0)
{
if (DeadAction != null)
DeadAction(this);
}
}
}
public int MaxHP
{
get { return f_maxHp; }
set
{
if (value < 0)
value = 0;
f_maxHp = value;
}
}
public bool IsDead
{
get { return f_hp == 0; }
}
#endregion
#region
public override void OnSpawn()
{
this.DeadAction += OnDie;
}
public override void OnUnspawn()
{
HP = 0;
MaxHP = 0;
while (HPChangedAction != null)
HPChangedAction -= HPChangedAction;
while (DeadAction != null)
DeadAction -= DeadAction;
}
#endregion
#region
public virtual void Damage(int hit)
{
if (IsDead)
return;
HP -= hit;
}
protected virtual void OnDie(FBRole role) {}
#endregion
}
}