diff --git a/CHANGELOG.md b/CHANGELOG.md index a25628d..aff1416 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,15 @@ +# [3.0.0-preview.30](https://github.com/mob-sakai/ParticleEffectForUGUI/compare/v3.0.0-preview.29...v3.0.0-preview.30) (2020-09-02) + + +### Bug Fixes + +* ignore missing object on initialize ([8bd9b62](https://github.com/mob-sakai/ParticleEffectForUGUI/commit/8bd9b621b9efcd242c410405d066494a1d53f9a3)) + + +### Features + +* add API to bind ParticleSystem object ([a77bbd3](https://github.com/mob-sakai/ParticleEffectForUGUI/commit/a77bbd3a9a65d5fd1198bd8e580982ca8e07fca8)) + # [3.0.0-preview.29](https://github.com/mob-sakai/ParticleEffectForUGUI/compare/v3.0.0-preview.28...v3.0.0-preview.29) (2020-09-01) diff --git a/Scripts/UIParticle.cs b/Scripts/UIParticle.cs index 9874ac1..7cc701c 100755 --- a/Scripts/UIParticle.cs +++ b/Scripts/UIParticle.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Linq; using System.Runtime.CompilerServices; using UnityEngine; using UnityEngine.Rendering; @@ -123,6 +124,43 @@ namespace Coffee.UIExtensions particles.Exec(p => p.Stop()); } + public void SetParticleSystemInstance(GameObject instance) + { + SetParticleSystemInstance(instance, true); + } + + public void SetParticleSystemInstance(GameObject instance, bool destroy) + { + if (!instance) return; + + foreach (Transform child in transform) + { + var go = child.gameObject; + go.SetActive(false); + if (!destroy) continue; + +#if UNITY_EDITOR + if (!Application.isPlaying) + DestroyImmediate(go); + else +#endif + Destroy(go); + } + + var tr = instance.transform; + tr.SetParent(transform, false); + tr.localPosition = Vector3.zero; + + RefreshParticles(); + } + + public void SetParticleSystemPrefab(GameObject prefab) + { + if (!prefab) return; + + SetParticleSystemInstance(Instantiate(prefab.gameObject), true); + } + public void RefreshParticles() { GetComponentsInChildren(particles); @@ -321,7 +359,7 @@ namespace Coffee.UIExtensions return; } - if (!this || 0 < particles.Count) return; + if (!this || particles.Any(x => x)) return; m_IgnoreCanvasScaler = true; diff --git a/Scripts/UIParticleUpdater.cs b/Scripts/UIParticleUpdater.cs index 29141eb..db3280d 100755 --- a/Scripts/UIParticleUpdater.cs +++ b/Scripts/UIParticleUpdater.cs @@ -40,6 +40,7 @@ namespace Coffee.UIExtensions private static void Refresh() { + Profiler.BeginSample("[UIParticle] Refresh"); for (var i = 0; i < s_ActiveParticles.Count; i++) { try @@ -51,6 +52,7 @@ namespace Coffee.UIExtensions Debug.LogException(e); } } + Profiler.EndSample(); } private static void Refresh(UIParticle particle) diff --git a/package.json b/package.json index 84f61d3..2fb75f0 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "com.coffee.ui-particle", "displayName": "UI Particle", "description": "This plugin provide a component to render particle effect for uGUI.\nThe particle rendering is maskable and sortable, without Camera, RenderTexture or Canvas.", - "version": "3.0.0-preview.29", + "version": "3.0.0-preview.30", "unity": "2018.2", "license": "MIT", "repository": {