Skip to content

Commit

Permalink
fix: ignore material check and transform check
Browse files Browse the repository at this point in the history
Add default sort by index.

Close #119
  • Loading branch information
LacusCon authored and mob-sakai committed Jan 6, 2021
1 parent 429ff2d commit d11cd0a
Showing 1 changed file with 28 additions and 15 deletions.
43 changes: 28 additions & 15 deletions Scripts/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -222,29 +223,41 @@ public static void SortForRendering(this List<ParticleSystem> 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<ParticleSystem> 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;
Expand Down Expand Up @@ -283,4 +296,4 @@ public static void Exec(this List<ParticleSystem> self, Action<ParticleSystem> a
self.ForEach(action);
}
}
}
}

0 comments on commit d11cd0a

Please sign in to comment.