예제 #1
0
    public static void LayerSorterChecker()
    {
        SpriteRenderer[] spriteRenderers = GameObject.FindObjectsOfType(typeof(SpriteRenderer)) as SpriteRenderer[];
        int count = spriteRenderers.Length;

        bool needUpdate = false;

        for (int i = 0; i < count; i++)
        {
            GameObject        srGO        = spriteRenderers[i].gameObject;
            OnePadLayerSorter layerSorter = srGO.GetComponent <OnePadLayerSorter>();
            if (layerSorter == null || layerSorter.SortLayerName != spriteRenderers[i].sortingLayerName)
            {
                needUpdate = true;
                break;
            }
        }
        if (needUpdate)
        {
            if (EditorUtility.DisplayDialog("ONEPad Layer Sorter", "You need update Layer sorter.", "Update now", "Avoid"))
            {
                int addCount = AutoAddLayerSorterSilent();
                EditorUtility.DisplayDialog("ONEPad Layer Sorter", addCount.ToString() + " Layer sorter added", "OK");
            }
        }
        else
        {
            EditorUtility.DisplayDialog("ONEPad Layer Sorter", "Aready All Layer sorter setted", "OK");
        }
    }
예제 #2
0
    public static int AutoAddLayerSorterSilent()
    {
        OnePadLayerSorterEditor.RemoveAllLayerSorterSilent();
        SpriteRenderer[] spriteRenderers = GameObject.FindObjectsOfType(typeof(SpriteRenderer)) as SpriteRenderer[];
        int count = spriteRenderers.Length;

        for (int i = 0; i < count; i++)
        {
            GameObject        srGO        = spriteRenderers[i].gameObject;
            OnePadLayerSorter layerSorter = srGO.AddComponent <OnePadLayerSorter>();
            layerSorter.SortLayerName = spriteRenderers[i].sortingLayerName;
        }

        EditorApplication.SaveScene();
        return(count);
    }