移除 bd

This commit is contained in:
2026-05-27 16:28:40 +08:00
parent 0b7568a96f
commit 0082c0b727
535 changed files with 10 additions and 35957 deletions

View File

@@ -1,25 +0,0 @@
#if GRAPH_DESIGNER
/// ---------------------------------------------
/// Behavior Designer
/// Copyright (c) Opsive. All Rights Reserved.
/// https://www.opsive.com
/// ---------------------------------------------
namespace Opsive.BehaviorDesigner.Runtime.Tasks.Conditionals
{
using Opsive.BehaviorDesigner.Runtime.Components;
using Opsive.GraphDesigner.Runtime;
/// <summary>
/// A TaskObject implementation of the Conditional task.
/// </summary>
[NodeIcon("dea5c23eac9d12c4cbd380cc879816ea", "2963cf3eb0c036449829254b2074c4c3")]
public abstract class Conditional : Task, IConditional, IConditionalReevaluation
{
/// <summary>
/// Reevaluates the task logic. Returns a TaskStatus indicating how the behavior tree flow should proceed.
/// </summary>
/// <returns>The status of the task during the reevaluation phase.</returns>
public virtual TaskStatus OnReevaluateUpdate() { return OnUpdate(); }
}
}
#endif

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 3a2db972855f8ce48b67b75699c1745a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,37 +0,0 @@
#if GRAPH_DESIGNER
/// ---------------------------------------------
/// Behavior Designer
/// Copyright (c) Opsive. All Rights Reserved.
/// https://www.opsive.com
/// ---------------------------------------------
namespace Opsive.BehaviorDesigner.Runtime.Tasks.Conditionals
{
using Opsive.GraphDesigner.Runtime;
using UnityEngine;
/// <summary>
/// A TaskObject implementation of the Conditional task. This class can be used when the task should not be grouped by the StackedConditional task.
/// </summary>
[NodeIcon("dea5c23eac9d12c4cbd380cc879816ea", "2963cf3eb0c036449829254b2074c4c3")]
public abstract class ConditionalNode : Task, ITreeLogicNode, IConditional, IConditionalReevaluation
{
[Tooltip("The index of the node.")]
[SerializeField] ushort m_Index;
[Tooltip("The parent index of the node. ushort.MaxValue indicates no parent.")]
[SerializeField] ushort m_ParentIndex;
[Tooltip("The sibling index of the node. ushort.MaxValue indicates no sibling.")]
[SerializeField] ushort m_SiblingIndex;
public ushort Index { get => m_Index; set => m_Index = value; }
public ushort ParentIndex { get => m_ParentIndex; set => m_ParentIndex = value; }
public ushort SiblingIndex { get => m_SiblingIndex; set => m_SiblingIndex = value; }
public ushort RuntimeIndex { get; set; }
/// <summary>
/// Reevaluates the task logic. Returns a TaskStatus indicating how the behavior tree flow should proceed.
/// </summary>
/// <returns>The status of the task during the reevaluation phase.</returns>
public virtual TaskStatus OnReevaluateUpdate() { return OnUpdate(); }
}
}
#endif

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 5a27f55166c97394ba777a25ede3e192
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,262 +0,0 @@
#if GRAPH_DESIGNER
/// ---------------------------------------------
/// Behavior Designer
/// Copyright (c) Opsive. All Rights Reserved.
/// https://www.opsive.com
/// ---------------------------------------------
namespace Opsive.BehaviorDesigner.Runtime.Tasks.Conditionals
{
using Opsive.GraphDesigner.Runtime;
using Opsive.GraphDesigner.Runtime.Variables;
using Opsive.Shared.Events;
using UnityEngine;
/// <summary>
/// A TaskObject implementation of the Conditional task. This class can be used when the task should not be grouped by the StackedConditional task.
/// </summary>
[NodeIcon("e6fc90c130121da4f9067b5e15b02975", "69959064b54a0cb4cb077dbb6967a3e1")]
[Opsive.Shared.Utility.Description("Returns success as soon as the event specified by eventName has been received.")]
public class HasReceivedEvent : TargetBehaviorTreeConditional
{
[Tooltip("The name of the event that should be registered.")]
[SerializeField] protected SharedVariable<string> m_EventName;
[Tooltip("Is the event a global event?")]
[SerializeField] protected SharedVariable<bool> m_GlobalEvent;
[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_EventRegistered;
private bool m_EventReceived;
private bool m_ResetEventReceived = true;
/// <summary>
/// The behavior tree has started.
/// </summary>
public override void OnBehaviorTreeStarted()
{
base.OnBehaviorTreeStarted();
RegisterEvents();
}
/// <summary>
/// Initializes the target behavior tree.
/// </summary>
protected override void InitializeTarget()
{
if (m_ResolvedBehaviorTree != null) {
UnregisterEvents();
}
base.InitializeTarget();
RegisterEvents();
}
/// <summary>
/// Registers for the events.
/// </summary>
private void RegisterEvents()
{
if (m_EventRegistered) {
return;
}
if (string.IsNullOrEmpty(m_EventName.Value)) {
Debug.LogError("Error: Unable to receive event. The event name is empty.");
return;
}
if (m_StoredValue1 == null || !m_StoredValue1.IsShared) {
if (m_GlobalEvent.Value) {
EventHandler.RegisterEvent(m_EventName.Value, ReceivedEvent);
} else {
EventHandler.RegisterEvent(m_ResolvedBehaviorTree, m_EventName.Value, ReceivedEvent);
}
} else {
if (m_StoredValue2 == null || !m_StoredValue2.IsShared) {
if (m_GlobalEvent.Value) {
EventHandler.RegisterEvent<object>(m_EventName.Value, ReceivedEvent);
} else {
EventHandler.RegisterEvent<object>(m_ResolvedBehaviorTree, m_EventName.Value, ReceivedEvent);
}
} else {
if (m_StoredValue3 == null || !m_StoredValue3.IsShared) {
if (m_GlobalEvent.Value) {
EventHandler.RegisterEvent<object, object>(m_EventName.Value, ReceivedEvent);
} else {
EventHandler.RegisterEvent<object, object>(m_ResolvedBehaviorTree, m_EventName.Value, ReceivedEvent);
}
} else {
if (m_GlobalEvent.Value) {
EventHandler.RegisterEvent<object, object, object>(m_EventName.Value, ReceivedEvent);
} else {
EventHandler.RegisterEvent<object, object, object>(m_ResolvedBehaviorTree, m_EventName.Value, ReceivedEvent);
}
}
}
}
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; }
m_EventRegistered = true;
m_RegisteredEventName = m_EventName.Value;
}
/// <summary>
/// The event name or parameter count has changed. Update the events.
/// </summary>
private void UpdateEvents()
{
UnregisterEvents();
RegisterEvents();
}
/// <summary>
/// A parameterless event has been recevied.
/// </summary>
private void ReceivedEvent()
{
m_EventReceived = true;
}
/// <summary>
/// A single parameter event has been received.
/// </summary>
/// <param name="arg1">The first parameter.</param>
private void ReceivedEvent(object arg1)
{
m_EventReceived = true;
if (m_StoredValue1 != null && m_StoredValue1.IsShared) { m_StoredValue1.SetValue(arg1); }
}
/// <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)
{
m_EventReceived = true;
if (m_StoredValue1 != null && m_StoredValue1.IsShared) { m_StoredValue1.SetValue(arg1); }
if (m_StoredValue2 != null && m_StoredValue2.IsShared) { m_StoredValue2.SetValue(arg2); }
}
/// <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)
{
m_EventReceived = true;
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); }
}
/// <summary>
/// Callback when the task is started.
/// </summary>
public override void OnStart()
{
base.OnStart();
if (m_ResetEventReceived) {
m_EventReceived = false;
}
}
/// <summary>
/// The task has been updated.
/// </summary>
/// <returns>True if an event has been received.</returns>
public override TaskStatus OnUpdate()
{
return m_EventReceived ? TaskStatus.Success : TaskStatus.Failure;
}
/// <summary>
/// Reevaluates the task logic.
/// </summary>
/// <returns>The status of the task during the reevaluation phase.</returns>
public override TaskStatus OnReevaluateUpdate()
{
if (m_EventReceived) {
// OnStart/OnUpdate will be called immediately after the task is reevaluated. Do not reset the receive status.
m_ResetEventReceived = false;
return TaskStatus.Success;
}
return TaskStatus.Failure;
}
/// <summary>
/// The task has ended.
/// </summary>
public override void OnEnd()
{
base.OnEnd();
m_EventReceived = false;
m_ResetEventReceived = true;
}
/// <summary>
/// The behavior tree has been stopped.
/// </summary>
/// <param name="paused">Is the behavior tree paused?</param>
public override void OnBehaviorTreeStopped(bool paused)
{
base.OnBehaviorTreeStopped(paused);
UnregisterEvents();
m_EventReceived = false;
m_ResetEventReceived = true;
}
/// <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.
if (m_GlobalEvent.Value) {
EventHandler.UnregisterEvent(m_RegisteredEventName, ReceivedEvent);
EventHandler.UnregisterEvent<object>(m_RegisteredEventName, ReceivedEvent);
EventHandler.UnregisterEvent<object, object>(m_RegisteredEventName, ReceivedEvent);
EventHandler.UnregisterEvent<object, object, object>(m_RegisteredEventName, ReceivedEvent);
} else {
EventHandler.UnregisterEvent(m_ResolvedBehaviorTree, m_RegisteredEventName, ReceivedEvent);
EventHandler.UnregisterEvent<object>(m_ResolvedBehaviorTree, m_RegisteredEventName, ReceivedEvent);
EventHandler.UnregisterEvent<object, object>(m_ResolvedBehaviorTree, m_RegisteredEventName, ReceivedEvent);
EventHandler.UnregisterEvent<object, object, object>(m_ResolvedBehaviorTree, m_RegisteredEventName, ReceivedEvent);
}
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; }
m_EventRegistered = false;
m_RegisteredEventName = string.Empty;
}
}
}
#endif

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 3c2c0606584fdc345a81cf527b283e30
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,38 +0,0 @@
#if GRAPH_DESIGNER
/// ---------------------------------------------
/// Behavior Designer
/// Copyright (c) Opsive. All Rights Reserved.
/// https://www.opsive.com
/// ---------------------------------------------
namespace Opsive.BehaviorDesigner.Runtime.Tasks.Conditionals
{
using Opsive.GraphDesigner.Runtime;
using Opsive.GraphDesigner.Runtime.Variables;
using System.Collections;
using UnityEngine;
[Opsive.Shared.Utility.Description("Returns true if the specified variable has a value.")]
public class HasValue : Conditional
{
[Tooltip("The variable to compare.")]
[SerializeField] protected SharedVariable m_Variable;
/// <summary>
/// Executes the task.
/// </summary>
/// <returns>The execution status of the task.</returns>
public override TaskStatus OnUpdate()
{
object variableValue = null;
if (m_Variable == null || (variableValue = m_Variable.GetValue()) == null || variableValue.Equals(null)) {
return TaskStatus.Failure;
}
if (variableValue is IList listValue) {
return listValue.Count > 0 ? TaskStatus.Success : TaskStatus.Failure;
}
return TaskStatus.Success;
}
}
}
#endif

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: e1e162d80f7bf49419493fe43c33c0a5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,29 +0,0 @@
#if GRAPH_DESIGNER
/// ---------------------------------------------
/// Behavior Designer
/// Copyright (c) Opsive. All Rights Reserved.
/// https://www.opsive.com
/// ---------------------------------------------
namespace Opsive.BehaviorDesigner.Runtime.Tasks.Conditionals
{
using Opsive.GraphDesigner.Runtime;
[NodeIcon("e0a8f1df788b6274a9a24003859dfa7e")]
[Opsive.Shared.Utility.Description("Returns true if the specified behavior tree is active.")]
public class IsBehaviorTreeActive : TargetBehaviorTreeConditional
{
/// <summary>
/// Executes the task logic.
/// </summary>
/// <returns>The status of the task.</returns>
public override TaskStatus OnUpdate()
{
if (m_ResolvedBehaviorTree == null) {
return TaskStatus.Failure;
}
return m_ResolvedBehaviorTree.IsActive() ? TaskStatus.Success : TaskStatus.Failure;
}
}
}
#endif

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 2d23ca37ee86b15428911307549ab429
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: a1963b538eafb4144b6fdd080af86056
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,32 +0,0 @@
#if GRAPH_DESIGNER
/// ---------------------------------------------
/// Behavior Designer
/// Copyright (c) Opsive. All Rights Reserved.
/// https://www.opsive.com
/// ---------------------------------------------
namespace Opsive.BehaviorDesigner.Runtime.Tasks.Conditionals.Math
{
using Opsive.GraphDesigner.Runtime;
using Opsive.GraphDesigner.Runtime.Variables;
using UnityEngine;
[Opsive.Shared.Utility.Description("Compares two boolean values.")]
[Shared.Utility.Category("Math")]
public class BoolComparison : Conditional
{
[Tooltip("The first boolean.")]
[SerializeField] protected SharedVariable<bool> m_Bool1;
[Tooltip("The second boolean.")]
[SerializeField] protected SharedVariable<bool> m_Bool2;
/// <summary>
/// Executes the task.
/// </summary>
/// <returns>The execution status of the task.</returns>
public override TaskStatus OnUpdate()
{
return m_Bool1.Value == m_Bool2.Value ? TaskStatus.Success : TaskStatus.Failure;
}
}
}
#endif

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 20df1d25d6eab8b429d6c8fe6af5a87a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,60 +0,0 @@
#if GRAPH_DESIGNER
/// ---------------------------------------------
/// Behavior Designer
/// Copyright (c) Opsive. All Rights Reserved.
/// https://www.opsive.com
/// ---------------------------------------------
namespace Opsive.BehaviorDesigner.Runtime.Tasks.Conditionals.Math
{
using Opsive.GraphDesigner.Runtime.Variables;
using UnityEngine;
[Opsive.Shared.Utility.Description("Compares two float values.")]
[Shared.Utility.Category("Math")]
public class FloatComparison : Conditional
{
/// <summary>
/// Specifies the type of comparison that should be performed.
/// </summary>
protected enum Operation
{
LessThan,
LessThanOrEqualTo,
EqualTo,
NotEqualTo,
GreaterThanOrEqualTo,
GreaterThan
}
[Tooltip("The operation that should be performed.")]
[SerializeField] protected SharedVariable<Operation> m_Operation;
[Tooltip("The first float.")]
[SerializeField] protected SharedVariable<float> m_Float1;
[Tooltip("The second float.")]
[SerializeField] protected SharedVariable<float> m_Float2;
/// <summary>
/// Executes the task.
/// </summary>
/// <returns>The execution status of the task.</returns>
public override TaskStatus OnUpdate()
{
switch (m_Operation.Value) {
case Operation.LessThan:
return m_Float1.Value < m_Float2.Value ? TaskStatus.Success : TaskStatus.Failure;
case Operation.LessThanOrEqualTo:
return m_Float1.Value <= m_Float2.Value ? TaskStatus.Success : TaskStatus.Failure;
case Operation.EqualTo:
return m_Float1.Value == m_Float2.Value ? TaskStatus.Success : TaskStatus.Failure;
case Operation.NotEqualTo:
return m_Float1.Value != m_Float2.Value ? TaskStatus.Success : TaskStatus.Failure;
case Operation.GreaterThanOrEqualTo:
return m_Float1.Value >= m_Float2.Value ? TaskStatus.Success : TaskStatus.Failure;
case Operation.GreaterThan:
return m_Float1.Value > m_Float2.Value ? TaskStatus.Success : TaskStatus.Failure;
}
return TaskStatus.Failure;
}
}
}
#endif

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: a440ba0c2e06f5c4aaeaf7921c721c69
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,32 +0,0 @@
#if GRAPH_DESIGNER
/// ---------------------------------------------
/// Behavior Designer
/// Copyright (c) Opsive. All Rights Reserved.
/// https://www.opsive.com
/// ---------------------------------------------
namespace Opsive.BehaviorDesigner.Runtime.Tasks.Conditionals.Math
{
using Opsive.GraphDesigner.Runtime;
using Opsive.GraphDesigner.Runtime.Variables;
using UnityEngine;
[Opsive.Shared.Utility.Description("Compares two GameObject values.")]
[Shared.Utility.Category("Math")]
public class GameObjectComparison : Conditional
{
[Tooltip("The first GameObject.")]
[SerializeField] protected SharedVariable<GameObject> m_GameObject1;
[Tooltip("The second GameObject.")]
[SerializeField] protected SharedVariable<GameObject> m_GameObject2;
/// <summary>
/// Executes the task.
/// </summary>
/// <returns>The execution status of the task.</returns>
public override TaskStatus OnUpdate()
{
return m_GameObject1.Value == m_GameObject2.Value ? TaskStatus.Success : TaskStatus.Failure;
}
}
}
#endif

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 3462716a0f02f06448a43ed06afe8ea8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,61 +0,0 @@
#if GRAPH_DESIGNER
/// ---------------------------------------------
/// Behavior Designer
/// Copyright (c) Opsive. All Rights Reserved.
/// https://www.opsive.com
/// ---------------------------------------------
namespace Opsive.BehaviorDesigner.Runtime.Tasks.Conditionals.Math
{
using Opsive.GraphDesigner.Runtime;
using Opsive.GraphDesigner.Runtime.Variables;
using UnityEngine;
[Opsive.Shared.Utility.Description("Compares two integer values.")]
[Shared.Utility.Category("Math")]
public class IntComparison : Conditional
{
/// <summary>
/// Specifies the type of comparison that should be performed.
/// </summary>
protected enum Operation
{
LessThan,
LessThanOrEqualTo,
EqualTo,
NotEqualTo,
GreaterThanOrEqualTo,
GreaterThan
}
[Tooltip("The operation that should be performed.")]
[SerializeField] protected SharedVariable<Operation> m_Operation;
[Tooltip("The first integer.")]
[SerializeField] protected SharedVariable<int> m_Integer1;
[Tooltip("The second integer.")]
[SerializeField] protected SharedVariable<int> m_Integer2;
/// <summary>
/// Executes the task.
/// </summary>
/// <returns>The execution status of the task.</returns>
public override TaskStatus OnUpdate()
{
switch (m_Operation.Value) {
case Operation.LessThan:
return m_Integer1.Value < m_Integer2.Value ? TaskStatus.Success : TaskStatus.Failure;
case Operation.LessThanOrEqualTo:
return m_Integer1.Value <= m_Integer2.Value ? TaskStatus.Success : TaskStatus.Failure;
case Operation.EqualTo:
return m_Integer1.Value == m_Integer2.Value ? TaskStatus.Success : TaskStatus.Failure;
case Operation.NotEqualTo:
return m_Integer1.Value != m_Integer2.Value ? TaskStatus.Success : TaskStatus.Failure;
case Operation.GreaterThanOrEqualTo:
return m_Integer1.Value >= m_Integer2.Value ? TaskStatus.Success : TaskStatus.Failure;
case Operation.GreaterThan:
return m_Integer1.Value > m_Integer2.Value ? TaskStatus.Success : TaskStatus.Failure;
}
return TaskStatus.Failure;
}
}
}
#endif

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: a375a939d653fe147a5a14a0c2bef1ff
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,32 +0,0 @@
#if GRAPH_DESIGNER
/// ---------------------------------------------
/// Behavior Designer
/// Copyright (c) Opsive. All Rights Reserved.
/// https://www.opsive.com
/// ---------------------------------------------
namespace Opsive.BehaviorDesigner.Runtime.Tasks.Conditionals.Math
{
using Opsive.GraphDesigner.Runtime;
using Opsive.GraphDesigner.Runtime.Variables;
using UnityEngine;
[Opsive.Shared.Utility.Description("Compares two Vector2 values.")]
[Shared.Utility.Category("Math")]
public class Vector2Comparison : Conditional
{
[Tooltip("The first Vector2.")]
[SerializeField] protected SharedVariable<Vector2> m_Vector1;
[Tooltip("The second Vector2.")]
[SerializeField] protected SharedVariable<Vector2> m_Vector2;
/// <summary>
/// Executes the task.
/// </summary>
/// <returns>The execution status of the task.</returns>
public override TaskStatus OnUpdate()
{
return m_Vector1.Value == m_Vector2.Value ? TaskStatus.Success : TaskStatus.Failure;
}
}
}
#endif

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 7c2b3d80126bb1f4d861fd3179310f4e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,32 +0,0 @@
#if GRAPH_DESIGNER
/// ---------------------------------------------
/// Behavior Designer
/// Copyright (c) Opsive. All Rights Reserved.
/// https://www.opsive.com
/// ---------------------------------------------
namespace Opsive.BehaviorDesigner.Runtime.Tasks.Conditionals.Math
{
using Opsive.GraphDesigner.Runtime;
using Opsive.GraphDesigner.Runtime.Variables;
using UnityEngine;
[Opsive.Shared.Utility.Description("Compares two Vector3 values.")]
[Shared.Utility.Category("Math")]
public class Vector3Comparison : Conditional
{
[Tooltip("The first Vector3.")]
[SerializeField] protected SharedVariable<Vector3> m_Vector1;
[Tooltip("The second Vector3.")]
[SerializeField] protected SharedVariable<Vector3> m_Vector2;
/// <summary>
/// Executes the task.
/// </summary>
/// <returns>The execution status of the task.</returns>
public override TaskStatus OnUpdate()
{
return m_Vector1.Value == m_Vector2.Value ? TaskStatus.Success : TaskStatus.Failure;
}
}
}
#endif

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 56a06b56642c23e41be3a6ed24331bc4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 61662c8f56bf6ff448ec2a4c8761613a
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,61 +0,0 @@
#if GRAPH_DESIGNER
/// ---------------------------------------------
/// Behavior Designer
/// Copyright (c) Opsive. All Rights Reserved.
/// https://www.opsive.com
/// ---------------------------------------------
namespace Opsive.BehaviorDesigner.Runtime.Tasks.Conditionals.Physics
{
using Opsive.GraphDesigner.Runtime;
using Opsive.GraphDesigner.Runtime.Variables;
using UnityEngine;
[Opsive.Shared.Utility.Description("Returns success when a collision starts. This task will only receive the physics callback if it is being reevaluated (with a conditional abort or under a parallel task).")]
[Shared.Utility.Category("Physics")]
public class HasEnteredCollision : Conditional
{
[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;
protected override bool ReceiveCollisionEnterCallback => true;
private bool m_EnteredCollision;
/// <summary>
/// Returns true when the agent has caused a collision.
/// </summary>
/// <returns>True when the agent has caused a collision.</returns>
public override TaskStatus OnUpdate()
{
return m_EnteredCollision ? TaskStatus.Success : TaskStatus.Failure;
}
/// <summary>
/// The task has ended.
/// </summary>
public override void OnEnd()
{
base.OnEnd();
m_EnteredCollision = false;
}
/// <summary>
/// The agent has caused a collision.
/// </summary>
/// <param name="collision">The collision that caused the event.</param>
protected override void OnCollisionEnter(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_EnteredCollision = true;
}
}
}
#endif

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 9ce4017c15025f648a4a737683b98b18
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,61 +0,0 @@
#if GRAPH_DESIGNER
/// ---------------------------------------------
/// Behavior Designer
/// Copyright (c) Opsive. All Rights Reserved.
/// https://www.opsive.com
/// ---------------------------------------------
namespace Opsive.BehaviorDesigner.Runtime.Tasks.Conditionals.Physics
{
using Opsive.GraphDesigner.Runtime;
using Opsive.GraphDesigner.Runtime.Variables;
using UnityEngine;
[Opsive.Shared.Utility.Description("Returns success when a 2D collision starts. This task will only receive the physics callback if it is being reevaluated (with a conditional abort or under a parallel task).")]
[Shared.Utility.Category("Physics")]
public class HasEnteredCollision2D : Conditional
{
[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;
protected override bool ReceiveCollisionEnterCallback => true;
private bool m_EnteredCollision;
/// <summary>
/// Returns true when the agent has caused a collision.
/// </summary>
/// <returns>True when the agent has caused a collision.</returns>
public override TaskStatus OnUpdate()
{
return m_EnteredCollision ? TaskStatus.Success : TaskStatus.Failure;
}
/// <summary>
/// The task has ended.
/// </summary>
public override void OnEnd()
{
base.OnEnd();
m_EnteredCollision = false;
}
/// <summary>
/// The agent has caused a collision.
/// </summary>
/// <param name="collision">The collision that caused the event.</param>
protected override void OnCollisionEnter2D(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_EnteredCollision = true;
}
}
}
#endif

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 37fa749cbcf6f7c459159eba18e9ca31
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,60 +0,0 @@
#if GRAPH_DESIGNER
/// ---------------------------------------------
/// Behavior Designer
/// Copyright (c) Opsive. All Rights Reserved.
/// https://www.opsive.com
/// ---------------------------------------------
namespace Opsive.BehaviorDesigner.Runtime.Tasks.Conditionals.Physics
{
using Opsive.GraphDesigner.Runtime.Variables;
using UnityEngine;
[Opsive.Shared.Utility.Description("Returns success when an object enters the trigger. This task will only receive the physics callback if it is being reevaluated (with a conditional abort or under a parallel task).")]
[Shared.Utility.Category("Physics")]
public class HasEnteredTrigger : Conditional
{
[Tooltip("The tag of the GameObject that the trigger should be checked against.")]
[SerializeField] protected SharedVariable<string> m_Tag;
[Tooltip("The entered trigger.")]
[SerializeField] protected SharedVariable<Collider> m_StoredOtherCollider;
protected override bool ReceiveTriggerEnterCallback => true;
private bool m_EnteredTrigger;
/// <summary>
/// Returns true when the agent has entered a trigger.
/// </summary>
/// <returns>True when the agent has entered a trigger.</returns>
public override TaskStatus OnUpdate()
{
return m_EnteredTrigger ? TaskStatus.Success : TaskStatus.Failure;
}
/// <summary>
/// The task has ended.
/// </summary>
public override void OnEnd()
{
base.OnEnd();
m_EnteredTrigger = false;
}
/// <summary>
/// The agent has entered a trigger.
/// </summary>
/// <param name="other">The trigger that the agent entered.</param>
protected override void OnTriggerEnter(Collider other)
{
if (!string.IsNullOrEmpty(m_Tag.Value) && !other.gameObject.CompareTag(m_Tag.Value)) {
return;
}
if (m_StoredOtherCollider != null && m_StoredOtherCollider.IsShared) { m_StoredOtherCollider.Value = other; }
m_EnteredTrigger = true;
}
}
}
#endif

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: fe018fbcfb4b7404f865318125440626
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,61 +0,0 @@
#if GRAPH_DESIGNER
/// ---------------------------------------------
/// Behavior Designer
/// Copyright (c) Opsive. All Rights Reserved.
/// https://www.opsive.com
/// ---------------------------------------------
namespace Opsive.BehaviorDesigner.Runtime.Tasks.Conditionals.Physics
{
using Opsive.GraphDesigner.Runtime;
using Opsive.GraphDesigner.Runtime.Variables;
using UnityEngine;
[Opsive.Shared.Utility.Description("Returns success when an object enters the 2D trigger. This task will only receive the physics callback if it is being reevaluated (with a conditional abort or under a parallel task).")]
[Shared.Utility.Category("Physics")]
public class HasEnteredTrigger2D : Conditional
{
[Tooltip("The tag of the GameObject that the trigger should be checked against.")]
[SerializeField] protected SharedVariable<string> m_Tag;
[Tooltip("The entered trigger.")]
[SerializeField] protected SharedVariable<Collider2D> m_StoredOtherCollider;
protected override bool ReceiveTriggerEnter2DCallback => true;
private bool m_EnteredTrigger;
/// <summary>
/// Returns true when the agent has entered a trigger.
/// </summary>
/// <returns>True when the agent has entered a trigger.</returns>
public override TaskStatus OnUpdate()
{
return m_EnteredTrigger ? TaskStatus.Success : TaskStatus.Failure;
}
/// <summary>
/// The task has ended.
/// </summary>
public override void OnEnd()
{
base.OnEnd();
m_EnteredTrigger = false;
}
/// <summary>
/// The agent has entered a trigger.
/// </summary>
/// <param name="other">The trigger that the agent entered.</param>
protected override void OnTriggerEnter2D(Collider2D other)
{
if (!string.IsNullOrEmpty(m_Tag.Value) && !other.gameObject.CompareTag(m_Tag.Value)) {
return;
}
if (m_StoredOtherCollider != null && m_StoredOtherCollider.IsShared) { m_StoredOtherCollider.Value = other; }
m_EnteredTrigger = true;
}
}
}
#endif

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 83caefa20e976f047b96f600eecffaed
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,61 +0,0 @@
#if GRAPH_DESIGNER
/// ---------------------------------------------
/// Behavior Designer
/// Copyright (c) Opsive. All Rights Reserved.
/// https://www.opsive.com
/// ---------------------------------------------
namespace Opsive.BehaviorDesigner.Runtime.Tasks.Conditionals.Physics
{
using Opsive.GraphDesigner.Runtime;
using Opsive.GraphDesigner.Runtime.Variables;
using UnityEngine;
[Opsive.Shared.Utility.Description("Returns success when a collision ends. This task will only receive the physics callback if it is being reevaluated (with a conditional abort or under a parallel task).")]
[Shared.Utility.Category("Physics")]
public class HasExitedCollision : Conditional
{
[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;
protected override bool ReceiveCollisionExitCallback => true;
private bool m_ExitedCollision;
/// <summary>
/// Returns true when the agent has left a collision.
/// </summary>
/// <returns>True when the agent has left a collision.</returns>
public override TaskStatus OnUpdate()
{
return m_ExitedCollision ? TaskStatus.Success : TaskStatus.Failure;
}
/// <summary>
/// The task has ended.
/// </summary>
public override void OnEnd()
{
base.OnEnd();
m_ExitedCollision = false;
}
/// <summary>
/// The agent has left a collision.
/// </summary>
/// <param name="collision">The collision that caused the event.</param>
protected override void OnCollisionExit(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_ExitedCollision = true;
}
}
}
#endif

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: c3ac7ec5199af7049b246d4eabfb0d51
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,61 +0,0 @@
#if GRAPH_DESIGNER
/// ---------------------------------------------
/// Behavior Designer
/// Copyright (c) Opsive. All Rights Reserved.
/// https://www.opsive.com
/// ---------------------------------------------
namespace Opsive.BehaviorDesigner.Runtime.Tasks.Conditionals.Physics
{
using Opsive.GraphDesigner.Runtime;
using Opsive.GraphDesigner.Runtime.Variables;
using UnityEngine;
[Opsive.Shared.Utility.Description("Returns success when a 2D collision ends. This task will only receive the physics callback if it is being reevaluated (with a conditional abort or under a parallel task).")]
[Shared.Utility.Category("Physics")]
public class HasExitedCollision2D : Conditional
{
[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;
protected override bool ReceiveCollisionExit2DCallback => true;
private bool m_ExitedCollision;
/// <summary>
/// Returns true when the agent has left a collision.
/// </summary>
/// <returns>True when the agent has left a collision.</returns>
public override TaskStatus OnUpdate()
{
return m_ExitedCollision ? TaskStatus.Success : TaskStatus.Failure;
}
/// <summary>
/// The task has ended.
/// </summary>
public override void OnEnd()
{
base.OnEnd();
m_ExitedCollision = false;
}
/// <summary>
/// The agent has left a collision.
/// </summary>
/// <param name="collision">The collision that caused the event.</param>
protected override void OnCollisionExit2D(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_ExitedCollision = true;
}
}
}
#endif

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 5fdb5f736525568428350e746b5b6d59
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,61 +0,0 @@
#if GRAPH_DESIGNER
/// ---------------------------------------------
/// Behavior Designer
/// Copyright (c) Opsive. All Rights Reserved.
/// https://www.opsive.com
/// ---------------------------------------------
namespace Opsive.BehaviorDesigner.Runtime.Tasks.Conditionals.Physics
{
using Opsive.GraphDesigner.Runtime;
using Opsive.GraphDesigner.Runtime.Variables;
using UnityEngine;
[Opsive.Shared.Utility.Description("Returns success when an object exits the trigger. This task will only receive the physics callback if it is being reevaluated (with a conditional abort or under a parallel task).")]
[Shared.Utility.Category("Physics")]
public class HasExitedTrigger : Conditional
{
[Tooltip("The tag of the GameObject that the trigger should be checked against.")]
[SerializeField] protected SharedVariable<string> m_Tag;
[Tooltip("The exited trigger.")]
[SerializeField] protected SharedVariable<Collider> m_StoredOtherCollider;
protected override bool ReceiveTriggerExitCallback => true;
private bool m_ExitedTrigger;
/// <summary>
/// Returns true when the agent has exited a trigger.
/// </summary>
/// <returns>True when the agent has exited a trigger.</returns>
public override TaskStatus OnUpdate()
{
return m_ExitedTrigger ? TaskStatus.Success : TaskStatus.Failure;
}
/// <summary>
/// The task has ended.
/// </summary>
public override void OnEnd()
{
base.OnEnd();
m_ExitedTrigger = false;
}
/// <summary>
/// The agent has exited a trigger.
/// </summary>
/// <param name="other">The trigger that the agent exited.</param>
protected override void OnTriggerExit(Collider other)
{
if (!string.IsNullOrEmpty(m_Tag.Value) && !other.gameObject.CompareTag(m_Tag.Value)) {
return;
}
if (m_StoredOtherCollider != null && m_StoredOtherCollider.IsShared) { m_StoredOtherCollider.Value = other; }
m_ExitedTrigger = true;
}
}
}
#endif

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 9bde13c58ab44304da9e904934375552
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,61 +0,0 @@
#if GRAPH_DESIGNER
/// ---------------------------------------------
/// Behavior Designer
/// Copyright (c) Opsive. All Rights Reserved.
/// https://www.opsive.com
/// ---------------------------------------------
namespace Opsive.BehaviorDesigner.Runtime.Tasks.Conditionals.Physics
{
using Opsive.GraphDesigner.Runtime;
using Opsive.GraphDesigner.Runtime.Variables;
using UnityEngine;
[Opsive.Shared.Utility.Description("Returns success when an object exits the 2D trigger. This task will only receive the physics callback if it is being reevaluated (with a conditional abort or under a parallel task).")]
[Shared.Utility.Category("Physics")]
public class HasExitedTrigger2D : Conditional
{
[Tooltip("The tag of the GameObject that the trigger should be checked against.")]
[SerializeField] protected SharedVariable<string> m_Tag;
[Tooltip("The exited trigger.")]
[SerializeField] protected SharedVariable<Collider2D> m_StoredOtherCollider;
protected override bool ReceiveTriggerExit2DCallback => true;
private bool m_ExitedTrigger;
/// <summary>
/// Returns true when the agent has exited a trigger.
/// </summary>
/// <returns>True when the agent has exited a trigger.</returns>
public override TaskStatus OnUpdate()
{
return m_ExitedTrigger ? TaskStatus.Success : TaskStatus.Failure;
}
/// <summary>
/// The task has ended.
/// </summary>
public override void OnEnd()
{
base.OnEnd();
m_ExitedTrigger = false;
}
/// <summary>
/// The agent has exited a trigger.
/// </summary>
/// <param name="other">The trigger that the agent exited.</param>
protected override void OnTriggerExit2D(Collider2D other)
{
if (!string.IsNullOrEmpty(m_Tag.Value) && !other.gameObject.CompareTag(m_Tag.Value)) {
return;
}
if (m_StoredOtherCollider != null && m_StoredOtherCollider.IsShared) { m_StoredOtherCollider.Value = other; }
m_ExitedTrigger = true;
}
}
}
#endif

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 74c369fe788ddbb4ab2b9265bdf4e9c0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,229 +0,0 @@
#if GRAPH_DESIGNER
/// ---------------------------------------------
/// Behavior Designer
/// Copyright (c) Opsive. All Rights Reserved.
/// https://www.opsive.com
/// ---------------------------------------------
namespace Opsive.BehaviorDesigner.Runtime.Tasks.Conditionals
{
using Opsive.BehaviorDesigner.Runtime.Components;
using Opsive.GraphDesigner.Runtime;
using Opsive.GraphDesigner.Runtime.Variables;
using Unity.Burst;
using Unity.Entities;
using UnityEngine;
using System;
/// <summary>
/// A node representation of the random probability task.
/// </summary>
[NodeIcon("69bf50f8923f54c4c8bb8e258883a411", "6c5770241610a4c4aae4ac3af0ac8bf8")]
[Opsive.Shared.Utility.Description("The random probability task will return success when the random probability is below the succeed probability. It will otherwise return failure.")]
public class RandomProbability : ECSConditionalTask<RandomProbabilityTaskSystem, RandomProbabilityComponent>, IReevaluateResponder, ICloneable
{
[Tooltip("The probability of the task returning success.")]
[SerializeField] [Range(0, 1)] float m_SuccessProbability;
[Tooltip("The seed of the random number generator. Set to 0 to use the entity index as the seed.")]
[SerializeField] uint m_Seed;
public float SuccessProbability { get => m_SuccessProbability; set => m_SuccessProbability = value; }
public uint Seed { get => m_Seed; set => m_Seed = value; }
public override ComponentType Flag { get => typeof(RandomProbabilityFlag); }
public ComponentType ReevaluateFlag { get => typeof(RandomProbabilityReevaluateFlag); }
public System.Type ReevaluateSystemType { get => typeof(RandomProbabilityReevaluateTaskSystem); }
/// <summary>
/// Returns a new TBufferElement for use by the system.
/// </summary>
/// <returns>A new TBufferElement for use by the system.</returns>
public override RandomProbabilityComponent GetBufferElement()
{
return new RandomProbabilityComponent()
{
Index = RuntimeIndex,
SuccessProbability = m_SuccessProbability,
Seed = m_Seed,
};
}
/// <summary>
/// Resets the task to its default values.
/// </summary>
public override void Reset()
{
m_SuccessProbability = 1;
}
/// <summary>
/// Creates a deep clone of the component.
/// </summary>
/// <returns>A deep clone of the component.</returns>
public object Clone()
{
var clone = Activator.CreateInstance<RandomProbability>();
clone.Index = Index;
clone.ParentIndex = ParentIndex;
clone.SiblingIndex = SiblingIndex;
clone.SuccessProbability = SuccessProbability;
return clone;
}
}
/// <summary>
/// The DOTS data structure for the RandomProbability class.
/// </summary>
public struct RandomProbabilityComponent : IBufferElementData
{
[Tooltip("The index of the node.")]
public ushort Index;
[Tooltip("The probability of the task returning success.")]
public float SuccessProbability;
[Tooltip("The seed of the random number generator.")]
public uint Seed;
[Tooltip("The random number generator for the task.")]
public Unity.Mathematics.Random RandomNumberGenerator;
}
/// <summary>
/// A DOTS tag indicating when a RandomProbability node is active.
/// </summary>
public struct RandomProbabilityFlag : IComponentData, IEnableableComponent { }
/// <summary>
/// Runs the RandomProbability logic.
/// </summary>
[DisableAutoCreation]
public partial struct RandomProbabilityTaskSystem : ISystem
{
/// <summary>
/// Creates the job.
/// </summary>
/// <param name="state">The current state of the system.</param>
[BurstCompile]
private void OnUpdate(ref SystemState state)
{
var query = SystemAPI.QueryBuilder().WithAllRW<TaskComponent>().WithAllRW<RandomProbabilityComponent>().WithAll<RandomProbabilityFlag, EvaluateFlag>().Build();
state.Dependency = new RandomProbabilityJob().ScheduleParallel(query, state.Dependency);
}
/// <summary>
/// Job which executes the task logic.
/// </summary>
[BurstCompile]
private partial struct RandomProbabilityJob : IJobEntity
{
/// <summary>
/// Executes the random probability logic.
/// </summary>
/// <param name="entity">The entity that is running the logic.</param>
/// <param name="taskComponents">An array of TaskComponents.</param>
/// <param name="randomProbabilityComponents">An array of RandomProbabilityComponents.</param>
[BurstCompile]
public void Execute(Entity entity, ref DynamicBuffer<TaskComponent> taskComponents, ref DynamicBuffer<RandomProbabilityComponent> randomProbabilityComponents)
{
for (int i = 0; i < randomProbabilityComponents.Length; ++i) {
var randomProbabilityComponent = randomProbabilityComponents[i];
var taskComponent = taskComponents[randomProbabilityComponent.Index];
if (taskComponent.Status == TaskStatus.Queued) {
// Generate a new random number seed for each entity.
if (randomProbabilityComponent.RandomNumberGenerator.state == 0) {
randomProbabilityComponent.RandomNumberGenerator = Unity.Mathematics.Random.CreateFromIndex(randomProbabilityComponent.Seed != 0 ? randomProbabilityComponent.Seed : (uint)entity.Index);
}
// NextFloat updates the RandomNumberGenerator so the component must be replaced.
var probability = randomProbabilityComponent.RandomNumberGenerator.NextFloat();
var randomProbabilityBuffer = randomProbabilityComponents;
randomProbabilityBuffer[i] = randomProbabilityComponent;
// The task will always change status.
taskComponent.Status = probability < randomProbabilityComponent.SuccessProbability ? TaskStatus.Success : TaskStatus.Failure;
taskComponents[randomProbabilityComponent.Index] = taskComponent;
} else if (taskComponent.Status == TaskStatus.Running) {
// A status of running means the task is being resumed from a conditional abort. Return success.
taskComponent.Status = TaskStatus.Success;
taskComponents[randomProbabilityComponent.Index] = taskComponent;
}
}
}
}
}
/// <summary>
/// A DOTS tag indicating when an RandomProbability node needs to be reevaluated.
/// </summary>
public struct RandomProbabilityReevaluateFlag : IComponentData, IEnableableComponent
{
}
/// <summary>
/// Runs the RandomProbability reevaluation logic.
/// </summary>
[DisableAutoCreation]
public partial struct RandomProbabilityReevaluateTaskSystem : ISystem
{
/// <summary>
/// Updates the reevaluation logic.
/// </summary>
/// <param name="state">The current state of the system.</param>
[BurstCompile]
private void OnUpdate(ref SystemState state)
{
foreach (var (taskComponents, randomProbabilityComponents, entity) in
SystemAPI.Query<DynamicBuffer<TaskComponent>, DynamicBuffer<RandomProbabilityComponent>>().WithAll<RandomProbabilityReevaluateFlag, EvaluateFlag>().WithEntityAccess()) {
for (int i = 0; i < randomProbabilityComponents.Length; ++i) {
var randomProbabilityComponent = randomProbabilityComponents[i];
var taskComponent = taskComponents[randomProbabilityComponent.Index];
if (!taskComponent.Reevaluate) {
continue;
}
// NextFloat updates the RandomNumberGenerator so the component must be replaced.
var probability = randomProbabilityComponent.RandomNumberGenerator.NextFloat();
var randomProbabilityBuffer = randomProbabilityComponents;
randomProbabilityBuffer[i] = randomProbabilityComponent;
var status = probability < randomProbabilityComponent.SuccessProbability ? TaskStatus.Success : TaskStatus.Failure;
if (status != taskComponent.Status) {
taskComponent.Status = status;
var buffer = taskComponents;
buffer[taskComponent.Index] = taskComponent;
}
}
}
}
}
[NodeIcon("69bf50f8923f54c4c8bb8e258883a411", "6c5770241610a4c4aae4ac3af0ac8bf8")]
[Opsive.Shared.Utility.Description("The random probability task will return success when the random probability is below the succeed probability. It will otherwise return failure.")]
public class SharedRandomProbability : Conditional
{
[Tooltip("The probability of the task returning success.")]
[SerializeField] SharedVariable<float> m_SuccessProbability;
[Tooltip("The seed of the random number generator. Set to 0 to disable.")]
[SerializeField] int m_Seed;
public SharedVariable<float> SuccessProbability { get => m_SuccessProbability; set => m_SuccessProbability = value; }
public int Seed { get => m_Seed; set => m_Seed = value; }
/// <summary>
/// Callback when the task is initialized.
/// </summary>
public override void OnAwake()
{
if (m_Seed != 0) {
UnityEngine.Random.InitState(m_Seed);
}
}
/// <summary>
/// Executes the task logic.
/// </summary>
/// <returns>The status of the task.</returns>
public override TaskStatus OnUpdate()
{
return UnityEngine.Random.value < m_SuccessProbability.Value ? TaskStatus.Success : TaskStatus.Failure;
}
}
}
#endif

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: b6240825104968e44a250a717de2f39a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,49 +0,0 @@
#if GRAPH_DESIGNER
/// ---------------------------------------------
/// Behavior Designer
/// Copyright (c) Opsive. All Rights Reserved.
/// https://www.opsive.com
/// ---------------------------------------------
namespace Opsive.BehaviorDesigner.Runtime.Tasks.Conditionals
{
using Opsive.GraphDesigner.Runtime;
/// <summary>
/// The StackedConditional task allows for multiple conditionals to be added to the same node.
/// </summary>
[NodeIcon("b2368834b8b80144a8b1ab97b609e966", "86fbf527a2c761e45bc4a47cf4894902")]
[Opsive.Shared.Utility.Description("Allows multiple conditional tasks to be added to a single node.")]
public class StackedConditional : StackedTask, IConditional, IConditionalReevaluation
{
/// <summary>
/// Reevaluates the task logic. Returns a TaskStatus indicating how the behavior tree flow should proceed.
/// </summary>
/// <returns>The status of the task during the reevaluation phase.</returns>
public TaskStatus OnReevaluateUpdate()
{
if (m_Tasks == null) {
return TaskStatus.Failure;
}
for (int i = 0; i < m_Tasks.Length; ++i) {
if (m_Tasks[i] == null) {
continue;
}
TaskStatus executionStatus;
if (m_Tasks[i] is IConditionalReevaluation reevaluateTask) {
executionStatus = reevaluateTask.OnReevaluateUpdate();
} else { // Use the regular update method if the task isn't designed for conditional aborts.
executionStatus = m_Tasks[i].OnUpdate();
}
if (m_ComparisonType == ComparisonType.Sequence && executionStatus == TaskStatus.Failure) {
return TaskStatus.Failure;
} else if (m_ComparisonType == ComparisonType.Selector && executionStatus == TaskStatus.Success) {
return TaskStatus.Success;
}
}
return m_ComparisonType == ComparisonType.Sequence ? TaskStatus.Success : TaskStatus.Failure;
}
}
}
#endif

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 73c25e0bc2411614e950faaf32f8cfa1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,71 +0,0 @@
#if GRAPH_DESIGNER
/// ---------------------------------------------
/// Behavior Designer
/// Copyright (c) Opsive. All Rights Reserved.
/// https://www.opsive.com
/// ---------------------------------------------
namespace Opsive.BehaviorDesigner.Runtime.Tasks.Conditionals
{
using Opsive.GraphDesigner.Runtime.Variables;
using UnityEngine;
/// <summary>
/// A TaskObject Conditional task which implements the shared TargetGameObject/TreeUserID objects.
/// </summary>
public abstract class TargetBehaviorTreeConditional : Conditional
{
[Tooltip("The GameObject of the target behavior tree. If the value is null the current GameObject will be used.")]
[SerializeField] protected SharedVariable<GameObject> m_TargetGameObject;
[Tooltip("The index of the tree if there are multiple behavior trees on the same GameObject.")]
[SerializeField] protected SharedVariable<int> m_TreeIndex;
protected BehaviorTree m_ResolvedBehaviorTree;
/// <summary>
/// Initializes the task.
/// </summary>
public override void OnAwake()
{
m_TargetGameObject.OnValueChange += InitializeTarget;
m_TreeIndex.OnValueChange += InitializeTarget;
InitializeTarget();
}
/// <summary>
/// Initializes the target behavior tree.
/// </summary>
protected virtual void InitializeTarget()
{
if (m_TargetGameObject.Value == null) {
m_ResolvedBehaviorTree = m_BehaviorTree;
} else {
var behaviorTrees = m_TargetGameObject.Value.GetComponents<BehaviorTree>();
if (behaviorTrees.Length == 1) {
m_ResolvedBehaviorTree = behaviorTrees[0];
} else if (behaviorTrees.Length > 1) {
for (int i = 0; i < behaviorTrees.Length; ++i) {
if (behaviorTrees[i].Index == m_TreeIndex.Value) {
m_ResolvedBehaviorTree = behaviorTrees[i];
break;
}
}
// If the UserID can't be found then use the first behavior tree.
if (m_ResolvedBehaviorTree == null) {
m_ResolvedBehaviorTree = behaviorTrees[0];
}
}
}
}
/// <summary>
/// The behavior tree has been destroyed.
/// </summary>
public override void OnDestroy()
{
m_TargetGameObject.OnValueChange -= InitializeTarget;
m_TreeIndex.OnValueChange -= InitializeTarget;
}
}
}
#endif

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 8829f667141e1c04d95d5f9f2f68c7e2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,53 +0,0 @@
#if GRAPH_DESIGNER
/// ---------------------------------------------
/// Behavior Designer
/// Copyright (c) Opsive. All Rights Reserved.
/// https://www.opsive.com
/// ---------------------------------------------
namespace Opsive.BehaviorDesigner.Runtime.Tasks.Conditionals
{
using Opsive.GraphDesigner.Runtime.Variables;
using UnityEngine;
/// <summary>
/// A TaskObject Conditional task which returns the current GameObject if the target is null.
/// </summary>
public abstract class TargetGameObjectConditional : Conditional
{
[Tooltip("The GameObject of the target behavior tree. If the value is null the current GameObject will be used.")]
[SerializeField] protected SharedVariable<GameObject> m_TargetGameObject;
protected override GameObject gameObject => m_ResolvedGameObject;
protected override Transform transform => m_ResolvedTransform;
protected GameObject m_ResolvedGameObject;
protected Transform m_ResolvedTransform;
/// <summary>
/// Initializes the task.
/// </summary>
public override void OnAwake()
{
m_TargetGameObject.OnValueChange += InitializeTarget;
InitializeTarget();
}
/// <summary>
/// Initializes the target GameObject.
/// </summary>
protected virtual void InitializeTarget()
{
m_ResolvedGameObject = (m_TargetGameObject.Value == null || m_TargetGameObject.Value.Equals(null)) ? m_GameObject : m_TargetGameObject.Value;
m_ResolvedTransform = m_ResolvedGameObject.transform;
}
/// <summary>
/// The behavior tree has been destroyed.
/// </summary>
public override void OnDestroy()
{
m_TargetGameObject.OnValueChange -= InitializeTarget;
}
}
}
#endif

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: e53a3005031301c4c9f7c723c82763ce
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: