File size: 1,290 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
using Photon.Deterministic;
using System;
using System.Collections.Generic;

namespace Quantum
{
	[Serializable]
	public unsafe partial class BTRoot : BTDecorator
	{
		[BotSDKHidden] public Int32 NodesAmount;

		public override BTNodeType NodeType
		{
			get
			{
				return BTNodeType.Root;
			}
		}

		protected unsafe override BTStatus OnUpdate(BTParams btParams)
		{

			btParams.Agent->Current = this;

			if (_childInstance != null)
			{
				return _childInstance.RunUpdate(btParams);
			}

			return BTStatus.Success;
		}

		public void InitializeTree(Frame frame, BTAgent* agent, AIBlackboardComponent* blackboard)
		{
			InitNodesRecursively(frame, this, agent, blackboard);
		}

		private static void InitNodesRecursively(Frame frame, BTNode node, BTAgent* agent, AIBlackboardComponent* blackboard)
		{
			node.Init(frame, blackboard, agent);

			if (node is BTDecorator decoratorNode)
			{
				BTNode childNode = frame.FindAsset<BTNode>(decoratorNode.Child.Id);
				InitNodesRecursively(frame, childNode, agent, blackboard);
			}

			if (node is BTComposite compositeNode)
			{
				foreach (var child in compositeNode.Children)
				{
					BTNode childNode = frame.FindAsset<BTNode>(child.Id);
					InitNodesRecursively(frame, childNode, agent, blackboard);
				}
			}
		}
	}
}