Пример #1
0
    private float pingPong   = 0.01F; // 粒子在来回运动的时候的游离范围

    void Start()
    {
        ps           = this.GetComponent <ParticleSystem>();
        particle_arr = new ParticleSystem.Particle[resolution];
        hp           = new HaloParticle[resolution];
        ps.Emit(resolution);
        ps.GetParticles(particle_arr);
        // 初始化各个粒子的位置
        for (int i = 0; i < resolution; i++)
        {
            // 使得粒子集中在平均半径处
            float shiftMinRadius = Random.Range(1, (min_radius + max_radius) / (2 * min_radius));
            float shiftMaxRadius = Random.Range((min_radius + max_radius) / (2 * max_radius), 1);
            //粒子角度,添加一个偏移量,使粒子集中于π/4和5π/4处
            float shiftMinAngle = Random.Range(1, 1.5f);
            float shiftMaxAngle = Random.Range(0.75f, 1);
            // 粒子的角度为[0, 2π], 按照平面直角坐标系的参数方程进行设定
            float angle = Random.Range(Mathf.PI * shiftMinAngle, Mathf.PI * 2 * shiftMaxAngle) - Mathf.PI / 4;
            if (Random.Range(0, 100) > 50)
            {
                angle -= Mathf.PI;
            }

            float radius = Random.Range(min_radius * shiftMinRadius, max_radius * shiftMaxRadius);
            float time   = Random.Range(0.0f, 360.0f);
            hp[i] = new HaloParticle(radius, angle, time);
            particle_arr[i].position = new Vector3(radius * Mathf.Cos(angle), radius * Mathf.Sin(angle), 0);
        }
        ps.SetParticles(particle_arr, particle_arr.Length);
    }
Пример #2
0
    // Start is called before the first frame update
    void Start()
    {
        particleSystem = this.GetComponent <ParticleSystem> ();
        particleArray  = new ParticleSystem.Particle[haloResolution];
        haloParticle   = new HaloParticle[haloResolution];
        particleSystem.Emit(haloResolution);
        particleSystem.GetParticles(particleArray);
        for (int i = 0; i < haloResolution; ++i)
        {
            float shiftMinRadius = Random.Range(1, (maxRadius + minRadius) / 2 / minRadius);
            float shiftMaxRadius = Random.Range((maxRadius + minRadius) / 2 / maxRadius, 1);
            float radius         = Random.Range(minRadius * shiftMinRadius, maxRadius * shiftMaxRadius);

            float angle = Random.Range(0, Mathf.PI * 2);

            haloParticle[i]           = new HaloParticle(radius, angle);
            particleArray[i].position = new Vector3(radius * Mathf.Cos(angle), radius * Mathf.Sin(angle), 0);
        }
        particleSystem.SetParticles(particleArray, particleArray.Length);
    }