@@ -222,8 +222,6 @@ public struct EntityMoveNode : INodeData
222
222
{
223
223
public float3 Velocity ; // node data saved in `INodeBlob`
224
224
225
- [EntitiesBT .Core .ReadWrite (typeof (Translation ))] // declare readwrite access of `Translation` component
226
- [EntitiesBT .Core .ReadOnly (typeof (BehaviorTreeTickDeltaTime ))] // declare readonly access of `BehaviorTreeTickDeltaTime` component
227
225
public NodeState Tick <TNodeBlob , TBlackboard >(int index , ref TNodeBlob blob , ref TBlackboard bb )
228
226
where TNodeBlob : struct , INodeBlob
229
227
where TBlackboard : struct , IBlackboard
@@ -345,30 +343,67 @@ public struct SomeNode : INodeData
345
343
// read-write access
346
344
BlobVariantReaderAndWriter <double > FloatVariable ;
347
345
348
- // declare right access types for `Tick` method
349
- [EntitiesBT .Core .ReadWrite (typeof (ReadWriteComponentData ))]
350
- [EntitiesBT .Core .ReadOnly (typeof (ReadOnlyComponentData ))]
346
+ // leave method attribute to be empty and will generate right access of this method
351
347
public NodeState Tick <TNodeBlob , TBlackboard >(int index , ref TNodeBlob blob , ref TBlackboard blackboard )
352
348
where TNodeBlob : struct , INodeBlob
353
349
where TBlackboard : struct , IBlackboard
354
350
{
355
- // access `ComponentData`s by variables or directly from `blackboard`
356
- // ...
351
+ // generate `[ReadOnly(typeof(ReadOnlyComponent)]` on `Tick` method
352
+ bb .GetData <ReadOnlyComponent >();
353
+
354
+ // generate `[ReadWrite(typeof(ReadWriteComponent)]` on `Tick` method
355
+ bb .GetDataRef <ReadWriteComponent >();
356
+
357
357
return NodeState .Success ;
358
358
}
359
359
360
- // also declare right access types for `Reset` method if there's any
360
+ // or manually declare right access types for this method
361
361
[EntitiesBT .Core .ReadWrite (typeof (ReadWriteComponentData ))]
362
+ [EntitiesBT .Core .ReadOnly (typeof (ReadOnlyComponentData ))]
362
363
public void Reset <TNodeBlob , TBlackboard >(int index , ref TNodeBlob blob , ref TBlackboard bb )
363
364
where TNodeBlob : struct , INodeBlob
364
365
where TBlackboard : struct , IBlackboard
365
366
{
366
- // access `ComponentData`s by variables or directly from `blackboard`
367
+ // generate `[ReadOnly(typeof(ReadOnlyComponent)]` on `Reset` method
368
+ bb .GetData <ReadOnlyComponent >();
369
+
370
+ // generate `[ReadWrite(typeof(ReadWriteComponent)]` on `Reset` method
371
+ bb .GetDataRef <ReadWriteComponent >();
372
+
367
373
// ...
368
374
}
369
375
}
370
376
```
371
377
378
+ make sure to mark outside method call with right access attributes to generate right access type on ` Tick ` or ` Reset ` method of node
379
+
380
+ ``` c#
381
+
382
+ public static Extension
383
+ {
384
+ [ReadOnly (typeof (FooComponent )), ReadWrite (typeof (BarComponent ))]
385
+ public static void Call <[ReadWrite] T , [ReadOnly] U >([ReadOnly ] Type type ) { /* ... */ }
386
+ }
387
+
388
+ public struct SomeNode : INodeData
389
+ {
390
+ // leave method attribute to be empty to generate automatically
391
+ public NodeState Tick <TNodeBlob , TBlackboard >(int index , ref TNodeBlob blob , ref TBlackboard blackboard )
392
+ where TNodeBlob : struct , INodeBlob
393
+ where TBlackboard : struct , IBlackboard
394
+ {
395
+ // the following call will generate access attributes on `Tick` like below:
396
+ // [ReadOnly(typeof(FooComponent))]
397
+ // [ReadWrite(typeof(BarComponent))]
398
+ // [ReadWrite(typeof(int))]
399
+ // [ReadOnly(typeof(float))]
400
+ // [ReadOnly(typeof(long))]
401
+ Extension .Call <int , float >(typeof (long ));
402
+ return NodeState .Success ;
403
+ }
404
+ }
405
+ ```
406
+
372
407
#### Advanced: automatically generate unity components from nodes
373
408
<img width =" 692 " alt =" image " src =" https://user-images.githubusercontent.com/683655/88620751-56218100-d0d1-11ea-9a88-e9b2dfeee252.png " >
374
409
0 commit comments