protected override void OnUpdate() { var entities = cmdTargetGroup.ToEntityArray(Allocator.TempJob); if (entities.Length == 1) { var ent = entities[0]; if (!EntityManager.HasComponent <PlayerCommandData>(ent)) { PostUpdateCommands.AddBuffer <PlayerCommandData>(ent); var ctc = EntityManager.GetComponentData <CommandTargetComponent>(ent); ctc.targetEntity = ent; PostUpdateCommands.SetComponent(ent, ctc); } else { var cmdBuf = EntityManager.GetBuffer <PlayerCommandData>(ent); PlayerCommandData cmdData = default; cmdData.tick = m_TimeSystem.predictTargetTick; cmdData.horizontal = Input.GetAxisRaw("Horizontal"); cmdData.vertical = Input.GetAxisRaw("Vertical"); cmdBuf.AddCommandData(cmdData); } } entities.Dispose(); }
protected override void OnUpdate() { for (int i = 0; i < cannonData.Length; i++) { IngridientCannon cannon = cannonData.cannons[i]; cannon.FireCooldown -= Time.deltaTime; if (cannon.CanFire) { //Fire var position = cannonData.positions[i].Value; var heading = cannonData.headings[i].Value; PostUpdateCommands.CreateEntity(BootStrap.IngredientSpawnArchetype); PostUpdateCommands.SetComponent(new IngridientSpawnData { spawnPosition = new Position2D { Value = position }, spawnHeading = new Heading2D { Value = heading }, IngridientType = Random.Range(0, BootStrap.IngredientsData.Length) //Random for now }); cannon.FireCooldown = BootStrap.GameSettings.CannonFireRate; } cannonData.cannons[i] = cannon; } }
void SpawnEnemy() { var state = m_State.S[0]; var oldState = UnityEngine.Random.state; UnityEngine.Random.state = state.RandomState; float3 spawnPosition = ComputeSpawnLocation(); state.SpawnedEnemyCount++; PostUpdateCommands.CreateEntity(TwoStickBootstrap.BasicEnemyArchetype); PostUpdateCommands.SetComponent(new Position { Value = spawnPosition }); PostUpdateCommands.SetComponent(new Rotation { Value = quaternion.LookRotation(new float3(0.0f, 0.0f, -1.0f), math.up()) }); PostUpdateCommands.SetComponent(new Health { Value = TwoStickBootstrap.Settings.enemyInitialHealth }); PostUpdateCommands.SetComponent(new EnemyShootState { Cooldown = 0.5f }); PostUpdateCommands.SetComponent(new MoveSpeed { speed = TwoStickBootstrap.Settings.enemySpeed }); PostUpdateCommands.AddSharedComponent(TwoStickBootstrap.EnemyLook); state.RandomState = UnityEngine.Random.state; m_State.S[0] = state; UnityEngine.Random.state = oldState; }
protected override void OnUpdate() { float bulletSpeed = Boot.Settings.BulletSpeed; Entity bulletPrototype = Boot.Instance.PlayerBulletEntity; float dt = Time.deltaTime; Entities.ForEach((ref Player player, ref PlayerInput playerInput, ref Translation pos, ref Rotation rotation) => { if (math.lengthsq(playerInput.Shoot) > .5f * .5f) { player.CurrFireCooldown -= dt; if (player.CurrFireCooldown <= 0) { var newBullet = PostUpdateCommands.Instantiate(bulletPrototype); float3 vel = math.mul(rotation.Value, new float3(0, 0, bulletSpeed)); PostUpdateCommands.AddComponent(newBullet, new Velocity { Value = vel.xy }); PostUpdateCommands.SetComponent(newBullet, new Translation { Value = pos.Value }); player.CurrFireCooldown += player.FireCooldown; } player.CurrFireCooldown = math.max(player.CurrFireCooldown, 0); } }); }
protected override void OnUpdate() { Settings settings = Bootstrap.Settings; int quantityToSpawn = settings.FoodCount - m_Data.Length; for (int i = 0; i < quantityToSpawn; i++) { PostUpdateCommands.CreateEntity(Bootstrap.FoodArchetype); float possibleSize = settings.ArenaSize * 10 * 0.9f; PostUpdateCommands.SetComponent(new Position { Value = new float3( Random.Range(-possibleSize / 2.0f, possibleSize / 2.0f), Random.Range(-possibleSize / 2.0f, possibleSize / 2.0f), 0.0f ) }); PostUpdateCommands.SetComponent(new Scale { Value = new float3(1.0f, 1.0f, 1.0f) }); PostUpdateCommands.SetComponent(new Size { Value = settings.FoodSize }); PostUpdateCommands.SetComponent( new Scale { Value = new float3(settings.FoodSize, settings.FoodSize, settings.FoodSize) } ); PostUpdateCommands.AddSharedComponent(Bootstrap.FoodLook); } }
private void MoveSelected(int2 coord, EntityManager entityManager) { var entities = _selectedQuery.ToEntityArray(Allocator.TempJob); for (var index = 0; index < entities.Length; index++) { Entity entity = entities[index]; if (entityManager.HasComponent <Path>(entity)) { PostUpdateCommands.RemoveComponent <Path>(entity); } if (!entityManager.HasComponent <MoveTo>(entity)) { PostUpdateCommands.AddComponent <MoveTo>(entity); } PostUpdateCommands.SetComponent(entity, new MoveTo { Coord = coord }); } entities.Dispose(); }
protected override void OnUpdate() { var localInputDataEntity = GetSingleton <CommandTargetComponent>().targetEntity; if (localInputDataEntity == Entity.Null) { var localPlayerId = GetSingleton <NetworkIdComponent>().Value; Entities.WithAll <MovableComponent>().WithNone <CharacterSyncData>().ForEach((Entity ent, ref GhostOwnerComponent ghostOwner) => { if (ghostOwner.NetworkId == localPlayerId) { PostUpdateCommands.AddBuffer <CharacterSyncData>(ent); PostUpdateCommands.SetComponent(GetSingletonEntity <CommandTargetComponent>(), new CommandTargetComponent { targetEntity = ent }); CameraFollow.instance.CharacterEntity = ent; } }); return; } var input = default(CharacterSyncData); input.Tick = World.GetExistingSystem <ClientSimulationSystemGroup>().ServerTick; input.Horizontal = Input.GetAxis("Horizontal"); input.Vertical = Input.GetAxis("Vertical"); var inputBuffer = EntityManager.GetBuffer <CharacterSyncData>(localInputDataEntity); inputBuffer.AddCommandData(input); }
void SpawnIsland() { var state = islandStateGroup.islandSpawnState[0]; PostUpdateCommands.CreateEntity(Bootstrap.islandArchetype); var spawnLocation = state.islandCount == 0 ? new float3(0f, -2.9392f, 0f) : state.lastPosition + GetSpawnLocation(); PostUpdateCommands.SetComponent(new Position() { Value = spawnLocation }); var randomScale = GetRandomScale(); PostUpdateCommands.SetComponent(new Scale() { Value = randomScale }); PostUpdateCommands.SetComponent(new Island()); PostUpdateCommands.AddSharedComponent(Bootstrap.islandLook); state.islandCount++; state.lastPosition = spawnLocation; state.lastSize = randomScale; islandStateGroup.islandSpawnState[0] = state; }
protected override void OnUpdate() { Entity loaderSingleton = GetSingletonEntity <SceneLoadInfo>(); SceneLoadInfo loadInfo = EntityManager.GetComponentData <SceneLoadInfo>(loaderSingleton); string toLoad = loadInfo.sceneToLoad.ToString().Trim(); string toUnload = loadInfo.sceneToUnload.ToString().Trim(); PostUpdateCommands.DestroyEntity(loaderSingleton); bool isClient = World.GetExistingSystem <ClientSimulationSystemGroup>() != null; UnityEngine.Debug.Log($"client: {isClient}, Processing scene request - load {toLoad} - unload {toUnload}"); if (toLoad.Length > 0 && SubSceneReferences.Instance.ContainsScene(toLoad)) { SubSceneReferences.Instance.LoadScene(toLoad, this.sceneSystem); GameFlow flow = toLoad == GameStateSystem.LobbySceneName ? GameFlow.Lobby : GameFlow.InGame; Entity entity = GetSingletonEntity <GameStateSystem.GameState>(); PostUpdateCommands.SetComponent(entity, new GameStateSystem.GameState { loadedScene = toLoad, stage = flow, }); } if (toUnload.Length > 0 && SubSceneReferences.Instance.ContainsScene(toUnload)) { SubSceneReferences.Instance.UnloadScene(toUnload, this.sceneSystem); } }
protected override void OnUpdate() { EntityManager manager = World.Active.GetOrCreateManager <EntityManager>(); for (int turretIdx = 0; turretIdx < m_turretData.Length; ++turretIdx) { if (m_turretData.State[turretIdx].TimeSinceLastFire >= 1.0f && m_turretData.State[turretIdx].CanFire == 1) { ComponentTypes.TurretHeadState stateCopy = m_turretData.State[turretIdx]; Entity body = m_turretData.Parent[turretIdx].Value; Position bodyPosition = manager.GetComponentData <Position>(body); PostUpdateCommands.CreateEntity(Bootstrap.MissileArchetype); PostUpdateCommands.SetComponent(new Position { Value = new Vector3(bodyPosition.Value.x, bodyPosition.Value.y, bodyPosition.Value.z) + new Vector3(m_turretData.Positions[turretIdx].Value.x, m_turretData.Positions[turretIdx].Value.y, m_turretData.Positions[turretIdx].Value.z) }); PostUpdateCommands.SetComponent(new MoveSpeed { speed = 10.0f }); PostUpdateCommands.SetComponent(new Rotation { Value = Quaternion.Euler(0.0f, stateCopy.Angle, 0.0f) }); PostUpdateCommands.SetComponent(new ComponentTypes.MissileState { BirthTime = Time.time }); PostUpdateCommands.AddSharedComponent(Bootstrap.MissileLook); stateCopy.TimeSinceLastFire = 0.0f; m_turretData.State[turretIdx] = stateCopy; } } }
public unsafe void LoadFITLayer(MemoryMap map) { var objectCount = GetObjectCount(0, 0, map); if (objectCount == 0) { return; } mColliders.Add(new NativeList <BlobAssetReference <Unity.Physics.Collider> >(Allocator.Persistent)); mColliders[0].ResizeUninitialized(objectCount); CreateLoadParallelJob(0, 0, map, mColliders[0]).Schedule(objectCount, 100).Complete(); for (int i = 0; i < mColliders[0].Length; i++) { var e = PostUpdateCommands.CreateEntity(mIFCArchetype); PostUpdateCommands.SetComponent(e, new IFCGuid { mValue = &map.mNames[i * 22] }); PostUpdateCommands.SetComponent(e, new IFCObjectID { Voxel = new Voxel { Layer = 0, Index = 0 }, Index = i }); PostUpdateCommands.SetComponent(e, new Unity.Physics.PhysicsCollider { Value = mColliders[0][i] }); } }
protected override void OnUpdate() { var entities = m_Players.ToEntityArray(Allocator.TempJob); var cubes = m_Players.ToComponentDataArray <RepCubeComponentData>(Allocator.TempJob); var transforms = m_Players.ToComponentArray <Transform>(); for (int i = 0; i < entities.Length; ++i) { var ent = entities[i]; var cube = cubes[i]; var tr = transforms[i]; var cmdBuf = EntityManager.GetBuffer <PlayerCommandData>(ent); PlayerCommandData cmd; cmdBuf.GetDataAtTick(m_ServerSimulationSystemGroup.ServerTick, out cmd); cube.position.x += cmd.horizontal * 0.1f; cube.position.z += cmd.vertical * 0.1f; PostUpdateCommands.SetComponent(ent, cube); tr.position = cube.position; } entities.Dispose(); cubes.Dispose(); }
void SpawnEnemy() { var state = m_State.S[0]; var oldState = Random.state; Random.state = state.RandomState; float2 spawnPosition = ComputeSpawnLocation(); state.SpawnedEnemyCount++; PostUpdateCommands.CreateEntity(TwoStickBootstrap.BasicEnemyArchetype); PostUpdateCommands.SetComponent(new Position2D { Value = spawnPosition }); PostUpdateCommands.SetComponent(new Heading2D { Value = new float2(0.0f, -1.0f) }); PostUpdateCommands.SetComponent(default(Enemy)); PostUpdateCommands.SetComponent(new Health { Value = TwoStickBootstrap.Settings.enemyInitialHealth }); PostUpdateCommands.SetComponent(new EnemyShootState { Cooldown = 0.5f }); PostUpdateCommands.SetComponent(new MoveSpeed { speed = TwoStickBootstrap.Settings.enemySpeed }); PostUpdateCommands.AddSharedComponent(TwoStickBootstrap.EnemyLook); state.RandomState = Random.state; m_State.S[0] = state; Random.state = oldState; }
void SetComponentParent <T>() { var group = GetComponentGroup( ComponentType.ReadOnly <NetworkComponentData <T> >(), ComponentType.Create <ComponentEntity>()); var entities = group.GetEntityArray(); var reference = group.GetComponentDataArray <ComponentEntity>(); for (int i = 0; i < entities.Length; i++) { var entity = new Entity { Index = reference[i].Index, Version = reference[i].Version }; PostUpdateCommands.SetComponent( entity, new NetworkComponentState <T> { dataEntity = entities[i] }); PostUpdateCommands.RemoveComponent <ComponentEntity>(entities[i]); } }
protected override void OnUpdate() { StepCounter++; // Make sure we only collect max Y value when the body is bouncing back up using (var entities = m_VerificationGroup.ToEntityArray(Allocator.TempJob)) { foreach (var entity in entities) { var translation = EntityManager.GetComponentData <Translation>(entity); var velocity = EntityManager.GetComponentData <PhysicsVelocity>(entity).Linear; var verifyRestitution = EntityManager.GetComponentData <VerifyRestitutionData>(entity); if (velocity.y > 0) { verifyRestitution.MaxY = math.max(verifyRestitution.MaxY, translation.Value.y); if (StepCounter > 55) { // Biggest bounce should be near the original height, which is 1 Assert.IsTrue(verifyRestitution.MaxY > 0.9f); } PostUpdateCommands.SetComponent(entity, verifyRestitution); } } } }
protected override void OnUpdate() { var childrenBuffer = GetBufferFromEntity <Child>(true); Entities.With(canvasQuery).ForEach((Entity entity, CanvasSortOrder s0, DynamicBuffer <Child> b0) => { // Clear the list so that we can build a render hierarchy. batchedEntityList.Clear(); var renderBatchEntity = PostUpdateCommands.CreateEntity(renderBatchArchetype); PostUpdateCommands.SetComponent(renderBatchEntity, new RenderGroupID { Value = s0.Value }); var buffer = PostUpdateCommands.AddBuffer <RenderElement>(renderBatchEntity); RecurseChildren(in b0, in childrenBuffer); buffer.ResizeUninitialized(batchedEntityList.Count); for (int i = 0; i < buffer.Length; i++) { buffer[i] = new RenderElement { Value = batchedEntityList[i] }; } PostUpdateCommands.RemoveComponent <DirtyTag>(entity); }); }
void SpawnEnemy() { var state = m_State.EnemySpawnState[0]; var settings = AsteroidsArcadeBootstrap.Settings; var spawnData = ComputeSpawnLocationAndHeading(settings); var speed = GetRandom(AsteroidsArcadeBootstrap.Settings.enemyMinSpeed, AsteroidsArcadeBootstrap.Settings.enemyMaxSpeed); PostUpdateCommands.CreateEntity(AsteroidsArcadeBootstrap.EnemyAsteroidArchetype); PostUpdateCommands.SetComponent(new EnemySubdivide { Value = 2 }); PostUpdateCommands.SetComponent(new Position2D { Value = spawnData.pos }); PostUpdateCommands.SetComponent(new Health { Value = settings.enemyHealth }); PostUpdateCommands.SetComponent(new Heading2D { Value = spawnData.heading }); PostUpdateCommands.SetComponent(default(Enemy)); PostUpdateCommands.SetComponent(new MoveSpeed { speed = speed }); PostUpdateCommands.AddSharedComponent(AsteroidsArcadeBootstrap.EnemyAsteroidBigLook); m_State.EnemySpawnState[0] = state; }
protected override void OnUpdate() { var customRendererEntityArray = _customRendererGroup.ToEntityArray(Allocator.TempJob); for (int i = 0; i < customRendererEntityArray.Length; i++) { var customRendererEntity = customRendererEntityArray[i]; var rootRendererData = EntityManager.GetComponentObject <RootRendererData>(customRendererEntity); var groupData = RegisterRendererInGroup(customRendererEntity); var rootRenderId = groupData.RootRenderId; rootRendererData.SetIndex(rootRenderId); PostUpdateCommands.AddSharedComponent(customRendererEntity, new RemoveRenderer { CustomRendererIndex = rootRenderId, }); PostUpdateCommands.SetComponent(customRendererEntity, new RendererRoot() { RenderEntityListId = rootRenderId, }); } customRendererEntityArray.Dispose(); }
// 更新時に呼ばれる protected override void OnUpdate() { Entities.WithNone <SendRpcCommandRequestComponent>().ForEach((Entity reqEnt, ref GoInGameRequest req, ref ReceiveRpcCommandRequestComponent reqSrc) => { // ゲーム参加リクエストの受信 PostUpdateCommands.AddComponent <NetworkStreamInGame>(reqSrc.SourceConnection); UnityEngine.Debug.Log(String.Format("Server setting connection {0} to in game", EntityManager.GetComponentData <NetworkIdComponent>(reqSrc.SourceConnection).Value)); #if true // Cubeの生成 var ghostCollection = GetSingleton <GhostPrefabCollectionComponent>(); var ghostId = NetCodeTestGhostSerializerCollection.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>(reqSrc.SourceConnection).Value }); PostUpdateCommands.AddBuffer <CubeInput>(player); PostUpdateCommands.SetComponent(reqSrc.SourceConnection, new CommandTargetComponent { targetEntity = player }); #endif // ゲーム参加リクエストの破棄 PostUpdateCommands.DestroyEntity(reqEnt); }); }
void SpawnOne() { SpawnerState state = _state.CurrentState[0]; float3 spawnPosition = GetRandomPosition(); state.CurrentCount++; Debug.Log($"spawn new enemy at {spawnPosition}"); PostUpdateCommands.CreateEntity(Bootloader.EnemyArchveType); PostUpdateCommands.SetComponent(new Position { Value = spawnPosition }); PostUpdateCommands.SetComponent(new Rotation { Value = quaternion.LookRotation(new float3(0.0f, 0.0f, -1.0f), math.up()) }); PostUpdateCommands.SetComponent(new MoveSpeed { Speed = GameSettings.ENEMY_SPEED }); PostUpdateCommands.SetComponent(new Health { Value = GameSettings.ENEMY_HP }); PostUpdateCommands.AddSharedComponent(Bootloader.EnemyPrefab); // PostUpdateCommands.AddSharedComponent(Bootloader.EnemyPrefab); _state.CurrentState[0] = state; }
protected override void OnUpdate() { var state = _data.State[0]; if (state.SpawnedEntitiesCount >= state.SpawnLimit) { return; } state.SpawnCooldown -= Time.deltaTime; if (state.SpawnCooldown > 0.0f) { _data.State[0] = state; return; } state.SpawnCooldown = state.SpawnInterval; state.SpawnedEntitiesCount++; _data.State[0] = state; var rnd = Random.insideUnitCircle * 3; var pos = new float3(rnd.x, Random.value * 7 + 6, rnd.y); PostUpdateCommands.CreateEntity(BoxArchetype); PostUpdateCommands.SetComponent(new Prefab { PrefabId = 0 }); PostUpdateCommands.SetComponent(new Position { Value = pos }); }
protected override void OnUpdate() { if (logicFrames.Count <= 0) { return; } //run logic frame var logicFrame = logicFrames.Dequeue(); switch (logicFrame.opId) { case OPType.CreateAgent: var instance = PostUpdateCommands.Instantiate(prefab); PostUpdateCommands.AddComponent(instance, new AgentComponent { nexPosition = new float3(0), position = new float3(0), moveSpeed = 1 }); PostUpdateCommands.SetComponent(instance, new LocalToWorld() { Value = new float4x4(quaternion.identity, new float3(0, 0, 0)) }); break; case OPType.Idle: break; } }
protected override void OnUpdate() { // Get all entities with the ReceiveRpc's component (and without the SendRpc's component), // and which also have a GoInGameRequest component indicating they wish to join the game. Entities.WithNone <SendRpcCommandRequestComponent>().ForEach((Entity reqEnt, ref GoInGameRequest req, ref ReceiveRpcCommandRequestComponent reqSrc) => { // Mark that entity as in game PostUpdateCommands.AddComponent <NetworkStreamInGame>(reqSrc.SourceConnection); UnityEngine.Debug.Log(String.Format("Server setting connection {0} to in game", EntityManager.GetComponentData <NetworkIdComponent>(reqSrc.SourceConnection).Value)); // Generate a controllable cube for this newly connected player with an input buffer // See CubeInput.cs var ghostCollection = GetSingleton <GhostPrefabCollectionComponent>(); var ghostId = NetCubeGhostSerializerCollection.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>(reqSrc.SourceConnection).Value }); PostUpdateCommands.AddBuffer <CubeInput>(player); PostUpdateCommands.SetComponent(reqSrc.SourceConnection, new CommandTargetComponent { targetEntity = player }); // We don't need that request any more, destroy it. PostUpdateCommands.DestroyEntity(reqEnt); }); }
protected override void Update(Entity abilityEntity, Ability_Melee.LocalState localState) { if (localState.rayQueryId == -1) { return; } var queryReciever = World.GetExistingManager <RaySphereQueryReciever>(); RaySphereQueryReciever.Query query; RaySphereQueryReciever.QueryResult queryResult; queryReciever.GetResult(localState.rayQueryId, out query, out queryResult); localState.rayQueryId = -1; if (queryResult.hitCollisionOwner != Entity.Null) { var charAbility = EntityManager.GetComponentData <CharBehaviour>(abilityEntity); var settings = EntityManager.GetComponentData <Ability_Melee.Settings>(abilityEntity); var damageEventBuffer = EntityManager.GetBuffer <DamageEvent>(queryResult.hitCollisionOwner); DamageEvent.AddEvent(damageEventBuffer, charAbility.character, settings.damage, query.direction, settings.damageImpulse); var interpolatedState = EntityManager.GetComponentData <Ability_Melee.InterpolatedState>(abilityEntity); interpolatedState.impactTick = m_world.worldTime.tick; PostUpdateCommands.SetComponent(abilityEntity, interpolatedState); } EntityManager.SetComponentData(abilityEntity, localState); }
protected override void OnUpdate() { var localInput = GetSingleton <CommandTargetComponent>().targetEntity; if (localInput == Entity.Null) { var localPlayerId = GetSingleton <NetworkIdComponent>().Value; Entities.WithNone <InputCommandData>().ForEach((Entity ent, ref PlayerComponent player) => { if (player.PlayerId == localPlayerId) { PostUpdateCommands.AddBuffer <InputCommandData>(ent); PostUpdateCommands.SetComponent(GetSingletonEntity <CommandTargetComponent>(), new CommandTargetComponent { targetEntity = ent }); } }); return; } var input = default(InputCommandData); input.tick = World.GetExistingSystem <ClientSimulationSystemGroup>().ServerTick; localAngleH += Input.GetAxis("Horizontal"); localAngleV -= Input.GetAxis("Vertical"); input.angleH = localAngleH; input.angleV = localAngleV; input.speed = defaultspeed; var inputBuffer = EntityManager.GetBuffer <InputCommandData>(localInput); inputBuffer.AddCommandData(input); }
protected override void OnUpdate() { if (!GameServerManagement.IsCurrentlyHosting) { return; } for (var i = 0; i != m_Group.Length; i++) { var ev = m_Group.Events[i]; if (!EntityManager.Exists(ev.ServerTarget)) { continue; } var entity = ev.ServerTarget; if (!EntityManager.HasComponent <StStamina>(entity) || !EntityManager.HasComponent <DefStDodgeStaminaUsageData>(entity)) { continue; } var staminaComponent = EntityManager.GetComponentData <StStamina>(entity); var usageComponent = EntityManager.GetComponentData <DefStDodgeStaminaUsageData>(entity); staminaComponent.Value -= usageComponent.BaseRemove; Debug.Log("Updated stamina usage (from dodge) -= " + usageComponent.BaseRemove); PostUpdateCommands.SetComponent(entity, staminaComponent); } }
protected unsafe override void OnUpdate() { var em = World.Active.EntityManager; Entities.WithAll <PhysicsCollider, ChangeColliderType, RenderMesh>().ForEach( (Entity entity, ref ChangeColliderType modifier) => { modifier.LocalTime -= Time.fixedDeltaTime; if (modifier.LocalTime > 0.0f) { return; } modifier.LocalTime = modifier.TimeToSwap; var collider = em.GetComponentData <PhysicsCollider>(entity); if (collider.ColliderPtr->Type == modifier.ColliderA.ColliderPtr->Type) { PostUpdateCommands.SetComponent(entity, modifier.ColliderB); PostUpdateCommands.SetSharedComponent(entity, em.GetSharedComponentData <RenderMesh>(modifier.EntityB)); } else { PostUpdateCommands.SetComponent(entity, modifier.ColliderA); PostUpdateCommands.SetSharedComponent(entity, em.GetSharedComponentData <RenderMesh>(modifier.EntityA)); } }); }
protected override void OnUpdate() { m_CachedDefaultGravity = Physics.gravity; for (int i = 0; i != m_Group.Length; i++) { var entity = m_Group.Entities[i]; var velocity = m_Group.Velocities[i]; var runInput = m_Group.RunInputs[i]; var setting = m_Group.Settings[i]; var input = m_Group.Inputs[i]; var process = m_Group.Proccesses[i]; var state = m_Group.States[i]; var transform = m_Group.Transforms[i]; ProcessItem(ref entity, ref velocity, ref runInput, ref setting, ref input, ref process, ref state, transform); for (int frameIndex = 0; frameIndex != m_PhysicUpdaterSystem.LastIterationCount; frameIndex++) { ProcessPhysicItem(m_PhysicUpdaterSystem.LastFixedTimeStep, ref setting, ref input, ref process, ref velocity, ref state); } PostUpdateCommands.SetComponent(entity, velocity); PostUpdateCommands.SetComponent(entity, setting); PostUpdateCommands.SetComponent(entity, input); PostUpdateCommands.SetComponent(entity, process); } }
protected override void OnUpdate() { for (int index = 0; index < playerInputData.Length; index++) { PlayerInput playerInput = playerInputData.Input[index]; var position = playerInputData.Position[index].Value; var heading = playerInputData.Heading[index].Value; //TODO: Move Input.GetMouseButtonDown to PlayerInputSystem if (playerInput.CoolDownFinished && Input.GetMouseButtonDown(0)) { heading = math.normalize(playerInput.PlayerHeading); playerInput.FireCooldown = BootStrap.GameSettings.PlayerFireRate; PostUpdateCommands.CreateEntity(BootStrap.ArrowArchetype); PostUpdateCommands.SetComponent(new ArrowSpawnData { Position = new Position2D { Value = position }, Heading = new Heading2D { Value = heading } }); } playerInputData.Input[index] = playerInput; } }
// 敵の生成 void SpawnEnemy(ref EnemySpawnSystemData data, ref EnemySpawnSystemSettings spawnSettings) { ++data.SpawnedEnemyCount; var type = UnityEngine.Random.Range(0, spawnSettings.MaxBarrageType); var pos = spawnSettings.RandomArea(); PostUpdateCommands.CreateEntity(MainECS_Manager.CommonEnemyArchetype); PostUpdateCommands.SetComponent(new Position2D { Value = pos }); PostUpdateCommands.SetComponent(new EnemyData { }); PostUpdateCommands.AddSharedComponent(MainECS_Manager.EnemyLook); PostUpdateCommands.AddSharedComponent(MainECS_Manager.EnemyCollision); switch ((BarrageType)type) { case BarrageType.CircularBullet: { PostUpdateCommands.AddSharedComponent(MainECS_Manager.BarrageSettings_CircularBullet); } break; case BarrageType.DirectionBullet: { PostUpdateCommands.AddSharedComponent(MainECS_Manager.BarrageSettings_DirectionBullet); } break; } }