diff --git a/CHANGELOG.md b/CHANGELOG.md index 74a8033..eff4dfa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,17 @@ +# [3.0.0-preview.24](https://github.com/mob-sakai/ParticleEffectForUGUI/compare/v3.0.0-preview.23...v3.0.0-preview.24) (2020-09-01) + + +### Bug Fixes + +* hide camera for baking ([30b4703](https://github.com/mob-sakai/ParticleEffectForUGUI/commit/30b4703e2a1746efc4b7db154354f80fd0593b98)) +* In ignore canvas scaler mode, Transform.localScale is zero ([cc71f2b](https://github.com/mob-sakai/ParticleEffectForUGUI/commit/cc71f2bdac1a61fd5e5fc85d0a69589e05a0f79d)), closes [#89](https://github.com/mob-sakai/ParticleEffectForUGUI/issues/89) +* In prefab mode, an error occurs ([a222f37](https://github.com/mob-sakai/ParticleEffectForUGUI/commit/a222f3710b530c7fc9fab10f25bd28d820ffebe2)), closes [#88](https://github.com/mob-sakai/ParticleEffectForUGUI/issues/88) + + +### Features + +* remove menu in inspector ([e7f8f51](https://github.com/mob-sakai/ParticleEffectForUGUI/commit/e7f8f512122a01423de415b55e3190d62bda146a)) + # [3.0.0-preview.23](https://github.com/mob-sakai/ParticleEffectForUGUI/compare/v3.0.0-preview.22...v3.0.0-preview.23) (2020-08-31) diff --git a/Scripts/BakingCamera.cs b/Scripts/BakingCamera.cs index 70130df..f0005bb 100644 --- a/Scripts/BakingCamera.cs +++ b/Scripts/BakingCamera.cs @@ -53,7 +53,6 @@ namespace Coffee.UIExtensions // This camera object is just for internal use gameObject.hideFlags = HideFlags.HideAndDontSave; - gameObject.hideFlags = HideFlags.DontSave; var inst = gameObject.AddComponent(); inst._camera = gameObject.AddComponent(); diff --git a/Scripts/Editor/UIParticleEditor.cs b/Scripts/Editor/UIParticleEditor.cs index d5e03d6..d37d72d 100644 --- a/Scripts/Editor/UIParticleEditor.cs +++ b/Scripts/Editor/UIParticleEditor.cs @@ -16,6 +16,9 @@ namespace Coffee.UIExtensions //################################ private static readonly GUIContent s_ContentRenderingOrder = new GUIContent("Rendering Order"); private static readonly GUIContent s_ContentRefresh = new GUIContent("Refresh"); + private static readonly GUIContent s_ContentFix = new GUIContent("Fix"); + private static readonly List s_TempParents = new List(); + private static readonly List s_TempChildren = new List(); private SerializedProperty _spScale; private SerializedProperty _spIgnoreCanvasScaler; @@ -81,7 +84,17 @@ namespace Coffee.UIExtensions serializedObject.Update(); // IgnoreCanvasScaler - EditorGUILayout.PropertyField(_spIgnoreCanvasScaler); + using (var ccs = new EditorGUI.ChangeCheckScope()) + { + EditorGUILayout.PropertyField(_spIgnoreCanvasScaler); + if (ccs.changed) + { + foreach (UIParticle p in targets) + { + p.ignoreCanvasScaler = _spIgnoreCanvasScaler.boolValue; + } + } + } // Scale EditorGUILayout.PropertyField(_spScale); @@ -91,6 +104,8 @@ namespace Coffee.UIExtensions _ro.DoLayoutList(); + serializedObject.ApplyModifiedProperties(); + // Does the shader support UI masks? if (current.maskable && current.GetComponentInParent()) { @@ -108,7 +123,46 @@ namespace Coffee.UIExtensions } } - serializedObject.ApplyModifiedProperties(); + // Does the shader support UI masks? + + if (FixButton(current.m_IsTrail,"This UIParticle component should be removed. The UIParticle for trails is no longer needed.")) + { + DestroyUIParticle(current); + return; + } + current.GetComponentsInParent(true, s_TempParents); + if (FixButton(1 < s_TempParents.Count,"This UIParticle component should be removed. The parent UIParticle exists.")) + { + DestroyUIParticle(current); + return; + } + current.GetComponentsInChildren(true, s_TempChildren); + if (FixButton(1 < s_TempChildren.Count,"The children UIParticle component should be removed.")) + { + s_TempChildren.ForEach(child => DestroyUIParticle(child, true)); + } + } + + void DestroyUIParticle(UIParticle p, bool ignoreCurrent = false) + { + if (!p || ignoreCurrent && target == p) return; + + var cr = p.canvasRenderer; + DestroyImmediate(p); + DestroyImmediate(cr); + } + + bool FixButton(bool show, string text) + { + if (!show) return false; + using (new EditorGUILayout.HorizontalScope(GUILayout.ExpandWidth(true))) + { + EditorGUILayout.HelpBox(text, MessageType.Warning, true); + using (new EditorGUILayout.VerticalScope()) + { + return GUILayout.Button(s_ContentFix, GUILayout.Width(30)); + } + } } } } diff --git a/Scripts/UIParticle.cs b/Scripts/UIParticle.cs index 4458d2e..916dabe 100755 --- a/Scripts/UIParticle.cs +++ b/Scripts/UIParticle.cs @@ -20,7 +20,7 @@ namespace Coffee.UIExtensions , ISerializationCallbackReceiver #endif { - [HideInInspector] [SerializeField] bool m_IsTrail = false; + [HideInInspector] [SerializeField] internal bool m_IsTrail = false; [Tooltip("Ignore canvas scaler")] [SerializeField] [FormerlySerializedAs("m_IgnoreParent")] bool m_IgnoreCanvasScaler = true; @@ -34,6 +34,7 @@ namespace Coffee.UIExtensions [Tooltip("Particles")] [SerializeField] private List m_Particles = new List(); + private bool _shouldBeRemoved; private DrivenRectTransformTracker _tracker; private Mesh _bakedMesh; private readonly List _modifiedMaterials = new List(); @@ -56,7 +57,14 @@ namespace Coffee.UIExtensions public bool ignoreCanvasScaler { get { return m_IgnoreCanvasScaler; } - set { m_IgnoreCanvasScaler = value; } + set + { + // if (m_IgnoreCanvasScaler == value) return; + m_IgnoreCanvasScaler = value; + _tracker.Clear(); + if (isActiveAndEnabled && m_IgnoreCanvasScaler) + _tracker.Add(this, rectTransform, DrivenTransformProperties.Scale); + } } /// @@ -244,20 +252,24 @@ namespace Coffee.UIExtensions /// protected override void OnEnable() { - InitializeIfNeeded(); - _cachedPosition = transform.localPosition; _activeMeshIndices = 0; UIParticleUpdater.Register(this); particles.Exec(p => p.GetComponent().enabled = false); - _tracker.Add(this, rectTransform, DrivenTransformProperties.Scale); + + if (isActiveAndEnabled && m_IgnoreCanvasScaler) + { + _tracker.Add(this, rectTransform, DrivenTransformProperties.Scale); + } // Create objects. _bakedMesh = new Mesh(); _bakedMesh.MarkDynamic(); base.OnEnable(); + + InitializeIfNeeded(); } /// @@ -266,7 +278,8 @@ namespace Coffee.UIExtensions protected override void OnDisable() { UIParticleUpdater.Unregister(this); - particles.Exec(p => p.GetComponent().enabled = true); + if (!_shouldBeRemoved) + particles.Exec(p => p.GetComponent().enabled = true); _tracker.Clear(); // Destroy object. @@ -299,28 +312,25 @@ namespace Coffee.UIExtensions private void InitializeIfNeeded() { + if (enabled && m_IsTrail) + { + UnityEngine.Debug.LogWarningFormat(this, "[UIParticle] The UIParticle component should be removed: {0}\nReason: UIParticle for trails is no longer needed.", name); + gameObject.hideFlags = HideFlags.None; + _shouldBeRemoved = true; + enabled = false; + return; + } + else if (enabled && transform.parent && transform.parent.GetComponentInParent()) + { + UnityEngine.Debug.LogWarningFormat(this, "[UIParticle] The UIParticle component should be removed: {0}\nReason: The parent UIParticle exists.", name); + gameObject.hideFlags = HideFlags.None; + _shouldBeRemoved = true; + enabled = false; + return; + } + if (!this || 0 < particles.Count) return; - if (m_IsTrail) - { - UnityEngine.Debug.LogWarningFormat("[UIParticle] Remove this UIParticle: {0}\nReason: UIParticle for trails is no longer needed.", name); - if (Application.isPlaying) - Destroy(gameObject); - else - DestroyImmediate(gameObject); - return; - } - - if (transform.parent && transform.parent.GetComponentInParent()) - { - UnityEngine.Debug.LogWarningFormat("[UIParticle] Remove this UIParticle: {0}\nReason: The parent UIParticle exists.", name); - if (Application.isPlaying) - Destroy(this); - else - DestroyImmediate(this); - return; - } - m_IgnoreCanvasScaler = true; // refresh. diff --git a/Scripts/UIParticleUpdater.cs b/Scripts/UIParticleUpdater.cs index 9a9b9d3..90142e4 100755 --- a/Scripts/UIParticleUpdater.cs +++ b/Scripts/UIParticleUpdater.cs @@ -57,7 +57,7 @@ namespace Coffee.UIExtensions private static void Refresh(UIParticle particle) { - if (!particle) return; + if (!particle || !particle.canvas || !particle.canvasRenderer) return; Profiler.BeginSample("Modify scale"); ModifyScale(particle); @@ -131,8 +131,6 @@ namespace Coffee.UIExtensions MeshHelper.Clear(); particle.bakedMesh.Clear(false); - // if (!particle.isValid) return; - // Get camera for baking mesh. var camera = BakingCamera.GetCamera(particle.canvas); var root = particle.transform; diff --git a/package.json b/package.json index 4031529..19f37be 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.23", + "version": "3.0.0-preview.24", "unity": "2018.2", "license": "MIT", "repository": {