diff --git a/CHANGELOG.md b/CHANGELOG.md index fc96f17..0efce0d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +# [3.0.0-preview.36](https://github.com/mob-sakai/ParticleEffectForUGUI/compare/v3.0.0-preview.35...v3.0.0-preview.36) (2020-09-28) + + +### Bug Fixes + +* do not bake particle system to mesh when the alpha is zero ([1775713](https://github.com/mob-sakai/ParticleEffectForUGUI/commit/1775713c2dbeef09ad3eb1f49b53cf44bf61d535)), closes [#102](https://github.com/mob-sakai/ParticleEffectForUGUI/issues/102) +* in Unity 2018.x, sample import failed on Windows ([f5861b0](https://github.com/mob-sakai/ParticleEffectForUGUI/commit/f5861b0add1477987d6b9a3db26979fde50930ad)) + # [3.0.0-preview.35](https://github.com/mob-sakai/ParticleEffectForUGUI/compare/v3.0.0-preview.34...v3.0.0-preview.35) (2020-09-27) diff --git a/Scripts/AnimatableProperty.cs b/Scripts/AnimatableProperty.cs index 5656db5..4273db4 100644 --- a/Scripts/AnimatableProperty.cs +++ b/Scripts/AnimatableProperty.cs @@ -1,5 +1,4 @@ -using System; -using UnityEngine; +using UnityEngine; namespace Coffee.UIExtensions { diff --git a/Scripts/BakingCamera.cs b/Scripts/BakingCamera.cs index 9fa0833..1ae94f1 100644 --- a/Scripts/BakingCamera.cs +++ b/Scripts/BakingCamera.cs @@ -1,6 +1,6 @@ using UnityEngine; -namespace Coffee.UIExtensions +namespace Coffee.UIParticleExtensions { internal class BakingCamera : MonoBehaviour { diff --git a/Scripts/CombineInstanceEx.cs b/Scripts/CombineInstanceEx.cs index 9ff470a..99df9d4 100644 --- a/Scripts/CombineInstanceEx.cs +++ b/Scripts/CombineInstanceEx.cs @@ -1,8 +1,7 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using UnityEngine; -namespace Coffee.UIExtensions +namespace Coffee.UIParticleExtensions { internal class CombineInstanceEx { diff --git a/Scripts/Editor/AnimatedPropertiesEditor.cs b/Scripts/Editor/AnimatedPropertiesEditor.cs index 6e598cd..fab0e83 100644 --- a/Scripts/Editor/AnimatedPropertiesEditor.cs +++ b/Scripts/Editor/AnimatedPropertiesEditor.cs @@ -1,4 +1,3 @@ -using System; using UnityEditor; using UnityEngine; using System.Collections.Generic; diff --git a/Scripts/Editor/ImportSampleMenu.cs b/Scripts/Editor/ImportSampleMenu.cs new file mode 100644 index 0000000..7a18e2c --- /dev/null +++ b/Scripts/Editor/ImportSampleMenu.cs @@ -0,0 +1,70 @@ +#if !UNITY_2019_1_OR_NEWER +using System.IO; +using System.Linq; +using System.Text.RegularExpressions; +using UnityEditor; + +static class ImportSampleMenu_UIParticle +{ + private const string k_DisplayName = "UI Particle"; + private const string k_JsonGuid = "823dc693d087a4b559c7e1547274cc7d"; + + [MenuItem("Assets/Samples/" + k_DisplayName + "/Import Demo")] + private static void ImportDemo() + { + ImportSample(k_JsonGuid, "Demo"); + } + + private static void ImportSample(string jsonGuid, string sampleName) + { + var jsonPath = AssetDatabase.GUIDToAssetPath(jsonGuid); + var packageRoot = Path.GetDirectoryName(jsonPath).Replace('\\', '/'); + var json = File.ReadAllText(jsonPath); + var version = Regex.Match(json, "\"version\"\\s*:\\s*\"([^\"]+)\"").Groups[1].Value; + var src = string.Format("{0}/Samples~/{1}", packageRoot, sampleName); + var dst = string.Format("Assets/Samples/{0}/{1}/{2}", k_DisplayName, version, sampleName); + var previousPath = GetPreviousSamplePath(k_DisplayName, sampleName); + + // Remove the previous sample directory. + if (!string.IsNullOrEmpty(previousPath)) + { + var msg = "A different version of the sample is already imported at\n\n" + + previousPath + + "\n\nIt will be deleted when you update. Are you sure you want to continue?"; + if (!EditorUtility.DisplayDialog("Sample Importer", msg, "OK", "Cancel")) + return; + + FileUtil.DeleteFileOrDirectory(previousPath); + + var metaFile = previousPath + ".meta"; + if (File.Exists(metaFile)) + FileUtil.DeleteFileOrDirectory(metaFile); + } + + if (!Directory.Exists(dst)) + FileUtil.DeleteFileOrDirectory(dst); + + var dstDir = Path.GetDirectoryName(dst); + if (!Directory.Exists(dstDir)) + Directory.CreateDirectory(dstDir); + + if (Directory.Exists(src)) + FileUtil.CopyFileOrDirectory(src, dst); + else + throw new DirectoryNotFoundException(src); + + AssetDatabase.Refresh(ImportAssetOptions.ImportRecursive); + } + + private static string GetPreviousSamplePath(string displayName, string sampleName) + { + var sampleRoot = string.Format("Assets/Samples/{0}", displayName); + var sampleRootInfo = new DirectoryInfo(sampleRoot); + if (!sampleRootInfo.Exists) return null; + + return sampleRootInfo.GetDirectories() + .Select(versionDir => Path.Combine(versionDir.ToString(), sampleName)) + .FirstOrDefault(Directory.Exists); + } +} +#endif diff --git a/Scripts/Editor/UIParticleMenu.cs.meta b/Scripts/Editor/ImportSampleMenu.cs.meta similarity index 100% rename from Scripts/Editor/UIParticleMenu.cs.meta rename to Scripts/Editor/ImportSampleMenu.cs.meta diff --git a/Scripts/Editor/UIParticleMenu.cs b/Scripts/Editor/UIParticleMenu.cs deleted file mode 100644 index 05e445b..0000000 --- a/Scripts/Editor/UIParticleMenu.cs +++ /dev/null @@ -1,113 +0,0 @@ -using System.IO; -using System.Text.RegularExpressions; -using UnityEditor; -using UnityEngine; -using UnityEngine.UI; - -namespace Coffee.UIExtensions -{ - public class UIParticleMenu - { -#if !UNITY_2019_1_OR_NEWER - static string GetPreviousSamplePath(string displayName, string sampleName) - { - string sampleRoot = string.Format("Assets/Samples/{0}", displayName); - var sampleRootInfo = new DirectoryInfo(sampleRoot); - if (!sampleRootInfo.Exists) return null; - - foreach (var versionDir in sampleRootInfo.GetDirectories()) - { - var samplePath = Path.Combine(versionDir.ToString(), sampleName); - if (Directory.Exists(samplePath)) - return samplePath; - } - - return null; - } - - - static void ImportSample(string packageName, string sampleName) - { - string jsonPath = string.Format("Packages/{0}/package.json", packageName); - string json = File.ReadAllText(jsonPath); - string version = Regex.Match(json, "\"version\"\\s*:\\s*\"([^\"]+)\"").Groups[1].Value; - string displayName = Regex.Match(json, "\"displayName\"\\s*:\\s*\"([^\"]+)\"").Groups[1].Value; - string src = string.Format("{0}/Samples~/{1}", Path.GetDirectoryName(jsonPath), sampleName); - string dst = string.Format("Assets/Samples/{0}/{1}/{2}", displayName, version, sampleName); - string previous = GetPreviousSamplePath(displayName, sampleName); - - if (!string.IsNullOrEmpty(previous)) - { - string msg = "A different version of the sample is already imported at\n\n" - + previous - + "\n\nIt will be deleted when you update. Are you sure you want to continue?"; - if (!EditorUtility.DisplayDialog("Sample Importer", msg, "OK", "Cancel")) - return; - - FileUtil.DeleteFileOrDirectory(previous + ".meta"); - FileUtil.DeleteFileOrDirectory(previous); - - string versionDir = Path.GetDirectoryName(previous); - if (Directory.GetFiles(versionDir, "*.meta", SearchOption.TopDirectoryOnly).Length == 0) - { - FileUtil.DeleteFileOrDirectory(versionDir + ".meta"); - FileUtil.DeleteFileOrDirectory(versionDir); - } - } - - Directory.CreateDirectory(Path.GetDirectoryName(dst)); - FileUtil.CopyFileOrDirectory(src, dst); - AssetDatabase.ImportAsset(dst, ImportAssetOptions.ImportRecursive); - } - - [MenuItem("Assets/Samples/Import UIParticle Demo")] - static void ImportSample() - { - ImportSample("com.coffee.ui-particle", "Demo"); - } - - [MenuItem("Assets/Samples/Import UIParticle Demo (Cartoon FX & War FX Demo)")] - static void ImportSample_CFX() - { - ImportSample("com.coffee.ui-particle", "Cartoon FX & War FX Demo"); - } -#endif - - [MenuItem("GameObject/UI/Particle System (Empty)", false, 2018)] - public static void AddParticleEmpty(MenuCommand menuCommand) - { - // Create empty UI element. - EditorApplication.ExecuteMenuItem("GameObject/UI/Image"); - var ui = Selection.activeGameObject; - Object.DestroyImmediate(ui.GetComponent()); - - // Add UIParticle. - var uiParticle = ui.AddComponent(); - uiParticle.name = "UIParticle"; - uiParticle.scale = 10; - uiParticle.rectTransform.sizeDelta = Vector2.zero; - } - - [MenuItem("GameObject/UI/Particle System", false, 2019)] - public static void AddParticle(MenuCommand menuCommand) - { - // Create empty UIEffect. - AddParticleEmpty(menuCommand); - var uiParticle = Selection.activeGameObject.GetComponent(); - - // Create ParticleSystem. - EditorApplication.ExecuteMenuItem("GameObject/Effects/Particle System"); - var ps = Selection.activeGameObject; - ps.transform.SetParent(uiParticle.transform, false); - ps.transform.localPosition = Vector3.zero; - - // Assign default material. - var renderer = ps.GetComponent(); - var defaultMat = AssetDatabase.GetBuiltinExtraResource("Default-Particle.mat"); - renderer.material = defaultMat ? defaultMat : renderer.material; - - // Refresh particles. - uiParticle.RefreshParticles(); - } - } -} diff --git a/Scripts/MeshHelper.cs b/Scripts/MeshHelper.cs index f18ce1b..3830706 100644 --- a/Scripts/MeshHelper.cs +++ b/Scripts/MeshHelper.cs @@ -1,9 +1,8 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using UnityEngine; using UnityEngine.Profiling; -namespace Coffee.UIExtensions +namespace Coffee.UIParticleExtensions { internal static class MeshHelper { diff --git a/Scripts/UIParticle.cs b/Scripts/UIParticle.cs index ef08421..04db9ca 100755 --- a/Scripts/UIParticle.cs +++ b/Scripts/UIParticle.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Linq; using System.Runtime.CompilerServices; +using Coffee.UIParticleExtensions; using UnityEngine; using UnityEngine.Rendering; using UnityEngine.Serialization; diff --git a/Scripts/UIParticleUpdater.cs b/Scripts/UIParticleUpdater.cs index 1bbb34c..23c2523 100755 --- a/Scripts/UIParticleUpdater.cs +++ b/Scripts/UIParticleUpdater.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using Coffee.UIParticleExtensions; using UnityEngine; using UnityEngine.Profiling; @@ -196,6 +197,10 @@ private static void BakeMesh(UIParticle particle) Profiler.EndSample(); } + // #102: Do not bake particle system to mesh when the alpha is zero. + if (Mathf.Approximately( particle.canvasRenderer.GetInheritedAlpha(), 0)) + continue; + // Bake main particles. var r = currentPs.GetComponent(); if (CanBakeMesh(r)) diff --git a/Scripts/Utils.cs b/Scripts/Utils.cs index ee75539..c8ffd22 100644 --- a/Scripts/Utils.cs +++ b/Scripts/Utils.cs @@ -3,7 +3,7 @@ using System.Reflection; using UnityEngine; -namespace Coffee.UIExtensions +namespace Coffee.UIParticleExtensions { internal static class SpriteExtensions { diff --git a/package.json b/package.json index fecb6be..850b1ea 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.35", + "version": "3.0.0-preview.36", "unity": "2018.2", "license": "MIT", "repository": {