Exemplo n.º 1
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            BulletUpdateJob bulletJob = new BulletUpdateJob()
            {
                deltaTime = Time.deltaTime
            };
            JobHandle jobHandle = bulletJob.Schedule(this, inputDeps);

            return(jobHandle);
        }
        protected override unsafe JobHandle OnUpdate(JobHandle inputDeps)
        {
            if (this._playerGroup.CalculateLength() != 1)
            {
                return(inputDeps);
            }

            float deltaTime     = Time.deltaTime;
            var   handle        = inputDeps;
            var   commandBuffer = this._transformBarrierSystem.CreateCommandBuffer();

            // プレイヤーの更新(バリア回復処理)
            var playerStatus = this._playerGroup.GetComponentDataArray <PlayerStatus>()[0];
            {
                // バリアが尽きていたら負け
                if (playerStatus.BarrierPoint <= 0f)
                {
                    var playerEntities = this._playerGroup.GetEntityArray();
                    commandBuffer.SetComponent(playerEntities[0], Destroyable.Kill);
                    return(handle);
                }
                playerStatus.BarrierPoint += playerStatus.PlayerParam.RecoveryBarrierPoint * deltaTime;
                playerStatus.BarrierPoint  = math.clamp(playerStatus.BarrierPoint, 0f, playerStatus.PlayerParam.MaxBarrierPoint);
            }

            // 自機の弾の生成
            {
                var length       = this._playerBulletGenerateGroup.CalculateLength();
                var entities     = this._playerBulletGenerateGroup.GetEntityArray();
                var generateData = this._playerBulletGenerateGroup.GetComponentDataArray <PlayerBulletGenerate>();
                var bulletData   = this._playerBulletGenerateGroup.GetComponentDataArray <BulletData>();
                for (int i = 0; i < length; i++)
                {
                    commandBuffer.Instantiate(this._prefabEntities.PlayerBulletPrefab);
                    commandBuffer.SetComponent(new Position2D {
                        Value = generateData[i].CreatePosition
                    });
                    commandBuffer.SetComponent(bulletData[i]);

                    // 通知用Entityの破棄
                    commandBuffer.DestroyEntity(entities[i]);
                    // 弾のエネルギー消費
                    playerStatus.BarrierPoint -= playerStatus.PlayerParam.ShotEnergy;
                }
            }
            // 敵機の生成
            {
                var length       = this._enemyGenerateGroup.CalculateLength();
                var entities     = this._enemyGenerateGroup.GetEntityArray();
                var enemyData    = this._enemyGenerateGroup.GetComponentDataArray <EnemyData>();
                var generateData = this._enemyGenerateGroup.GetComponentDataArray <EnemyGenerate>();
                for (int i = 0; i < length; i++)
                {
                    var data = enemyData[i];
                    commandBuffer.Instantiate(this._prefabEntities.EnemyPrefabs[(int)data.EnemyID]);
                    commandBuffer.SetComponent(new Position2D {
                        Value = generateData[i].CreatePosition
                    });
                    commandBuffer.SetComponent(data);

                    // 通知用Entityの破棄
                    commandBuffer.DestroyEntity(entities[i]);
                }
            }

            // 敵の更新
            var enemyGroupLength = this._enemyGroup.CalculateLength();

            handle = new EnemyUpdateJob
            {
                DeltaTime         = deltaTime,
                EnemyBulletPrefab = this._prefabEntities.EnemyBulletPrefab,
                PlayerPosition    = this._playerGroup.GetComponentDataArray <Position2D>()[0].Value,
                EnemyParams       = this._enemyParams,

                RandomPtr       = this._randomPtr,
                BarrageParamPtr = this._barrageParamPtr,

                EnemyPositions = this._enemyGroup.GetComponentDataArray <Position2D>(),
                Destroyables   = this._enemyGroup.GetComponentDataArray <Destroyable>(),
                EnemyData      = this._enemyGroup.GetComponentDataArray <EnemyData>(),

                CommandBuffer = commandBuffer.ToConcurrent()
            }.Schedule(enemyGroupLength, 32, handle);

            // 弾の移動
            handle = new BulletUpdateJob {
                DeltaTime = deltaTime
            }.Schedule(this, handle);

            return(handle);
        }