#if GRAPH_DESIGNER
/// ---------------------------------------------
/// Behavior Designer
/// Copyright (c) Opsive. All Rights Reserved.
/// https://www.opsive.com
/// ---------------------------------------------
namespace Opsive.BehaviorDesigner.Runtime.Tasks.Events
{
using Opsive.GraphDesigner.Runtime;
using Opsive.GraphDesigner.Runtime.Variables;
using UnityEngine;
///
/// The EventNode that is invoked when the agent exits a trigger.
///
[AllowMultipleTypes]
[NodeIcon("06864c37115f11445b04701c616d0e14", "8b8a2793322238240b4f25171d772003")]
public class OnTriggerExit : EventNode
{
[Tooltip("The tag of the GameObject that the trigger should be checked against.")]
[SerializeField] protected SharedVariable m_Tag;
[Tooltip("The exited trigger GameObject.")]
[SerializeField] protected SharedVariable m_StoredOtherColliderGameObject;
///
/// Initializes the node to the specified graph.
///
/// The graph that is initializing the task.
public override void Initialize(IGraph graph)
{
base.Initialize(graph);
m_BehaviorTree.OnBehaviorTreeDestroyed += Destroy;
m_BehaviorTree.OnBehaviorTreeTriggerExit += ExitedTrigger;
}
///
/// The agent has exited a trigger.
///
/// The trigger that the agent exited.
private void ExitedTrigger(Collider other)
{
if (!string.IsNullOrEmpty(m_Tag.Value) && !other.gameObject.CompareTag(m_Tag.Value)) {
return;
}
if (m_StoredOtherColliderGameObject != null && m_StoredOtherColliderGameObject.IsShared) { m_StoredOtherColliderGameObject.Value = other.gameObject; }
m_BehaviorTree.StartBranch(this);
}
///
/// The behavior tree has been destroyed.
///
private void Destroy()
{
m_BehaviorTree.OnBehaviorTreeDestroyed -= Destroy;
m_BehaviorTree.OnBehaviorTreeTriggerExit -= ExitedTrigger;
}
}
}
#endif