-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathBTDebugPrioritySelector.cs
More file actions
54 lines (46 loc) · 1.75 KB
/
BTDebugPrioritySelector.cs
File metadata and controls
54 lines (46 loc) · 1.75 KB
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
using System;
using EntitiesBT.Core;
using EntitiesBT.Entities;
using EntitiesBT.Nodes;
using UnityEngine;
namespace EntitiesBT.DebugView
{
[AddComponentMenu("")] // hide from component menu
public class BTDebugPrioritySelector : BTDebugView<PrioritySelectorNode>
{
public int[] DefaultWeights;
public int[] RuntimeWeights;
public override void Init()
{
var blob = Blob;
ref var runtime = ref blob.GetNodeData<PrioritySelectorNode, NodeBlobRef>(Index).Weights;
RuntimeWeights = runtime.ToArray();
ref var @default = ref blob.GetNodeDefaultData<PrioritySelectorNode, NodeBlobRef>(Index).Weights;
DefaultWeights = @default.ToArray();
}
public override void Tick()
{
var blob = Blob;
ref var runtime = ref blob.GetNodeData<PrioritySelectorNode, NodeBlobRef>(Index).Weights;
RuntimeWeights = runtime.ToArray();
}
protected override void OnValidate()
{
if (!IsValid) return;
var blob = Blob;
ref var @default = ref blob.GetNodeDefaultData<PrioritySelectorNode, NodeBlobRef>(Index);
SetData(ref @default, DefaultWeights);
ref var runtime = ref blob.GetNodeData<PrioritySelectorNode, NodeBlobRef>(Index);
SetData(ref runtime, RuntimeWeights);
void SetData(ref PrioritySelectorNode data, int[] array)
{
Array.Resize(ref array, data.Weights.Length);
for (var i = 0; i < array.Length; i++)
{
if (array[i] < 0) array[i] = 0;
data.Weights[i] = array[i];
}
}
}
}
}