protected override void OnUpdate() { Entities.ForEach((Entity interactionEntity, ref CarCheckpointInteractionComponent interaction) => { PostUpdateCommands.DestroyEntity(interactionEntity); var checkpointNumber = EntityManager.GetComponentData <CheckpointComponent>(interaction.Checkpoint).CheckpointNumber; var carProgressionComponent = EntityManager.GetComponentData <ProgressionComponent>(interaction.Car); var nextCheckpointNumberOfCar = (carProgressionComponent.CrossedCheckpoints + 1) % checkpointInitializationSystem.numberOfCheckpoints; if (checkpointNumber == nextCheckpointNumberOfCar) { carProgressionComponent.CrossedCheckpoints++; EntityManager.SetComponentData(interaction.Car, carProgressionComponent); if (carProgressionComponent.CrossedCheckpoints == checkpointInitializationSystem.numberOfCheckpoints * GameSession.serverSession.laps) { var playerId = EntityManager.GetComponentData <SynchronizedCarComponent>(interaction.Car).PlayerId; finishedPlayers++; Entities.ForEach((Entity connectionEntity, ref NetworkIdComponent networkIdComponent) => { if (playerId == networkIdComponent.Value) { Debug.Log("Player " + playerId + " finished!"); var playerFinishedRequest = PostUpdateCommands.CreateEntity(); PostUpdateCommands.AddComponent(playerFinishedRequest, new PlayerFinishedRequest { Position = finishedPlayers }); PostUpdateCommands.AddComponent(playerFinishedRequest, new SendRpcCommandRequestComponent { TargetConnection = connectionEntity }); } }); } } }); }
// ============================================================================================================= protected override void OnUpdate() { // This function will find all entities with Health and Translation components // and will execute the code below. Entities.ForEach((Entity entity, ref Health health, ref Translation pos) => { if (health.lifePoints <= 0) { if (EntityManager.HasComponent(entity, typeof(PlayerTag))) { GameSettings.Instance.PlayerDied(); } else if (EntityManager.HasComponent(entity, typeof(EnemyTag))) { PostUpdateCommands.DestroyEntity(entity); Debug.Log("Destroyed entity."); BulletImpactPool.Instance.PlayBulletImpact(pos.Value); } } }); }
private void SetMenuVisibility(bool isVisible) { if (isVisible) { Entities.WithAll <MainMenuTag, Disabled>().ForEach(entity => { PostUpdateCommands.RemoveComponent <Disabled>(entity); }); #if UNITY_DOTSPLAYER Entities.WithAll <MainMenuTag, AudioSource, Disabled>().ForEach(entity => { PostUpdateCommands.AddComponent <AudioSourceStart>(entity); }); #endif } else { Entities.WithAll <MainMenuTag>() .ForEach(entity => { PostUpdateCommands.AddComponent <Disabled>(entity); }); } }
protected override void OnUpdate() { if (Input.GetButton("Dodge")) { return; } PostUpdateCommands.RemoveComponent <Dodging>(player.GetSingletonEntity()); PostUpdateCommands.AddComponent <ReadyToDodge>(player.GetSingletonEntity(), new ReadyToDodge { Value = 0 }); PostUpdateCommands.AddComponent <DodgeUp>(player.GetSingletonEntity(), new DodgeUp { }); /* ----------------- DEVELOPER SETTINGS - REMOVE ME -------------------- */ if (Bootstrap.DeveloperSettings.DebugDodgeState) { Debug.Log($"<color=blue>{this.GetType()}</color> Dodge Release End"); } /* ----------------- DEVELOPER SETTINGS - REMOVE ME -------------------- */ }
private void SpawnRocket(int i) { Entity rocketEntity = PostUpdateCommands.CreateEntity(RocketArchetype); PostUpdateCommands.SetComponent(rocketEntity, new Translation { Value = new float3(m_rocketDockGroup.RocketDocks[i].Value) }); PostUpdateCommands.SetComponent(rocketEntity, new Rotation { Value = quaternion.identity }); PostUpdateCommands.SetComponent(rocketEntity, new ObjectSpeed { Value = GameManager.instance.RocketSpeed }); PostUpdateCommands.SetComponent(rocketEntity, new RocketProximityState { Value = 0 }); PostUpdateCommands.SetComponent(rocketEntity, new RocketCollision { Height = 1.5f, Radius = 0.2f }); PostUpdateCommands.SetSharedComponent(rocketEntity, RocketRenderData); }
protected override void OnUpdate() { var settings = AsteroidsArcadeBootstrap.Settings; var playfield = settings.playfield; for (int index = 0; index < m_Data.Length; ++index) { var position = m_Data.Position[index].Value; var entity = m_Data.Entity[index]; //Check if entity in inside playfield and if it is try add cross edge component if (position.x < playfield.xMax && position.x > playfield.xMin && position.y < playfield.xMax && position.y > playfield.yMin) { PostUpdateCommands.RemoveComponent <OutsidePlayfield>(entity); PostUpdateCommands.AddComponent(entity, default(InPlayfield)); } } }
protected override void OnUpdate() { var entities = inputGroup.GetEntityArray(); var spatialIdData = inputGroup.GetComponentDataArray <SpatialEntityId>(); for (var i = 0; i < entities.Length; i++) { var authChanges = componentUpdateSystem.GetAuthorityChangesReceived(spatialIdData[i].EntityId, PlayerInput.ComponentId); if (authChanges.Count > 0) { var entity = entities[i]; PostUpdateCommands.AddComponent(entity, CameraComponentDefaults.Input); PostUpdateCommands.AddComponent(entity, CameraComponentDefaults.Transform); Cursor.lockState = CursorLockMode.Locked; // Disable system after first run. Enabled = false; } } }
public void SetAllScreensVisibility(bool isVisible) { for (int i = 0; i < screenGroup.Length; i++) { var entity = screenGroup.entity[i]; if (isVisible) { if (!EntityManager.HasComponent <Visible>(entity)) { PostUpdateCommands.AddComponent(entity, new Visible()); } } else { if (EntityManager.HasComponent <Visible>(entity)) { PostUpdateCommands.RemoveComponent <Visible>(entity); } } } }
protected override void OnUpdate() { var gameUi = SurvivalShooterBootstrap.Settings.GameUi; var scorePerDeath = SurvivalShooterBootstrap.Settings.ScorePerDeath; Entities.With(query).ForEach( (Entity entity, CapsuleCollider collider, Animator animator, AudioSource audio) => { collider.isTrigger = true; animator.SetTrigger(DeadHash); audio.clip = SurvivalShooterBootstrap.Settings.EnemyDeathClip; audio.Play(); PostUpdateCommands.RemoveComponent <DeadData>(entity); score += scorePerDeath; gameUi.OnEnemyKilled(score); }); }
protected override void OnUpdate() { var dt = Time.deltaTime; var launcherData = group.GetComponentDataArray <Launcher.Component>(); var entities = group.GetEntityArray(); for (var i = 0; i < entities.Length; i++) { var launcher = launcherData[i]; launcher.RechargeTimeLeft -= dt; if (launcher.RechargeTimeLeft < 0.0f) { launcher.RechargeTimeLeft = 0.0f; launcher.EnergyLeft = 100; PostUpdateCommands.RemoveComponent <Recharging>(entities[i]); } launcherData[i] = launcher; } }
protected override void OnUpdate() { Profiler.BeginSample(name); var incomingEntityArray = IncomingGroup.ToEntityArray(Allocator.TempJob); if (incomingEntityArray.Length > 0) { var incomingComponentDataArray = IncomingGroup.ToComponentDataArray <T>(Allocator.TempJob); for (var i = 0; i < incomingComponentDataArray.Length; i++) { var entity = incomingEntityArray[i]; PostUpdateCommands.AddComponent(entity, new K()); Initialize(entity, incomingComponentDataArray[i]); } incomingComponentDataArray.Dispose(); } incomingEntityArray.Dispose(); Profiler.EndSample(); }
protected override void OnUpdate() { for (int i = 0; i < group.Length; i++) { Stats stats = group.Stats[i]; Metabolism meta = group.Metabolism[i]; float hungerFactor = Mathf.Floor(1.0f + ((DateTime.Now.Ticks - stats.LastMealTime) / (1000 * TimeSpan.TicksPerMillisecond * meta.MealtimeInterval))); float healthPenalty = meta.HealthDecayRate * Time.fixedDeltaTime; stats.Age += Time.fixedDeltaTime; stats.Health -= healthPenalty * hungerFactor; PostUpdateCommands.SetComponent <Stats>(group.Entity[i], stats); if (stats.Health <= 0 && !EntityManager.HasComponent <Destroy>(group.Entity[i])) { PostUpdateCommands.AddComponent <Destroy>(group.Entity[i], new Destroy()); } } }
protected override void Initialize(Entity entity, ReplicatedDataEntity spawned) { var typeId = spawned.typeId; spawned.id = m_network.RegisterEntity(spawned.id, (ushort)typeId, spawned.predictingPlayerId); // spawned.name = spawned.name + "_" + spawned.id; GameDebug.Assert(typeId < m_assetRegistry.entries.Length, "TypeId:{0} outside range Length:{1}", typeId, m_assetRegistry.entries.Length); GameDebug.Assert(m_assetRegistry.entries[typeId].factory != null, "No valid factory for replicated type:{0}", typeId); var serializableArray = m_assetRegistry.entries[typeId].factory.CreateSerializables(EntityManager, entity); m_entityCollection.Register(spawned.id, entity, serializableArray); PostUpdateCommands.SetComponent(entity, spawned); if (ReplicatedEntityModuleServer.m_showInfo.IntValue > 0) { GameDebug.Log("HandleReplicatedEntityDataDespawn.Initialize entity:" + entity + " type:" + spawned.typeId + " id:" + spawned.id); } }
protected override void OnUpdate() { Entities.WithNone <SendRpcCommandRequestComponent>().ForEach((Entity entity, ref GoInGameRequest cmd, ref ReceiveRpcCommandRequestComponent req) => { PostUpdateCommands.AddComponent <NetworkStreamInGame>(req.SourceConnection); Debug.Log($"We received a command! {cmd.Value} {req.SourceConnection}"); var ghostCollection = GetSingleton <GhostPrefabCollectionComponent>(); var ghostId = BasicUnityDOTSNetworkTestGhostSerializerCollection.FindGhostType <CubeSnapshotData>(); var prefab = EntityManager.GetBuffer <GhostPrefabBuffer>(ghostCollection.serverPrefabs)[ghostId].Value; var player = EntityManager.Instantiate(prefab); EntityManager.SetComponentData(player, new MovableCubeComponent { PlayerId = EntityManager.GetComponentData <NetworkIdComponent>(req.SourceConnection).Value }); PostUpdateCommands.AddBuffer <CubeInput>(player); PostUpdateCommands.SetComponent(req.SourceConnection, new CommandTargetComponent { targetEntity = player }); PostUpdateCommands.DestroyEntity(entity); }); }
protected override void OnUpdate() { Entities.ForEach((Entity reqEnt, ref FireBulletRequest req, ref ReceiveRpcCommandRequestComponent reqSrc) => { PostUpdateCommands.AddComponent <NetworkStreamInGame>(reqSrc.SourceConnection); #if true var ghostCollection = GetSingleton <GhostPrefabCollectionComponent>(); var ghostId = NetCubeGhostSerializerCollection.FindGhostType <CubeSnapshotData>(); var prefab = EntityManager.GetBuffer <GhostPrefabBuffer>(ghostCollection.serverPrefabs)[ghostId].Value; var bullet = EntityManager.Instantiate(prefab); var p = UnityEngine.Random.insideUnitSphere; PostUpdateCommands.SetComponent(bullet, new Translation() { Value = new float3(p.x, p.y, p.z) }); #endif PostUpdateCommands.DestroyEntity(reqEnt); }); }
protected override void OnUpdate() { Entities.WithNone <SendRpcCommandRequestComponent> ().ForEach((Entity reqEnt, ref ProjectileRequest request, ref ReceiveRpcCommandRequestComponent reqSrc) => { PostUpdateCommands.AddComponent <NetworkStreamInGame> (reqSrc.SourceConnection); var ghostCollection = GetSingleton <GhostPrefabCollectionComponent> (); var ghostId = NetCubeGhostSerializerCollection.FindGhostType <SphereSnapshotData> (); var prefab = EntityManager.GetBuffer <GhostPrefabBuffer> (ghostCollection.serverPrefabs) [ghostId].Value; var projectile = EntityManager.Instantiate(prefab); PostUpdateCommands.AddComponent(projectile, new InitProjectileComponent { origin = new float3(request.ox, request.oy, request.oz) }); PostUpdateCommands.AddComponent(projectile, new ProjectileComponent { playerId = request.playerId, vector = new float3(request.vx, request.vy, request.vz), }); PostUpdateCommands.DestroyEntity(reqEnt); }); }
protected sealed override void OnUpdate() { OnReactiveUpdate(); foreach (var kvp in _reactiveGroups) { var group = kvp.Value; var isUpdateGroup = _reactiveUpdates.TryGetValue(kvp.Key, out var updateGroup); var addGroupEntities = group.AddGroup.GetEntityArray(); for (var index = 0; index < addGroupEntities.Length; index++) { group.AddComponent(PostUpdateCommands, addGroupEntities[index]); if (isUpdateGroup) { updateGroup.AddComponent(PostUpdateCommands, addGroupEntities[index]); } } var removeGroupEntities = group.RemoveGroup.GetEntityArray(); for (var index = 0; index < removeGroupEntities.Length; index++) { group.RemoveComponent(PostUpdateCommands, removeGroupEntities[index]); if (isUpdateGroup) { updateGroup.RemoveComponent(PostUpdateCommands, addGroupEntities[index]); // will these cause issues on deleted entities? } } } foreach (var kvp in _reactiveUpdates) { var entities = kvp.Value.Group.GetEntityArray(); for (var index = 0; index < entities.Length; index++) { PostUpdateCommands.RemoveComponent <ReactiveChanged>(entities[index]); } } }
protected override void OnUpdate() { var mgr = EntityManager; { EntityCommandBuffer ecb = new EntityCommandBuffer(Allocator.Temp); Entities .WithAll <AudioSource>() .ForEach((Entity e, ref AudioSourceStop tag) => { StopSource(e); PostUpdateCommands.RemoveComponent <AudioSourceStop>(e); }); ecb.Playback(EntityManager); ecb.Dispose(); } { EntityCommandBuffer ecb = new EntityCommandBuffer(Allocator.Temp); Entities .WithAll <AudioSource>() .ForEach((Entity e, ref AudioSourceStart tag) => { if (PlaySource(e)) { PostUpdateCommands.RemoveComponent <AudioSourceStart>(e); } }); ecb.Playback(EntityManager); ecb.Dispose(); } { EntityCommandBuffer ecb = new EntityCommandBuffer(Allocator.Temp); Entities .ForEach((Entity e, ref AudioSource tag) => { tag.isPlaying = IsPlaying(e); }); ecb.Playback(EntityManager); ecb.Dispose(); } }
protected override void OnUpdate() { base.OnUpdate(); var hasResourceOreRenderers = GetComponentDataFromEntity <HasResourceOreRenderer>(); // resource ore has zero count so remove Entities .ForEach((Entity changeProvider, ref ResourceOreChange resourceOreChange) => { var oreEntity = resourceOreChange.oreEntity; if (hasResourceOreRenderers.Exists(oreEntity)) { var visual = hasResourceOreRenderers[oreEntity]; if (visual.Valid) { PostUpdateCommands.DestroyEntity(visual.VisualEntity); } } PostUpdateCommands.DestroyEntity(changeProvider); }); // create new renderer for ore without renderer Entities .WithNone <HasResourceOreRenderer>() .ForEach((Entity entity, ref ResourceOre ore, ref MapIndex mapIndex) => { var visualEntity = new Entity(); if (ore.IsValid) { visualEntity = CreateVisualEntity("Map/Tile", ore.Type.Value.Color, ref mapIndex, 1); } EntityManager.AddComponentData(entity, new HasResourceOreRenderer { VisualEntity = visualEntity, Valid = ore.IsValid }); }); }
protected override void OnUpdate() { if (filter.Length > 0) { for (int index = 0; index < filter.Length; index++) { var bid = filter.Bids[index]; var value = bid.Value; var chips = new Chips(); if (value == 0) { if (EntityManager.HasComponent <Chips>(filter.Entities[index])) { EntityManager.RemoveComponent <Chips>(filter.Entities[index]); } } else { var sizeIndex = 9; while (sizeIndex >= 0 && value > 0) { var chipsCount = value / chipSizes[sizeIndex]; chips[sizeIndex] = chipsCount; value -= chipsCount * chipSizes[sizeIndex]; sizeIndex--; } if (!EntityManager.HasComponent <Chips>(filter.Entities[index])) { PostUpdateCommands.AddComponent(filter.Entities[index], chips); } else { PostUpdateCommands.SetComponent(filter.Entities[index], chips); } } } } }
void Shoot(float3 enemyPos, float3 playerPos) { float3 directionToPlayer = playerPos - enemyPos; Vector2 dirNormalize; dirNormalize.x = directionToPlayer.x; dirNormalize.y = directionToPlayer.y; dirNormalize.Normalize(); directionToPlayer.x = dirNormalize.x; directionToPlayer.y = dirNormalize.y; Entity e = PostUpdateCommands.CreateEntity(ProjectileBehaviour.GetArchetype()); PostUpdateCommands.SetComponent(e, new ProjectileStatsComponent { SpeedModifier = 10f, Alive = true, IsFromPlayer = false, Direction = directionToPlayer }); PostUpdateCommands.SetComponent(e, new Translation { Value = enemyPos }); PostUpdateCommands.SetComponent(e, new Scale { Value = 0.4f }); PostUpdateCommands.SetComponent(e, new ColliderComponent { Size = .2f }); PostUpdateCommands.SetSharedComponent(e, new RenderMesh { mesh = GlobalObjects.mesh, material = GlobalObjects.material }); }
protected override void OnUpdate() { var localInput = GetSingleton <CommandTargetComponent>().targetEntity; if (localInput == Entity.Null) { var localPlayerId = GetSingleton <NetworkIdComponent>().Value; Debug.Log($"Setting up input for local player {localPlayerId}"); Entities.WithNone <CubeInput>().ForEach((Entity ent, ref MovableCubeComponent cube) => { if (cube.PlayerId == localPlayerId) { Debug.Log($"Cube {ent} is local player"); PostUpdateCommands.AddBuffer <CubeInput>(ent); PostUpdateCommands.SetComponent(GetSingletonEntity <CommandTargetComponent>(), new CommandTargetComponent { targetEntity = ent }); } }); return; } var input = default(CubeInput); input.tick = World.GetExistingSystem <ClientSimulationSystemGroup>().ServerTick; if (Input.GetKey("a")) { input.horizontal -= 1; } if (Input.GetKey("d")) { input.horizontal += 1; } var inputBuffer = EntityManager.GetBuffer <CubeInput>(localInput); inputBuffer.AddCommandData(input); }
protected override void OnUpdate() { var activeMap = MapManager.ActiveMap; if (activeMap == null) { Debug.LogError("Active map needed for the collision system"); return; } var map = activeMap.map; Entities.WithNone <BlockMovementSysComp, ExcludeFromSimulation>().ForEach((Entity entity, ref BlockMovement block) => { Hex position = block.position; bool posValue; if (!map.MovementMapValues.TryGetValue(position, out posValue)) { Debug.LogError($"Cannot register the block movement entity in {position} if it is not inside the map!"); return; } if (!posValue) { Debug.LogError($"You cannot block the movement of a already ocupied position: {position}!"); } map.SetMovementMapValue(position, false); PostUpdateCommands.AddComponent <BlockMovementSysComp>(entity, new BlockMovementSysComp() { position = position }); }); Entities.WithNone <BlockMovement>().ForEach((Entity entity, ref BlockMovementSysComp sysComp) => { map.SetMovementMapValue(sysComp.position, true); PostUpdateCommands.RemoveComponent <BlockMovementSysComp>(entity); }); }
protected override void OnUpdate() { Entities.WithAll <MoveAnimation>().ForEach ( (Entity id, ref Move move, ref Translation trans) => { if ((trans.Value != move.moveTarget).x || (trans.Value != move.moveTarget).y) { Vector2 newPos = Vector2.MoveTowards(new Vector2(trans.Value.x, trans.Value.y), new Vector2(move.moveTarget.x, move.moveTarget.y), 3f * Time.deltaTime); PostUpdateCommands.SetComponent(id, new Translation() { Value = new Vector3(newPos.x, newPos.y, 0.5f) }); animationManager.instance.DestroyMassAnimationInstance(new animationManager.particleAnimation() { name = "UnitCircle", position = new Vector3(trans.Value.x, trans.Value.y, -30) }); animationManager.instance.CreateMassAnimationName(new animationManager.particleAnimation() { name = "UnitCircle", position = new Vector3(newPos.x, newPos.y, -30) }, EntityManager.GetSharedComponentData <Team>(id).value, true); } else { animationManager.instance.DestroyMassAnimationInstance(new animationManager.particleAnimation() { name = "UnitCircle", position = new Vector3(trans.Value.x, trans.Value.y, -30) }); animationManager.instance.CreateMassAnimationName(new animationManager.particleAnimation() { name = "UnitCircle", position = new Vector3(trans.Value.x, trans.Value.y, -30) }, EntityManager.GetSharedComponentData <Team>(id).value, true); PostUpdateCommands.RemoveComponent <MoveAnimation>(id); PostUpdateCommands.AddComponent <UnitAttack>(id, new UnitAttack() { }); } } ); }
protected override void OnUpdate() { var requestArray = SpawnGroup.ToComponentDataArray <CharacterSpawnRequest>(Allocator.Persistent); if (requestArray.Length == 0) { requestArray.Dispose(); return; } var requestEntityArray = SpawnGroup.ToEntityArray(Allocator.Persistent); // Copy requests as spawning will invalidate Group var spawnRequests = new CharacterSpawnRequest[requestArray.Length]; for (var i = 0; i < requestArray.Length; i++) { spawnRequests[i] = requestArray[i]; PostUpdateCommands.DestroyEntity(requestEntityArray[i]); } for (var i = 0; i < spawnRequests.Length; i++) { var request = spawnRequests[i]; var playerState = EntityManager.GetComponentData <Player.State>(request.playerEntity); var charEntity = SpawnCharacter(playerState.playerId, request.position, request.rotation, request.characterType); GameDebug.Log(World, Character.ShowLifetime, "Spawning character:{0} ", charEntity); //We cannot serialize references yet so we hook up manually on client side based on PlayerId. //but we set it here none the less for our server side uses if any playerState.controlledEntity = charEntity; EntityManager.SetComponentData(request.playerEntity, playerState); } requestEntityArray.Dispose(); requestArray.Dispose(); }
protected override void OnUpdate() { if (GameManager.IsGameOver()) { return; } //On each frame, cache the player’s position float3 playerPosition = (float3)GameManager.GetPlayerPosition(); Entities.WithAll <EnemyTag>().ForEach((Entity enemy, ref Translation enemyPos) => { // Disregard the player y value playerPosition.y = enemyPos.Value.y; // Check if the player and enemy are close enough if (math.distance(enemyPos.Value, playerPosition) <= thresholdDistance) { FXManager.Instance.CreateExplosion(enemyPos.Value); //FXManager.Instance.CreateExplosion(playerPosition); //GameManager.EndGame(); // Remove the Entity. This is an Entity Command Buffer that waits for a safe time to remove any Entities or data PostUpdateCommands.DestroyEntity(enemy); } // Check collisions between the enemy with the player bullets float3 enemyPosition = enemyPos.Value; Entities.WithAll <BulletTag>().ForEach((Entity bullet, ref Translation bulletPos) => { if (math.distance(enemyPosition, bulletPos.Value) <= thresholdDistance) { PostUpdateCommands.DestroyEntity(enemy); PostUpdateCommands.DestroyEntity(bullet); FXManager.Instance.CreateExplosion(enemyPosition); GameManager.AddScore(1); } }); }); }
protected override void OnUpdate() { for (int i = 0; i < newEntityData.Length; ++i) { PostUpdateCommands.AddComponent(newEntityData.Entities[i], new ShouldRequestPlayerTag()); } for (var i = 0; i < sendData.Length; ++i) { if (vector3FPosition == null || String.IsNullOrEmpty(playerDatabaseId)) { return; } var request = new CreatePlayerRequestType(vector3FPosition, playerDatabaseId); var createPlayerRequest = PlayerCreator.CreatePlayer.CreateRequest(playerCreatorEntityId, request); sendData.RequestSenders[i].RequestsToSend .Add(createPlayerRequest); PostUpdateCommands.RemoveComponent <ShouldRequestPlayerTag>(sendData.Entities[i]); } // Currently this has a race condition where you can receive two entites // The fix for this is more sophisticted server side handling of requests for (var i = 0; i < responseData.Length; ++i) { foreach (var receivedResponse in responseData.Responses[i].Responses) { if (receivedResponse.StatusCode == StatusCode.AuthorityLost) { PostUpdateCommands.AddComponent(responseData.Entities[i], new ShouldRequestPlayerTag()); } else if (receivedResponse.StatusCode != StatusCode.Success) { logDispatcher.HandleLog(LogType.Error, new LogEvent( $"Create player request failed: {receivedResponse.Message}")); } } } }
protected override void OnUpdate() { int enemiesLeft = 0; Entities.ForEach((Entity e, ref EnemyComponent enemyComponent) => { enemiesLeft++; }); if (enemiesLeft == 0) { Entities.ForEach((Entity e, ref DoorComponent doorComponent, ref WallComponent wallComponent) => { doorComponent.locked = false; }); if (GlobalObjects.mapLogic.currentRoom.finalRoom) { Debug.Log("GAME OVER WIN"); Entities.ForEach((Entity e) => { PostUpdateCommands.DestroyEntity(e); }); Application.LoadLevel(3); } } Entities.ForEach((Entity e, ref DoorComponent doorComponent, ref WallComponent wallComponent) => { if (doorComponent.locked == false) { entityManager.RemoveComponent <WallComponent>(e); } }); }
protected override void OnUpdate() { for (int i = 0; i < m_Data.Length; i++) { var shootInput = m_Data.ShootInput[i]; var rayShooter = m_Data.RayShooter[i]; var rayShooterCamera = rayShooter.Camera;; if (shootInput.IsShooting) { Vector3 point = new Vector3(rayShooterCamera.pixelWidth / 2, rayShooterCamera.pixelHeight / 2, 0); Ray ray = rayShooterCamera.ScreenPointToRay(point); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { var hitObject = hit.collider.gameObject; bool targetable = false; int index = 0; for (int j = 0; j < m_TargetData.Length; j++) { if (hitObject == m_TargetData.Targetable[j].gameObject) { targetable = true; index = j; break; } } if (targetable) { PostUpdateCommands.AddComponent(m_TargetData.Entities[index], new DeadComponent() { Timer = 1f }); } var go = GameObject.Instantiate(rayShooter.PrefabMarker, hit.point, Quaternion.identity); go.transform.SetParent(hit.collider.gameObject.transform); } } } }
protected override void OnUpdate() { Entities.WithAllReadOnly <CellDestroyNotification>().ForEach((Entity entity, ref CellDestroyNotification notification) => { if (_cellViews.TryGetValue(notification.Entity, out var cellView)) { if (cellView != null) { GameObject.Destroy(cellView.gameObject); } _cellViews.Remove(notification.Entity); } }); Entities.WithAllReadOnly <CellWorldPosition>().ForEach((ref CellWorldPosition position) => { if (!_cellViews.TryGetValue(position.Cell, out var cellView)) { cellView = GameObject.Instantiate(_cellContentPrefab).GetComponent <CellContentController>(); _cellViews.Add(position.Cell, cellView); cellView.SetContent(EntityManager.GetComponentData <CellContent>(position.Cell)); cellView.SetSelected(false); } cellView.transform.position = new Vector3(position.x * 1.0f, position.y * 1.0f); }); Entities.WithAllReadOnly <CellUpdatedNotification>().ForEach((Entity entity, ref CellUpdatedNotification notification) => { var cellEntity = notification.Entity; if (_cellViews.TryGetValue(cellEntity, out var cellView)) { cellView.SetSelected(EntityManager.GetComponentData <CellSelectionFlag>(cellEntity).Value); // var position = EntityManager.GetComponentData<CellWorldPosition>(cellEntity); // cellView.transform.position = new Vector3(position.x * 1.0f, position.y * 1.0f); } PostUpdateCommands.DestroyEntity(entity); }); }