From ac3e147bd9d7f5590f497f5e959dea6bdc6815fc Mon Sep 17 00:00:00 2001 From: mob-sakai <12690315+mob-sakai@users.noreply.github.com> Date: Wed, 18 Dec 2024 19:46:32 +0900 Subject: [PATCH] fix: rendering issues when playing with opening a prefab stage close #345 --- .../Internal/Extensions/SpriteExtensions.cs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/Runtime/Internal/Extensions/SpriteExtensions.cs b/Runtime/Internal/Extensions/SpriteExtensions.cs index e0d4e65..9e3d1c2 100644 --- a/Runtime/Internal/Extensions/SpriteExtensions.cs +++ b/Runtime/Internal/Extensions/SpriteExtensions.cs @@ -17,11 +17,15 @@ namespace Coffee.UIParticleInternal Type.GetType("UnityEditor.Experimental.U2D.SpriteEditorExtension, UnityEditor") ?? Type.GetType("UnityEditor.U2D.SpriteEditorExtension, UnityEditor"); - private static readonly MethodInfo s_GetActiveAtlasTextureMethod = s_SpriteEditorExtensionType - .GetMethod("GetActiveAtlasTexture", BindingFlags.Static | BindingFlags.NonPublic); + private static readonly Func s_GetActiveAtlasTextureMethod = + (Func)Delegate.CreateDelegate(typeof(Func), + s_SpriteEditorExtensionType + .GetMethod("GetActiveAtlasTexture", BindingFlags.Static | BindingFlags.NonPublic)); - private static readonly MethodInfo s_GetActiveAtlasMethod = s_SpriteEditorExtensionType - .GetMethod("GetActiveAtlas", BindingFlags.Static | BindingFlags.NonPublic); + private static readonly Func s_GetActiveAtlasMethod = + (Func)Delegate.CreateDelegate(typeof(Func), + s_SpriteEditorExtensionType + .GetMethod("GetActiveAtlas", BindingFlags.Static | BindingFlags.NonPublic)); /// /// Get the actual texture of a sprite in play mode or edit mode. @@ -30,9 +34,7 @@ namespace Coffee.UIParticleInternal { if (!self) return null; - if (Application.isPlaying) return self.texture; - - var ret = s_GetActiveAtlasTextureMethod.Invoke(null, new object[] { self }) as Texture2D; + var ret = s_GetActiveAtlasTextureMethod(self); return ret ? ret : self.texture; } @@ -43,7 +45,7 @@ namespace Coffee.UIParticleInternal { if (!self) return null; - return s_GetActiveAtlasMethod.Invoke(null, new object[] { self }) as SpriteAtlas; + return s_GetActiveAtlasMethod(self); } #else ///