示例#1
0
    private void DrawFindButton(SpAtlas atlas, SpSource source, Rect rect, Texture2D sourceTexture)
    {
        EditorGUI.BeginDisabledGroup(sourceTexture == null && source.Flag == SpFlag.JustCreated);
        {
            if (GUI.Button(rect, "find", EditorStyles.miniButtonMid) == true)
            {
                var sourceName    = source.Name;
                var sourceSprites = source.Sprites;
                var foundSprites  = source.FindSprites(atlas.Sprites, sourceSprites);

                if (foundSprites.Count > 0)
                {
                    Selection.objects = foundSprites.ToArray();
                }
                else
                {
                    var sprite = atlas.Sprites.Find(s => s.name == sourceName);

                    if (sprite != null)
                    {
                        Selection.activeObject = sprite;
                    }
                    else
                    {
                        Debug.Log("Failed to find linked sprites");
                    }
                }
            }
        }
        EditorGUI.EndDisabledGroup();
    }
示例#2
0
    private void DrawDestroyButton(SpAtlas atlas, SpSource source, Rect rect)
    {
        if (GUI.Button(rect, "x", EditorStyles.miniButtonRight) == true)
        {
            switch (source.Flag)
            {
            case SpFlag.None:
            {
                source.Flag = SpFlag.MarkedForDestruction;
            }
            break;

            case SpFlag.JustCreated:
            {
                atlas.Sources.Remove(source);
            }
            break;

            case SpFlag.MarkedForDestruction:
            {
                source.Flag = SpFlag.None;
            }
            break;
            }
        }
    }
示例#3
0
    private void AddSource(string newIdentifier)
    {
        var newSource = new SpSource();

        newSource.Identifier = newIdentifier;
        newSource.Trim       = DefaultTrim;
        newSource.PadSize    = DefaultPadSize;
        newSource.PadStyle   = DefaultPadStyle;

        Sources.Add(newSource);
    }
示例#4
0
 private void DrawSelectButton(SpSource source, Rect rect, Texture2D sourceTexture)
 {
     EditorGUI.BeginDisabledGroup(sourceTexture == null);
     {
         if (GUI.Button(rect, "select", EditorStyles.miniButtonLeft) == true)
         {
             Selection.activeObject = sourceTexture;
         }
     }
     EditorGUI.EndDisabledGroup();
 }
示例#5
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);
        }
    }
示例#6
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);
        }
    }
    private static void CompileRect(List <SpRect> rects, SpSource source, SpPixels pixels, string name, Sprite sprite = null)
    {
        var newRect = new SpRect();

        newRect.Name   = name;
        newRect.Source = source;
        newRect.Pixels = pixels;

        // Read pivot and border from sprite
        if (sprite != null)
        {
            newRect.Pivot  = SpHelper.GetSpritePivot(sprite);
            newRect.Border = sprite.border;
        }
        // Use default pivot and border settings
        else
        {
            newRect.Pivot  = new Vector2(0.5f, 0.5f);
            newRect.Border = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
        }

        // Override the pivot?
        if (source.UseCustomPivot == true)
        {
            newRect.Pivot = source.CustomPivot;
        }

        // Override the border?
        if (source.UseCustomBorder == true)
        {
            newRect.Border = source.CustomBorder;
        }

        newRect.Trim();

        rects.Add(newRect);
    }
示例#8
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();
    }
    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();
    }