Exemplo n.º 1
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();
    }
Exemplo n.º 2
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;
            }

            DrawSelectButton(source, rect1, sourceTexture);

            DrawFindButton(atlas, source, rect2, sourceTexture);

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