diff --git a/spine-unity/Assets/spine-unity/Ghost/SkeletonGhost.cs b/spine-unity/Assets/spine-unity/Ghost/SkeletonGhost.cs index fe827aebe..3717bc9a6 100644 --- a/spine-unity/Assets/spine-unity/Ghost/SkeletonGhost.cs +++ b/spine-unity/Assets/spine-unity/Ghost/SkeletonGhost.cs @@ -11,7 +11,7 @@ using System.Collections.Generic; public class SkeletonGhost : MonoBehaviour { public bool ghostingEnabled = true; public float spawnRate = 0.05f; - public Color32 color = new Color32(0xFF, 0xFF, 0xFF, 0x00); + public Color32 color = new Color32(0xFF, 0xFF, 0xFF, 0x00); // default for additive. [Tooltip("Remember to set color alpha to 0 if Additive is true")] public bool additive = true; public int maximumGhosts = 10; @@ -21,6 +21,10 @@ public class SkeletonGhost : MonoBehaviour { [Range(0, 1)] public float textureFade = 1; + [Header("Sorting")] + public bool sortWithDistanceOnly; + public float zOffset = 0f; + float nextSpawnTime; SkeletonGhostRenderer[] pool; int poolIndex = 0; @@ -100,14 +104,16 @@ public class SkeletonGhost : MonoBehaviour { materials[i] = ghostMat; } - pool[poolIndex].Initialize(meshFilter.sharedMesh, materials, color, additive, fadeSpeed, meshRenderer.sortingOrder - 1); - go.transform.parent = transform; + var goTransform = go.transform; + goTransform.parent = transform; - go.transform.localPosition = Vector3.zero; - go.transform.localRotation = Quaternion.identity; - go.transform.localScale = Vector3.one; + pool[poolIndex].Initialize(meshFilter.sharedMesh, materials, color, additive, fadeSpeed, meshRenderer.sortingLayerID, (sortWithDistanceOnly) ? meshRenderer.sortingOrder : meshRenderer.sortingOrder - 1); - go.transform.parent = null; + goTransform.localPosition = new Vector3(0f, 0f, zOffset); + goTransform.localRotation = Quaternion.identity; + goTransform.localScale = Vector3.one; + + goTransform.parent = null; poolIndex++; diff --git a/spine-unity/Assets/spine-unity/Ghost/SkeletonGhostRenderer.cs b/spine-unity/Assets/spine-unity/Ghost/SkeletonGhostRenderer.cs index 6ce7dfefb..dbf4b0e3d 100644 --- a/spine-unity/Assets/spine-unity/Ghost/SkeletonGhostRenderer.cs +++ b/spine-unity/Assets/spine-unity/Ghost/SkeletonGhostRenderer.cs @@ -20,13 +20,14 @@ public class SkeletonGhostRenderer : MonoBehaviour { meshFilter = gameObject.AddComponent(); } - public void Initialize (Mesh mesh, Material[] materials, Color32 color, bool additive, float speed, int sortingOrder) { + public void Initialize (Mesh mesh, Material[] materials, Color32 color, bool additive, float speed, int sortingLayerID, int sortingOrder) { StopAllCoroutines(); gameObject.SetActive(true); meshRenderer.sharedMaterials = materials; + meshRenderer.sortingLayerID = sortingLayerID; meshRenderer.sortingOrder = sortingOrder; meshFilter.sharedMesh = (Mesh)Instantiate(mesh);