protected override void OnUpdate() { HavokCollisionEvents collisionEvents = ((HavokSimulation)stepPhysicsWorld.Simulation).CollisionEvents; var player = GetComponentDataFromEntity <PlayerTag>(true); var enemy = GetComponentDataFromEntity <EnemyTag>(true); var playerEntity = GameVariables.Player.Entity; Entity entity = Entity.Null; bool isHit = false; Job.WithCode(() => { foreach (var collisionEvent in collisionEvents) { if (player.HasComponent(collisionEvent.Entities.EntityA)) { if (enemy.HasComponent(collisionEvent.Entities.EntityB)) { entity = collisionEvent.Entities.EntityB; isHit = true; } } if (player.HasComponent(collisionEvent.Entities.EntityB)) { if (enemy.HasComponent(collisionEvent.Entities.EntityA)) { entity = collisionEvent.Entities.EntityA; isHit = true; } } } }).Run(); if (isHit) { LifeComponent lifeComponent = EntityManager.GetComponentData <LifeComponent>(playerEntity); LifeComponent lifeComponentRat = EntityManager.GetComponentData <LifeComponent>(entity); if (EntityManager.GetComponentData <TypeData>(entity).Value == Type.Rat) { lifeComponentRat.DecrementLife(); EntityManager.SetComponentData(entity, lifeComponentRat); } if (lifeComponent.DecrementLifeWithInvincibility()) { SoundEventSystem.PlayerHitSound(); EntityManager.SetComponentData(playerEntity, lifeComponent); UIManager.OnPlayerHit(); } } }
protected override void OnUpdate() { float dt = Time.DeltaTime; //Get Entities Entity playerEntity = GameVariables.Player.Entity; //Get Components DirectionData direction = EntityManager.GetComponentData <DirectionData>(playerEntity); DashComponent dash = EntityManager.GetComponentData <DashComponent>(playerEntity); InputComponent inputs = EntityManager.GetComponentData <InputComponent>(playerEntity); Rotation rotation = EntityManager.GetComponentData <Rotation>(playerEntity); //Is Player currently dashing? -> Keep moving if (dash.IsDashing) { dash.CurrentDashTime -= dt; direction.Value = GetVelocity(dash); EntityManager.SetComponentData(playerEntity, direction); EventsHolder.StateEvents.Add(new StateInfo { Entity = GameVariables.Player.Entity, DesiredState = State.Dashing, Action = StateInfo.ActionType.TryChange }); } //Is dash finished? -> Unlock inputs... else if (dash.WasDashingPreviousFrame) { OnDashEnd(ref dash); } if (!dash.IsAvailable) { dash.CurrentCooldownTime -= dt; } if (TryDash(dash, inputs)) { //Dash Dash(ref dash, inputs, rotation); //Set Player invincibility GlobalEvents.PlayerEvents.SetInvincibility(InvincibilityType.Dash); SoundEventSystem.PlayDashSound(); } EntityManager.SetComponentData(playerEntity, dash); }
protected override void OnUpdate() { //Get Player Health LifeComponent playerLife = EntityManager.GetComponentData <LifeComponent>(GameVariables.Player.Entity); //Look if Player Died if (playerLife.IsDead()) { //Get Current MapType MapType currentMapType = EventsHolder.LevelEvents.CurrentLevel; SoundEventSystem.PlayerDieSound(); if (currentMapType == MapType.Level_Hell) { #if UNITY_EDITOR Debug.Log("Player died in Hell World... Returning to main menu."); #endif //Stop HelloWorldSystem World.GetExistingSystem <HellWorldSystem>().Enabled = false; //Restart Game from beginning GlobalEvents.GameEvents.RestartGame(); ChangeWorldDelaySystem.OnChangeWorld += () => { SwapWeaponSystem.SwapWeaponBetweenWorld(WeaponType.Pistol, MapType.Level_Hell, MapType.LevelMenu); }; return; } //Save current Level info EventsHolder.LevelEvents.DeathCount++; //Load Hell Level OnLoadHellLevel(ref playerLife); } if (playerLife.Invincibility == InvincibilityType.Hit) { GlobalEvents.CameraEvents.ShakeCam(.2f, 1, 1.5f); UIManager.RefreshPlayerHp(true); } }
protected override void OnUpdate() { HavokTriggerEvents triggerEvents = ((HavokSimulation)stepPhysicsWorld.Simulation).TriggerEvents; var amunitionComponents = GetComponentDataFromEntity <AmmunitionComponent>(true); NativeList <Entity> ammunitions = new NativeList <Entity>(Allocator.Temp); foreach (var triggerEvent in triggerEvents) { if (amunitionComponents.HasComponent(triggerEvent.Entities.EntityA)) { if (!ammunitions.Contains(triggerEvent.Entities.EntityA)) { ammunitions.Add(triggerEvent.Entities.EntityA); } } if (amunitionComponents.HasComponent(triggerEvent.Entities.EntityB)) { if (!ammunitions.Contains(triggerEvent.Entities.EntityB)) { ammunitions.Add(triggerEvent.Entities.EntityB); } } } foreach (var entity in ammunitions) { AmmunitionComponent ac = EntityManager.GetComponentData <AmmunitionComponent>(entity); EntityManager.DestroyEntity(entity); gunComponent = EntityManager.GetComponentData <GunComponent>(GameVariables.Player.PlayerWeaponEntities[ac.TypeAmmunition]); gunComponent.CurrentAmountBulletOnPlayer = math.clamp(gunComponent.CurrentAmountBulletOnPlayer + ac.AmmunitionQuantity, 0, gunComponent.MaxBulletOnPlayer); EntityManager.SetComponentData(GameVariables.Player.PlayerWeaponEntities[ac.TypeAmmunition], gunComponent); SoundEventSystem.PlayPickupSound(DropType.AmmunitionShotgun); UIManager.RefreshBulletsText(); //TODO Play VFX } ammunitions.Dispose(); }
protected override void OnCreate() { var world = World.DefaultGameObjectInjectionWorld; stateEventSystem = world.GetOrCreateSystem <StateEventSystem>(); animationEventSystem = world.GetOrCreateSystem <AnimationEventSystem>(); interactableEventSystem = world.GetOrCreateSystem <InteractableEventSystem>(); soundEventSystem = world.GetOrCreateSystem <SoundEventSystem>(); lootSystem = world.GetOrCreateSystem <LootSystem>(); visualEventSystem = world.GetOrCreateSystem <VisualEventSystem>(); cleanupSystem = world.GetOrCreateSystem <CleanupSystem>(); dropSystem = world.GetOrCreateSystem <DropSystem>(); uiSystem = world.GetOrCreateSystem <UISystem>(); globalEventListenerSystem = world.GetOrCreateSystem <GlobalEventListenerSystem>(); playerCollisionSystem = world.GetOrCreateSystem <PlayerCollisionSystem>(); invincibleSystem = world.GetOrCreateSystem <InvincibleSystem>(); interactableDoorSystem = world.GetOrCreateSystem <InteractableDoorSystem>(); var presentation = world.GetOrCreateSystem <PresentationManager>(); presentation.AddSystemToUpdateList(stateEventSystem); presentation.AddSystemToUpdateList(animationEventSystem); presentation.AddSystemToUpdateList(interactableEventSystem); presentation.AddSystemToUpdateList(lootSystem); presentation.AddSystemToUpdateList(visualEventSystem); presentation.AddSystemToUpdateList(soundEventSystem); presentation.AddSystemToUpdateList(cleanupSystem); presentation.AddSystemToUpdateList(dropSystem); presentation.AddSystemToUpdateList(uiSystem); presentation.AddSystemToUpdateList(globalEventListenerSystem); presentation.AddSystemToUpdateList(invincibleSystem); presentation.AddSystemToUpdateList(interactableDoorSystem); // presentation.AddSystemToUpdateList(playerCollisionSystem); presentation.SortSystemUpdateList(); }