添加bd
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
#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 UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// A base IEventNode implementation.
|
||||
/// </summary>
|
||||
[NodeIcon("9041375773f69454792084ab67820b7e", "b1382ad24c668174c9a6e0bd00f229e3")]
|
||||
public abstract class EventNode : IEventNode, IEventNodeGameObjectReceiver
|
||||
{
|
||||
[Tooltip("The index of the ITreeLogicNode that the IEventNode is connected to. ushort.MaxValue indicates no connection.")]
|
||||
[SerializeField] protected ushort m_ConnectedIndex;
|
||||
|
||||
public ushort ConnectedIndex { get => m_ConnectedIndex; set => m_ConnectedIndex = value; }
|
||||
|
||||
protected BehaviorTree m_BehaviorTree;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the node to the specified graph.
|
||||
/// </summary>
|
||||
/// <param name="graph">The graph that is initializing the task.</param>
|
||||
public virtual void Initialize(IGraph graph)
|
||||
{
|
||||
m_BehaviorTree = graph as BehaviorTree;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ae332159f8bb5f14c8a6d12075be9bab
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,60 @@
|
||||
#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;
|
||||
|
||||
[AllowMultipleTypes]
|
||||
[NodeIcon("06864c37115f11445b04701c616d0e14", "8b8a2793322238240b4f25171d772003")]
|
||||
[Opsive.Shared.Utility.Description("Invoked when the agent causes a collision.")]
|
||||
public class OnCollisionEnter : EventNode
|
||||
{
|
||||
[Tooltip("The tag of the GameObject that the collision should be checked against.")]
|
||||
[SerializeField] protected SharedVariable<string> m_Tag;
|
||||
[Tooltip("The collided GameObject.")]
|
||||
[SerializeField] protected SharedVariable<GameObject> m_StoredCollisionGameObject;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the node to the specified graph.
|
||||
/// </summary>
|
||||
/// <param name="graph">The graph that is initializing the task.</param>
|
||||
public override void Initialize(IGraph graph)
|
||||
{
|
||||
base.Initialize(graph);
|
||||
|
||||
m_BehaviorTree.OnBehaviorTreeDestroyed += Destroy;
|
||||
m_BehaviorTree.OnBehaviorTreeCollisionEnter += EnteredCollision;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The agent has caused a collision.
|
||||
/// </summary>
|
||||
/// <param name="collision">The collision that caused the event.</param>
|
||||
private void EnteredCollision(Collision collision)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(m_Tag.Value) && !collision.gameObject.CompareTag(m_Tag.Value)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_StoredCollisionGameObject != null && m_StoredCollisionGameObject.IsShared) { m_StoredCollisionGameObject.Value = collision.gameObject; }
|
||||
|
||||
m_BehaviorTree.StartBranch(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The behavior tree has been destroyed.
|
||||
/// </summary>
|
||||
private void Destroy()
|
||||
{
|
||||
m_BehaviorTree.OnBehaviorTreeDestroyed -= Destroy;
|
||||
m_BehaviorTree.OnBehaviorTreeCollisionEnter -= EnteredCollision;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8e38ab2e4d966814f8b760b1f9d64416
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,60 @@
|
||||
#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;
|
||||
|
||||
[AllowMultipleTypes]
|
||||
[NodeIcon("06864c37115f11445b04701c616d0e14", "8b8a2793322238240b4f25171d772003")]
|
||||
[Opsive.Shared.Utility.Description("Invoked when the agent causes a 2D collision.")]
|
||||
public class OnCollisionEnter2D : EventNode
|
||||
{
|
||||
[Tooltip("The tag of the GameObject that the collision should be checked against.")]
|
||||
[SerializeField] protected SharedVariable<string> m_Tag;
|
||||
[Tooltip("The collided GameObject.")]
|
||||
[SerializeField] protected SharedVariable<GameObject> m_StoredCollisionGameObject;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the node to the specified graph.
|
||||
/// </summary>
|
||||
/// <param name="graph">The graph that is initializing the task.</param>
|
||||
public override void Initialize(IGraph graph)
|
||||
{
|
||||
base.Initialize(graph);
|
||||
|
||||
m_BehaviorTree.OnBehaviorTreeDestroyed += Destroy;
|
||||
m_BehaviorTree.OnBehaviorTreeCollisionEnter2D += EnteredCollision2D;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The agent has caused a 2D collision.
|
||||
/// </summary>
|
||||
/// <param name="collision">The collision that caused the event.</param>
|
||||
private void EnteredCollision2D(Collision2D collision)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(m_Tag.Value) && !collision.gameObject.CompareTag(m_Tag.Value)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_StoredCollisionGameObject != null && m_StoredCollisionGameObject.IsShared) { m_StoredCollisionGameObject.Value = collision.gameObject; }
|
||||
|
||||
m_BehaviorTree.StartBranch(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The behavior tree has been destroyed.
|
||||
/// </summary>
|
||||
private void Destroy()
|
||||
{
|
||||
m_BehaviorTree.OnBehaviorTreeDestroyed -= Destroy;
|
||||
m_BehaviorTree.OnBehaviorTreeCollisionEnter2D -= EnteredCollision2D;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2280b16f94f390e43a89c0550eac22cc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,60 @@
|
||||
#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;
|
||||
|
||||
[AllowMultipleTypes]
|
||||
[NodeIcon("06864c37115f11445b04701c616d0e14", "8b8a2793322238240b4f25171d772003")]
|
||||
[Opsive.Shared.Utility.Description("Invoked when the agent leaves a collision.")]
|
||||
public class OnCollisionExit : EventNode
|
||||
{
|
||||
[Tooltip("The tag of the GameObject that the collision should be checked against.")]
|
||||
[SerializeField] protected SharedVariable<string> m_Tag;
|
||||
[Tooltip("The collided GameObject.")]
|
||||
[SerializeField] protected SharedVariable<GameObject> m_StoredCollisionGameObject;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the node to the specified graph.
|
||||
/// </summary>
|
||||
/// <param name="graph">The graph that is initializing the task.</param>
|
||||
public override void Initialize(IGraph graph)
|
||||
{
|
||||
base.Initialize(graph);
|
||||
|
||||
m_BehaviorTree.OnBehaviorTreeDestroyed += Destroy;
|
||||
m_BehaviorTree.OnBehaviorTreeCollisionExit += ExitedCollision;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The agent has left a collision.
|
||||
/// </summary>
|
||||
/// <param name="collision">The collision that caused the event.</param>
|
||||
private void ExitedCollision(Collision collision)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(m_Tag.Value) && !collision.gameObject.CompareTag(m_Tag.Value)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_StoredCollisionGameObject != null && m_StoredCollisionGameObject.IsShared) { m_StoredCollisionGameObject.Value = collision.gameObject; }
|
||||
|
||||
m_BehaviorTree.StartBranch(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The behavior tree has been destroyed.
|
||||
/// </summary>
|
||||
private void Destroy()
|
||||
{
|
||||
m_BehaviorTree.OnBehaviorTreeDestroyed -= Destroy;
|
||||
m_BehaviorTree.OnBehaviorTreeCollisionExit -= ExitedCollision;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fee2099d2a111594eadaee56c4998a20
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,60 @@
|
||||
#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;
|
||||
|
||||
[AllowMultipleTypes]
|
||||
[NodeIcon("06864c37115f11445b04701c616d0e14", "8b8a2793322238240b4f25171d772003")]
|
||||
[Opsive.Shared.Utility.Description("Invoked when the agent leaves a 2D collision.")]
|
||||
public class OnCollisionExit2D : EventNode
|
||||
{
|
||||
[Tooltip("The tag of the GameObject that the collision should be checked against.")]
|
||||
[SerializeField] protected SharedVariable<string> m_Tag;
|
||||
[Tooltip("The collided GameObject.")]
|
||||
[SerializeField] protected SharedVariable<GameObject> m_StoredCollisionGameObject;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the node to the specified graph.
|
||||
/// </summary>
|
||||
/// <param name="graph">The graph that is initializing the task.</param>
|
||||
public override void Initialize(IGraph graph)
|
||||
{
|
||||
base.Initialize(graph);
|
||||
|
||||
m_BehaviorTree.OnBehaviorTreeDestroyed += Destroy;
|
||||
m_BehaviorTree.OnBehaviorTreeCollisionExit2D += ExitedCollision2D;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The agent has left a 2D collision.
|
||||
/// </summary>
|
||||
/// <param name="collision">The collision that caused the event.</param>
|
||||
private void ExitedCollision2D(Collision2D collision)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(m_Tag.Value) && !collision.gameObject.CompareTag(m_Tag.Value)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_StoredCollisionGameObject != null && m_StoredCollisionGameObject.IsShared) { m_StoredCollisionGameObject.Value = collision.gameObject; }
|
||||
|
||||
m_BehaviorTree.StartBranch(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The behavior tree has been destroyed.
|
||||
/// </summary>
|
||||
private void Destroy()
|
||||
{
|
||||
m_BehaviorTree.OnBehaviorTreeDestroyed -= Destroy;
|
||||
m_BehaviorTree.OnBehaviorTreeCollisionExit2D -= ExitedCollision2D;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2bcef3a2041a6144fb9692d1244330af
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,130 @@
|
||||
#if GRAPH_DESIGNER
|
||||
/// ---------------------------------------------
|
||||
/// Behavior Designer
|
||||
/// Copyright (c) Opsive. All Rights Reserved.
|
||||
/// https://www.opsive.com
|
||||
/// ---------------------------------------------
|
||||
namespace Opsive.BehaviorDesigner.Runtime.Tasks.Events
|
||||
{
|
||||
using Opsive.BehaviorDesigner.Runtime.Components;
|
||||
using Opsive.BehaviorDesigner.Runtime.Groups;
|
||||
using Opsive.GraphDesigner.Runtime;
|
||||
using Unity.Burst;
|
||||
using Unity.Entities;
|
||||
using UnityEngine;
|
||||
|
||||
[AllowMultipleTypes]
|
||||
[NodeIcon("10ed9753a0870c84889dc42a7de397a8", "98f584ca47ddad64d9878314395ce160")]
|
||||
[Opsive.Shared.Utility.Description("EventNode that is invoked when an interrupt occurs.")]
|
||||
public class OnInterrupt : IEventNode, IEventNodeEntityReceiver
|
||||
{
|
||||
[Tooltip("The index of the ITreeLogicNode that the IEventNode is connected to. ushort.MaxValue indicates no connection.")]
|
||||
[SerializeField] protected ushort m_ConnectedIndex;
|
||||
[Tooltip("The node that caused the interruption.")]
|
||||
[SerializeField] ILogicNode m_InterruptionSource;
|
||||
public ushort ConnectedIndex { get => m_ConnectedIndex; set => m_ConnectedIndex = value; }
|
||||
|
||||
/// <summary>
|
||||
/// Adds the IBufferElementData to the entity.
|
||||
/// </summary>
|
||||
/// <param name="world">The world that the entity exists in.</param>
|
||||
/// <param name="entity">The entity that the IBufferElementData should be assigned to.</param>
|
||||
/// <param name="gameObject">The GameObject that the entity is attached to.</param>
|
||||
/// <param name="taskOffset">The offset between the connected index and the runtime index.</param>
|
||||
public void AddBufferElement(World world, Entity entity, GameObject gameObject, ushort taskOffset)
|
||||
{
|
||||
if (m_InterruptionSource == null || m_InterruptionSource.Index < 0) {
|
||||
Debug.LogError("Error: An Interruption Source task must be specified within the OnInterrupt node.");
|
||||
return;
|
||||
}
|
||||
|
||||
DynamicBuffer<OnInterruptEventComponent> buffer;
|
||||
if (world.EntityManager.HasBuffer<OnInterruptEventComponent>(entity)) {
|
||||
buffer = world.EntityManager.GetBuffer<OnInterruptEventComponent>(entity);
|
||||
} else {
|
||||
buffer = world.EntityManager.AddBuffer<OnInterruptEventComponent>(entity);
|
||||
}
|
||||
buffer.Add(new OnInterruptEventComponent() {
|
||||
ConnectedIndex = (ushort)(m_ConnectedIndex - taskOffset),
|
||||
InterruptionSourceIndex = m_InterruptionSource.RuntimeIndex,
|
||||
});
|
||||
|
||||
var interruptSystemGroup = world.GetOrCreateSystemManaged<InterruptTaskSystemGroup>();
|
||||
interruptSystemGroup.AddSystemToUpdateList(world.GetOrCreateSystem<OnInterruptSystem>());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears the IBufferElementData from the entity.
|
||||
/// </summary>
|
||||
/// <param name="world">The world that the entity exists in.</param>
|
||||
/// <param name="entity">The entity that the IBufferElementData should be cleared from.</param>
|
||||
public void ClearBufferElement(World world, Entity entity)
|
||||
{
|
||||
DynamicBuffer<OnInterruptEventComponent> buffer;
|
||||
if (world.EntityManager.HasBuffer<OnInterruptEventComponent>(entity)) {
|
||||
buffer = world.EntityManager.GetBuffer<OnInterruptEventComponent>(entity);
|
||||
buffer.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The DOTS data structure for the OnInterrupt class.
|
||||
/// </summary>
|
||||
public struct OnInterruptEventComponent : IBufferElementData
|
||||
{
|
||||
[Tooltip("The index of the ILogicNode that the IEventNode is connected to.")]
|
||||
public ushort ConnectedIndex;
|
||||
[Tooltip("The index of the node that can invoke the interrupt.")]
|
||||
public ushort InterruptionSourceIndex;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Processes any interrupts.
|
||||
/// </summary>
|
||||
[DisableAutoCreation]
|
||||
public partial struct OnInterruptSystem : ISystem
|
||||
{
|
||||
/// <summary>
|
||||
/// Updates the logic.
|
||||
/// </summary>
|
||||
/// <param name="state">The current state of the system.</param>
|
||||
[BurstCompile]
|
||||
private void OnUpdate(ref SystemState state)
|
||||
{
|
||||
foreach (var (branchComponents, taskComponents, onInterruptEvents, entity) in
|
||||
SystemAPI.Query<DynamicBuffer<BranchComponent>, DynamicBuffer<TaskComponent>, DynamicBuffer<OnInterruptEventComponent>>().WithAll<InterruptFlag>().WithEntityAccess()) {
|
||||
for (int i = 0; i < branchComponents.Length; ++i) {
|
||||
var branchComponent = branchComponents[i];
|
||||
if (branchComponent.InterruptType != InterruptType.None) {
|
||||
// The branch is going to cause an interrupt.
|
||||
for (int j = 0; j < onInterruptEvents.Length; ++j) {
|
||||
var onInterruptEvent = onInterruptEvents[j];
|
||||
if (branchComponent.ActiveIndex >= onInterruptEvent.InterruptionSourceIndex &&
|
||||
branchComponent.ActiveIndex < taskComponents[onInterruptEvent.InterruptionSourceIndex].SiblingIndex) {
|
||||
// Trigger the callback.
|
||||
var startTask = taskComponents[onInterruptEvent.ConnectedIndex];
|
||||
if (startTask.Status != TaskStatus.Queued && startTask.Status != TaskStatus.Running) {
|
||||
startTask.Status = TaskStatus.Queued;
|
||||
var taskComponentsBuffer = taskComponents;
|
||||
taskComponentsBuffer[onInterruptEvent.ConnectedIndex] = startTask;
|
||||
|
||||
var activeTag = taskComponents[onInterruptEvent.ConnectedIndex].FlagComponentType;
|
||||
state.EntityManager.SetComponentEnabled(entity, activeTag, true);
|
||||
|
||||
var connectedBranchIndex = taskComponents[onInterruptEvent.ConnectedIndex].BranchIndex;
|
||||
branchComponent = branchComponents[connectedBranchIndex];
|
||||
branchComponent.ActiveIndex = branchComponent.NextIndex = onInterruptEvent.ConnectedIndex;
|
||||
branchComponent.ActiveFlagComponentType = activeTag;
|
||||
var branchComponentsBuffer = branchComponents;
|
||||
branchComponentsBuffer[connectedBranchIndex] = branchComponent;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 29da32620f380b34aa56ef14a1088104
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,167 @@
|
||||
#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 Opsive.Shared.Events;
|
||||
using UnityEngine;
|
||||
|
||||
[AllowMultipleTypes]
|
||||
[Opsive.Shared.Utility.Description("Invoked when the specified event is received.")]
|
||||
public class OnReceivedEvent : EventNode
|
||||
{
|
||||
[Tooltip("The name of the event that starts the branch.")]
|
||||
[SerializeField] protected SharedVariable<string> m_EventName;
|
||||
[Tooltip("Optionally store the first sent argument.")]
|
||||
[RequireShared] [SerializeField] protected SharedVariable m_StoredValue1;
|
||||
[Tooltip("Optionally store the second sent argument.")]
|
||||
[RequireShared] [SerializeField] protected SharedVariable m_StoredValue2;
|
||||
[Tooltip("Optionally store the third sent argument.")]
|
||||
[RequireShared] [SerializeField] protected SharedVariable m_StoredValue3;
|
||||
|
||||
private string m_RegisteredEventName;
|
||||
private bool m_Initialized;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the node to the specified graph.
|
||||
/// </summary>
|
||||
/// <param name="graph">The graph that is initializing the task.</param>
|
||||
public override void Initialize(IGraph graph)
|
||||
{
|
||||
if (m_Initialized) {
|
||||
return;
|
||||
}
|
||||
m_Initialized = true;
|
||||
|
||||
base.Initialize(graph);
|
||||
|
||||
m_BehaviorTree.OnBehaviorTreeDestroyed += Destroy;
|
||||
|
||||
m_EventName.OnValueChange += UpdateEvents;
|
||||
if (m_StoredValue1 != null) { m_StoredValue1.OnValueChange += UpdateEvents; }
|
||||
if (m_StoredValue2 != null) { m_StoredValue2.OnValueChange += UpdateEvents; }
|
||||
if (m_StoredValue3 != null) { m_StoredValue3.OnValueChange += UpdateEvents; }
|
||||
|
||||
RegisterEvents();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers for the events.
|
||||
/// </summary>
|
||||
private void RegisterEvents()
|
||||
{
|
||||
if (m_StoredValue1 == null || !m_StoredValue1.IsShared) {
|
||||
EventHandler.RegisterEvent(m_BehaviorTree, m_EventName.Value, ReceivedEvent);
|
||||
} else {
|
||||
if (m_StoredValue2 == null || !m_StoredValue2.IsShared) {
|
||||
EventHandler.RegisterEvent<object>(m_BehaviorTree, m_EventName.Value, ReceivedEvent);
|
||||
} else {
|
||||
if (m_StoredValue3 == null || !m_StoredValue3.IsShared) {
|
||||
EventHandler.RegisterEvent<object, object>(m_BehaviorTree, m_EventName.Value, ReceivedEvent);
|
||||
} else {
|
||||
EventHandler.RegisterEvent<object, object, object>(m_BehaviorTree, m_EventName.Value, ReceivedEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_RegisteredEventName = m_EventName.Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unregisters for the events that were registered.
|
||||
/// </summary>
|
||||
private void UnregisterEvents()
|
||||
{
|
||||
// The events must be registered first in order to be unregistered.
|
||||
if (string.IsNullOrEmpty(m_RegisteredEventName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Unregister from all parameters. This will ensure no events are subscribed if the parameters change.
|
||||
EventHandler.UnregisterEvent(m_BehaviorTree, m_RegisteredEventName, ReceivedEvent);
|
||||
EventHandler.UnregisterEvent<object>(m_BehaviorTree, m_RegisteredEventName, ReceivedEvent);
|
||||
EventHandler.UnregisterEvent<object, object>(m_BehaviorTree, m_RegisteredEventName, ReceivedEvent);
|
||||
EventHandler.UnregisterEvent<object, object, object>(m_BehaviorTree, m_RegisteredEventName, ReceivedEvent);
|
||||
|
||||
m_RegisteredEventName = string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The event name or parameter count has changed. Update the events.
|
||||
/// </summary>
|
||||
private void UpdateEvents()
|
||||
{
|
||||
UnregisterEvents();
|
||||
RegisterEvents();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The event has been received.
|
||||
/// </summary>
|
||||
private void ReceivedEvent()
|
||||
{
|
||||
m_BehaviorTree.StartBranch(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A single parameter event has been received.
|
||||
/// </summary>
|
||||
/// <param name="arg1">The first parameter.</param>
|
||||
private void ReceivedEvent(object arg1)
|
||||
{
|
||||
if (m_StoredValue1 != null && m_StoredValue1.IsShared) { m_StoredValue1.SetValue(arg1); }
|
||||
|
||||
m_BehaviorTree.StartBranch(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A two parameter event has been received.
|
||||
/// </summary>
|
||||
/// <param name="arg1">The first parameter.</param>
|
||||
/// <param name="arg2">The second parameter.</param>
|
||||
private void ReceivedEvent(object arg1, object arg2)
|
||||
{
|
||||
if (m_StoredValue1 != null && m_StoredValue1.IsShared) { m_StoredValue1.SetValue(arg1); }
|
||||
if (m_StoredValue2 != null && m_StoredValue2.IsShared) { m_StoredValue2.SetValue(arg2); }
|
||||
|
||||
m_BehaviorTree.StartBranch(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A three parameter event has been received.
|
||||
/// </summary>
|
||||
/// <param name="arg1">The first parameter.</param>
|
||||
/// <param name="arg2">The second parameter.</param>
|
||||
/// <param name="arg3">The third parameter.</param>
|
||||
private void ReceivedEvent(object arg1, object arg2, object arg3)
|
||||
{
|
||||
if (m_StoredValue1 != null && m_StoredValue1.IsShared) { m_StoredValue1.SetValue(arg1); }
|
||||
if (m_StoredValue2 != null && m_StoredValue2.IsShared) { m_StoredValue2.SetValue(arg2); }
|
||||
if (m_StoredValue3 != null && m_StoredValue3.IsShared) { m_StoredValue3.SetValue(arg3); }
|
||||
|
||||
m_BehaviorTree.StartBranch(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The behavior tree has been destroyed.
|
||||
/// </summary>
|
||||
private void Destroy()
|
||||
{
|
||||
m_BehaviorTree.OnBehaviorTreeDestroyed -= Destroy;
|
||||
|
||||
m_EventName.OnValueChange -= UpdateEvents;
|
||||
if (m_StoredValue1 != null) { m_StoredValue1.OnValueChange -= UpdateEvents; }
|
||||
if (m_StoredValue2 != null) { m_StoredValue2.OnValueChange -= UpdateEvents; }
|
||||
if (m_StoredValue3 != null) { m_StoredValue3.OnValueChange -= UpdateEvents; }
|
||||
|
||||
UnregisterEvents();
|
||||
m_Initialized = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 08f3abf304431564faa9a446da5525be
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,60 @@
|
||||
#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;
|
||||
|
||||
[AllowMultipleTypes]
|
||||
[NodeIcon("06864c37115f11445b04701c616d0e14", "8b8a2793322238240b4f25171d772003")]
|
||||
[Opsive.Shared.Utility.Description("Invoked when the agent enters a trigger.")]
|
||||
public class OnTriggerEnter : EventNode
|
||||
{
|
||||
[Tooltip("The tag of the GameObject that the trigger should be checked against.")]
|
||||
[SerializeField] protected SharedVariable<string> m_Tag;
|
||||
[Tooltip("The entered trigger GameObject.")]
|
||||
[SerializeField] protected SharedVariable<GameObject> m_StoredOtherColliderGameObject;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the node to the specified graph.
|
||||
/// </summary>
|
||||
/// <param name="graph">The graph that is initializing the task.</param>
|
||||
public override void Initialize(IGraph graph)
|
||||
{
|
||||
base.Initialize(graph);
|
||||
|
||||
m_BehaviorTree.OnBehaviorTreeDestroyed += Destroy;
|
||||
m_BehaviorTree.OnBehaviorTreeTriggerEnter += EnteredTrigger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The agent has entered a trigger.
|
||||
/// </summary>
|
||||
/// <param name="other">The trigger that the agent entered.</param>
|
||||
private void EnteredTrigger(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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The behavior tree has been destroyed.
|
||||
/// </summary>
|
||||
private void Destroy()
|
||||
{
|
||||
m_BehaviorTree.OnBehaviorTreeDestroyed -= Destroy;
|
||||
m_BehaviorTree.OnBehaviorTreeTriggerEnter -= EnteredTrigger;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fedf6996bd7cfba4395c582ba40e2b47
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,60 @@
|
||||
#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;
|
||||
|
||||
[AllowMultipleTypes]
|
||||
[NodeIcon("06864c37115f11445b04701c616d0e14", "8b8a2793322238240b4f25171d772003")]
|
||||
[Opsive.Shared.Utility.Description("Invoked when the agent enters a 2D trigger.")]
|
||||
public class OnTriggerEnter2D : EventNode
|
||||
{
|
||||
[Tooltip("The tag of the GameObject that the trigger should be checked against.")]
|
||||
[SerializeField] protected SharedVariable<string> m_Tag;
|
||||
[Tooltip("The entered trigger GameObject.")]
|
||||
[SerializeField] protected SharedVariable<GameObject> m_StoredOtherColliderGameObject;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the node to the specified graph.
|
||||
/// </summary>
|
||||
/// <param name="graph">The graph that is initializing the task.</param>
|
||||
public override void Initialize(IGraph graph)
|
||||
{
|
||||
base.Initialize(graph);
|
||||
|
||||
m_BehaviorTree.OnBehaviorTreeDestroyed += Destroy;
|
||||
m_BehaviorTree.OnBehaviorTreeTriggerEnter2D += EnteredTrigger2D;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The agent has entered a 2D trigger.
|
||||
/// </summary>
|
||||
/// <param name="other">The trigger that the agent entered.</param>
|
||||
private void EnteredTrigger2D(Collider2D 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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The behavior tree has been destroyed.
|
||||
/// </summary>
|
||||
private void Destroy()
|
||||
{
|
||||
m_BehaviorTree.OnBehaviorTreeDestroyed -= Destroy;
|
||||
m_BehaviorTree.OnBehaviorTreeTriggerEnter2D -= EnteredTrigger2D;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1d33b9315f8977947bcb04bd9eced13e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,60 @@
|
||||
#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;
|
||||
|
||||
[AllowMultipleTypes]
|
||||
[NodeIcon("06864c37115f11445b04701c616d0e14", "8b8a2793322238240b4f25171d772003")]
|
||||
[Opsive.Shared.Utility.Description("Invoked when the agent exits a trigger.")]
|
||||
public class OnTriggerExit : EventNode
|
||||
{
|
||||
[Tooltip("The tag of the GameObject that the trigger should be checked against.")]
|
||||
[SerializeField] protected SharedVariable<string> m_Tag;
|
||||
[Tooltip("The exited trigger GameObject.")]
|
||||
[SerializeField] protected SharedVariable<GameObject> m_StoredOtherColliderGameObject;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the node to the specified graph.
|
||||
/// </summary>
|
||||
/// <param name="graph">The graph that is initializing the task.</param>
|
||||
public override void Initialize(IGraph graph)
|
||||
{
|
||||
base.Initialize(graph);
|
||||
|
||||
m_BehaviorTree.OnBehaviorTreeDestroyed += Destroy;
|
||||
m_BehaviorTree.OnBehaviorTreeTriggerExit += ExitedTrigger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The agent has exited a trigger.
|
||||
/// </summary>
|
||||
/// <param name="other">The trigger that the agent exited.</param>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The behavior tree has been destroyed.
|
||||
/// </summary>
|
||||
private void Destroy()
|
||||
{
|
||||
m_BehaviorTree.OnBehaviorTreeDestroyed -= Destroy;
|
||||
m_BehaviorTree.OnBehaviorTreeTriggerExit -= ExitedTrigger;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ee0ed271175ff684c8999ca1427a3f43
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,60 @@
|
||||
#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;
|
||||
|
||||
[AllowMultipleTypes]
|
||||
[NodeIcon("06864c37115f11445b04701c616d0e14", "8b8a2793322238240b4f25171d772003")]
|
||||
[Opsive.Shared.Utility.Description("Invoked when the agent exits a 2D trigger.")]
|
||||
public class OnTriggerExit2D : EventNode
|
||||
{
|
||||
[Tooltip("The tag of the GameObject that the trigger should be checked against.")]
|
||||
[SerializeField] protected SharedVariable<string> m_Tag;
|
||||
[Tooltip("The exited trigger GameObject.")]
|
||||
[SerializeField] protected SharedVariable<GameObject> m_StoredOtherColliderGameObject;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the node to the specified graph.
|
||||
/// </summary>
|
||||
/// <param name="graph">The graph that is initializing the task.</param>
|
||||
public override void Initialize(IGraph graph)
|
||||
{
|
||||
base.Initialize(graph);
|
||||
|
||||
m_BehaviorTree.OnBehaviorTreeDestroyed += Destroy;
|
||||
m_BehaviorTree.OnBehaviorTreeTriggerExit2D += ExitedTrigger2D;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The agent has exited a 2D trigger.
|
||||
/// </summary>
|
||||
/// <param name="other">The trigger that the agent exited.</param>
|
||||
private void ExitedTrigger2D(Collider2D 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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The behavior tree has been destroyed.
|
||||
/// </summary>
|
||||
private void Destroy()
|
||||
{
|
||||
m_BehaviorTree.OnBehaviorTreeDestroyed -= Destroy;
|
||||
m_BehaviorTree.OnBehaviorTreeTriggerExit2D -= ExitedTrigger2D;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: da04e1db385cc9d4ba72bccc9450531c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,24 @@
|
||||
#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 UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// The EventNode that is invoked when the behavior tree starts.
|
||||
/// </summary>
|
||||
[NodeIcon("8c35407905159694e8b83df15d3b039b", "df820d6e71423194188c7dcb1c1ae2e2")]
|
||||
public class Start : IEventNode
|
||||
{
|
||||
[Tooltip("The index of the ITreeLogicNode that the IEventNode is connected to. ushort.MaxValue indicates no connection.")]
|
||||
[SerializeField] protected ushort m_ConnectedIndex;
|
||||
|
||||
public ushort ConnectedIndex { get => m_ConnectedIndex; set => m_ConnectedIndex = value; }
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a59ed1fcf4540d54fbc57ff4e2a3fe04
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user