这次作业差点就忘记交了,还是蛮简单的。下面开始讲实现步骤。
1.初始设置
建立一个halo的项目,并设置如下:
2.代码部分
光圈粒子部分:
基础粒子部分
public class HaloParticle {
02. public HaloParticle(float r = 0, float a = 0) {
03. radius = r;
04. angle = a;
05. }
06. public float radius {
07. get;
08. set;
09. }
10. public float angle {
11. get;
12. set;
13. }
14.}
外光圈部分:
先创建粒子系统、最大最小半径、粒子总数以及一个HaloParticle数组存粒子状态属性,注意粒子集中在扇道中心
public class OuterHalo{
public ParticleSystem _particle_system;
private ParticleSystem.Particle[] _particle_array;
private int _halo_resolution = 3000;
private float _min_radius = 2F;
private float _max_radius = 4.5F;
private HaloParticle[] _halo_particle;
void Start () {
_particle_system = this.GetComponent<ParticleSystem> ();
_particle_array = new ParticleSystem.Particle[_halo_resolution];
_halo_particle = new HaloParticle[_halo_resolution];
_particle_system.maxParticles = _halo_resolution;
_particle_system.Emit (_halo_resolution);
_particle_system.GetParticles (_particle_array);
for (int i = 0; i < _halo_resolution; ++i) {
//粒子半径,添加一个偏移量,使粒子集中于平均半径处
float shiftMinRadius = Random.Range(1, ((_max_radius + _min_radius) / 2) / _min_radius);
float shiftMaxRadius = Random.Range(((_max_radius + _min_radius) / 2) / _max_radius, 1);
float radius = Random.Range (_min_radius * shiftMinRadius, _max_radius * shiftMaxRadius);
//粒子角度
float angle = Random.Range (0, Mathf.PI * 2);
_halo_particle [i] = new HaloParticle (radius, angle);
_particle_array [i].position = new Vector3 (radius * Mathf.Cos (angle), radius * Mathf.Sin (angle), 0);
}
_particle_system.SetParticles (_particle_array, _particle_array.Length);
}
void Update () {
for (int i = 0; i < _halo_resolution; ++i) {
_halo_particle [i].angle -= Random.Range(0, 1F / 360);
_particle_array [i].position = new Vector3 (_halo_particle [i].radius * Mathf.Cos (_halo_particle [i].angle), _halo_particle [i].radius * Mathf.Sin (_halo_particle [i].angle), 0);
}
_particle_system.SetParticles (_particle_array, _particle_array.Length);
}
}
内光圈部分:
有一点注意的地方是内光圈有两个缺口,要在start()中使例子向π/4和5π/4聚集,即可实现缺口
public class InnerHalo{
public ParticleSystem _particle_system;
private ParticleSystem.Particle[] _particle_array;
private int _halo_resolution = 3000;
private float _min_radius = 2F;
private float _max_radius = 4.5F;
private HaloParticle[] _halo_particle;
void Start () {
_particle_system = this.GetComponent<ParticleSystem> ();
_particle_array = new ParticleSystem.Particle[_halo_resolution];
_halo_particle = new HaloParticle[_halo_resolution];
_particle_system.maxParticles = _halo_resolution;
_particle_system.Emit (_halo_resolution);
_particle_system.GetParticles (_particle_array);
for (int i = 0; i < _halo_resolution; ++i) {
//粒子半径,添加一个偏移量,使粒子集中于平均半径处
float shiftMinRadius = Random.Range(1, ((_max_radius + _min_radius) / 2) / _min_radius);
float shiftMaxRadius = Random.Range(((_max_radius + _min_radius) / 2) / _max_radius, 1);
float radius = Random.Range (_min_radius * shiftMinRadius, _max_radius * shiftMaxRadius);
//粒子角度
float angle = Random.Range (0, Mathf.PI * 2);
_halo_particle [i] = new HaloParticle (radius, angle);
_particle_array [i].position = new Vector3 (radius * Mathf.Cos (angle), radius * Mathf.Sin (angle), 0);
}
_particle_system.SetParticles (_particle_array, _particle_array.Length);
float shiftMinAngle = Random.Range(1, (Mathf.PI * 3 / 2) / Mathf.PI);
float shiftMaxAngle = Random.Range((Mathf.PI * 3 / 2) / Mathf.PI / 2, 1);
float angle = Random.Range (Mathf.PI * shiftMinAngle, Mathf.PI * 2 * shiftMaxAngle) - Mathf.PI / 4;
if (Random.Range (0, 100) < 50)
angle -= Mathf.PI;
}
void Update () {
for (int i = 0; i < _halo_resolution; ++i) {
_halo_particle [i].angle -= Random.Range(0, 1F / 360);
_particle_array [i].position = new Vector3 (_halo_particle [i].radius * Mathf.Cos (_halo_particle [i].angle), _halo_particle [i].radius * Mathf.Sin (_halo_particle [i].angle), 0);
}
_particle_system.SetParticles (_particle_array, _particle_array.Length);
}
}
3.成果
大致如此