chore: initial commit
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
#if GRAPH_DESIGNER
|
||||
/// ---------------------------------------------
|
||||
/// Behavior Designer
|
||||
/// Copyright (c) Opsive. All Rights Reserved.
|
||||
/// https://www.opsive.com
|
||||
/// ---------------------------------------------
|
||||
namespace Opsive.BehaviorDesigner.Runtime.Groups
|
||||
{
|
||||
using Opsive.BehaviorDesigner.Runtime.Systems;
|
||||
using Unity.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// Grouping for the systems that should before other systems.
|
||||
/// </summary>
|
||||
[UpdateInGroup(typeof(BehaviorTreeSystemGroup), OrderFirst = true)]
|
||||
public partial class BeforeTraversalSystemGroup : ComponentSystemGroup
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Grouping for the task systems that should reevaluate.
|
||||
/// </summary>
|
||||
[UpdateInGroup(typeof(BeforeTraversalSystemGroup))]
|
||||
public partial class ReevaluateTaskSystemGroup : ComponentSystemGroup
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Grouping for the systems that run before the tree execution.
|
||||
/// </summary>
|
||||
[UpdateInGroup(typeof(BehaviorTreeSystemGroup))]
|
||||
public partial class InterruptSystemGroup : ComponentSystemGroup
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Grouping for the task systems that can cause interrupts.
|
||||
/// </summary>
|
||||
[UpdateInGroup(typeof(InterruptSystemGroup))]
|
||||
[UpdateAfter(typeof(InterruptSystem))]
|
||||
[UpdateBefore(typeof(InterruptCleanupSystem))]
|
||||
public partial class InterruptTaskSystemGroup : ComponentSystemGroup
|
||||
{
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 83e6fa82f6125e140a3d0bd4737feeb3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,80 @@
|
||||
#if GRAPH_DESIGNER
|
||||
/// ---------------------------------------------
|
||||
/// Behavior Designer
|
||||
/// Copyright (c) Opsive. All Rights Reserved.
|
||||
/// https://www.opsive.com
|
||||
/// ---------------------------------------------
|
||||
namespace Opsive.BehaviorDesigner.Runtime.Groups
|
||||
{
|
||||
using Opsive.BehaviorDesigner.Runtime.Systems;
|
||||
using Unity.Entities;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// System group which runs all of the behavior tree systems.
|
||||
/// </summary>
|
||||
[UpdateInGroup(typeof(SimulationSystemGroup))]
|
||||
[UpdateAfter(typeof(BeginSimulationEntityCommandBufferSystem))]
|
||||
public partial class BehaviorTreeSystemGroup : ComponentSystemGroup
|
||||
{
|
||||
private bool m_Alive;
|
||||
|
||||
public bool Alive { get => m_Alive; }
|
||||
|
||||
/// <summary>
|
||||
/// Disable the group if there are no behavior trees.
|
||||
/// </summary>
|
||||
[RuntimeInitializeOnLoadMethod]
|
||||
private static void Init()
|
||||
{
|
||||
if (BehaviorTree.BehaviorTreeCount > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
var worlds = World.All;
|
||||
for (int i = 0; i < worlds.Count; ++i) {
|
||||
var systemGroup = worlds[i].GetExistingSystemManaged<BehaviorTreeSystemGroup>();
|
||||
if (systemGroup == null) {
|
||||
continue;
|
||||
}
|
||||
systemGroup.Enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The group has been created.
|
||||
/// </summary>
|
||||
protected override void OnCreate()
|
||||
{
|
||||
base.OnCreate();
|
||||
|
||||
m_Alive = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update the system group.
|
||||
/// </summary>
|
||||
protected override void OnUpdate()
|
||||
{
|
||||
base.OnUpdate();
|
||||
|
||||
// Stop running if all trees have completed.
|
||||
var systemHandle = World.GetExistingSystem<DetermineEvaluationSystem>();
|
||||
var system = EntityManager.WorldUnmanaged.GetUnsafeSystemRef<DetermineEvaluationSystem>(systemHandle);
|
||||
if (!system.Active) {
|
||||
Enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The group has been destroyed.
|
||||
/// </summary>
|
||||
protected override void OnDestroy()
|
||||
{
|
||||
base.OnDestroy();
|
||||
|
||||
m_Alive = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 905219e69953a5e479911f095744ec54
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,41 @@
|
||||
#if GRAPH_DESIGNER
|
||||
/// ---------------------------------------------
|
||||
/// Behavior Designer
|
||||
/// Copyright (c) Opsive. All Rights Reserved.
|
||||
/// https://www.opsive.com
|
||||
/// ---------------------------------------------
|
||||
namespace Opsive.BehaviorDesigner.Runtime.Groups
|
||||
{
|
||||
using System;
|
||||
using Unity.Entities;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Group that executes all of the tasks.
|
||||
/// </summary>
|
||||
[UpdateInGroup(typeof(TraversalSystemGroup))]
|
||||
public partial class TraversalTaskSystemGroup : ComponentSystemGroup
|
||||
{
|
||||
[Tooltip("Callback before the outher tasks are updated.")]
|
||||
public Action OnPreUpdate;
|
||||
[Tooltip("Callback after the outher tasks are updated.")]
|
||||
public Action OnPostUpdate;
|
||||
|
||||
/// <summary>
|
||||
/// Updates the group.
|
||||
/// </summary>
|
||||
protected override void OnUpdate()
|
||||
{
|
||||
if (OnPreUpdate != null) {
|
||||
OnPreUpdate();
|
||||
}
|
||||
|
||||
base.OnUpdate();
|
||||
|
||||
if (OnPostUpdate != null) {
|
||||
OnPostUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f48a72a09e70b944a82639a4d549f090
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,76 @@
|
||||
#if GRAPH_DESIGNER
|
||||
/// ---------------------------------------------
|
||||
/// Behavior Designer
|
||||
/// Copyright (c) Opsive. All Rights Reserved.
|
||||
/// https://www.opsive.com
|
||||
/// ---------------------------------------------
|
||||
namespace Opsive.BehaviorDesigner.Runtime.Groups
|
||||
{
|
||||
using Opsive.BehaviorDesigner.Runtime.Systems;
|
||||
using Unity.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// Main group for the systems that are responsible for traversing the behavior tree.
|
||||
/// </summary>
|
||||
[UpdateInGroup(typeof(BehaviorTreeSystemGroup))]
|
||||
[UpdateAfter(typeof(InterruptSystemGroup))]
|
||||
public partial class TraversalSystemGroup : ComponentSystemGroup
|
||||
{
|
||||
private SystemHandle m_EvaluationSystemHandle;
|
||||
private SystemHandle m_DetermineEvaluationSystemHandle;
|
||||
|
||||
/// <summary>
|
||||
/// The group has been created.
|
||||
/// </summary>
|
||||
protected override void OnCreate()
|
||||
{
|
||||
base.OnCreate();
|
||||
|
||||
m_EvaluationSystemHandle = World.GetExistingSystem<EvaluationSystem>();
|
||||
m_DetermineEvaluationSystemHandle = World.GetExistingSystem<DetermineEvaluationSystem>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the systems. Determines if the systems need to keep being evaluated.
|
||||
/// </summary>
|
||||
protected override void OnUpdate()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
var count = 0;
|
||||
#endif
|
||||
bool evaluate;
|
||||
do {
|
||||
base.OnUpdate();
|
||||
|
||||
var determineEvaluationSystem = EntityManager.WorldUnmanaged.GetUnsafeSystemRef<DetermineEvaluationSystem>(m_DetermineEvaluationSystemHandle);
|
||||
determineEvaluationSystem.Complete(EntityManager);
|
||||
evaluate = determineEvaluationSystem.Evaluate;
|
||||
|
||||
var evaluationSystem = EntityManager.WorldUnmanaged.GetUnsafeSystemRef<EvaluationSystem>(m_EvaluationSystemHandle);
|
||||
evaluationSystem.Complete(EntityManager);
|
||||
|
||||
#if UNITY_EDITOR
|
||||
if (evaluate) {
|
||||
count++;
|
||||
if (count == ushort.MaxValue / 10) {
|
||||
UnityEngine.Debug.LogWarning("An infinite loop would have been caused by the TraversalSystemGroup. Please email support@opsive.com with steps to reproduce this error.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
} while (evaluate);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The group has stopped running.
|
||||
/// </summary>
|
||||
protected override void OnStopRunning()
|
||||
{
|
||||
base.OnStopRunning();
|
||||
|
||||
var evaluationSystem = EntityManager.WorldUnmanaged.GetUnsafeSystemRef<EvaluationSystem>(m_EvaluationSystemHandle);
|
||||
evaluationSystem.Complete(EntityManager, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2c1ad397e3cdf7a44ae172b5ae92c2e4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user