public void Execute(Entity entity, int index, [ReadOnly] ref HelloSpawner8 spawner, [ReadOnly] ref LocalToWorld location)
            {
                var random = new Random(1);

                for (int x = 0; x < spawner.CountX; x++)
                {
                    for (int y = 0; y < spawner.CountY; y++)
                    {
                        Entity instance = CommandBuffer.Instantiate(index, spawner.Prefab);

                        // Place the instantiated in a grid with some noise
                        var position = math.transform(location.Value, new float3(x * 1.3F, noise.cnoise(new float2(x, y) * 0.21F) * 2, y * 1.3F));
                        CommandBuffer.SetComponent(index, instance, new Translation {
                            Value = position
                        });
                        CommandBuffer.SetComponent(index, instance, new LifeTime {
                            Value = random.NextFloat(10.0F, 100.0F)
                        });
                        CommandBuffer.SetComponent(index, instance, new RotationSpeed {
                            RadiansPerSecond = math.radians(random.NextFloat(25.0F, 90.0F))
                        });
                    }
                }

                CommandBuffer.DestroyEntity(index, entity);
            }
    public void Spawn(int numEnemies)
    {
        for (int i = 0; i < numEnemies; i++)
        {
            float   distance    = r.NextFloat(10f, 90f);
            Vector2 randomPoint = UnityEngine.Random.insideUnitCircle.normalized * distance;
            float3  position    = new float3(randomPoint.x, 0.5f, randomPoint.y);
            var     entity      = entityManager.Instantiate(enemyEntityPrefab);

            entityManager.SetComponentData(entity, new Translation {
                Value = position
            });
            entityManager.SetComponentData(entity, new Rotation {
                Value = Quaternion.Euler(0, r.NextFloat(0, 360), 0)
            });

            // createSingleEnemy(
            //     entityManager,
            //     frozenEnemyArchetype,
            //     position, //position
            //     Quaternion.Euler(0,r.NextFloat(0,360),0), //orientation
            //     cubeMesh,
            //     iceMaterial);
        }
    }
Example #3
0
        void Insert()
        {
            var obstacle = ObstaclePrefabs[_r.NextInt(ObstaclePrefabs.Length)];
            var scale    = ObstacleMinScale + _r.NextFloat() * ObstacleScaleRange;
            var rot      = _r.NextFloat(2 * math.PI);
            var vertices = obstacle.Vertices.Select(f => DemoMath.Rotate(scale * f, rot)).ToList();

            var min = new float2(float.MaxValue);
            var max = new float2(float.MinValue);

            for (var i = 0; i < vertices.Count; i++)
            {
                min = math.min(vertices[i], min);
                max = math.max(vertices[i], max);
            }

            var size   = max - min;
            var range  = _size - new float2(0, 2 * SpawnRectHeight) - size;
            var offset = _r.NextFloat2(range) + new float2(0, SpawnRectHeight) - _size / 2;

            for (var i = 0; i < vertices.Count; i++)
            {
                vertices[i] += (Vector2)(offset - min);
            }

            Plane.InsertObstacle(vertices);
        }
Example #4
0
        private void PixelColoringThread(int start, int end)
        {
            uint seed = (uint)((start + 1) * (System.DateTime.Now.Millisecond * 1000 + System.DateTime.Now.Second + 1));

            Unity.Mathematics.Random random = new Unity.Mathematics.Random(seed);
            TDRay ray;

            ray.origin = this.scene.camera.position;
            float3 result;
            float  u, v;

            for (int k = start; k < end; ++k)
            {
                result = float3.zero;

                for (int i = 0; i < this.renderConfiguration.sampleRate; ++i)
                {
                    u = random.NextFloat() * this.worldWidthPerPixel;
                    v = random.NextFloat() * this.worldHeightPerPixel;

                    ray.direction = math.normalize(this.screenPixelPositions[k] + new float3(u, v, 0) - this.scene.camera.position);

                    result += this.TraceColor(ray, random);
                }

                accumulatedColor[k] = (accumulatedColor[k] * this.renderConfiguration.sampleRate * numIterations + result)
                                      / (this.renderConfiguration.sampleRate * (numIterations + 1));
            }
        }
        protected override void OnUpdate()
        {
            EndSimulationEntityCommandBufferSystem endSimECBSystem = World.GetOrCreateSystem <EndSimulationEntityCommandBufferSystem>();

            EntityCommandBuffer.ParallelWriter parallelWriter = endSimECBSystem.CreateCommandBuffer().AsParallelWriter();
            Random random = new Random((uint)Environment.TickCount);

            Entities.ForEach((Entity entity, int entityInQueryIndex, in StressTestCommand cmd) =>
            {
                for (int i = 0; i < cmd.Count; i++)
                {
                    Entity obj = parallelWriter.Instantiate(entityInQueryIndex, cmd.Prefab);

                    float3 moveStart      = random.NextFloat3Direction() * cmd.StartMoveRadius;
                    float3 moveEnd        = random.NextFloat3Direction() * cmd.EndMoveRadius;
                    EaseDesc moveEaseDesc = new EaseDesc(cmd.MoveEaseType, cmd.MoveEaseExponent);
                    Tween.Move(parallelWriter, entityInQueryIndex, obj, moveStart, moveEnd, cmd.MoveDuration, moveEaseDesc, cmd.MoveIsPingPong, cmd.MoveLoopCount);

                    quaternion rotateEnd    = quaternion.AxisAngle(random.NextFloat3Direction(), random.NextFloat(cmd.MinRotateDegree, cmd.MaxRotateDegree));
                    EaseDesc rotateEaseDesc = new EaseDesc(cmd.RotateEaseType, cmd.RotateEaseExponent);
                    Tween.Rotate(parallelWriter, entityInQueryIndex, obj, quaternion.identity, rotateEnd, cmd.RotateDuration, rotateEaseDesc, cmd.RotateIsPingPong, cmd.RotateLoopCount);

                    float3 scaleStart      = new float3(random.NextFloat(cmd.MinStartScale, cmd.MaxStartScale));
                    float3 scaleEnd        = new float3(random.NextFloat(cmd.MinEndScale, cmd.MaxEndScale));
                    EaseDesc scaleEaseDesc = new EaseDesc(cmd.ScaleEaseType, cmd.ScaleEaseExponent);
                    Tween.Scale(parallelWriter, entityInQueryIndex, obj, scaleStart, scaleEnd, cmd.ScaleDuration, scaleEaseDesc, cmd.ScaleIsPingPong, cmd.ScaleLoopCount);
                }

                parallelWriter.RemoveComponent <StressTestCommand>(entityInQueryIndex, entity);
            }).ScheduleParallel();

            endSimECBSystem.AddJobHandleForProducer(Dependency);
        }
Example #6
0
        void Start()
        {
            // Ensure gameobject conversion when loading a scene
            World.All[0].GetOrCreateSystem <InitializationSystemGroup>().Update();

            _size = Plane.GetComponent <DotsNavPlane>().Size;
            FindObjectOfType <CameraController>().Initialize(_size);
            _r = new Random((uint)DateTime.Now.Ticks);

            var placedStarts = new List <Circle>();
            var placedGoals  = new List <Circle>();

            for (int i = 0; i < AgentAmount; i++)
            {
                var agent = Instantiate(AgentPrefab);

                var preferredSpeed = _r.NextFloat(PreferredSpeedMin, PreferredSpeedMin + PreferredSpeedRange);
                agent.GetComponent <DemoAgent>().PreferredSpeed            = preferredSpeed;
                agent.GetComponent <DotsNavLocalAvoidanceAgent>().MaxSpeed = preferredSpeed * MaxSpeedFactor;

                var r            = AgentMinRadius + i * AgentRadiusRange / AgentAmount;
                var dotsNavAgent = agent.GetComponent <DotsNavAgent>();
                dotsNavAgent.Radius        = r;
                dotsNavAgent.Plane         = Plane;
                agent.transform.localScale = new Vector3(r, r, r) * 2;

                var    cycles = 0;
                float2 pos;
                do
                {
                    pos = -_size / 2 + new float2(r + _r.NextFloat() * (_size.x - 2 * r), r + _r.NextFloat() * (SpawnRectHeight - 2 * r));
                } while (placedStarts.Any(p => math.length(p.Position - pos) < r + p.Radius) && ++cycles < 1000);

                agent.transform.position = pos.ToXxY();
                placedStarts.Add(new Circle {
                    Position = pos, Radius = r
                });

                cycles = 0;

                do
                {
                    pos = _size / 2 - new float2(r + _r.NextFloat() * (_size.x - 2 * r), r + _r.NextFloat() * (SpawnRectHeight - 2 * r));
                } while (placedGoals.Any(p => math.length(p.Position - pos) < r + p.Radius) && ++cycles < 1000);

                placedGoals.Add(new Circle {
                    Position = pos, Radius = r
                });

                agent.FindPath(pos.ToXxY());
            }

            Help.gameObject.SetActive(!Application.isEditor && !Closed);

            for (int i = 0; i < ObstacleAmount; i++)
            {
                Insert();
            }
        }