/// <summary> /// Spawn particle GameObject in scene. /// </summary> public void SpawnParticle() { if (particlePrefab == null) { Debug.LogError("Don't have Particle Prefab to spawn!!"); return; } Vector3 vSpawnPosition = particleSpawnPosition != null ? particleSpawnPosition.position : transform.position; ParticleSystem hParticle; InstantiateParticle(); ChangeStopActionToDisable(); AddParticleController(); #region Method void InstantiateParticle() { if (!Global_ParticlePoolingManager.TryGetParticle(particlePrefab, out hParticle)) { hParticle = Instantiate(particlePrefab, vSpawnPosition, particlePrefab.transform.rotation); } else { hParticle.transform.SetParent(null); hParticle.transform.position = vSpawnPosition; hParticle.transform.rotation = particlePrefab.transform.rotation; hParticle.gameObject.SetActive(true); } } void ChangeStopActionToDisable() { ParticleSystem.MainModule hMainModule = hParticle.main; hMainModule.stopAction = ParticleSystemStopAction.Disable; } void AddParticleController() { var hParticleController = hParticle.GetComponent <Particle_GameObjectController>(); if (hParticleController == null) { hParticleController = hParticle.gameObject.AddComponent <Particle_GameObjectController>(); } hParticleController.particlePrefab = particlePrefab; } #endregion }
void Awake() { if (m_hinstance == null) { m_hinstance = this; } else if (m_hinstance != this) { Destroy(this); return; } Application.quitting += OnAppQuit; }
void DelayRegister() { Global_ParticlePoolingManager.RegisterToPooling(this); }