Skip to content

Commit

Permalink
fix: texture sheet animation module Sprite mode not working
Browse files Browse the repository at this point in the history
Close #79
  • Loading branch information
mob-sakai committed Aug 12, 2020
1 parent a77a4ed commit 30d1d5d
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions Packages/UIParticle/Scripts/UIParticle.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Profiling;
using UnityEngine.Rendering;
using UnityEngine.UI;
using ShaderPropertyType = Coffee.UIExtensions.UIParticle.AnimatableProperty.ShaderPropertyType;

#if UNITY_EDITOR
using System.Reflection;
#endif

namespace Coffee.UIExtensions
{
Expand Down Expand Up @@ -90,9 +90,7 @@ public override Texture mainTexture
var textureSheet = cachedParticleSystem.textureSheetAnimation;
if (textureSheet.enabled && textureSheet.mode == ParticleSystemAnimationMode.Sprites && 0 < textureSheet.spriteCount)
{
var sprite = textureSheet.GetSprite(0);
textureSheet.uvChannelMask = (UVChannelFlags) (sprite && sprite.packed ? -1 : 0);
tex = sprite ? sprite.texture : null;
tex = GetActualTexture(textureSheet.GetSprite(0));
}
Profiler.EndSample();
}
Expand Down Expand Up @@ -607,5 +605,24 @@ void UpdateAnimatableMaterialProperties()
}
}
}

#if UNITY_EDITOR
private static MethodInfo miGetActiveAtlasTexture = typeof(UnityEditor.Experimental.U2D.SpriteEditorExtension)
.GetMethod("GetActiveAtlasTexture", BindingFlags.Static | BindingFlags.NonPublic);

static Texture2D GetActualTexture(Sprite sprite)
{
if (!sprite) return null;

if (Application.isPlaying) return sprite.texture;
var ret = miGetActiveAtlasTexture.Invoke(null, new[] {sprite}) as Texture2D;
return ret ? ret : sprite.texture;
}
#else
static Texture2D GetActualTexture(Sprite sprite)
{
return sprite ? sprite.texture : null;
}
#endif
}
}

0 comments on commit 30d1d5d

Please sign in to comment.