diff --git a/Packages/src/Editor/UIParticleEditor.cs b/Packages/src/Editor/UIParticleEditor.cs index ac4014a..bb18889 100644 --- a/Packages/src/Editor/UIParticleEditor.cs +++ b/Packages/src/Editor/UIParticleEditor.cs @@ -61,6 +61,7 @@ namespace Coffee.UIExtensions private SerializedProperty _autoScalingMode; private SerializedProperty _useCustomView; private SerializedProperty _customViewSize; + private SerializedProperty _timeScaleMultiplier; private ReorderableList _ro; private bool _showMax; private bool _is3DScaleMode; @@ -97,6 +98,7 @@ namespace Coffee.UIExtensions _autoScalingMode = serializedObject.FindProperty("m_AutoScalingMode"); _useCustomView = serializedObject.FindProperty("m_UseCustomView"); _customViewSize = serializedObject.FindProperty("m_CustomViewSize"); + _timeScaleMultiplier = serializedObject.FindProperty("m_TimeScaleMultiplier"); var sp = serializedObject.FindProperty("m_Particles"); _ro = new ReorderableList(sp.serializedObject, sp, true, true, true, true) @@ -241,6 +243,9 @@ namespace Coffee.UIExtensions _customViewSize.floatValue = Mathf.Max(0.1f, _customViewSize.floatValue); } + // Time Scale Multiplier + EditorGUILayout.PropertyField(_timeScaleMultiplier); + // Target ParticleSystems. EditorGUI.BeginChangeCheck(); _ro.DoLayoutList(); diff --git a/Packages/src/README.md b/Packages/src/README.md index 4a6081d..6754092 100644 --- a/Packages/src/README.md +++ b/Packages/src/README.md @@ -179,7 +179,7 @@ _This package requires **Unity 2019.3 or later**._ `UIParticle` controls the ParticleSystems that are attached to its own game objects and child game objects. -![](https://github.com/mob-sakai/ParticleEffectForUGUI/assets/12690315/1cf5753b-33fc-4cef-91c3-413c515a954f) +![](https://github.com/user-attachments/assets/bc9eb783-afce-4102-ac61-aee9ea8d6f2f) - **Maskable**: Does this graphic allow maskable. - **Scale**: Scale the rendering particles. When the `3D` toggle is enabled, 3D scale (x, y, z) is supported. @@ -201,6 +201,7 @@ _This package requires **Unity 2019.3 or later**._ - **UIParticle:** UIParticle.scale will be adjusted. - **Use Custom View:** Use this if the particles are not displayed correctly due to min/max particle size. - **Custom view size:** Change the bake view size. +- **Time Scale Multiplier:** Time scale multiplier. - **Rendering Order**: The ParticleSystem list to be rendered. You can change the order and the materials. **NOTE:** Press the `Refresh` button to reconstruct the rendering order based on children ParticleSystem's sorting order @@ -231,7 +232,7 @@ and z-position. If you want to mask particles, set a stencil-supported shader (such as `UI/UIAdditive`) to the material for ParticleSystem. If you use some custom shaders, see -the [How to Make a Custom Shader to Support Mask/RectMask2D Component](#how-to-make-a-custom-shader-to-support-maskrectmask2d-component) +the [How to Make a Custom Shader to Support Mask/RectMask2D Component](#how-to-make-a-custom-shader-to-support-mask-and-rectmask2d-component) section. ![](https://user-images.githubusercontent.com/12690315/95017591-3b512700-0695-11eb-864e-04166ea1809a.png) diff --git a/Packages/src/Runtime/Internal/Extensions/ComponentExtensions.cs b/Packages/src/Runtime/Internal/Extensions/ComponentExtensions.cs index f14fc1d..e9ec78b 100644 --- a/Packages/src/Runtime/Internal/Extensions/ComponentExtensions.cs +++ b/Packages/src/Runtime/Internal/Extensions/ComponentExtensions.cs @@ -204,7 +204,7 @@ namespace Coffee.UIParticleInternal target.enabled = false; // Find MonoScript of the specified component. - foreach (var script in Resources.FindObjectsOfTypeAll()) + foreach (var script in MonoImporter.GetAllRuntimeMonoScripts()) { if (script.GetClass() != typeof(T)) { diff --git a/Packages/src/Runtime/Internal/Utilities/Misc.cs b/Packages/src/Runtime/Internal/Utilities/Misc.cs index 3f6fb47..4eac3d8 100644 --- a/Packages/src/Runtime/Internal/Utilities/Misc.cs +++ b/Packages/src/Runtime/Internal/Utilities/Misc.cs @@ -3,11 +3,16 @@ using System.Diagnostics; using UnityEditor; using UnityEngine; using Object = UnityEngine.Object; -#if UNITY_EDITOR && UNITY_2021_2_OR_NEWER +#if UNITY_EDITOR +using System.IO; +using System.Linq; +using System.Reflection; +#if UNITY_2021_2_OR_NEWER using UnityEditor.SceneManagement; -#elif UNITY_EDITOR +#else using UnityEditor.Experimental.SceneManagement; #endif +#endif namespace Coffee.UIParticleInternal { @@ -72,5 +77,56 @@ namespace Coffee.UIParticleInternal public static bool isBatchOrBuilding => Application.isBatchMode || BuildPipeline.isBuildingPlayer; #endif + + [Conditional("UNITY_EDITOR")] + public static void QueuePlayerLoopUpdate() + { +#if UNITY_EDITOR + if (!EditorApplication.isPlaying) + { + EditorApplication.QueuePlayerLoopUpdate(); + } +#endif + } } + +#if !UNITY_2021_2_OR_NEWER + [AttributeUsage(AttributeTargets.Class)] + [Conditional("UNITY_EDITOR")] + internal class IconAttribute : Attribute + { + private readonly string _path; + + public IconAttribute(string path) + { + _path = path; + } + +#if UNITY_EDITOR + private static Action s_SetIconForObject = typeof(EditorGUIUtility) + .GetMethod("SetIconForObject", BindingFlags.Static | BindingFlags.NonPublic) + .CreateDelegate(typeof(Action), null) as Action; + + [InitializeOnLoadMethod] + private static void InitializeOnLoadMethod() + { + if (Misc.isBatchOrBuilding) return; + + var types = TypeCache.GetTypesWithAttribute(); + var scripts = MonoImporter.GetAllRuntimeMonoScripts(); + foreach (var type in types) + { + var script = scripts.FirstOrDefault(x => x.GetClass() == type); + if (!script) continue; + + var path = type.GetCustomAttribute()?._path; + var icon = AssetDatabase.LoadAssetAtPath(path); + if (!icon) continue; + + s_SetIconForObject(script, icon); + } + } +#endif + } +#endif } diff --git a/Packages/src/Runtime/UIParticle.cs b/Packages/src/Runtime/UIParticle.cs index 4bfb92e..3f4feb9 100644 --- a/Packages/src/Runtime/UIParticle.cs +++ b/Packages/src/Runtime/UIParticle.cs @@ -17,6 +17,7 @@ namespace Coffee.UIExtensions /// /// Render maskable and sortable particle effect ,without Camera, RenderTexture or Canvas. /// + [Icon("Packages/com.coffee.ui-particle/Icons/UIParticleIcon.png")] [ExecuteAlways] [RequireComponent(typeof(RectTransform))] [RequireComponent(typeof(CanvasRenderer))] @@ -119,6 +120,10 @@ namespace Coffee.UIExtensions "Change the bake view size.")] private float m_CustomViewSize = 10; + [SerializeField] + [Tooltip("Time scale multiplier.")] + private float m_TimeScaleMultiplier = 1; + [SerializeField] private bool m_Maskable = true; @@ -285,6 +290,15 @@ namespace Coffee.UIExtensions set => m_CustomViewSize = Mathf.Max(0.1f, value); } + /// + /// Time scale multiplier. + /// + public float timeScaleMultiplier + { + get => m_TimeScaleMultiplier; + set => m_TimeScaleMultiplier = value; + } + internal bool useMeshSharing => m_MeshSharing != MeshSharing.None; internal bool isPrimary => diff --git a/Packages/src/Runtime/UIParticle.cs.meta b/Packages/src/Runtime/UIParticle.cs.meta index f076457..1dc794d 100644 --- a/Packages/src/Runtime/UIParticle.cs.meta +++ b/Packages/src/Runtime/UIParticle.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {fileID: 2800000, guid: 5f0675613942149309588d556e33d990, type: 3} + icon: {instanceID: 0} userData: assetBundleName: assetBundleVariant: diff --git a/Packages/src/Runtime/UIParticleProjectSettings.cs b/Packages/src/Runtime/UIParticleProjectSettings.cs index ab295d6..6da0170 100644 --- a/Packages/src/Runtime/UIParticleProjectSettings.cs +++ b/Packages/src/Runtime/UIParticleProjectSettings.cs @@ -5,6 +5,7 @@ using UnityEngine; namespace Coffee.UIExtensions { + [Icon("Packages/com.coffee.ui-particle/Icons/UIParticleIcon.png")] public class UIParticleProjectSettings : PreloadedProjectSettings { [Header("Setting")] diff --git a/Packages/src/Runtime/UIParticleProjectSettings.cs.meta b/Packages/src/Runtime/UIParticleProjectSettings.cs.meta index ca6db89..22e35af 100644 --- a/Packages/src/Runtime/UIParticleProjectSettings.cs.meta +++ b/Packages/src/Runtime/UIParticleProjectSettings.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {fileID: 2800000, guid: 5f0675613942149309588d556e33d990, type: 3} + icon: {instanceID: 0} userData: assetBundleName: assetBundleVariant: diff --git a/Packages/src/Runtime/UIParticleRenderer.cs b/Packages/src/Runtime/UIParticleRenderer.cs index a73b4b4..fc1ea73 100644 --- a/Packages/src/Runtime/UIParticleRenderer.cs +++ b/Packages/src/Runtime/UIParticleRenderer.cs @@ -15,6 +15,7 @@ using UnityEngine.UI; namespace Coffee.UIExtensions { + [Icon("Packages/com.coffee.ui-particle/Icons/UIParticleIcon.png")] [ExecuteAlways] [RequireComponent(typeof(RectTransform))] [RequireComponent(typeof(CanvasRenderer))] @@ -628,6 +629,7 @@ namespace Coffee.UIExtensions : main.useUnscaledTime ? Time.unscaledDeltaTime : Time.deltaTime; + deltaTime *= _parent.timeScaleMultiplier; // Pre-warm: if (0 < deltaTime && _preWarm) diff --git a/Packages/src/Runtime/UIParticleRenderer.cs.meta b/Packages/src/Runtime/UIParticleRenderer.cs.meta index 9896f40..2f3f29c 100644 --- a/Packages/src/Runtime/UIParticleRenderer.cs.meta +++ b/Packages/src/Runtime/UIParticleRenderer.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {fileID: 2800000, guid: 5f0675613942149309588d556e33d990, type: 3} + icon: {instanceID: 0} userData: assetBundleName: assetBundleVariant: diff --git a/Packages/src/Runtime/UIParticleUpdater.cs b/Packages/src/Runtime/UIParticleUpdater.cs index 4df5153..2e353e9 100644 --- a/Packages/src/Runtime/UIParticleUpdater.cs +++ b/Packages/src/Runtime/UIParticleUpdater.cs @@ -40,13 +40,26 @@ namespace Coffee.UIExtensions #if UNITY_EDITOR [InitializeOnLoadMethod] + private static void InitializeOnLoad() + { + UIExtraCallbacks.onAfterCanvasRebuild += Refresh; + + EditorApplication.playModeStateChanged += state => + { + UIExtraCallbacks.onAfterCanvasRebuild -= Refresh; + if (state == PlayModeStateChange.EnteredEditMode || state == PlayModeStateChange.EnteredPlayMode) + { + UIExtraCallbacks.onAfterCanvasRebuild += Refresh; + } + }; + } #else [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] -#endif private static void InitializeOnLoad() { UIExtraCallbacks.onAfterCanvasRebuild += Refresh; } +#endif private static void Refresh() {