I was wondering how I might go about this…
I want to create a database of particle systems with each one being assigned an ID number and then be able to spawn one by providing its ID number. How might I go about this? Ideally I want this to be done via a static function call.
Any help at all is appreciated. Thanks.
that would be done through prefabs you instantiate
Create your prefab particles, put them in the Resources/Particles folder (you create that yourself), name them something programmatic (i.e. 1, 2, 3) that your program will grab them by.
Then you just load them up:
ParticleManager.js
private var particleSystems : HashTable = new HashTable();
static function RequestParticleSystem( identifier : String ) : Object {
if ( !particleSystems.Contains( identifier ) ) {
particleSystems.Add( identifier, Resources.Load( "Particles/" + identifier ) );
}
return particleSystems[identifier];
}
User.js
var myExplosionParticle : String = "0001";
var ps : Object = ParticleManager.RequestParticleSystem(myExplosionParticle);
var go : GameObject = Instantiate( ps );
That’ll be imperfect for large amounts of particle systems, since it keeps references in memory rather than freeing them, but you can adjust it to fit your needs. 