Files
Cielonos/Packages/com.opsive.behaviordesigner/Samples~/Scripts/Tasks/Harvest.cs
SoulliesOfficial 50ee502684 完善
2026-02-13 09:22:11 -05:00

55 lines
1.7 KiB
C#

/// ---------------------------------------------
/// Behavior Designer
/// Copyright (c) Opsive. All Rights Reserved.
/// https://www.opsive.com
/// ---------------------------------------------
namespace Opsive.BehaviorDesigner.Samples
{
using Opsive.BehaviorDesigner.Runtime.Tasks;
using Opsive.BehaviorDesigner.Runtime.Tasks.Actions;
using UnityEngine;
/// <summary>
/// Uses the ingredients to craft the item
/// </summary>
[Shared.Utility.Category("Behavior Designer Samples")]
public class Craft : Action
{
[Tooltip("Should the crafting be started?")]
[SerializeField] protected bool m_StartCraft;
protected override bool ReceiveTriggerEnterCallback => true;
private CraftTrigger m_CraftTrigger;
/// <summary>
/// Picks up the resource.
/// </summary>
/// <returns>Success if the agent was able to pickup the resource, otherwise failure if the resource is null.</returns>
public override TaskStatus OnUpdate()
{
if (m_CraftTrigger == null) {
return TaskStatus.Failure;
}
if (m_StartCraft) {
m_CraftTrigger.StartCraft();
} else {
m_CraftTrigger.Craft();
}
return TaskStatus.Success;
}
/// <summary>
/// The agent has entered a trigger.
/// </summary>
/// <param name="other">The trigger that the agent entered.</param>
protected override void OnTriggerEnter(Collider other)
{
CraftTrigger craftTrigger;
if ((craftTrigger = other.GetComponent<CraftTrigger>()) != null) {
m_CraftTrigger = craftTrigger;
}
}
}
}