Exemple #1
0
        protected override void OnUpdate()
        {
            Entities
            .WithoutBurst()
            .WithStructuralChanges()
            .WithAll <EntitySpawnData>()
            .ForEach((Entity entity) => EntityManager.AddBuffer <EntityLifeTimeBuffer>(entity))
            .Run()
            ;

            var deltaTime = TimeSpan.FromSeconds(World.Time.DeltaTime);
            var random    = new Random((uint)Environment.TickCount);

            Entities
            .WithoutBurst()
            .WithStructuralChanges()
            .ForEach((Entity spawner, DynamicBuffer <EntityLifeTimeBuffer> entities, in EntitySpawnData data) =>
            {
                var ecb = new EntityCommandBuffer(Allocator.Temp);

                var newEntities = ecb.SetBuffer <EntityLifeTimeBuffer>(spawner);
                foreach (var entity in entities)
                {
                    var buffer       = entity;
                    buffer.LifeTime -= deltaTime;
                    if (buffer.LifeTime <= TimeSpan.Zero)
                    {
                        ecb.DestroyEntity(buffer.Entity);
                    }
                    else
                    {
                        newEntities.Add(buffer);
                    }
                }

                var count = data.Count - entities.Length;
                for (var i = 0; i < count; i++)
                {
                    var instance = ecb.Instantiate(data.Prefab);
                    var position = random.NextFloat3(data.PositionBounds.min, data.PositionBounds.max);
                    ecb.SetComponent(instance, new Translation {
                        Value = position
                    });
                    var lifetime = TimeSpan.FromSeconds(random.NextFloat(data.LifeTimeRange.x, data.LifeTimeRange.y));
                    newEntities.Add(new EntityLifeTimeBuffer {
                        Entity = instance, LifeTime = lifetime
                    });
                }

                ecb.Playback(EntityManager);
                ecb.Dispose();
            }).Run();
        }
Exemple #2
0
        public void TestAabbTransform()
        {
            Random rnd = new Random(0x12345678);

            for (int i = 0; i < 100; i++)
            {
                quaternion r = rnd.NextQuaternionRotation();
                float3     t = rnd.NextFloat3();

                Aabb orig = new Aabb();
                orig.Include(rnd.NextFloat3());
                orig.Include(rnd.NextFloat3());

                Aabb outAabb1 = Unity.Physics.Math.TransformAabb(new RigidTransform(r, t), orig);

                Physics.Math.MTransform bFromA = new Physics.Math.MTransform(r, t);
                Aabb outAabb2 = Unity.Physics.Math.TransformAabb(bFromA, orig);

                TestUtils.AreEqual(outAabb1.Min, outAabb2.Min, 1e-3f);
                TestUtils.AreEqual(outAabb1.Max, outAabb2.Max, 1e-3f);
            }
        }
Exemple #3
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            var time = Time.DeltaTime;

            timeSinceStart += time;
            var random = new Random((uint)(timeSinceStart * 1000f));

            return(Entities.WithBurst().ForEach((ref BugAiComponent ai, ref PhysicsVelocity velocity, in BugComponent bug) =>
            {
                ai.TimeTillNextTurn -= time;
                if (ai.TimeTillNextTurn <= 0)
                {
                    velocity.Angular = random.NextFloat3(ai.RotationRange.x, ai.RotationRange.y);
                    velocity.Angular = random.NextBool() ? velocity.Angular : -velocity.Angular;
                    ai.TimeTillNextTurn = random.NextFloat(ai.IntervalRangeSec.x, ai.IntervalRangeSec.y);
                }
            })
                   .Schedule(inputDeps));
        }