Skip to content

Commit 9f41bb1

Browse files
authored
update readme (#150)
1 parent 4757572 commit 9f41bb1

File tree

1 file changed

+44
-9
lines changed

1 file changed

+44
-9
lines changed

README.md

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,6 @@ public struct EntityMoveNode : INodeData
222222
{
223223
public float3 Velocity; // node data saved in `INodeBlob`
224224
225-
[EntitiesBT.Core.ReadWrite(typeof(Translation))] // declare readwrite access of `Translation` component
226-
[EntitiesBT.Core.ReadOnly(typeof(BehaviorTreeTickDeltaTime))] // declare readonly access of `BehaviorTreeTickDeltaTime` component
227225
public NodeState Tick<TNodeBlob, TBlackboard>(int index, ref TNodeBlob blob, ref TBlackboard bb)
228226
where TNodeBlob : struct, INodeBlob
229227
where TBlackboard : struct, IBlackboard
@@ -345,30 +343,67 @@ public struct SomeNode : INodeData
345343
// read-write access
346344
BlobVariantReaderAndWriter<double> FloatVariable;
347345

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
351347
public NodeState Tick<TNodeBlob, TBlackboard>(int index, ref TNodeBlob blob, ref TBlackboard blackboard)
352348
where TNodeBlob : struct, INodeBlob
353349
where TBlackboard : struct, IBlackboard
354350
{
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+
357357
return NodeState.Success;
358358
}
359359

360-
// also declare right access types for `Reset` method if there's any
360+
// or manually declare right access types for this method
361361
[EntitiesBT.Core.ReadWrite(typeof(ReadWriteComponentData))]
362+
[EntitiesBT.Core.ReadOnly(typeof(ReadOnlyComponentData))]
362363
public void Reset<TNodeBlob, TBlackboard>(int index, ref TNodeBlob blob, ref TBlackboard bb)
363364
where TNodeBlob : struct, INodeBlob
364365
where TBlackboard : struct, IBlackboard
365366
{
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+
367373
// ...
368374
}
369375
}
370376
```
371377

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+
372407
#### Advanced: automatically generate unity components from nodes
373408
<img width="692" alt="image" src="https://user-images.githubusercontent.com/683655/88620751-56218100-d0d1-11ea-9a88-e9b2dfeee252.png">
374409

0 commit comments

Comments
 (0)