35 lines
1.0 KiB
C#
35 lines
1.0 KiB
C#
using Opsive.BehaviorDesigner.Runtime.Tasks;
|
|
using Opsive.GraphDesigner.Runtime.Variables;
|
|
using Opsive.Shared.Utility;
|
|
using UnityEngine;
|
|
|
|
namespace Cielonos.MainGame.Characters.AI
|
|
{
|
|
[Category("Cielonos")]
|
|
[Description("消耗能量")]
|
|
public class ConsumeEnergy : AutomataActionBase
|
|
{
|
|
private AttributeSubmodule attributeSm;
|
|
public SharedVariable<float> energyCost;
|
|
|
|
public override void OnAwake()
|
|
{
|
|
base.OnAwake();
|
|
attributeSm = self.attributeSm;
|
|
}
|
|
|
|
public override TaskStatus OnUpdate()
|
|
{
|
|
if (!attributeSm.Has("Energy")) return TaskStatus.Failure;
|
|
|
|
if (attributeSm["Energy"] >= energyCost.Value)
|
|
{
|
|
attributeSm["Energy"] -= energyCost.Value;
|
|
Debug.Log($"Consumed {energyCost.Value} energy. Remaining energy: {attributeSm["Energy"]}");
|
|
return TaskStatus.Success;
|
|
}
|
|
|
|
return TaskStatus.Failure;
|
|
}
|
|
}
|
|
} |