예제 #1
0
    public void SortByY(string layerName)
    {
        SpriteRenderer[] sprites = FindObjectsOfType <SpriteRenderer>();
        foreach (var sprite in sprites)
        {
            bool isInLayer = sprite.sortingLayerName == layerName;
            if (isInLayer)
            {
                Undo.RegisterCompleteObjectUndo(sprite.transform, "SortByY");
                sprite.sortingOrder = SpriteSortingOrderProvider.GetSortingOrder(sprite.gameObject);
            }
        }

        SpriteGroup[] groups = FindObjectsOfType <SpriteGroup>();

        foreach (var group in groups)
        {
            bool isInLayer = group.sortingLayerName == layerName;
            if (isInLayer)
            {
                Undo.RegisterCompleteObjectUndo(group, "SortByY");
                group.sortingOrder = -(int)(group.transform.position.y * 100);
            }
        }

        Undo.FlushUndoRecordObjects();
    }
예제 #2
0
 private void Recalculate()
 {
     sortingOrder = SpriteSortingOrderProvider.GetSortingOrder(gameObject);
     GetComponent <SpriteRenderer>().sortingOrder = sortingOrder;
     Apply();
 }