Exemplo n.º 1
0
            public CharacterStateHitbox ToStateHitbox(ref BlobBuilder builder)
            {
                var stateHitbox = new CharacterStateHitbox {
                    Hitbox = this.Hitbox
                };

                builder.Construct(ref stateHitbox.Positions, BakedPositions.ToArray());
                return(stateHitbox);
            }
        protected override void OnUpdate()
        {
            float deltaTime = Time.fixedDeltaTime;

            var sampleJob = Entities
                            .WithName("SampleFrames")
                            .ForEach((ref PlayerComponent player, ref CharacterFrame frame, in PlayerCharacter character) => {
                player.StateTick++;
                bool validState = GetState(player, character, out CharacterState state);
                if (!validState)
                {
                    return;
                }
                frame = state.Frames[math.min(player.StateTick, state.Frames.Length - 1)];
            }).Schedule(Dependency);

            var hitboxJob = Entities
                            .WithName("UpdateHitboxes")
                            .ForEach((ref Hitbox hitbox, ref HitboxState state, ref Translation translation) => {
                var player = state.Player;
                if (!HasComponent <PlayerComponent>(player) ||
                    !HasComponent <PlayerCharacter>(player) ||
                    !HasComponent <CharacterFrame>(player))
                {
                    return;
                }
                state.Enabled = GetComponent <CharacterFrame>(player).IsHitboxActive((int)state.ID);
                if (!state.Enabled)
                {
                    state.PreviousPosition = null;
                }

                var playerComponent = GetComponent <PlayerComponent>(player);
                var character       = GetComponent <PlayerCharacter>(player);
                bool validState     = GetState(playerComponent, character, out CharacterState playerState);
                if (!validState || state.ID >= playerState.Hitboxes.Length)
                {
                    return;
                }
                ref CharacterStateHitbox data = ref playerState.Hitboxes[state.ID];
                hitbox      = data.Hitbox;
                translation = data.Positions[math.min(playerComponent.StateTick, data.Positions.Length - 1)];
            }).ScheduleParallel(sampleJob);