Ejemplo n.º 1
0
        public EnableCommandBuffer CreateEnableCommandBuffer()
        {
            //Todo: We use Persistent allocator here because of the NativeReference. This recreates the DisposeSentinal stuff except with the slower allocator.
            var ecb      = new EnableCommandBuffer(Allocator.Persistent);
            var instance = new PlaybackInstance
            {
                type = PlaybackType.Enable,
                requestingSystemType = World.ExecutingSystemType(),
            };

            m_playbackInstances.Add(instance);
            m_enableCommandBuffers.Add(ecb);
            return(ecb);
        }
Ejemplo n.º 2
0
        protected override void OnUpdate()
        {
            var enabledShipList = new NativeList <Entity>(Allocator.TempJob);

            var ecb = new EnableCommandBuffer(Allocator.TempJob);

            Entities.WithAll <SpawnPointTag>().ForEach((Entity entity, ref SpawnPayload payload, in SpawnTimes times) =>
            {
                if (times.enableTime <= 0f && payload.disabledShip != Entity.Null)
                {
                    var ship = payload.disabledShip;
                    ecb.Add(ship);
                    SetComponent(ship, GetComponent <Translation>(entity));
                    SetComponent(ship, GetComponent <Rotation>(entity));
                    payload.disabledShip = Entity.Null;

                    enabledShipList.Add(ship);
                }
            }).Run();

            ecb.Playback(EntityManager, GetBufferFromEntity <LinkedEntityGroup>(true));
            ecb.Dispose();

            //Todo: It seems that if you Instantiate and then immediately disable a Transform hierarchy, the disabled entities do not get their child buffers.
            //This hack attempts to dirty the children so that the transform system picks up on this.
            var linkedBfe  = GetBufferFromEntity <LinkedEntityGroup>(true);
            var parentCdfe = GetComponentDataFromEntity <Parent>(false);

            Job.WithCode(() =>
            {
                for (int i = 0; i < enabledShipList.Length; i++)
                {
                    var ship         = enabledShipList[i];
                    var linkedBuffer = linkedBfe[ship];
                    for (int j = 0; j < linkedBuffer.Length; j++)
                    {
                        var e = linkedBuffer[j].Value;
                        if (parentCdfe.HasComponent(e))
                        {
                            var p         = parentCdfe[e];
                            parentCdfe[e] = p;
                        }
                    }
                }
            }).Run();

            enabledShipList.Dispose();
        }