68 lines
1.7 KiB
C#
68 lines
1.7 KiB
C#
using Sirenix.OdinInspector;
|
|
using UnityEngine;
|
|
|
|
// ReSharper disable once CheckNamespace
|
|
namespace BlueWaterProject
|
|
{
|
|
[SelectionBase]
|
|
public class HouseInfo : MonoBehaviour, IDamageable
|
|
{
|
|
#region Property and variable
|
|
|
|
[SerializeField] private IslandInfo islandInfo;
|
|
|
|
[SerializeField] private float maxHp = 500f;
|
|
|
|
[DisableIf("@true")]
|
|
[SerializeField] private float currentHp;
|
|
|
|
#endregion
|
|
|
|
#region Unity built-in function
|
|
|
|
private void Awake()
|
|
{
|
|
SetCurrentHp(maxHp);
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
RemoveIslandInfo();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Interface property and function
|
|
|
|
public void TakeDamage(float attackerPower, float attackerShieldPenetrationRate = default, Vector3? attackPos = null)
|
|
{
|
|
var changeHp = Mathf.Max(currentHp - attackerPower, 0);
|
|
SetCurrentHp(changeHp);
|
|
|
|
// 건물 파괴
|
|
if (changeHp == 0f)
|
|
{
|
|
Destroy(gameObject);
|
|
RemoveIslandInfo();
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Custom function
|
|
|
|
private void RemoveIslandInfo()
|
|
{
|
|
if (islandInfo == null) return;
|
|
|
|
islandInfo.RemoveListElement(islandInfo.HouseList, transform);
|
|
islandInfo.RemoveListElement(islandInfo.TargetAllList, transform);
|
|
}
|
|
|
|
public float GetCurrentHp() => currentHp;
|
|
public void SetCurrentHp(float value) => currentHp = value;
|
|
public void SetIslandInfo(IslandInfo island) => islandInfo = island;
|
|
|
|
#endregion
|
|
}
|
|
} |