void AddSprites(tk2dSpriteSheetSource spriteSheet)
        {
            int        spriteSheetId         = SpriteCollection.GetSpriteSheetId(spriteSheet);
            List <int> usedSpriteCoordinates = new List <int>();

            var tex      = spriteSheet.texture;
            int regionId = 0;

            int numTilesX, numTilesY;

            GetNumTilesForSpriteSheet(spriteSheet, out numTilesX, out numTilesY);
            for (int idY = 0; idY < numTilesY; ++idY)
            {
                for (int idX = 0; idX < numTilesX; ++idX)
                {
                    int x, y;
                    GetTileCoordinateForSpriteSheet(spriteSheet, idX, idY, out x, out y);

                    int spriteSlot = GetSpriteSlotForSpriteSheetCell(spriteSheetId, idX, idY);
                    SpriteCollection.textureRefs[spriteSlot] = spriteSheet.texture;
                    var param = SpriteCollection.textureParams[spriteSlot];
                    param.hasSpriteSheetId = true;
                    param.spriteSheetId    = spriteSheetId;
                    param.spriteSheetX     = idX;
                    param.spriteSheetY     = idY;
                    param.extractRegion    = true;
                    param.regionId         = regionId;
                    param.regionX          = x;
                    param.regionY          = tex.height - spriteSheet.tileHeight - y;
                    param.regionW          = spriteSheet.tileWidth;
                    param.regionH          = spriteSheet.tileHeight;
                    param.pad = spriteSheet.pad;
                    int id = idY * numTilesX + idX;
                    param.name = tex.name + "/" + id.ToString();
                    usedSpriteCoordinates.Add(GetSpriteCoordinateHash(idX, idY));

                    regionId++;
                }
            }

            // Delete sprites from sprite sheet which aren't required any more
            for (int i = 0; i < SpriteCollection.textureParams.Count; ++i)
            {
                var p = SpriteCollection.textureParams[i];
                if (p.hasSpriteSheetId && p.spriteSheetId == spriteSheetId)
                {
                    int coordinateHash = GetSpriteCoordinateHash(p.spriteSheetX, p.spriteSheetY);
                    if (usedSpriteCoordinates.IndexOf(coordinateHash) == -1)
                    {
                        SpriteCollection.textureRefs[i] = null;
                        SpriteCollection.textureParams[i].Clear();
                    }
                }
            }

            host.OnSpriteCollectionChanged(true);
        }
        public void DrawSpriteEditorInspector(List <SpriteCollectionEditorEntry> entries, bool allowDelete, bool editingSpriteSheet)
        {
            var entry         = entries[entries.Count - 1];
            var param         = SpriteCollection.textureParams[entry.index];
            var spriteTexture = param.extractRegion?host.GetTextureForSprite(entry.index):SpriteCollection.textureParams[entry.index].texture;

            // Inspector
            EditorGUILayout.BeginVertical();

            // Header
            EditorGUILayout.BeginVertical(tk2dEditorSkin.SC_InspectorHeaderBG, GUILayout.MaxWidth(host.InspectorWidth), GUILayout.ExpandHeight(true));
            if (entries.Count > 1)
            {
                EditorGUILayout.TextField("Name", param.name);
            }
            else
            {
                string name = EditorGUILayout.TextField("Name", param.name);
                if (name != param.name)
                {
                    param.name = name;
                    entry.name = name;
                    host.OnSpriteCollectionSortChanged();
                }
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.PrefixLabel("Sprite Id");
                EditorGUILayout.SelectableLabel(entry.index.ToString(), EditorStyles.textField, GUILayout.ExpandWidth(true), GUILayout.Height(16));
                EditorGUILayout.EndHorizontal();
            }
            GUILayout.BeginHorizontal();
            bool doDelete            = false;
            bool doSelect            = false;
            bool doSelectSpriteSheet = false;

            if (entries.Count == 1)
            {
                if (param.extractRegion)
                {
                    EditorGUILayout.ObjectField("Texture", spriteTexture, typeof(Texture2D), false);
                }
                else
                {
                    SpriteCollection.textureParams[entry.index].texture = EditorGUILayout.ObjectField("Texture", spriteTexture, typeof(Texture2D), false) as Texture2D;
                }
                GUILayout.FlexibleSpace();
                GUILayout.BeginVertical();
                if (editingSpriteSheet && GUILayout.Button("Edit...", EditorStyles.miniButton, GUILayout.Width(miniButtonWidth)))
                {
                    doSelect = true;
                }
                if (!editingSpriteSheet && param.hasSpriteSheetId && GUILayout.Button("Source", EditorStyles.miniButton, GUILayout.Width(miniButtonWidth)))
                {
                    doSelectSpriteSheet = true;
                }
                if (allowDelete && GUILayout.Button("Delete", EditorStyles.miniButton, GUILayout.Width(miniButtonWidth)))
                {
                    doDelete = true;
                }
                GUILayout.EndVertical();
            }
            else
            {
                string countLabel = (entries.Count > 1)?entries.Count.ToString() + " sprites selected":"";
                GUILayout.Label(countLabel);
                GUILayout.FlexibleSpace();
                if (editingSpriteSheet && GUILayout.Button("Edit...", EditorStyles.miniButton, GUILayout.Width(miniButtonWidth)))
                {
                    doSelect = true;
                }
                if (!editingSpriteSheet && param.hasSpriteSheetId)
                {
                    int id = param.spriteSheetId;
                    foreach (var v in entries)
                    {
                        var p = SpriteCollection.textureParams[v.index];
                        if (!p.hasSpriteSheetId ||
                            p.spriteSheetId != id)
                        {
                            id = -1;
                            break;
                        }
                    }
                    if (id != -1 && GUILayout.Button("Source", EditorStyles.miniButton, GUILayout.Width(miniButtonWidth)))
                    {
                        doSelectSpriteSheet = true;
                    }
                }
                if (allowDelete && GUILayout.Button("Delete", EditorStyles.miniButton, GUILayout.Width(miniButtonWidth)))
                {
                    doDelete = true;
                }
            }
            GUILayout.EndHorizontal();
            EditorGUILayout.EndVertical();

            // make dragable
            tk2dPreferences.inst.spriteCollectionInspectorWidth -= (int)tk2dGuiUtility.DragableHandle(4819284, GUILayoutUtility.GetLastRect(), 0, tk2dGuiUtility.DragDirection.Horizontal);

            // Body
            EditorGUILayout.BeginVertical(tk2dEditorSkin.SC_InspectorBG, GUILayout.MaxWidth(host.InspectorWidth), GUILayout.ExpandHeight(true));

            if (SpriteCollection.AllowAltMaterials && SpriteCollection.altMaterials.Length > 1)
            {
                List <int>    altMaterialIndices = new List <int>();
                List <string> altMaterialNames   = new List <string>();
                for (int i = 0; i < SpriteCollection.altMaterials.Length; ++i)
                {
                    var mat = SpriteCollection.altMaterials[i];
                    if (mat == null)
                    {
                        continue;
                    }
                    altMaterialIndices.Add(i);
                    altMaterialNames.Add(mat.name);
                }

                GUILayout.BeginHorizontal();
                param.materialId = EditorGUILayout.IntPopup("Material", param.materialId, altMaterialNames.ToArray(), altMaterialIndices.ToArray());
                if (GUILayout.Button("Select", EditorStyles.miniButton, GUILayout.Width(miniButtonWidth)))
                {
                    List <int> spriteIdList = new List <int>();
                    for (int i = 0; i < SpriteCollection.textureParams.Count; ++i)
                    {
                        if (SpriteCollection.textureParams[i].materialId == param.materialId)
                        {
                            spriteIdList.Add(i);
                        }
                    }
                    host.SelectSpritesFromList(spriteIdList.ToArray());
                }
                GUILayout.EndHorizontal();
                HandleMultiSelection(entries, (a, b) => a.materialId == b.materialId, (a, b) => b.materialId = a.materialId);
            }

            if (SpriteCollection.premultipliedAlpha)
            {
                param.additive = EditorGUILayout.Toggle("Additive", param.additive);
                HandleMultiSelection(entries, (a, b) => a.additive == b.additive, (a, b) => b.additive = a.additive);
            }
            // fixup
            if (param.scale == Vector3.zero)
            {
                param.scale = Vector3.one;
            }
            param.scale = EditorGUILayout.Vector3Field("Scale", param.scale);
            HandleMultiSelection(entries, (a, b) => a.scale == b.scale, (a, b) => b.scale = a.scale);

            // Anchor
            var newAnchor = (tk2dSpriteCollectionDefinition.Anchor)EditorGUILayout.EnumPopup("Anchor", param.anchor);

            if (param.anchor != newAnchor)
            {
                // When anchor type is changed to custom, switch the editor to edit anchors
                if (newAnchor == tk2dSpriteCollectionDefinition.Anchor.Custom)
                {
                    textureEditor.SetMode(tk2dEditor.SpriteCollectionEditor.TextureEditor.Mode.Anchor);
                }
                param.anchor = newAnchor;
            }

            if (param.anchor == tk2dSpriteCollectionDefinition.Anchor.Custom)
            {
                EditorGUI.indentLevel++;
                EditorGUILayout.BeginHorizontal();
                param.anchorX = EditorGUILayout.FloatField("X", param.anchorX);
                bool roundAnchorX = GUILayout.Button("R", EditorStyles.miniButton, GUILayout.MaxWidth(24));
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();
                param.anchorY = EditorGUILayout.FloatField("Y", param.anchorY);
                bool roundAnchorY = GUILayout.Button("R", EditorStyles.miniButton, GUILayout.MaxWidth(24));
                EditorGUILayout.EndHorizontal();

                if (roundAnchorX)
                {
                    param.anchorX = Mathf.Round(param.anchorX);
                }
                if (roundAnchorY)
                {
                    param.anchorY = Mathf.Round(param.anchorY);
                }
                EditorGUI.indentLevel--;
                EditorGUILayout.Separator();

                HandleMultiSelection(entries,
                                     (a, b) => (a.anchor == b.anchor && a.anchorX == b.anchorX && a.anchorY == b.anchorY),
                                     delegate(tk2dSpriteCollectionDefinition a, tk2dSpriteCollectionDefinition b) {
                    b.anchor  = a.anchor;
                    b.anchorX = a.anchorX;
                    b.anchorY = a.anchorY;
                });
            }
            else
            {
                HandleMultiSelection(entries, (a, b) => a.anchor == b.anchor, (a, b) => b.anchor = a.anchor);
            }

            var newColliderType = (tk2dSpriteCollectionDefinition.ColliderType)EditorGUILayout.EnumPopup("Collider Type", param.colliderType);

            if (param.colliderType != newColliderType)
            {
                // when switching to custom collider mode, automatically switch editor mode
                if (newColliderType == tk2dSpriteCollectionDefinition.ColliderType.BoxCustom ||
                    newColliderType == tk2dSpriteCollectionDefinition.ColliderType.Polygon)
                {
                    textureEditor.SetMode(tk2dEditor.SpriteCollectionEditor.TextureEditor.Mode.Collider);
                }
                param.colliderType = newColliderType;
            }

            if (param.colliderType == tk2dSpriteCollectionDefinition.ColliderType.BoxCustom)
            {
                EditorGUI.indentLevel++;
                param.boxColliderMin = EditorGUILayout.Vector2Field("Min", param.boxColliderMin);
                param.boxColliderMax = EditorGUILayout.Vector2Field("Max", param.boxColliderMax);
                EditorGUI.indentLevel--;
                EditorGUILayout.Separator();

                HandleMultiSelection(entries,
                                     (a, b) => (a.colliderType == b.colliderType && a.boxColliderMin == b.boxColliderMin && a.boxColliderMax == b.boxColliderMax),
                                     delegate(tk2dSpriteCollectionDefinition a, tk2dSpriteCollectionDefinition b) {
                    b.colliderType   = a.colliderType;
                    b.boxColliderMin = a.boxColliderMin;
                    b.boxColliderMax = a.boxColliderMax;
                });
            }
            else if (param.colliderType == tk2dSpriteCollectionDefinition.ColliderType.Polygon)
            {
                EditorGUI.indentLevel++;
                param.polyColliderCap = (tk2dSpriteCollectionDefinition.PolygonColliderCap)EditorGUILayout.EnumPopup("Collider Cap", param.polyColliderCap);
                param.colliderConvex  = EditorGUILayout.Toggle("Convex", param.colliderConvex);
                param.colliderSmoothSphereCollisions = EditorGUILayout.Toggle(new GUIContent("SmoothSphereCollisions", "Smooth Sphere Collisions"), param.colliderSmoothSphereCollisions);
                EditorGUI.indentLevel--;
                EditorGUILayout.Separator();

                HandleMultiSelection(entries,
                                     (a, b) => (a.colliderType == b.colliderType && a.polyColliderCap == b.polyColliderCap &&
                                                a.colliderConvex == b.colliderConvex && a.colliderSmoothSphereCollisions == b.colliderSmoothSphereCollisions &&
                                                ComparePolyCollider(a.polyColliderIslands, b.polyColliderIslands)),
                                     delegate(tk2dSpriteCollectionDefinition a, tk2dSpriteCollectionDefinition b) {
                    b.colliderType    = a.colliderType;
                    b.polyColliderCap = a.polyColliderCap;
                    b.colliderConvex  = a.colliderConvex;
                    b.colliderSmoothSphereCollisions = a.colliderSmoothSphereCollisions;
                    CopyPolyCollider(a.polyColliderIslands, ref b.polyColliderIslands);
                });
            }
            else
            {
                HandleMultiSelection(entries, (a, b) => a.colliderType == b.colliderType, (a, b) => b.colliderType = a.colliderType);
            }

            // Mesh type
            if (param.dice && param.customSpriteGeometry)             // sanity check
            {
                param.dice = false; param.customSpriteGeometry = false;
            }
            CustomMeshType meshType = CustomMeshType.Default;

            if (param.customSpriteGeometry)
            {
                meshType = CustomMeshType.Custom;
            }
            else if (param.dice)
            {
                meshType = CustomMeshType.Diced;
            }
            else if (param.doubleSidedSprite)
            {
                meshType = CustomMeshType.DoubleSided;
            }
            CustomMeshType newMeshType = (CustomMeshType)EditorGUILayout.EnumPopup("Render Mesh", meshType);

            if (newMeshType != meshType)
            {
                // Fix up
                param.customSpriteGeometry = false;
                param.dice = false;
                param.doubleSidedSprite = false;

                switch (newMeshType)
                {
                case CustomMeshType.Custom: param.customSpriteGeometry = true; break;

                case CustomMeshType.Diced:      param.dice = true;      break;

                case CustomMeshType.Default: break;

                case CustomMeshType.DoubleSided: param.doubleSidedSprite = true; break;
                }

                // Automatically switch to custom geom edit mode when explicitly switched
                if (param.customSpriteGeometry)
                {
                    textureEditor.SetMode(tk2dEditor.SpriteCollectionEditor.TextureEditor.Mode.Texture);
                }
            }

            // Sanity check dicing & multiple atlases
            if (!SpriteCollection.allowSpannedDicing && param.dice && SpriteCollection.allowMultipleAtlases)
            {
                EditorUtility.DisplayDialog("Sprite dicing",
                                            "Sprite dicing is unavailable when multiple atlases is enabled. " +
                                            "Please disable it and try again.", "Ok");
                param.dice = false;
            }

            // Dicing parameters
            if (param.dice)
            {
                EditorGUI.indentLevel++;
                param.diceUnitX = EditorGUILayout.IntField("Dice X", param.diceUnitX);
                param.diceUnitY = EditorGUILayout.IntField("Dice Y", param.diceUnitY);
                GUIContent diceFilter = new GUIContent("Dice Filter",
                                                       "Dice Filter lets you dice and only store a subset of the dices. This lets you perform more optimizations, drawing solid dices with a solid shader.\n\n" +
                                                       "Complete - Draw all dices (Default).\nSolidOnly - Only draw the solid dices.\nTransparent Only - Only draw transparent dices.");
                param.diceFilter = (tk2dSpriteCollectionDefinition.DiceFilter)EditorGUILayout.EnumPopup(diceFilter, param.diceFilter);
                EditorGUI.indentLevel--;
                EditorGUILayout.Separator();
            }

            HandleMultiSelection(entries,
                                 (a, b) => a.customSpriteGeometry == b.customSpriteGeometry && a.dice == b.dice && a.diceUnitX == b.diceUnitX && a.diceUnitY == b.diceUnitY && a.diceFilter == b.diceFilter,
                                 delegate(tk2dSpriteCollectionDefinition a, tk2dSpriteCollectionDefinition b) {
                b.customSpriteGeometry = a.customSpriteGeometry;
                b.dice       = a.dice;
                b.diceUnitX  = a.diceUnitX;
                b.diceUnitY  = a.diceUnitY;
                b.diceFilter = a.diceFilter;
                if (a.customSpriteGeometry)
                {
                    CopyPolyCollider(a.geometryIslands, ref b.geometryIslands);
                }
            });


            // Disable trimming
            if (!SpriteCollection.disableTrimming)
            {
                param.disableTrimming = EditorGUILayout.Toggle("Disable Trimming", param.disableTrimming);
                HandleMultiSelection(entries, (a, b) => a.disableTrimming == b.disableTrimming, (a, b) => b.disableTrimming = a.disableTrimming);
            }

            // Pad amount
            param.pad = (tk2dSpriteCollectionDefinition.Pad)EditorGUILayout.EnumPopup("Pad method", param.pad);
            HandleMultiSelection(entries, (a, b) => a.pad == b.pad, (a, b) => b.pad = a.pad);

            // Extra padding
            param.extraPadding = EditorGUILayout.IntPopup("Extra Padding", param.extraPadding, extraPadAmountLabels, extraPadAmountValues);
            HandleMultiSelection(entries, (a, b) => a.extraPadding == b.extraPadding, (a, b) => b.extraPadding = a.extraPadding);
            GUILayout.FlexibleSpace();

            // Draw additional inspector
            textureEditor.DrawTextureInspector(param, spriteTexture);

            EditorGUILayout.EndVertical();
            EditorGUILayout.EndVertical();             // inspector

            // make dragable
            tk2dPreferences.inst.spriteCollectionInspectorWidth -= (int)tk2dGuiUtility.DragableHandle(4819284, GUILayoutUtility.GetLastRect(), 0, tk2dGuiUtility.DragDirection.Horizontal);

            // Defer delete to avoid messing about anything else
            if (doDelete &&
                EditorUtility.DisplayDialog("Delete sprite", "Are you sure you want to delete the selected sprites?", "Yes", "No"))
            {
                foreach (var e in entries)
                {
                    SpriteCollection.textureParams[e.index] = new tk2dSpriteCollectionDefinition();
                }
                SpriteCollection.Trim();
                if (editingSpriteSheet)
                {
                    host.OnSpriteCollectionChanged(true);
                }
                else
                {
                    host.OnSpriteCollectionChanged(false);
                }
            }

            if (doSelect)
            {
                List <int> spriteIdList = new List <int>();
                foreach (var e in entries)
                {
                    spriteIdList.Add(e.index);
                }
                host.SelectSpritesFromList(spriteIdList.ToArray());
            }

            if (doSelectSpriteSheet)
            {
                List <int> spriteIdList = new List <int>();
                foreach (var e in entries)
                {
                    spriteIdList.Add(e.index);
                }
                host.SelectSpritesInSpriteSheet(param.spriteSheetId, spriteIdList.ToArray());
            }
        }
Ejemplo n.º 3
0
        public void DrawSpriteEditorInspector(List <SpriteCollectionEditorEntry> entries, bool allowDelete, bool editingSpriteSheet)
        {
            var entry         = entries[entries.Count - 1];
            var param         = SpriteCollection.textureParams[entry.index];
            var spriteTexture = param.extractRegion?host.GetTextureForSprite(entry.index):SpriteCollection.textureRefs[entry.index];

            // Inspector
            EditorGUILayout.BeginVertical();

            // Header
            EditorGUILayout.BeginVertical(tk2dEditorSkin.SC_InspectorHeaderBG, GUILayout.MaxWidth(host.InspectorWidth), GUILayout.ExpandHeight(true));
            if (entries.Count > 1)
            {
                EditorGUILayout.TextField("Name", param.name);
            }
            else
            {
                string name = EditorGUILayout.TextField("Name", param.name);
                if (name != param.name)
                {
                    param.name = name;
                    entries[entries.Count - 1].name = name;
                    host.OnSpriteCollectionSortChanged();
                }
            }
            GUILayout.BeginHorizontal();
            bool doDelete            = false;
            bool doSelect            = false;
            bool doSelectSpriteSheet = false;

            if (entries.Count == 1)
            {
                if (param.extractRegion)
                {
                    EditorGUILayout.ObjectField("Texture", spriteTexture, typeof(Texture2D), false);
                }
                else
                {
                    SpriteCollection.textureRefs[entry.index] = EditorGUILayout.ObjectField("Texture", spriteTexture, typeof(Texture2D), false) as Texture2D;
                }
                GUILayout.FlexibleSpace();
                GUILayout.BeginVertical();
                if (editingSpriteSheet && GUILayout.Button("Edit...", EditorStyles.miniButton, GUILayout.Width(miniButtonWidth)))
                {
                    doSelect = true;
                }
                if (!editingSpriteSheet && param.hasSpriteSheetId && GUILayout.Button("Source", EditorStyles.miniButton, GUILayout.Width(miniButtonWidth)))
                {
                    doSelectSpriteSheet = true;
                }
                if (allowDelete && GUILayout.Button("Delete", EditorStyles.miniButton, GUILayout.Width(miniButtonWidth)))
                {
                    doDelete = true;
                }
                GUILayout.EndVertical();
            }
            else
            {
                string countLabel = (entries.Count > 1)?entries.Count.ToString() + " sprites selected":"";
                GUILayout.Label(countLabel);
                GUILayout.FlexibleSpace();
                if (editingSpriteSheet && GUILayout.Button("Edit...", EditorStyles.miniButton, GUILayout.Width(miniButtonWidth)))
                {
                    doSelect = true;
                }
                if (!editingSpriteSheet && param.hasSpriteSheetId)
                {
                    int id = param.spriteSheetId;
                    foreach (var v in entries)
                    {
                        var p = SpriteCollection.textureParams[v.index];
                        if (!p.hasSpriteSheetId ||
                            p.spriteSheetId != id)
                        {
                            id = -1;
                            break;
                        }
                    }
                    if (id != -1 && GUILayout.Button("Source", EditorStyles.miniButton, GUILayout.Width(miniButtonWidth)))
                    {
                        doSelectSpriteSheet = true;
                    }
                }
                if (allowDelete && GUILayout.Button("Delete", EditorStyles.miniButton, GUILayout.Width(miniButtonWidth)))
                {
                    doDelete = true;
                }
            }
            GUILayout.EndHorizontal();
            EditorGUILayout.EndVertical();

            // Body
            EditorGUILayout.BeginVertical(tk2dEditorSkin.SC_InspectorBG, GUILayout.MaxWidth(host.InspectorWidth), GUILayout.ExpandHeight(true));

            if (SpriteCollection.AllowAltMaterials && SpriteCollection.altMaterials.Length > 1)
            {
                List <int>    altMaterialIndices = new List <int>();
                List <string> altMaterialNames   = new List <string>();
                for (int i = 0; i < SpriteCollection.altMaterials.Length; ++i)
                {
                    var mat = SpriteCollection.altMaterials[i];
                    if (mat == null)
                    {
                        continue;
                    }
                    altMaterialIndices.Add(i);
                    altMaterialNames.Add(mat.name);
                }

                GUILayout.BeginHorizontal();
                param.materialId = EditorGUILayout.IntPopup("Material", param.materialId, altMaterialNames.ToArray(), altMaterialIndices.ToArray());
                if (GUILayout.Button("Select", EditorStyles.miniButton, GUILayout.Width(miniButtonWidth)))
                {
                    List <int> spriteIdList = new List <int>();
                    for (int i = 0; i < SpriteCollection.textureParams.Count; ++i)
                    {
                        if (SpriteCollection.textureParams[i].materialId == param.materialId)
                        {
                            spriteIdList.Add(i);
                        }
                    }
                    host.SelectSpritesFromList(spriteIdList.ToArray());
                }
                GUILayout.EndHorizontal();
                HandleMultiSelection(entries, (a, b) => a.materialId == b.materialId, (a, b) => b.materialId = a.materialId);
            }

            if (SpriteCollection.premultipliedAlpha)
            {
                param.additive = EditorGUILayout.Toggle("Additive", param.additive);
                HandleMultiSelection(entries, (a, b) => a.additive == b.additive, (a, b) => b.additive = a.additive);
            }
            // fixup
            if (param.scale == Vector3.zero)
            {
                param.scale = Vector3.one;
            }
            param.scale = EditorGUILayout.Vector3Field("Scale", param.scale);
            HandleMultiSelection(entries, (a, b) => a.scale == b.scale, (a, b) => b.scale = a.scale);

            // Anchor
            param.anchor = (tk2dSpriteCollectionDefinition.Anchor)EditorGUILayout.EnumPopup("Anchor", param.anchor);
            if (param.anchor == tk2dSpriteCollectionDefinition.Anchor.Custom)
            {
                EditorGUI.indentLevel++;
                EditorGUILayout.BeginHorizontal();
                param.anchorX = EditorGUILayout.FloatField("X", param.anchorX);
                bool roundAnchorX = GUILayout.Button("R", EditorStyles.miniButton, GUILayout.MaxWidth(24));
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();
                param.anchorY = EditorGUILayout.FloatField("Y", param.anchorY);
                bool roundAnchorY = GUILayout.Button("R", EditorStyles.miniButton, GUILayout.MaxWidth(24));
                EditorGUILayout.EndHorizontal();

                if (roundAnchorX)
                {
                    param.anchorX = Mathf.Round(param.anchorX);
                }
                if (roundAnchorY)
                {
                    param.anchorY = Mathf.Round(param.anchorY);
                }
                EditorGUI.indentLevel--;
                EditorGUILayout.Separator();

                HandleMultiSelection(entries,
                                     (a, b) => (a.anchor == b.anchor && a.anchorX == b.anchorX && a.anchorY == b.anchorY),
                                     delegate(tk2dSpriteCollectionDefinition a, tk2dSpriteCollectionDefinition b) {
                    b.anchor  = a.anchor;
                    b.anchorX = a.anchorX;
                    b.anchorY = a.anchorY;
                });
            }
            else
            {
                HandleMultiSelection(entries, (a, b) => a.anchor == b.anchor, (a, b) => b.anchor = a.anchor);
            }

            param.colliderType = (tk2dSpriteCollectionDefinition.ColliderType)EditorGUILayout.EnumPopup("Collider Type", param.colliderType);
            if (param.colliderType == tk2dSpriteCollectionDefinition.ColliderType.BoxCustom)
            {
                EditorGUI.indentLevel++;
                param.boxColliderMin = EditorGUILayout.Vector2Field("Min", param.boxColliderMin);
                param.boxColliderMax = EditorGUILayout.Vector2Field("Max", param.boxColliderMax);
                EditorGUI.indentLevel--;
                EditorGUILayout.Separator();

                HandleMultiSelection(entries,
                                     (a, b) => (a.colliderType == b.colliderType && a.boxColliderMin == b.boxColliderMin && a.boxColliderMax == b.boxColliderMax),
                                     delegate(tk2dSpriteCollectionDefinition a, tk2dSpriteCollectionDefinition b) {
                    b.colliderType   = a.colliderType;
                    b.boxColliderMin = a.boxColliderMin;
                    b.boxColliderMax = a.boxColliderMax;
                });
            }
            else if (param.colliderType == tk2dSpriteCollectionDefinition.ColliderType.Polygon)
            {
                EditorGUI.indentLevel++;
                param.polyColliderCap = (tk2dSpriteCollectionDefinition.PolygonColliderCap)EditorGUILayout.EnumPopup("Collider Cap", param.polyColliderCap);
                param.colliderConvex  = EditorGUILayout.Toggle("Convex", param.colliderConvex);
                param.colliderSmoothSphereCollisions = EditorGUILayout.Toggle(new GUIContent("SmoothSphereCollisions", "Smooth Sphere Collisions"), param.colliderSmoothSphereCollisions);
                EditorGUI.indentLevel--;
                EditorGUILayout.Separator();

                HandleMultiSelection(entries,
                                     (a, b) => (a.colliderType == b.colliderType && a.polyColliderCap == b.polyColliderCap &&
                                                a.colliderConvex == b.colliderConvex && a.colliderSmoothSphereCollisions == b.colliderSmoothSphereCollisions &&
                                                ComparePolyCollider(a.polyColliderIslands, b.polyColliderIslands)),
                                     delegate(tk2dSpriteCollectionDefinition a, tk2dSpriteCollectionDefinition b) {
                    b.colliderType    = a.colliderType;
                    b.polyColliderCap = a.polyColliderCap;
                    b.colliderConvex  = a.colliderConvex;
                    b.colliderSmoothSphereCollisions = a.colliderSmoothSphereCollisions;
                    CopyPolyCollider(a.polyColliderIslands, ref b.polyColliderIslands);
                });
            }
            else
            {
                HandleMultiSelection(entries, (a, b) => a.colliderType == b.colliderType, (a, b) => b.colliderType = a.colliderType);
            }


            bool allowDicing         = !SpriteCollection.allowMultipleAtlases && !param.customSpriteGeometry;
            bool allowCustomGeometry = !param.dice;

            // Custom geometry
            if (allowCustomGeometry)
            {
                param.customSpriteGeometry = EditorGUILayout.Toggle("Custom Shape", param.customSpriteGeometry);
                HandleMultiSelection(entries, (a, b) => (a.customSpriteGeometry == b.customSpriteGeometry &&
                                                         ComparePolyCollider(a.geometryIslands, b.geometryIslands)),
                                     delegate(tk2dSpriteCollectionDefinition a, tk2dSpriteCollectionDefinition b){
                    b.customSpriteGeometry = a.customSpriteGeometry;
                    b.dice = a.dice;                             // mutually exclusive
                    CopyPolyCollider(a.geometryIslands, ref b.geometryIslands);
                });
            }

            // Dicing
            if (allowDicing)
            {
                param.dice = EditorGUILayout.Toggle("Dice", param.dice);
                if (param.dice)
                {
                    EditorGUI.indentLevel++;
                    param.diceUnitX = EditorGUILayout.IntField("X", param.diceUnitX);
                    param.diceUnitY = EditorGUILayout.IntField("Y", param.diceUnitY);
                    EditorGUI.indentLevel--;
                    EditorGUILayout.Separator();

                    HandleMultiSelection(entries,
                                         (a, b) => a.dice == b.dice && a.diceUnitX == b.diceUnitX && a.diceUnitY == b.diceUnitY,
                                         delegate(tk2dSpriteCollectionDefinition a, tk2dSpriteCollectionDefinition b) {
                        b.dice = a.dice;
                        b.customSpriteGeometry = a.customSpriteGeometry;                                 // mutually exclusive
                        b.diceUnitX            = a.diceUnitX;
                        b.diceUnitY            = a.diceUnitY;
                    });
                }
                else
                {
                    HandleMultiSelection(entries, (a, b) => a.dice == b.dice, (a, b) => b.dice = a.dice);
                }
            }

            // Pad amount
            param.pad = (tk2dSpriteCollectionDefinition.Pad)EditorGUILayout.EnumPopup("Pad method", param.pad);
            HandleMultiSelection(entries, (a, b) => a.pad == b.pad, (a, b) => b.pad = a.pad);

            // Extra padding
            param.extraPadding = EditorGUILayout.IntPopup("Extra Padding", param.extraPadding, extraPadAmountLabels, extraPadAmountValues);
            HandleMultiSelection(entries, (a, b) => a.extraPadding == b.extraPadding, (a, b) => b.extraPadding = a.extraPadding);
            GUILayout.FlexibleSpace();

            // Draw additional inspector
            textureEditor.DrawTextureInspector(param, spriteTexture);

            EditorGUILayout.EndVertical();
            EditorGUILayout.EndVertical();             // inspector

            // Defer delete to avoid messing about anything else
            if (doDelete)
            {
                foreach (var e in entries)
                {
                    SpriteCollection.textureRefs[e.index]   = null;
                    SpriteCollection.textureParams[e.index] = new tk2dSpriteCollectionDefinition();
                }
                SpriteCollection.Trim();
                if (editingSpriteSheet)
                {
                    host.OnSpriteCollectionChanged(true);
                }
                else
                {
                    host.OnSpriteCollectionChanged(false);
                }
            }

            if (doSelect)
            {
                List <int> spriteIdList = new List <int>();
                foreach (var e in entries)
                {
                    spriteIdList.Add(e.index);
                }
                host.SelectSpritesFromList(spriteIdList.ToArray());
            }

            if (doSelectSpriteSheet)
            {
                List <int> spriteIdList = new List <int>();
                foreach (var e in entries)
                {
                    spriteIdList.Add(e.index);
                }
                host.SelectSpritesInSpriteSheet(param.spriteSheetId, spriteIdList.ToArray());
            }
        }
        public bool Draw(List <SpriteCollectionEditorEntry> selectedEntries)
        {
            if (selectedEntries.Count == 0 || selectedEntries[0].type != SpriteCollectionEditorEntry.Type.Font)
            {
                return(false);
            }

            var entry = selectedEntries[selectedEntries.Count - 1];
            var font  = SpriteCollection.fonts[entry.index];

            bool doDelete = false;

            GUILayout.BeginHorizontal();

            // Body
            GUILayout.BeginVertical(tk2dEditorSkin.SC_BodyBackground, GUILayout.ExpandHeight(true), GUILayout.ExpandWidth(true));
            fontTextureScrollBar = GUILayout.BeginScrollView(fontTextureScrollBar);
            if (font.texture != null)
            {
                font.texture.filterMode = FilterMode.Point;
                int  border = 16;
                Rect rect   = GUILayoutUtility.GetRect(border + font.texture.width, border + font.texture.height, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
                tk2dGrid.Draw(rect);
                GUI.Label(new Rect(border + rect.x, border + rect.y, font.texture.width, font.texture.height), font.texture);
            }
            GUILayout.EndScrollView();
            GUILayout.EndVertical();

            // Inspector
            EditorGUIUtility.LookLikeControls(100.0f, 100.0f);
            fontEditorScrollBar = GUILayout.BeginScrollView(fontEditorScrollBar, GUILayout.ExpandHeight(true), GUILayout.Width(host.InspectorWidth));

            // Header
            GUILayout.BeginVertical(tk2dEditorSkin.SC_InspectorHeaderBG, GUILayout.ExpandWidth(true));
            Object newBmFont = EditorGUILayout.ObjectField("BM Font", font.bmFont, typeof(Object), false);

            if (newBmFont != font.bmFont)
            {
                font.texture = null;
                entry.name   = "Empty";
                font.bmFont  = newBmFont;
                if (newBmFont != null)
                {
                    string bmFontPath             = AssetDatabase.GetAssetPath(newBmFont);
                    tk2dEditor.Font.Info fontInfo = tk2dEditor.Font.Builder.ParseBMFont(bmFontPath);
                    if (fontInfo != null && fontInfo.texturePaths.Length > 0)
                    {
                        string path = System.IO.Path.GetDirectoryName(bmFontPath).Replace('\\', '/') + "/" + System.IO.Path.GetFileName(fontInfo.texturePaths[0]);;
                        font.texture = AssetDatabase.LoadAssetAtPath(path, typeof(Texture2D)) as Texture2D;
                    }

                    entry.name = font.Name;
                    host.OnSpriteCollectionSortChanged();
                }
            }
            GUILayout.BeginHorizontal();
            Texture2D newTexture = EditorGUILayout.ObjectField("Font Texture", font.texture, typeof(Texture2D), false) as Texture2D;

            if (newTexture != font.texture)
            {
                font.texture = newTexture;
                entry.name   = font.Name;
                host.OnSpriteCollectionSortChanged();
            }
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Delete", EditorStyles.miniButton))
            {
                doDelete = true;
            }
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();


            // Rest of inspector
            GUILayout.BeginVertical(tk2dEditorSkin.SC_InspectorBG, GUILayout.ExpandWidth(true));

            if (font.texture != null)
            {
                string assetPath = AssetDatabase.GetAssetPath(font.texture);
                if (assetPath.Length > 0)
                {
                    // make sure the source texture is npot and readable, and uncompressed
                    if (!tk2dSpriteCollectionBuilder.IsTextureImporterSetUp(assetPath))
                    {
                        if (tk2dGuiUtility.InfoBoxWithButtons(
                                "The texture importer needs to be reconfigured to be used as a font texture source. " +
                                "Please note that this will globally change this texture importer. ",
                                tk2dGuiUtility.WarningLevel.Info,
                                "Set up") != -1)
                        {
                            tk2dSpriteCollectionBuilder.ConfigureSpriteTextureImporter(assetPath);
                            AssetDatabase.ImportAsset(assetPath);
                        }
                    }
                }
            }

            if (SpriteCollection.AllowAltMaterials && SpriteCollection.altMaterials.Length > 1)
            {
                List <int>    altMaterialIndices = new List <int>();
                List <string> altMaterialNames   = new List <string>();
                for (int i = 0; i < SpriteCollection.altMaterials.Length; ++i)
                {
                    var mat = SpriteCollection.altMaterials[i];
                    if (mat == null)
                    {
                        continue;
                    }
                    altMaterialIndices.Add(i);
                    altMaterialNames.Add(mat.name);
                }
                font.materialId = EditorGUILayout.IntPopup("Material", font.materialId, altMaterialNames.ToArray(), altMaterialIndices.ToArray());
            }

            if (font.data == null || font.editorData == null)
            {
                if (tk2dGuiUtility.InfoBoxWithButtons(
                        "A data object is required to build a font. " +
                        "Please create one or drag an existing data object into the inspector slot.\n",
                        tk2dGuiUtility.WarningLevel.Info,
                        "Create") != -1)
                {
                    // make data folder
                    string root = SpriteCollection.GetOrCreateDataPath();

                    string name           = font.bmFont?font.bmFont.name:"Unknown Font";
                    string editorDataPath = tk2dGuiUtility.SaveFileInProject("Save Font Data", root, name, "prefab");
                    if (editorDataPath.Length > 0)
                    {
                        int    prefabOffset   = editorDataPath.ToLower().IndexOf(".prefab");
                        string dataObjectPath = editorDataPath.Substring(0, prefabOffset) + " data.prefab";

                        // Create data object
                        {
                            GameObject go = new GameObject();
                            go.AddComponent <tk2dFontData>();
                            tk2dEditorUtility.SetGameObjectActive(go, false);
        #if (UNITY_3_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4)
                            Object p = EditorUtility.CreateEmptyPrefab(dataObjectPath);
                            EditorUtility.ReplacePrefab(go, p);
        #else
                            Object p = PrefabUtility.CreateEmptyPrefab(dataObjectPath);
                            PrefabUtility.ReplacePrefab(go, p);
        #endif
                            GameObject.DestroyImmediate(go);
                            AssetDatabase.SaveAssets();
                            font.data = AssetDatabase.LoadAssetAtPath(dataObjectPath, typeof(tk2dFontData)) as tk2dFontData;
                        }

                        // Create editor object
                        {
                            GameObject go = new GameObject();
                            tk2dFont   f  = go.AddComponent <tk2dFont>();
                            f.proxyFont = true;
                            f.data      = font.data;
                            tk2dEditorUtility.SetGameObjectActive(go, false);

                                #if (UNITY_3_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4)
                            Object p = EditorUtility.CreateEmptyPrefab(editorDataPath);
                            EditorUtility.ReplacePrefab(go, p, ReplacePrefabOptions.ConnectToPrefab);
                                #else
                            Object p = PrefabUtility.CreateEmptyPrefab(editorDataPath);
                            PrefabUtility.ReplacePrefab(go, p, ReplacePrefabOptions.ConnectToPrefab);
                                #endif
                            GameObject.DestroyImmediate(go);

                            tk2dFont loadedFont = AssetDatabase.LoadAssetAtPath(editorDataPath, typeof(tk2dFont)) as tk2dFont;
                            tk2dEditorUtility.GetOrCreateIndex().AddOrUpdateFont(loadedFont);
                            tk2dEditorUtility.CommitIndex();

                            font.editorData = AssetDatabase.LoadAssetAtPath(editorDataPath, typeof(tk2dFont)) as tk2dFont;
                        }

                        entry.name = font.Name;
                        host.OnSpriteCollectionSortChanged();
                    }
                }
            }
            else
            {
                font.editorData = EditorGUILayout.ObjectField("Editor Data", font.editorData, typeof(tk2dFont), false) as tk2dFont;
                font.data       = EditorGUILayout.ObjectField("Font Data", font.data, typeof(tk2dFontData), false) as tk2dFontData;
            }

            if (font.data && font.editorData)
            {
                font.useGradient = EditorGUILayout.Toggle("Use Gradient", font.useGradient);
                if (font.useGradient)
                {
                    EditorGUI.indentLevel++;
                    Texture2D tex = EditorGUILayout.ObjectField("Gradient Tex", font.gradientTexture, typeof(Texture2D), false) as Texture2D;
                    if (font.gradientTexture != tex)
                    {
                        font.gradientTexture = tex;

                        List <Material> materials = new List <Material>();
                        materials.Add(SpriteCollection.altMaterials[font.materialId]);

                        for (int j = 0; j < SpriteCollection.platforms.Count; ++j)
                        {
                            if (!SpriteCollection.platforms[j].Valid)
                            {
                                continue;
                            }
                            tk2dSpriteCollection data = SpriteCollection.platforms[j].spriteCollection;
                            materials.Add(data.altMaterials[font.materialId]);
                        }

                        for (int j = 0; j < materials.Count; ++j)
                        {
                            if (!materials[j].HasProperty("_GradientTex"))
                            {
                                Debug.LogError(string.Format("Cant find parameter '_GradientTex' in material '{0}'", materials[j].name));
                            }
                            else if (materials[j].GetTexture("_GradientTex") != tex)
                            {
                                materials[j].SetTexture("_GradientTex", font.gradientTexture);
                                EditorUtility.SetDirty(materials[j]);
                            }
                        }
                    }

                    font.gradientCount = EditorGUILayout.IntField("Gradient Count", font.gradientCount);
                    EditorGUI.indentLevel--;
                }
            }

            //font.dupeCaps = EditorGUILayout.Toggle("Dupe caps", font.dupeCaps);
            font.flipTextureY = EditorGUILayout.Toggle("Flip Texture Y", font.flipTextureY);
            font.charPadX     = EditorGUILayout.IntField("Char Pad X", font.charPadX);

            GUILayout.EndVertical();
            GUILayout.EndScrollView();

            // make dragable
            tk2dPreferences.inst.spriteCollectionInspectorWidth -= (int)tk2dGuiUtility.DragableHandle(4819284, GUILayoutUtility.GetLastRect(), 0, tk2dGuiUtility.DragDirection.Horizontal);

            GUILayout.EndHorizontal();

            if (doDelete &&
                EditorUtility.DisplayDialog("Delete sprite", "Are you sure you want to delete the selected font?", "Yes", "No"))
            {
                font.active  = false;
                font.bmFont  = null;
                font.data    = null;
                font.texture = null;
                SpriteCollection.Trim();
                host.OnSpriteCollectionChanged(false);
            }

            return(true);
        }
        public bool Draw(List <SpriteCollectionEditorEntry> selectedEntries)
        {
            if (selectedEntries.Count == 0 || selectedEntries[0].type != SpriteCollectionEditorEntry.Type.Font)
            {
                return(false);
            }

            var entry = selectedEntries[selectedEntries.Count - 1];
            var font  = SpriteCollection.fonts[entry.index];

            bool doDelete = false;

            GUILayout.BeginHorizontal();

            // Body
            GUILayout.BeginVertical(tk2dEditorSkin.SC_BodyBackground, GUILayout.ExpandHeight(true), GUILayout.ExpandWidth(true));
            if (font.texture != null)
            {
                font.texture.filterMode = FilterMode.Point;
                GUILayout.Label(font.texture);
            }
            GUILayout.EndVertical();

            // Inspector
            EditorGUIUtility.LookLikeControls(100.0f, 100.0f);
            fontEditorScrollBar = GUILayout.BeginScrollView(fontEditorScrollBar, GUILayout.ExpandHeight(true), GUILayout.Width(host.InspectorWidth));

            // Header
            GUILayout.BeginVertical(tk2dEditorSkin.SC_InspectorHeaderBG, GUILayout.ExpandWidth(true));
            Object newBmFont = EditorGUILayout.ObjectField("BM Font", font.bmFont, typeof(Object), false);

            if (newBmFont != font.bmFont)
            {
                font.bmFont = newBmFont;
                entry.name  = font.Name;
                host.OnSpriteCollectionSortChanged();
            }
            GUILayout.BeginHorizontal();
            Texture2D newTexture = EditorGUILayout.ObjectField("Font Texture", font.texture, typeof(Texture2D), false) as Texture2D;

            if (newTexture != font.texture)
            {
                font.texture = newTexture;
                entry.name   = font.Name;
                host.OnSpriteCollectionSortChanged();
            }
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Delete", EditorStyles.miniButton))
            {
                doDelete = true;
            }
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();


            // Rest of inspector
            GUILayout.BeginVertical(tk2dEditorSkin.SC_InspectorBG, GUILayout.ExpandWidth(true));

            if (font.texture != null)
            {
                string assetPath = AssetDatabase.GetAssetPath(font.texture);
                if (assetPath.Length > 0)
                {
                    // make sure the source texture is npot and readable, and uncompressed
                    if (!tk2dSpriteCollectionBuilder.IsTextureImporterSetUp(assetPath))
                    {
                        if (tk2dGuiUtility.InfoBoxWithButtons(
                                "The texture importer needs to be reconfigured to be used as a font texture source. " +
                                "Please note that this will globally change this texture importer. ",
                                tk2dGuiUtility.WarningLevel.Info,
                                "Set up") != -1)
                        {
                            tk2dSpriteCollectionBuilder.ConfigureSpriteTextureImporter(assetPath);
                            AssetDatabase.ImportAsset(assetPath);
                        }
                    }
                }
            }

            if (font.data == null || font.editorData == null)
            {
                if (tk2dGuiUtility.InfoBoxWithButtons(
                        "A data object is required to build a font. " +
                        "Please create one or drag an existing data object into the inspector slot.\n",
                        tk2dGuiUtility.WarningLevel.Info,
                        "Create") != -1)
                {
                    string name           = font.bmFont?font.bmFont.name:"Unknown Font";
                    string editorDataPath = EditorUtility.SaveFilePanelInProject("Save Font Data", name, "prefab", "");
                    if (editorDataPath.Length > 0)
                    {
                        int    prefabOffset   = editorDataPath.ToLower().IndexOf(".prefab");
                        string dataObjectPath = editorDataPath.Substring(0, prefabOffset) + "data.prefab";


                        // Create data object
                        {
                            GameObject go = new GameObject();
                            go.AddComponent <tk2dFontData>();
                            go.active = false;
        #if (UNITY_3_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4)
                            Object p = EditorUtility.CreateEmptyPrefab(dataObjectPath);
                            EditorUtility.ReplacePrefab(go, p);
        #else
                            Object p = PrefabUtility.CreateEmptyPrefab(dataObjectPath);
                            PrefabUtility.ReplacePrefab(go, p);
        #endif
                            GameObject.DestroyImmediate(go);
                            AssetDatabase.SaveAssets();
                            font.data = AssetDatabase.LoadAssetAtPath(dataObjectPath, typeof(tk2dFontData)) as tk2dFontData;
                        }

                        // Create editor object
                        {
                            GameObject go = new GameObject();
                            tk2dFont   f  = go.AddComponent <tk2dFont>();
                            f.proxyFont = true;
                            f.data      = font.data;
                            go.active   = false;

                                #if (UNITY_3_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4)
                            Object p = EditorUtility.CreateEmptyPrefab(editorDataPath);
                            EditorUtility.ReplacePrefab(go, p, ReplacePrefabOptions.ConnectToPrefab);
                                #else
                            Object p = PrefabUtility.CreateEmptyPrefab(editorDataPath);
                            PrefabUtility.ReplacePrefab(go, p, ReplacePrefabOptions.ConnectToPrefab);
                                #endif
                            GameObject.DestroyImmediate(go);

                            tk2dEditorUtility.GetOrCreateIndex().AddFont(AssetDatabase.LoadAssetAtPath(editorDataPath, typeof(tk2dFont)) as tk2dFont);
                            tk2dEditorUtility.CommitIndex();

                            font.editorData = AssetDatabase.LoadAssetAtPath(editorDataPath, typeof(tk2dFont)) as tk2dFont;
                        }

                        entry.name = font.Name;
                        host.OnSpriteCollectionSortChanged();
                    }
                }
            }
            else
            {
                font.editorData = EditorGUILayout.ObjectField("Editor Data", font.editorData, typeof(tk2dFont), false) as tk2dFont;
                font.data       = EditorGUILayout.ObjectField("Font Data", font.data, typeof(tk2dFontData), false) as tk2dFontData;
            }

            //font.dupeCaps = EditorGUILayout.Toggle("Dupe caps", font.dupeCaps);
            font.flipTextureY = EditorGUILayout.Toggle("Flip Texture Y", font.flipTextureY);
            font.charPadX     = EditorGUILayout.IntField("Char Pad X", font.charPadX);

            GUILayout.EndVertical();
            GUILayout.EndScrollView();

            GUILayout.EndHorizontal();

            if (doDelete &&
                EditorUtility.DisplayDialog("Delete sprite", "Are you sure you want to delete the selected font?", "Yes", "No"))
            {
                font.active  = false;
                font.bmFont  = null;
                font.data    = null;
                font.texture = null;
                SpriteCollection.Trim();
                host.OnSpriteCollectionChanged(false);
            }

            return(true);
        }