コード例 #1
0
ファイル: Extensions.cs プロジェクト: ly774508966/EntitiesBT
        public static void AddBehaviorTree(
            this Entity entity
            , EntityManager dstManager
            , NodeBlobRef blob
            , int order = 0
            , AutoCreateType autoCreateType = AutoCreateType.None
            , BehaviorTreeThread thread     = BehaviorTreeThread.ForceRunOnMainThread
            , string debugName = default
            )
        {
            var bb = new EntityBlackboard {
                Entity = entity, EntityManager = dstManager
            };

            VirtualMachine.Reset(ref blob, ref bb);

            dstManager.AddBuffer <BehaviorTreeBufferElement>(entity);
            dstManager.AddComponent <CurrentBehaviorTreeComponent>(entity);

            var behaviorTreeEntity = dstManager.CreateEntity();

#if UNITY_EDITOR
            dstManager.SetName(behaviorTreeEntity, $"[BT]{dstManager.GetName(entity)}:{order}.{debugName}");
#endif
            var query     = blob.GetAccessTypes();
            var dataQuery = new BlackboardDataQuery(query, components =>
                                                    dstManager.CreateEntityQuery(components.ToArray()));
            dstManager.AddSharedComponentData(behaviorTreeEntity, dataQuery);

            dstManager.AddComponentData(behaviorTreeEntity, new BehaviorTreeComponent
            {
                Blob = blob, Thread = thread, AutoCreation = autoCreateType
            });
            dstManager.AddComponentData(behaviorTreeEntity, new BehaviorTreeTargetComponent {
                Value = entity
            });
            dstManager.AddComponentData(behaviorTreeEntity, new BehaviorTreeOrderComponent {
                Value = order
            });
        }
コード例 #2
0
 public static bool HasFlagFast(this AutoCreateType flags, AutoCreateType flag)
 {
     return((flags & flag) == flag);
 }
コード例 #3
0
 public BehaviorTreeComponent(NodeBlobRef blob, BehaviorTreeThread thread, AutoCreateType autoCreation)
 {
     Blob         = blob;
     Thread       = thread;
     AutoCreation = autoCreation;
 }
コード例 #4
0
 private bool HasFlag(AutoCreateType flag)
 {
     return((_autoCreateTypes & flag) == flag);
 }