Skip to content

Commit

Permalink
fix: component icons will no longer be displayed in the scene view
Browse files Browse the repository at this point in the history
  • Loading branch information
mob-sakai committed Feb 21, 2025
1 parent b63220b commit 6dfbdae
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ internal static void ConvertTo<T>(this Object context) where T : MonoBehaviour
target.enabled = false;

// Find MonoScript of the specified component.
foreach (var script in Resources.FindObjectsOfTypeAll<MonoScript>())
foreach (var script in MonoImporter.GetAllRuntimeMonoScripts())
{
if (script.GetClass() != typeof(T))
{
Expand Down
60 changes: 58 additions & 2 deletions Packages/src/Runtime/Internal/Utilities/Misc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@
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
{
Expand Down Expand Up @@ -72,5 +77,56 @@ public static T[] GetAllComponentsInPrefabStage<T>() where T : Component

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<Object, Texture2D> s_SetIconForObject = typeof(EditorGUIUtility)
.GetMethod("SetIconForObject", BindingFlags.Static | BindingFlags.NonPublic)
.CreateDelegate(typeof(Action<Object, Texture2D>), null) as Action<Object, Texture2D>;

[InitializeOnLoadMethod]
private static void InitializeOnLoadMethod()
{
if (Misc.isBatchOrBuilding) return;

var types = TypeCache.GetTypesWithAttribute<IconAttribute>();
var scripts = MonoImporter.GetAllRuntimeMonoScripts();
foreach (var type in types)
{
var script = scripts.FirstOrDefault(x => x.GetClass() == type);
if (!script) continue;

var path = type.GetCustomAttribute<IconAttribute>()?._path;
var icon = AssetDatabase.LoadAssetAtPath<Texture2D>(path);
if (!icon) continue;

s_SetIconForObject(script, icon);
}
}
#endif
}
#endif
}
1 change: 1 addition & 0 deletions Packages/src/Runtime/UIParticle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace Coffee.UIExtensions
/// <summary>
/// Render maskable and sortable particle effect ,without Camera, RenderTexture or Canvas.
/// </summary>
[Icon("Packages/com.coffee.ui-particle/Icons/UIParticleIcon.png")]
[ExecuteAlways]
[RequireComponent(typeof(RectTransform))]
[RequireComponent(typeof(CanvasRenderer))]
Expand Down
2 changes: 1 addition & 1 deletion Packages/src/Runtime/UIParticle.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Packages/src/Runtime/UIParticleProjectSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

namespace Coffee.UIExtensions
{
[Icon("Packages/com.coffee.ui-particle/Icons/UIParticleIcon.png")]
public class UIParticleProjectSettings : PreloadedProjectSettings<UIParticleProjectSettings>
{
[Header("Setting")]
Expand Down
2 changes: 1 addition & 1 deletion Packages/src/Runtime/UIParticleProjectSettings.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Packages/src/Runtime/UIParticleRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

namespace Coffee.UIExtensions
{
[Icon("Packages/com.coffee.ui-particle/Icons/UIParticleIcon.png")]
[ExecuteAlways]
[RequireComponent(typeof(RectTransform))]
[RequireComponent(typeof(CanvasRenderer))]
Expand Down
2 changes: 1 addition & 1 deletion Packages/src/Runtime/UIParticleRenderer.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6dfbdae

Please sign in to comment.