Skip to content

Commit 631b27b

Browse files
committed
Fix exception thrown by children.ChildContainers in VisualTask when calling AddDivider.
Add support for displaying BehaviorTree elements inside arrays.
1 parent 2781317 commit 631b27b

File tree

5 files changed

+259
-37
lines changed

5 files changed

+259
-37
lines changed

Assets/Samples/BehaviorTreeList.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using CleverCrow.Fluid.BTs.Trees;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
5+
namespace CleverCrow.Fluid.BTs.Samples
6+
{
7+
public class BehaviorTreeList : MonoBehaviour
8+
{
9+
protected void Awake()
10+
{
11+
for (int i = 0; i < 3; i++)
12+
{
13+
trees.Add(new BehaviorTreeBuilder(gameObject).Name($"Tree{i}").Sequence()
14+
.WaitTime(1)
15+
.ReturnSuccess()
16+
.End().Build());
17+
}
18+
}
19+
public List<BehaviorTree> trees = new List<BehaviorTree>();
20+
}
21+
}

Assets/Samples/BehaviorTreeList.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Samples/TreeSample.unity

Lines changed: 143 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,11 @@ RenderSettings:
3838
m_ReflectionIntensity: 1
3939
m_CustomReflection: {fileID: 0}
4040
m_Sun: {fileID: 0}
41-
m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1}
4241
m_UseRadianceAmbientProbe: 0
4342
--- !u!157 &3
4443
LightmapSettings:
4544
m_ObjectHideFlags: 0
46-
serializedVersion: 11
45+
serializedVersion: 12
4746
m_GIWorkflowMode: 1
4847
m_GISettings:
4948
serializedVersion: 2
@@ -98,13 +97,13 @@ LightmapSettings:
9897
m_TrainingDataDestination: TrainingData
9998
m_LightProbeSampleCountMultiplier: 4
10099
m_LightingDataAsset: {fileID: 0}
101-
m_UseShadowmask: 1
100+
m_LightingSettings: {fileID: 1443705540}
102101
--- !u!196 &4
103102
NavMeshSettings:
104103
serializedVersion: 2
105104
m_ObjectHideFlags: 0
106105
m_BuildSettings:
107-
serializedVersion: 2
106+
serializedVersion: 3
108107
agentTypeID: 0
109108
agentRadius: 0.5
110109
agentHeight: 2
@@ -117,7 +116,9 @@ NavMeshSettings:
117116
cellSize: 0.16666667
118117
manualTileSize: 0
119118
tileSize: 256
120-
accuratePlacement: 0
119+
buildHeightMesh: 0
120+
maxJobWorkers: 0
121+
preserveTilesOutsideBounds: 0
121122
debug:
122123
m_Flags: 0
123124
m_NavMeshData: {fileID: 0}
@@ -197,6 +198,7 @@ Light:
197198
m_UseColorTemperature: 0
198199
m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0}
199200
m_UseBoundingSphereOverride: 0
201+
m_UseViewFrustumForShadowCasterCull: 1
200202
m_ShadowRadius: 0
201203
m_ShadowAngle: 0
202204
--- !u!4 &294120168
@@ -206,12 +208,13 @@ Transform:
206208
m_PrefabInstance: {fileID: 0}
207209
m_PrefabAsset: {fileID: 0}
208210
m_GameObject: {fileID: 294120166}
211+
serializedVersion: 2
209212
m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261}
210213
m_LocalPosition: {x: 0, y: 3, z: 0}
211214
m_LocalScale: {x: 1, y: 1, z: 1}
215+
m_ConstrainProportionsScale: 0
212216
m_Children: []
213217
m_Father: {fileID: 0}
214-
m_RootOrder: 1
215218
m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0}
216219
--- !u!1 &322793818
217220
GameObject:
@@ -253,9 +256,17 @@ Camera:
253256
m_projectionMatrixMode: 1
254257
m_GateFitMode: 2
255258
m_FOVAxisMode: 0
259+
m_Iso: 200
260+
m_ShutterSpeed: 0.005
261+
m_Aperture: 16
262+
m_FocusDistance: 10
263+
m_FocalLength: 50
264+
m_BladeCount: 5
265+
m_Curvature: {x: 2, y: 11}
266+
m_BarrelClipping: 0.25
267+
m_Anamorphism: 0
256268
m_SensorSize: {x: 36, y: 24}
257269
m_LensShift: {x: 0, y: 0}
258-
m_FocalLength: 50
259270
m_NormalizedViewPortRect:
260271
serializedVersion: 2
261272
x: 0
@@ -289,12 +300,13 @@ Transform:
289300
m_PrefabInstance: {fileID: 0}
290301
m_PrefabAsset: {fileID: 0}
291302
m_GameObject: {fileID: 322793818}
303+
serializedVersion: 2
292304
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
293305
m_LocalPosition: {x: 0, y: 1, z: -10}
294306
m_LocalScale: {x: 1, y: 1, z: 1}
307+
m_ConstrainProportionsScale: 0
295308
m_Children: []
296309
m_Father: {fileID: 0}
297-
m_RootOrder: 0
298310
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
299311
--- !u!1 &343368638
300312
GameObject:
@@ -333,12 +345,13 @@ Transform:
333345
m_PrefabInstance: {fileID: 0}
334346
m_PrefabAsset: {fileID: 0}
335347
m_GameObject: {fileID: 343368638}
348+
serializedVersion: 2
336349
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
337350
m_LocalPosition: {x: 0, y: 0, z: 0}
338351
m_LocalScale: {x: 1, y: 1, z: 1}
352+
m_ConstrainProportionsScale: 0
339353
m_Children: []
340354
m_Father: {fileID: 0}
341-
m_RootOrder: 2
342355
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
343356
--- !u!1 &533478364
344357
GameObject:
@@ -369,18 +382,137 @@ MonoBehaviour:
369382
m_Script: {fileID: 11500000, guid: 035df0b7568e1804f9b2f6dfb0bd0645, type: 3}
370383
m_Name:
371384
m_EditorClassIdentifier:
372-
_toggle: 0
385+
_isTaskSuccess: 0
373386
--- !u!4 &533478366
374387
Transform:
375388
m_ObjectHideFlags: 0
376389
m_CorrespondingSourceObject: {fileID: 0}
377390
m_PrefabInstance: {fileID: 0}
378391
m_PrefabAsset: {fileID: 0}
379392
m_GameObject: {fileID: 533478364}
393+
serializedVersion: 2
394+
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
395+
m_LocalPosition: {x: 0, y: 0, z: 0}
396+
m_LocalScale: {x: 1, y: 1, z: 1}
397+
m_ConstrainProportionsScale: 0
398+
m_Children: []
399+
m_Father: {fileID: 0}
400+
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
401+
--- !u!850595691 &1443705540
402+
LightingSettings:
403+
m_ObjectHideFlags: 0
404+
m_CorrespondingSourceObject: {fileID: 0}
405+
m_PrefabInstance: {fileID: 0}
406+
m_PrefabAsset: {fileID: 0}
407+
m_Name: Settings.lighting
408+
serializedVersion: 6
409+
m_GIWorkflowMode: 1
410+
m_EnableBakedLightmaps: 1
411+
m_EnableRealtimeLightmaps: 1
412+
m_RealtimeEnvironmentLighting: 1
413+
m_BounceScale: 1
414+
m_AlbedoBoost: 1
415+
m_IndirectOutputScale: 1
416+
m_UsingShadowmask: 1
417+
m_BakeBackend: 1
418+
m_LightmapMaxSize: 1024
419+
m_BakeResolution: 40
420+
m_Padding: 2
421+
m_LightmapCompression: 3
422+
m_AO: 0
423+
m_AOMaxDistance: 1
424+
m_CompAOExponent: 1
425+
m_CompAOExponentDirect: 0
426+
m_ExtractAO: 0
427+
m_MixedBakeMode: 2
428+
m_LightmapsBakeMode: 1
429+
m_FilterMode: 1
430+
m_LightmapParameters: {fileID: 15204, guid: 0000000000000000f000000000000000, type: 0}
431+
m_ExportTrainingData: 0
432+
m_TrainingDataDestination: TrainingData
433+
m_RealtimeResolution: 2
434+
m_ForceWhiteAlbedo: 0
435+
m_ForceUpdates: 0
436+
m_FinalGather: 0
437+
m_FinalGatherRayCount: 256
438+
m_FinalGatherFiltering: 1
439+
m_PVRCulling: 1
440+
m_PVRSampling: 1
441+
m_PVRDirectSampleCount: 32
442+
m_PVRSampleCount: 512
443+
m_PVREnvironmentSampleCount: 256
444+
m_PVREnvironmentReferencePointCount: 2048
445+
m_LightProbeSampleCountMultiplier: 4
446+
m_PVRBounces: 2
447+
m_PVRMinBounces: 2
448+
m_PVREnvironmentImportanceSampling: 1
449+
m_PVRFilteringMode: 1
450+
m_PVRDenoiserTypeDirect: 1
451+
m_PVRDenoiserTypeIndirect: 1
452+
m_PVRDenoiserTypeAO: 1
453+
m_PVRFilterTypeDirect: 0
454+
m_PVRFilterTypeIndirect: 0
455+
m_PVRFilterTypeAO: 0
456+
m_PVRFilteringGaussRadiusDirect: 1
457+
m_PVRFilteringGaussRadiusIndirect: 5
458+
m_PVRFilteringGaussRadiusAO: 2
459+
m_PVRFilteringAtrousPositionSigmaDirect: 0.5
460+
m_PVRFilteringAtrousPositionSigmaIndirect: 2
461+
m_PVRFilteringAtrousPositionSigmaAO: 1
462+
m_PVRTiledBaking: 0
463+
m_NumRaysToShootPerTexel: -1
464+
m_RespectSceneVisibilityWhenBakingGI: 0
465+
--- !u!1 &1786752064
466+
GameObject:
467+
m_ObjectHideFlags: 0
468+
m_CorrespondingSourceObject: {fileID: 0}
469+
m_PrefabInstance: {fileID: 0}
470+
m_PrefabAsset: {fileID: 0}
471+
serializedVersion: 6
472+
m_Component:
473+
- component: {fileID: 1786752065}
474+
- component: {fileID: 1786752066}
475+
m_Layer: 0
476+
m_Name: BehaviorTreeList
477+
m_TagString: Untagged
478+
m_Icon: {fileID: 0}
479+
m_NavMeshLayer: 0
480+
m_StaticEditorFlags: 0
481+
m_IsActive: 1
482+
--- !u!4 &1786752065
483+
Transform:
484+
m_ObjectHideFlags: 0
485+
m_CorrespondingSourceObject: {fileID: 0}
486+
m_PrefabInstance: {fileID: 0}
487+
m_PrefabAsset: {fileID: 0}
488+
m_GameObject: {fileID: 1786752064}
489+
serializedVersion: 2
380490
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
381491
m_LocalPosition: {x: 0, y: 0, z: 0}
382492
m_LocalScale: {x: 1, y: 1, z: 1}
493+
m_ConstrainProportionsScale: 0
383494
m_Children: []
384495
m_Father: {fileID: 0}
385-
m_RootOrder: 3
386496
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
497+
--- !u!114 &1786752066
498+
MonoBehaviour:
499+
m_ObjectHideFlags: 0
500+
m_CorrespondingSourceObject: {fileID: 0}
501+
m_PrefabInstance: {fileID: 0}
502+
m_PrefabAsset: {fileID: 0}
503+
m_GameObject: {fileID: 1786752064}
504+
m_Enabled: 1
505+
m_EditorHideFlags: 0
506+
m_Script: {fileID: 11500000, guid: d249f0b66a31f2c41b4014c03856ae10, type: 3}
507+
m_Name:
508+
m_EditorClassIdentifier:
509+
trees: []
510+
--- !u!1660057539 &9223372036854775807
511+
SceneRoots:
512+
m_ObjectHideFlags: 0
513+
m_Roots:
514+
- {fileID: 322793821}
515+
- {fileID: 294120168}
516+
- {fileID: 343368640}
517+
- {fileID: 533478366}
518+
- {fileID: 1786752065}
Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,63 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Unity.Properties;
14
using UnityEditor;
25
using UnityEngine;
36

4-
namespace CleverCrow.Fluid.BTs.Trees.Editors {
7+
namespace CleverCrow.Fluid.BTs.Trees.Editors
8+
{
59
[CustomPropertyDrawer(typeof(BehaviorTree))]
6-
public class BehaviorTreeDrawer : PropertyDrawer {
7-
public override void OnGUI (Rect position, SerializedProperty property, GUIContent label) {
10+
public class BehaviorTreeDrawer : PropertyDrawer
11+
{
12+
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
13+
{
814
EditorGUI.BeginProperty(position, label, property);
9-
15+
1016
position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);
1117
GUI.enabled = Application.isPlaying;
12-
if (GUI.Button(position, "View Tree")) {
13-
var tree = fieldInfo.GetValue(property.serializedObject.targetObject) as IBehaviorTree;
14-
BehaviorTreeWindow.ShowTree(tree, tree.Name ?? property.displayName);
18+
if (GUI.Button(position, "View Tree"))
19+
{
20+
object value = fieldInfo.GetValue(property.serializedObject.targetObject);
21+
if (value is IBehaviorTree tree)
22+
{
23+
BehaviorTreeWindow.ShowTree(tree, tree.Name ?? property.displayName);
24+
}
25+
else if (value is IList<BehaviorTree> list)
26+
{
27+
if (TryGetArrayIndex(property.propertyPath, out int index) && list[index] is IBehaviorTree childTree)
28+
{
29+
BehaviorTreeWindow.ShowTree(childTree, childTree.Name ?? property.displayName);
30+
}
31+
}
1532
}
1633
GUI.enabled = true;
17-
34+
1835
EditorGUI.EndProperty();
1936
}
37+
private bool TryGetArrayIndex(string path, out int index)
38+
{
39+
const string arrayData = ".Array.data[";
40+
int arrayIndex = path.IndexOf(arrayData, StringComparison.Ordinal);
41+
if (arrayIndex < 0)
42+
{
43+
index = -1;
44+
return false;
45+
}
46+
47+
arrayIndex += arrayData.Length;
48+
int endIndex = path.IndexOf("]", arrayIndex, StringComparison.Ordinal);
49+
if (endIndex < 0)
50+
{
51+
index = -1;
52+
return false;
53+
}
54+
55+
string indexStr = path.Substring(arrayIndex, endIndex - arrayIndex);
56+
if (int.TryParse(indexStr, out index))
57+
return true;
58+
59+
index = -1;
60+
return false;
61+
}
2062
}
2163
}

0 commit comments

Comments
 (0)