void Update()
        {
            var dt     = 1.0f / 60;
            var aspect = (float)Screen.width / Screen.height;
            var pos    = math.float3(transform.position).xy;
            var spawn  = Time.deltaTime < 1.0f / 58 ? 400 : 20;

            // Bullet update job chain
            var handle = new BulletUpdateJob(_bullets, dt).Schedule(ActiveBulletCount, 64);

            handle = new BulletSweepJob(_bullets, _info, aspect).Schedule(handle);
            handle = new BulletSpawnJob(_bullets, _info, pos, spawn).Schedule(handle);
            handle.Complete();

            // Mesh construction
            if (_methodType == MethodType.Simple)
            {
                MeshBuilderSimple.Build(ActiveBulletSlice, _bulletSize, _mesh);
            }
            else
            {
                MeshBuilderAdvanced.Build(ActiveBulletSlice, _bulletSize, _mesh);
            }

            // Draw call
            Graphics.DrawMesh(_mesh, Vector3.zero, Quaternion.identity, _material, 0);

            // UI update
            _uiText.text = $"{ActiveBulletCount:n0} bullets";
        }
Example #2
0
        void Update()
        {
            var dt     = 1.0f / 60;
            var aspect = (float)Screen.width / Screen.height;
            var pos    = math.float3(transform.position).xy;
            var spawn  = Time.deltaTime < 1.0f / 58 ? 400 : 20;

            // FPS counter
            _deltaTime += (Time.unscaledDeltaTime - _deltaTime) * 0.1f;
            float  ms      = _deltaTime * 1000.0f;
            float  fps     = 1.0f / _deltaTime;
            string fpsText = string.Format("{0:0.0} ms ({1:0.} fps)", ms, fps);

            // Bullet update job chain
            var handle = new BulletUpdateJob(_bullets, dt).Schedule(ActiveBulletCount, 64);

            handle = new BulletSweepJob(_bullets, _info, aspect).Schedule(handle);

            _spawnFrequencyCounter += Time.deltaTime;

            //if (_spawnFrequencyCounter > _spawnFrequency)
            {
                _spawnFrequencyCounter = 0;
                handle = new BulletSpawnJob(_bullets, _info, pos, spawn).Schedule(handle);
            }

            handle.Complete();

            // Mesh construction
            if (_methodType == MethodType.Simple)
            {
                MeshBuilderSimple.Build(ActiveBulletSlice, _bulletSize, _mesh);
            }
            else
            {
                MeshBuilderAdvanced.Build(ActiveBulletSlice, _bulletSize, _mesh);
            }

            // Draw call
            Graphics.DrawMesh(_mesh, Vector3.zero, Quaternion.identity, _material, 0);

            // UI update
            _uiText.text = $"{fpsText}\n{ActiveBulletCount:n0} bullets";
        }