From 40ff828ff0697dc8f6597cfcf094cc63532a19dd Mon Sep 17 00:00:00 2001 From: mob-sakai <12690315+mob-sakai@users.noreply.github.com> Date: Thu, 27 Feb 2025 09:31:15 +0900 Subject: [PATCH] fix: component icons will no longer be displayed in the scene view (Unity 2021.2 or later) --- .../src/Runtime/Internal/Utilities/Misc.cs | 60 ++++++++++++++++++- Packages/src/Runtime/UIEffect.cs | 1 + Packages/src/Runtime/UIEffect.cs.meta | 2 +- .../src/Runtime/UIEffectProjectSettings.cs | 1 + .../Runtime/UIEffectProjectSettings.cs.meta | 2 +- Packages/src/Runtime/UIEffectReplica.cs | 1 + Packages/src/Runtime/UIEffectReplica.cs.meta | 2 +- Packages/src/Runtime/UIEffectTweener.cs | 2 + Packages/src/Runtime/UIEffectTweener.cs.meta | 2 +- 9 files changed, 67 insertions(+), 6 deletions(-) diff --git a/Packages/src/Runtime/Internal/Utilities/Misc.cs b/Packages/src/Runtime/Internal/Utilities/Misc.cs index 76d6527..7b3f0ba 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.UIEffectInternal { @@ -72,5 +77,56 @@ namespace Coffee.UIEffectInternal 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/UIEffect.cs b/Packages/src/Runtime/UIEffect.cs index e8ee1a1..ba7ce73 100644 --- a/Packages/src/Runtime/UIEffect.cs +++ b/Packages/src/Runtime/UIEffect.cs @@ -5,6 +5,7 @@ using UnityEngine.Rendering; namespace Coffee.UIEffects { + [Icon("Packages/com.coffee.ui-effect/Editor/UIEffectIconIcon.png")] [ExecuteAlways] [DisallowMultipleComponent] public class UIEffect : UIEffectBase diff --git a/Packages/src/Runtime/UIEffect.cs.meta b/Packages/src/Runtime/UIEffect.cs.meta index 6e99305..b5b4cf0 100644 --- a/Packages/src/Runtime/UIEffect.cs.meta +++ b/Packages/src/Runtime/UIEffect.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {fileID: 2800000, guid: 5b93acc4527c740459bbfbd3404191be, type: 3} + icon: {instanceID: 0} userData: assetBundleName: assetBundleVariant: diff --git a/Packages/src/Runtime/UIEffectProjectSettings.cs b/Packages/src/Runtime/UIEffectProjectSettings.cs index 5b9f2da..f39b0ad 100644 --- a/Packages/src/Runtime/UIEffectProjectSettings.cs +++ b/Packages/src/Runtime/UIEffectProjectSettings.cs @@ -8,6 +8,7 @@ using UnityEngine; namespace Coffee.UIEffects { + [Icon("Packages/com.coffee.ui-effect/Editor/UIEffectIconIcon.png")] public class UIEffectProjectSettings : PreloadedProjectSettings { [Tooltip( diff --git a/Packages/src/Runtime/UIEffectProjectSettings.cs.meta b/Packages/src/Runtime/UIEffectProjectSettings.cs.meta index c779dec..04372c0 100644 --- a/Packages/src/Runtime/UIEffectProjectSettings.cs.meta +++ b/Packages/src/Runtime/UIEffectProjectSettings.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {fileID: 2800000, guid: 5b93acc4527c740459bbfbd3404191be, type: 3} + icon: {instanceID: 0} userData: assetBundleName: assetBundleVariant: diff --git a/Packages/src/Runtime/UIEffectReplica.cs b/Packages/src/Runtime/UIEffectReplica.cs index d913a4d..ecdead2 100644 --- a/Packages/src/Runtime/UIEffectReplica.cs +++ b/Packages/src/Runtime/UIEffectReplica.cs @@ -3,6 +3,7 @@ using UnityEngine; namespace Coffee.UIEffects { + [Icon("Packages/com.coffee.ui-effect/Editor/UIEffectIconIcon.png")] public class UIEffectReplica : UIEffectBase { [SerializeField] private UIEffect m_Target; diff --git a/Packages/src/Runtime/UIEffectReplica.cs.meta b/Packages/src/Runtime/UIEffectReplica.cs.meta index 57f7ba4..43c4575 100644 --- a/Packages/src/Runtime/UIEffectReplica.cs.meta +++ b/Packages/src/Runtime/UIEffectReplica.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {fileID: 2800000, guid: 5b93acc4527c740459bbfbd3404191be, type: 3} + icon: {instanceID: 0} userData: assetBundleName: assetBundleVariant: diff --git a/Packages/src/Runtime/UIEffectTweener.cs b/Packages/src/Runtime/UIEffectTweener.cs index b4a367d..f7780f9 100644 --- a/Packages/src/Runtime/UIEffectTweener.cs +++ b/Packages/src/Runtime/UIEffectTweener.cs @@ -1,10 +1,12 @@ using System; +using Coffee.UIEffectInternal; using UnityEngine; using UnityEngine.Events; using UnityEngine.Serialization; namespace Coffee.UIEffects { + [Icon("Packages/com.coffee.ui-effect/Editor/UIEffectIconIcon.png")] [ExecuteAlways] [RequireComponent(typeof(UIEffectBase))] public class UIEffectTweener : MonoBehaviour diff --git a/Packages/src/Runtime/UIEffectTweener.cs.meta b/Packages/src/Runtime/UIEffectTweener.cs.meta index ddad62d..eff858c 100644 --- a/Packages/src/Runtime/UIEffectTweener.cs.meta +++ b/Packages/src/Runtime/UIEffectTweener.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {fileID: 2800000, guid: 5b93acc4527c740459bbfbd3404191be, type: 3} + icon: {instanceID: 0} userData: assetBundleName: assetBundleVariant: