File size: 2,505 Bytes
00437a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using System;

namespace Quantum
{
	/// <summary>
	/// Using this system is optional. It is only used to aim the Debugger on the Unity side.
	/// It is also safe to copy logic from this system into your own systems, if it better suits your architecture.
	/// </summary>
	public unsafe class BotSDKSystem : SystemSignalsOnly, ISignalOnComponentAdded<HFSMAgent>,
																												ISignalOnComponentAdded<BTAgent>, ISignalOnComponentRemoved<BTAgent>,
																												ISignalOnComponentAdded<UTAgent>, ISignalOnComponentRemoved<UTAgent>,
																												ISignalOnComponentAdded<GOAPAgent>, ISignalOnComponentRemoved<GOAPAgent>,
																												ISignalOnComponentRemoved<AIBlackboardComponent>
	{
		// -- HFSM
		public void OnAdded(Frame frame, EntityRef entity, HFSMAgent* component)
		{
			HFSMData* hfsmData = &component->Data;
			if (hfsmData->Root == default)
				return;

			HFSMRoot rootAsset = frame.FindAsset<HFSMRoot>(hfsmData->Root.Id);
			HFSMManager.Init(frame, entity, rootAsset);
		}

		// -- BT
		public void OnAdded(Frame frame, EntityRef entity, BTAgent* component)
		{
			// Mainly used to automatically initialize entity prototypes
			// If the prototype's Tree reference is not default and the BTAgent
			// is not initialized yet, then it is initialized here;
			if (component->Tree != default)
			{
				component->Initialize(frame, entity, component, component->Tree, false);
			}
		}

		public void OnRemoved(Frame frame, EntityRef entity, BTAgent* component)
		{
			component->Free(frame);
		}

		// -- UT

		public void OnAdded(Frame frame, EntityRef entity, UTAgent* component)
		{
			UTManager.Init(frame, &component->UtilityReasoner, component->UtilityReasoner.UTRoot, entity);
		}

		public void OnRemoved(Frame frame, EntityRef entity, UTAgent* component)
		{
			component->UtilityReasoner.Free(frame);
		}

		// -- GOAP

		void ISignalOnComponentAdded<GOAPAgent>.OnAdded(Frame frame, EntityRef entity, GOAPAgent* component)
		{
			if (component->Root == default)
				return;

			var rootAsset = frame.FindAsset<GOAPRoot>(component->Root.Id);
			GOAPManager.Initialize(frame, entity, rootAsset);
		}

		void ISignalOnComponentRemoved<GOAPAgent>.OnRemoved(Frame frame, EntityRef entity, GOAPAgent* component)
		{
			GOAPManager.Deinitialize(frame, entity);
		}

		// -- Blackboard

		public void OnRemoved(Frame frame, EntityRef entity, AIBlackboardComponent* component)
		{
			component->FreeBlackboardComponent(frame);
		}
	}
}