diff --git a/Scripts/Utils.cs b/Scripts/Utils.cs index 00d2240..b7c5753 100644 --- a/Scripts/Utils.cs +++ b/Scripts/Utils.cs @@ -9,8 +9,9 @@ namespace Coffee.UIParticleExtensions 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 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); @@ -222,29 +223,41 @@ public static void SortForRendering(this List self, Transform tr if (!Mathf.Approximately(aPos, bPos)) return (int) Mathf.Sign(bPos - aPos); + return (int) Mathf.Sign(GetIndex(self, a) - GetIndex(self, b)); + // Material instance ID: match - if (aMat.GetInstanceID() == bMat.GetInstanceID()) - return 0; + // if (aMat.GetInstanceID() == bMat.GetInstanceID()) + // return 0; // Transform: ascending - return TransformCompare(aTransform, bTransform); + // return TransformCompare(aTransform, bTransform); }); } - private static int TransformCompare(Transform a, Transform b) + private static int GetIndex(IReadOnlyList list, Object ps) { - while (true) + for (var i = 0; i < list.Count; i++) { - if (!a && !b) return 0; - if (!a) return -1; - if (!b) return 1; - if (a.parent == b.parent) return a.GetSiblingIndex() - b.GetSiblingIndex(); - - a = a.parent; - b = b.parent; + if (list[i].GetInstanceID() == ps.GetInstanceID()) return i; } + + return 0; } + // private static int TransformCompare(Transform a, Transform b) + // { + // while (true) + // { + // if (!a && !b) return 0; + // if (!a) return -1; + // if (!b) return 1; + // if (a.parent == b.parent) return a.GetSiblingIndex() - b.GetSiblingIndex(); + // + // a = a.parent; + // b = b.parent; + // } + // } + public static long GetMaterialHash(this ParticleSystem self, bool trail) { if (!self) return 0; @@ -283,4 +296,4 @@ public static void Exec(this List self, Action a self.ForEach(action); } } -} +} \ No newline at end of file