WXMC/.svn/pristine/c2/c2c0b52ad9d2b8de1952a8c4e2c492063438da21.svn-base
2024-12-04 16:18:46 +08:00

114 lines
2.2 KiB
Plaintext

using Sirenix.OdinInspector;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public enum BuffLifeTypes
{
Once,
Forever,
Time,
}
public enum BuffContext
{
Self,
SourceUnit,
}
public class PHomeBuff : MonoBehaviour
{
[SerializeField]
private string m_description;
public string Description
{
get
{
return m_description;
}
}
[SerializeField]
protected Sprite m_desImage;
public Sprite DesImage
{
get
{
return m_desImage;
}
}
[SerializeField]
protected Sprite m_lotteryImage;
public Sprite LotteryImage
{
get
{
return m_lotteryImage;
}
}
[HideInEditorMode]
public PHomeBuff BuffPrefab;
[HideInEditorMode]
public PHomeUnit SourceUnit;
[HideInEditorMode]
public PHomeUnit Unit;
public PHomeBuffManager BuffManager;
public BuffLifeTypes LifeType;
[ShowIf("LifeType", BuffLifeTypes.Time)]
public float LifeTime;
[HideInEditorMode]
public float LifeTimer;
public void StartBuffEvents()
{
foreach (var item in GetComponents<PHomeBuffEvent>())
{
item.FromBuff = this;
item.OnEventStart();
}
}
public void EndBuffEvents()
{
foreach (var item in GetComponents<PHomeBuffEvent>())
{
item.OnEventEnd();
}
}
public PHomeUnit GetUnit(BuffContext context, bool ensureFound = false)
{
PHomeUnit result = null;
switch (context)
{
case BuffContext.SourceUnit:
result = SourceUnit;
break;
case BuffContext.Self:
result = Unit;
break;
default:
break;
}
if (ensureFound && result == null)
{
throw new System.Exception($"Unit not found on buff {this} with context");
}
return result;
}
public float CalcBuffValue(BuffContext unitContext, PHomeUnitValues source, float ratio, float constValue)
{
PHomeUnit unit = GetUnit(unitContext, true);
return unit.GetValue(source) * ratio + constValue;
}
}