示例#1
0
            public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
            {
                NativeArray <Entity>                 entities       = chunk.GetNativeArray(EntityType);
                NativeArray <TTweenInfo>             infos          = chunk.GetNativeArray(InfoType);
                BufferAccessor <TweenState>          tweenBuffers   = chunk.GetBufferAccessor(TweenBufferType);
                BufferAccessor <TweenDestroyCommand> destroyBuffers = chunk.GetBufferAccessor(DestroyCommandType);

                for (int i = 0; i < entities.Length; i++)
                {
                    Entity entity = entities[i];

                    bool shouldDestroy = false;
                    DynamicBuffer <TweenDestroyCommand> destroyBuffer = destroyBuffers[i];
                    for (int j = 0; j < destroyBuffer.Length; j++)
                    {
                        TweenDestroyCommand command = destroyBuffer[j];
                        if (infos[i].GetTweenId() == command.Id)
                        {
                            shouldDestroy = true;
                            destroyBuffer.RemoveAt(j);
                        }
                    }

                    if (!shouldDestroy)
                    {
                        return;
                    }

                    DynamicBuffer <TweenState> tweenBuffer = tweenBuffers[i];
                    for (int j = 0; j < tweenBuffer.Length; j++)
                    {
                        TweenState tween = tweenBuffer[j];
                        if (infos[i].GetTweenId() == tween.Id)
                        {
                            tweenBuffer.RemoveAt(j);
                            ParallelWriter.RemoveComponent <TTweenInfo>(chunkIndex, entity);
                            break;
                        }
                    }

                    if (tweenBuffer.IsEmpty)
                    {
                        ParallelWriter.RemoveComponent <TweenState>(chunkIndex, entity);
                    }

                    if (destroyBuffer.IsEmpty)
                    {
                        ParallelWriter.RemoveComponent <TweenDestroyCommand>(chunkIndex, entity);
                    }
                }
            }
示例#2
0
        protected override void OnUpdate()
        {
            Entities
            .WithNone <TweenPause>()
            .ForEach((Entity entity, int entityInQueryIndex, ref DynamicBuffer <TweenState> tweenBuffer) =>
            {
                for (int i = tweenBuffer.Length - 1; i >= 0; i--)
                {
                    TweenState tween = tweenBuffer[i];

                    bool isInfiniteLoop  = tween.LoopCount == TweenState.LOOP_COUNT_INFINITE;
                    float normalizedTime = tween.GetNormalizedTime();
                    if (tween.IsReverting && normalizedTime <= 0.0f)
                    {
                        if (!isInfiniteLoop)
                        {
                            tween.LoopCount--;
                        }

                        tween.IsReverting = false;
                        tween.Time        = 0.0f;
                    }
                    else if (!tween.IsReverting && normalizedTime >= 1.0f)
                    {
                        if (tween.IsPingPong)
                        {
                            tween.IsReverting = true;
                            tween.Time        = tween.Duration / 2.0f;
                        }
                        else
                        {
                            if (!isInfiniteLoop)
                            {
                                tween.LoopCount--;
                            }

                            tween.Time = 0.0f;
                        }
                    }

                    if (!isInfiniteLoop && tween.LoopCount == 0)
                    {
                        tween.SetPendingDestroy();
                    }

                    tweenBuffer[i] = tween;
                }
            }).ScheduleParallel();
        }
            public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
            {
                bool hasTweenBuffer = chunk.Has(TweenBufferType);
                bool hasTargetType  = chunk.Has(TargetType);

                NativeArray <Entity>        entities = chunk.GetNativeArray(EntityType);
                NativeArray <TTweenCommand> commands = chunk.GetNativeArray(TweenCommandType);

                for (int i = 0; i < entities.Length; i++)
                {
                    Entity        entity  = entities[i];
                    TTweenCommand command = commands[i];

                    if (!hasTweenBuffer)
                    {
                        ParallelWriter.AddBuffer <TweenState>(chunkIndex, entity);
                        break;
                    }

                    if (!hasTargetType)
                    {
                        ParallelWriter.AddComponent <TTarget>(chunkIndex, entity);
                    }

                    TweenState tween = new TweenState(command.GetTweenParams(), ElapsedTime, chunkIndex,
                                                      TweenInfoTypeIndex);
                    ParallelWriter.AppendToBuffer(chunkIndex, entity, tween);

                    TTweenInfo info = default;
                    info.SetTweenId(tween.Id);
                    info.SetTweenInfo(command.GetTweenStart(), command.GetTweenEnd());
                    ParallelWriter.AddComponent(chunkIndex, entity, info);

                    ParallelWriter.RemoveComponent <TTweenCommand>(chunkIndex, entity);
                }
            }
        protected override void OnUpdate()
        {
            BufferFromEntity <TweenDestroyCommand> destroyBufferFromEntity = GetBufferFromEntity <TweenDestroyCommand>(true);

            EndSimulationEntityCommandBufferSystem endSimECBSystem = World.GetOrCreateSystem <EndSimulationEntityCommandBufferSystem>();

            EntityCommandBuffer.ParallelWriter parallelWriter = endSimECBSystem.CreateCommandBuffer().AsParallelWriter();

            Entities
            .WithReadOnly(destroyBufferFromEntity)
            .WithNone <TweenPause>()
            .ForEach((Entity entity, int entityInQueryIndex, ref DynamicBuffer <TweenState> tweenBuffer) =>
            {
                for (int i = tweenBuffer.Length - 1; i >= 0; i--)
                {
                    TweenState tween = tweenBuffer[i];

                    bool isInfiniteLoop  = tween.LoopCount == TweenState.LOOP_COUNT_INFINITE;
                    float normalizedTime = tween.GetNormalizedTime();
                    if (tween.IsReverting && normalizedTime <= 0.0f)
                    {
                        if (!isInfiniteLoop)
                        {
                            tween.LoopCount--;
                        }

                        tween.IsReverting = false;
                        tween.Time        = 0.0f;
                    }
                    else if (!tween.IsReverting && normalizedTime >= 1.0f)
                    {
                        if (tween.IsPingPong)
                        {
                            tween.IsReverting = true;
                            tween.Time        = tween.Duration / 2.0f;
                        }
                        else
                        {
                            if (!isInfiniteLoop)
                            {
                                tween.LoopCount--;
                            }

                            tween.Time = 0.0f;
                        }
                    }

                    if (!isInfiniteLoop && tween.LoopCount == 0)
                    {
                        if (!destroyBufferFromEntity.HasComponent(entity))
                        {
                            parallelWriter.AddBuffer <TweenDestroyCommand>(entityInQueryIndex, entity);
                        }

                        parallelWriter.AppendToBuffer(entityInQueryIndex, entity, new TweenDestroyCommand(tween.Id));
                    }

                    tweenBuffer[i] = tween;
                }
            }).ScheduleParallel();

            endSimECBSystem.AddJobHandleForProducer(Dependency);
        }