Skip to content

Instantly share code, notes, and snippets.

@sukedon
Last active February 29, 2016 15:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sukedon/fb9b4fdcc12a6dad644c to your computer and use it in GitHub Desktop.
Save sukedon/fb9b4fdcc12a6dad644c to your computer and use it in GitHub Desktop.
オブジェクトプーリングに対応したパーティクル再生クラス
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
public static class ParticleManager{
/// <summary>
/// プール用オブジェクトのリスト
/// </summary>
private static List<ParticlePooler> particlePoolerList = new List<ParticlePooler>();
/// <summary>
/// 指定した名前のパーティクル再生
/// 初めて再生するパーティクルはプール用オブジェクトを生成
/// </summary>
/// <param name="particleName">Particle name.</param>
/// <param name="position">Position.</param>
public static void PlayParticle(string particleName,Vector3 position){
//リストから指定した名前のプール用オブジェクトを取得
ParticlePooler pooler = particlePoolerList.Where(tempPooler => tempPooler.ParticleName == particleName).FirstOrDefault();
if(pooler == null){
//取得できなければ新たに生成
pooler = new ParticlePooler(particleName);
particlePoolerList.Add(pooler);
}
pooler.Play(position);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment