コード例 #1
0
        public static void InitEmitterRectSource(EntityManager mgr, Entity emitter, NativeArray <Entity> particles, bool isWorld)
        {
            var source = mgr.GetComponentData <EmitterRectSource>(emitter);

            var localToWorld = mgr.GetComponentData <LocalToWorld>(emitter);

            foreach (var particle in particles)
            {
                var pos2 = ParticlesUtil.RandomPointInRect(source.rect);
                var pos  = new float3(pos2.x, pos2.y, 0.0f);
                if (isWorld)
                {
                    pos = math.mul(localToWorld.Rotation, pos);
                }

                var Translation = mgr.GetComponentData <Translation>(particle);
                Translation.Value += pos;
                mgr.SetComponentData(particle, Translation);

                var   particleVelocity = mgr.GetComponentData <ParticleVelocity>(particle);//new ParticleVelocity();
                float speed            = particleVelocity.initSpeed;
                if (speed != 0f)
                {
                    var direction = math.normalizesafe(pos);
                    var velocity  = direction * speed;

                    particleVelocity.velocity = velocity;
                    mgr.SetComponentData(particle, particleVelocity);
                }
            }
        }
コード例 #2
0
        static void InitTime(EntityManager mgr, float deltaTime, Range lifetime, NativeArray <Entity> newParticles)
        {
            // The time is evenly distributted from 0.0 to deltaTime.

            // The time of each subsequent particle will be increased by this value.
            // particle.time[0..n] = (0 * timeStep, 1 * timeStep, 2 * timeStep, ..., n * timeStep).
            float timeStep = newParticles.Length > 1 ? (deltaTime / (float)(newParticles.Length - 1)) : 0.0f;

            // We need to subtract deltaTime from the particle's relative time, because later in
            // the same frame we are adding deltaTime to the particle's relative time when we process
            // them. This ensures that the first, newly created particle will start at a relative time 0.0.
            float time = -deltaTime;

            foreach (var particle in newParticles)
            {
                var cParticle = mgr.GetComponentData <Particle>(particle);
                cParticle.lifetime = ParticlesUtil.RandomRange(lifetime);
                cParticle.time     = time;
                time += timeStep;
                mgr.SetComponentData(particle, cParticle);
            }
        }