Exemple #1
0
    private void DrawAtlas(SpAtlas atlas)
    {
        EditorGUILayout.LabelField("Atlas", EditorStyles.boldLabel);

        var rect  = SpHelper.Reserve(14.0f);
        var width = rect.width / 3.0f;
        var rect0 = rect; rect0.width = width; rect0.x = rect.x + width * 0; rect0.xMax -= 2;
        var rect1 = rect; rect1.width = width; rect1.x = rect.x + width * 1; rect1.xMin += 1; rect1.xMax -= 1;
        var rect2 = rect; rect2.width = width; rect2.x = rect.x + width * 2; rect2.xMin += 2;

        if (GUI.Button(rect0, "Update", EditorStyles.miniButton) == true)
        {
            atlas.Update();
        }

        EditorGUI.BeginDisabledGroup(atlas.Texture == null);
        {
            if (GUI.Button(rect1, "Select", EditorStyles.miniButton) == true)
            {
                Selection.activeObject = atlas.Texture;
            }

            if (GUI.Button(rect2, "Link", EditorStyles.miniButton) == true)
            {
                SpLink_Wizard.Open(atlas);
            }
        }
        EditorGUI.EndDisabledGroup();
    }
Exemple #2
0
    private void DrawBorder(SpSource source)
    {
        var rect  = SpHelper.Reserve();
        var rect1 = rect; rect1.xMax = EditorGUIUtility.labelWidth + 32.0f;
        var rect2 = rect; rect2.xMin += EditorGUIUtility.labelWidth + 16.0f; rect2.y -= 16.0f;

        source.UseCustomBorder = EditorGUI.Toggle(rect1, "Custom Border", source.UseCustomBorder);

        if (source.UseCustomBorder == true)
        {
            source.CustomBorder = EditorGUI.Vector4Field(rect2, default(string), source.CustomBorder);
        }
    }
Exemple #3
0
    private void DrawPivot(SpSource source)
    {
        var rect  = SpHelper.Reserve();
        var rect1 = rect; rect1.xMax = EditorGUIUtility.labelWidth + 32.0f;
        var rect2 = rect; rect2.xMin += EditorGUIUtility.labelWidth + 16.0f;

        source.UseCustomPivot = EditorGUI.Toggle(rect1, "Custom Pivot", source.UseCustomPivot);

        if (source.UseCustomPivot == true)
        {
            source.CustomPivot = EditorGUI.Vector2Field(rect2, "", source.CustomPivot);
        }
    }
    public void OnGUI()
    {
        if (atlas != null)
        {
            EditorGUILayout.HelpBox("This tool will replace all your non-atlas sprites with these atlas sprites (e.g. in your prefabs & scripts)", MessageType.Info);

            EditorGUILayout.Separator();

            inScenes = (SpLink_Scene)EditorGUILayout.EnumPopup("In Scenes", inScenes);

            inPrefabs = EditorGUILayout.Toggle("In Prefabs", inPrefabs);

            inScriptableObjects = EditorGUILayout.Toggle("In Scriptable Objects", inScriptableObjects);

            inAnimationClips = EditorGUILayout.Toggle("In Animation Clips", inAnimationClips);

            EditorGUILayout.Separator();

            EditorGUILayout.LabelField("Replace", EditorStyles.boldLabel);

            scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition);
            {
                for (var i = 0; i < sourceSprites.Length; i++)
                {
                    var rect  = SpHelper.Reserve();
                    var rect0 = rect; rect0.xMax = rect0.center.x - 20;
                    var rect1 = rect; rect1.xMin = rect1.center.x + 20;
                    var rect2 = rect; rect2.xMin = rect2.center.x - 20; rect2.xMax = rect2.center.x + 20;

                    if (sourceSprites[i] == null)
                    {
                        GUI.Box(rect0, "", SpHelper.RedBox);
                    }

                    sourceSprites[i] = (Sprite)EditorGUI.ObjectField(rect0, sourceSprites[i], typeof(Sprite), true);
                    packedSprites[i] = (Sprite)EditorGUI.ObjectField(rect1, packedSprites[i], typeof(Sprite), true);

                    EditorGUI.LabelField(rect2, "With");
                }
            }
            EditorGUILayout.EndScrollView();

            EditorGUILayout.Separator();

            DrawButtons();
        }
        else
        {
            Close();
        }
    }
Exemple #5
0
    private void DrawDragAndDrop(SpAtlas atlas)
    {
        var dropRect = SpHelper.Reserve(48.0f);

        // Open drag and drop window?
        if (GUI.Button(dropRect, "Add Textures\n(Drag And Drop)") == true)
        {
            var drop = SpDrop_Window.Open();

            drop.CurrentAtlas = atlas;
            drop.Repaint();
        }

        SpHelper.DrawDragAndDropZone(dropRect);

        SpHelper.HandleDradAndDrop(atlas, dropRect);
    }
Exemple #6
0
    public void OnGUI()
    {
        var dropRect = SpHelper.Reserve(position.height - 2.0f);

        if (CurrentAtlas != null)
        {
            if (GUI.Button(dropRect, "Add To " + CurrentAtlas.name + "\n(Drag And Drop)") == true)
            {
                Selection.activeObject = CurrentAtlas;
            }

            SpHelper.DrawDragAndDropZone(dropRect);

            SpHelper.HandleDradAndDrop(CurrentAtlas, dropRect);
        }
        else
        {
            EditorGUI.BeginDisabledGroup(true);
            {
                GUI.Button(dropRect, "No Atlas Selected");
            }
            EditorGUI.EndDisabledGroup();
        }
    }
    private void DrawButtons()
    {
        var rect  = SpHelper.Reserve();
        var rect0 = rect; rect0.xMax = rect0.center.x - 1;
        var rect1 = rect; rect1.xMin = rect1.center.x + 1;

        if (GUI.Button(rect0, "Link Sprites") == true)
        {
            switch (inScenes)
            {
            case SpLink_Scene.This:
            {
                LinkInScene();
            }
            break;

            case SpLink_Scene.All:
            {
#if OLD_SCENE_MANAGEMENT
                if (EditorApplication.SaveCurrentSceneIfUserWantsTo() == true)
                {
                    var currentScene = EditorApplication.currentScene;
                    var sceneGuids   = AssetDatabase.FindAssets("t:scene");

                    foreach (var sceneGuid in sceneGuids)
                    {
                        var scenePath = AssetDatabase.GUIDToAssetPath(sceneGuid);

                        if (EditorApplication.OpenScene(scenePath) == true)
                        {
                            LinkInScene();

                            EditorApplication.SaveScene();
                        }
                    }

                    EditorApplication.OpenScene(currentScene);
                }
#else
                if (EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo() == true)
                {
                    var setup      = EditorSceneManager.GetSceneManagerSetup();
                    var sceneGuids = AssetDatabase.FindAssets("t:scene");

                    foreach (var sceneGuid in sceneGuids)
                    {
                        var scenePath = AssetDatabase.GUIDToAssetPath(sceneGuid);
                        var scene     = EditorSceneManager.OpenScene(scenePath, OpenSceneMode.Single);

                        if (scene.isLoaded == true)
                        {
                            LinkInScene();

                            EditorSceneManager.SaveScene(scene);
                        }
                    }

                    EditorSceneManager.RestoreSceneManagerSetup(setup);
                }
#endif
            }
            break;
            }

            if (inPrefabs == true)
            {
                LinkInPrefabs();
            }

            if (inScriptableObjects == true)
            {
                LinkInScriptableObjects();
            }

            if (inAnimationClips == true)
            {
                LinkInAnimationClips();
            }

#if OLD_SCENE_MANAGEMENT
            EditorApplication.MarkSceneDirty();
#else
            EditorSceneManager.MarkAllScenesDirty();
#endif
        }

        if (GUI.Button(rect1, "Cancel") == true)
        {
            Close();
        }
    }
Exemple #8
0
    private void DrawButtons()
    {
        var rect  = SpHelper.Reserve();
        var rect0 = rect; rect0.xMax = rect0.center.x - 1;
        var rect1 = rect; rect1.xMin = rect1.center.x + 1;

        if (GUI.Button(rect0, "Link Sprites") == true)
        {
            switch (inScenes)
            {
            case SpLink_Scene.This:
            {
                LinkInScene();
            }
            break;

            case SpLink_Scene.All:
            {
                if (EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
                {
                    currentScene = SceneManager.GetActiveScene();
                    var sceneGuids = AssetDatabase.FindAssets("t:scene");

                    foreach (var sceneGuid in sceneGuids)
                    {
                        var scenePath = AssetDatabase.GUIDToAssetPath(sceneGuid);

                        if (EditorSceneManager.OpenScene(scenePath) != default(Scene))
                        {
                            LinkInScene();

                            EditorSceneManager.SaveOpenScenes();
                        }
                    }

                    EditorSceneManager.OpenScene(currentScene.name);
                }
            }
            break;
            }

            if (inPrefabs == true)
            {
                LinkInPrefabs();
            }

            if (inScriptableObjects == true)
            {
                LinkInScriptableObjects();
            }

            if (inAnimationClips == true)
            {
                LinkInAnimationClips();
            }

            EditorSceneManager.MarkSceneDirty(currentScene);
        }

        if (GUI.Button(rect1, "Cancel") == true)
        {
            Close();
        }
    }
Exemple #9
0
    private void DrawSource(SpAtlas atlas, SpSource source)
    {
        var background    = default(GUIStyle);
        var sourceTexture = source.Texture;

        if (source.Flag == SpFlag.None && sourceTexture == null)
        {
            source.Flag = SpFlag.MarkedForDestruction;
        }

        if (source.Flag == SpFlag.JustCreated)
        {
            background = SpHelper.GreenBox;
            hasGreen   = true;
        }
        else if (source.Flag == SpFlag.MarkedForDestruction)
        {
            background = SpHelper.RedBox;
            hasRed     = true;
        }
        else
        {
            if (source.Dirty == true)
            {
                background = SpHelper.YellowBox;
                hasYellow  = true;
            }
        }

        SpHelper.BeginError(background != null, background);
        {
            var rect  = SpHelper.Reserve();
            var rect0 = rect; rect0.xMax -= 100.0f;
            var rect1 = rect; rect1.xMin = rect1.xMax - 45.0f; rect1.x -= 55.0f;
            var rect2 = rect; rect2.xMin = rect2.xMax - 35.0f; rect2.x -= 20.0f;
            var rect3 = rect; rect3.xMin = rect3.xMax - 20.0f;

            if (EditorGUI.Foldout(rect0, currentSource == source, source.Name) == true)
            {
                EditorGUI.BeginChangeCheck();
                {
                    currentSource = source;

                    EditorGUI.BeginDisabledGroup(source.Flag == SpFlag.MarkedForDestruction);
                    {
                        source.PadSize  = EditorGUILayout.IntField("Pad Size", source.PadSize);
                        source.PadStyle = (SpPadStyle)EditorGUILayout.EnumPopup("Pad Style", source.PadStyle);

                        if (source.PadStyle == SpPadStyle.Transparent)
                        {
                            source.Trim = EditorGUILayout.Toggle("Trim", source.Trim);
                        }

                        DrawPivot(source);
                        DrawBorder(source);
                    }
                    EditorGUI.EndDisabledGroup();
                }
                if (EditorGUI.EndChangeCheck() == true)
                {
                    source.Dirty = true;
                }
            }
            else if (currentSource == source)
            {
                currentSource = null;
            }

            // See if the PPU is inconsistent
            var importer = source.Importer;

            if (importer != null)
            {
                var ppu = importer.spritePixelsPerUnit;

                if (lastPpu < 0.0f)
                {
                    lastPpu = ppu;
                }

                if (lastPpu != ppu)
                {
                    EditorGUILayout.HelpBox("This sprite has an inconsistent PixelsPerUnit setting. These differences will be overridden in the final sprite.", MessageType.Warning);
                }
            }

            DrawSelectButton(source, rect1, sourceTexture);

            DrawFindButton(atlas, source, rect2, sourceTexture);

            DrawDestroyButton(atlas, source, rect3);
        }
        SpHelper.EndError();
    }
Exemple #10
0
    private void DrawButtons()
    {
        var rect  = SpHelper.Reserve();
        var width = rect.width / 3;
        var rect0 = new Rect(rect.xMin + width * 0, rect.yMin, width - 1, rect.height);
        var rect1 = new Rect(rect.xMin + width * 1 + 1, rect.yMin, width - 2, rect.height);
        var rect2 = new Rect(rect.xMin + width * 2, rect.yMin, width - 1, rect.height);

        if (GUI.Button(rect0, "Link Sprites") == true)
        {
            if (EditorUtility.DisplayDialog("Are you sure?", "This will search through your whole project and replace all sprites on the LEFT with sprites on the RIGHT. This may be difficult to undo if you make a mistake, so please back up your project first!", "ok") == true)
            {
                switch (inScenes)
                {
                case SpLink_Scene.This:
                {
                    LinkInScene();
                }
                break;

                case SpLink_Scene.All:
                {
#if OLD_SCENE_MANAGEMENT
                    if (EditorApplication.SaveCurrentSceneIfUserWantsTo() == true)
                    {
                        var currentScene = EditorApplication.currentScene;
                        var sceneGuids   = AssetDatabase.FindAssets("t:scene");

                        foreach (var sceneGuid in sceneGuids)
                        {
                            var scenePath = AssetDatabase.GUIDToAssetPath(sceneGuid);

                            if (EditorApplication.OpenScene(scenePath) == true)
                            {
                                LinkInScene();

                                EditorApplication.SaveScene();
                            }
                        }

                        EditorApplication.OpenScene(currentScene);
                    }
#else
                    if (EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo() == true)
                    {
                        var setup      = EditorSceneManager.GetSceneManagerSetup();
                        var sceneGuids = AssetDatabase.FindAssets("t:scene");

                        foreach (var sceneGuid in sceneGuids)
                        {
                            var scenePath = AssetDatabase.GUIDToAssetPath(sceneGuid);
                            var scene     = EditorSceneManager.OpenScene(scenePath, OpenSceneMode.Single);

                            if (scene.isLoaded == true)
                            {
                                LinkInScene();

                                EditorSceneManager.SaveScene(scene);
                            }
                        }

                        EditorSceneManager.RestoreSceneManagerSetup(setup);
                    }
#endif
                }
                break;
                }

                if (inPrefabs == true)
                {
                    LinkInPrefabs();
                }

                if (inScriptableObjects == true)
                {
                    LinkInScriptableObjects();
                }

                if (inAnimationClips == true)
                {
                    LinkInAnimationClips();
                }

#if OLD_SCENE_MANAGEMENT
                EditorApplication.MarkSceneDirty();
#else
                EditorSceneManager.MarkAllScenesDirty();
#endif
            }
        }

        if (GUI.Button(rect1, "Swap Sides") == true)
        {
            if (EditorUtility.DisplayDialog("Are you sure?", "This will swap all sprites on the left and right sides, but not link them. Please confirm the sprites and click Link to complete.", "ok") == true)
            {
                for (var i = 0; i < sourceSprites.Length; i++)
                {
                    var tempSprite = sourceSprites[i];

                    sourceSprites[i] = packedSprites[i];
                    packedSprites[i] = tempSprite;
                }
            }
        }

        if (GUI.Button(rect2, "Cancel") == true)
        {
            Close();
        }
    }
    private void DrawSource(SpAtlas atlas, SpSource source)
    {
        var background    = default(GUIStyle);
        var sourceTexture = source.Texture;

        if (source.Flag == SpFlag.None && sourceTexture == null)
        {
            source.Flag = SpFlag.MarkedForDestruction;
        }

        if (source.Flag == SpFlag.JustCreated)
        {
            background = SpHelper.GreenBox;
            hasGreen   = true;
        }
        else if (source.Flag == SpFlag.MarkedForDestruction)
        {
            background = SpHelper.RedBox;
            hasRed     = true;
        }
        else
        {
            if (source.Dirty == true)
            {
                background = SpHelper.YellowBox;
                hasYellow  = true;
            }
        }

        SpHelper.BeginError(background != null, background);
        {
            var rect  = SpHelper.Reserve();
            var rect0 = rect; rect0.xMax -= 100.0f;
            var rect1 = rect; rect1.xMin = rect1.xMax - 45.0f; rect1.x -= 55.0f;
            var rect2 = rect; rect2.xMin = rect2.xMax - 35.0f; rect2.x -= 20.0f;
            var rect3 = rect; rect3.xMin = rect3.xMax - 20.0f;

            if (EditorGUI.Foldout(rect0, currentSource == source, source.Name) == true)
            {
                EditorGUI.BeginChangeCheck();
                {
                    currentSource = source;

                    EditorGUI.BeginDisabledGroup(source.Flag == SpFlag.MarkedForDestruction);
                    {
                        source.PadSize  = EditorGUILayout.IntField("Pad Size", source.PadSize);
                        source.PadStyle = (SpPadStyle)EditorGUILayout.EnumPopup("Pad Style", source.PadStyle);

                        if (source.PadStyle == SpPadStyle.Transparent)
                        {
                            source.Trim = EditorGUILayout.Toggle("Trim", source.Trim);
                        }

                        DrawPivot(source);
                        DrawBorder(source);
                    }
                    EditorGUI.EndDisabledGroup();
                }
                if (EditorGUI.EndChangeCheck() == true)
                {
                    source.Dirty = true;
                }
            }
            else if (currentSource == source)
            {
                currentSource = null;
            }

            DrawSelectButton(source, rect1, sourceTexture);

            DrawFindButton(atlas, source, rect2, sourceTexture);

            DrawDestroyButton(atlas, source, rect3);
        }
        SpHelper.EndError();
    }