You've already forked ParticleEffectForUGUI
mirror of
https://github.com/mob-sakai/ParticleEffectForUGUI.git
synced 2026-05-15 20:50:08 +00:00
3.0.0-preview.19
# [3.0.0-preview.19](https://github.com/mob-sakai/ParticleEffectForUGUI/compare/v3.0.0-preview.18...v3.0.0-preview.19) (2020-08-28) ### Bug Fixes * baking camera settings for camera space ([436c5e4](436c5e47f7)) * fix local simulation ([7add9de](7add9defb7)) ### Features * add menu to create UIParticle ([2fa1843](2fa18431f0)) * add play/pause/stop api ([f09a386](f09a386bc5)) * support for changing rendering orders ([745d4a5](745d4a5988)) * Support for child ParticleSystem rendering ([4ee90be](4ee90be17c)) * UIParticle for trail is no longer needed ([466e43c](466e43cf93)) ### BREAKING CHANGES * The child UIParticle is no longer needed.
This commit is contained in:
95
Scripts/Utils.cs
Normal file
95
Scripts/Utils.cs
Normal file
@@ -0,0 +1,95 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Coffee.UIExtensions
|
||||
{
|
||||
internal static class SpriteExtensions
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
private static Type tSpriteEditorExtension = Type.GetType("UnityEditor.Experimental.U2D.SpriteEditorExtension, UnityEditor")
|
||||
?? Type.GetType("UnityEditor.U2D.SpriteEditorExtension, UnityEditor");
|
||||
|
||||
private static MethodInfo miGetActiveAtlasTexture = tSpriteEditorExtension
|
||||
.GetMethod("GetActiveAtlasTexture", BindingFlags.Static | BindingFlags.NonPublic);
|
||||
|
||||
public static Texture2D GetActualTexture(this Sprite self)
|
||||
{
|
||||
if (!self) return null;
|
||||
|
||||
if (Application.isPlaying) return self.texture;
|
||||
var ret = miGetActiveAtlasTexture.Invoke(null, new[] {self}) as Texture2D;
|
||||
return ret ? ret : self.texture;
|
||||
}
|
||||
#else
|
||||
internal static Texture2D GetActualTexture(this Sprite self)
|
||||
{
|
||||
return self ? self.texture : null;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
internal static class UintExtensions
|
||||
{
|
||||
public static int BitCount(this uint self)
|
||||
{
|
||||
self = (self & 0x55555555) + ((self >> 1) & 0x55555555);
|
||||
self = (self & 0x33333333) + ((self >> 2) & 0x33333333);
|
||||
self = (self & 0x0F0F0F0F) + ((self >> 4) & 0x0F0F0F0F);
|
||||
self = (self & 0x00FF00FF) + ((self >> 8) & 0x00FF00FF);
|
||||
return (int) ((self & 0x0000ffff) + (self >> 16));
|
||||
}
|
||||
}
|
||||
|
||||
internal static class ParticleSystemExtensions
|
||||
{
|
||||
public static void SortForRendering(this List<ParticleSystem> self, Transform transform)
|
||||
{
|
||||
self.Sort((a, b) =>
|
||||
{
|
||||
var tr = transform;
|
||||
var ra = a.GetComponent<ParticleSystemRenderer>();
|
||||
var rb = b.GetComponent<ParticleSystemRenderer>();
|
||||
|
||||
if (!Mathf.Approximately(ra.sortingFudge, rb.sortingFudge))
|
||||
return ra.sortingFudge < rb.sortingFudge ? 1 : -1;
|
||||
|
||||
var pa = tr.InverseTransformPoint(a.transform.position).z;
|
||||
var pb = tr.InverseTransformPoint(b.transform.position).z;
|
||||
|
||||
return Mathf.Approximately(pa, pb)
|
||||
? 0
|
||||
: pa < pb
|
||||
? 1
|
||||
: -1;
|
||||
});
|
||||
}
|
||||
|
||||
public static Texture2D GetTextureForSprite(this ParticleSystem self)
|
||||
{
|
||||
if (!self) return null;
|
||||
|
||||
// Get sprite's texture.
|
||||
var tsaModule = self.textureSheetAnimation;
|
||||
if (!tsaModule.enabled || tsaModule.mode != ParticleSystemAnimationMode.Sprites) return null;
|
||||
|
||||
for (var i = 0; i < tsaModule.spriteCount; i++)
|
||||
{
|
||||
var sprite = tsaModule.GetSprite(i);
|
||||
if (!sprite) continue;
|
||||
|
||||
return sprite.GetActualTexture();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void Exec(this List<ParticleSystem> self, Action<ParticleSystem> action)
|
||||
{
|
||||
self.RemoveAll(p => !p);
|
||||
self.ForEach(action);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user