public ParticleSystem.SubEmittersModule subEmitters ;

Description

访问粒子系统的子发射器模块。

不需要将粒子系统模块重新分配回系统;它们是接口而不是独立的对象。

using UnityEngine;
using System.Collections;

// A simple example showing access. public class ExampleClass : MonoBehaviour {

public ParticleSystem mySubEmitter;

void Start() { ParticleSystem ps = GetComponent<ParticleSystem>(); var sub = ps.subEmitters; sub.enabled = true; sub.AddSubEmitter(mySubEmitter, ParticleSystemSubEmitterType.Death, ParticleSystemSubEmitterProperties.InheritNothing); } }
using UnityEngine;

// An example showing how to create 2 particle systems; one as a sub-emitter. public class SubEmitterDeathExample : MonoBehaviour { void Start () { // A simple particle material with no texture. Material particleMaterial = new Material(Shader.Find("Particles/Alpha Blended Premultiply"));

// Create a green particle system. var rootSystemGO = new GameObject("Particle System"); rootSystemGO.transform.Rotate(-90, 0, 0); // Rotate so the system emits upwards. var rootParticleSystem = rootSystemGO.AddComponent<ParticleSystem>(); rootSystemGO.GetComponent<ParticleSystemRenderer>().material = particleMaterial; var mainModule = rootParticleSystem.main; mainModule.startColor = Color.green; mainModule.startSize = 0.5f;

// Create our sub-emitter and set up bursts. var subSystemGO = new GameObject("Particle System"); var subParticleSystem = subSystemGO.AddComponent<ParticleSystem>(); subSystemGO.GetComponent<ParticleSystemRenderer>().material = particleMaterial; var subMainModule = subParticleSystem.main; subMainModule.startColor = Color.red; subMainModule.startSize = 0.25f; var emissionModule = subParticleSystem.emission; emissionModule.SetBursts(new ParticleSystem.Burst[] { new ParticleSystem.Burst(0.0f, 10) }); // We will emit 10 particles upon death.

// Set up the sub-emitter. subSystemGO.transform.SetParent(rootSystemGO.transform); var subEmittersModule = rootParticleSystem.subEmitters; subEmittersModule.enabled = true; subEmittersModule.AddSubEmitter(subParticleSystem, ParticleSystemSubEmitterType.Death, ParticleSystemSubEmitterProperties.InheritNothing); } }