public void Commit()
 {
     spriteCollectionProxy.CopyToTarget();
     tk2dSpriteCollectionBuilder.ResetCurrentBuild();
     tk2dSpriteCollectionBuilder.Rebuild(_spriteCollection);
     spriteCollectionProxy.CopyFromSource();
 }
 public void Commit()
 {
     spriteCollectionProxy.DeleteUnusedData();
     spriteCollectionProxy.CopyToTarget();
     tk2dSpriteCollectionBuilder.ResetCurrentBuild();
     if (!tk2dSpriteCollectionBuilder.Rebuild(_spriteCollection))
     {
         EditorUtility.DisplayDialog("Failed to commit sprite collection",
                                     "Please check the console for more details.", "Ok");
     }
     spriteCollectionProxy.CopyFromSource();
 }
Esempio n. 3
0
    void DrawToolbar()
    {
        GUILayout.BeginHorizontal(EditorStyles.toolbar, GUILayout.ExpandWidth(true));

        // LHS
        GUILayout.BeginHorizontal(GUILayout.Width(leftBarWidth - 6));

        // Create Button
        GUIContent createButton     = new GUIContent("Create");
        Rect       createButtonRect = GUILayoutUtility.GetRect(createButton, EditorStyles.toolbarDropDown, GUILayout.ExpandWidth(false));

        if (GUI.Button(createButtonRect, createButton, EditorStyles.toolbarDropDown))
        {
            GUIUtility.hotControl = 0;
            GUIContent[] menuItems = new GUIContent[] {
                new GUIContent("Sprite Sheet"),
                new GUIContent("Font")
            };

            EditorUtility.DisplayCustomMenu(createButtonRect, menuItems, -1,
                                            delegate(object userData, string[] options, int selected) {
                switch (selected)
                {
                case 0:
                    int addedSpriteSheetIndex = spriteCollectionProxy.FindOrCreateEmptySpriteSheetSlot();
                    searchFilter = "";
                    PopulateEntries();
                    foreach (var entry in entries)
                    {
                        if (entry.type == SpriteCollectionEditorEntry.Type.SpriteSheet && entry.index == addedSpriteSheetIndex)
                        {
                            entry.selected = true;
                        }
                    }
                    UpdateSelection();
                    break;

                case 1:
                    if (SpriteCollection.allowMultipleAtlases)
                    {
                        EditorUtility.DisplayDialog("Create Font",
                                                    "Adding fonts to sprite collections isn't allowed when multi atlas spanning is enabled. " +
                                                    "Please disable it and try again.", "Ok");
                    }
                    else
                    {
                        int addedFontIndex = spriteCollectionProxy.FindOrCreateEmptyFontSlot();
                        searchFilter       = "";
                        PopulateEntries();
                        foreach (var entry in entries)
                        {
                            if (entry.type == SpriteCollectionEditorEntry.Type.Font && entry.index == addedFontIndex)
                            {
                                entry.selected = true;
                            }
                        }
                        UpdateSelection();
                    }
                    break;
                }
            }
                                            , null);
        }

        // Filter box
        GUILayout.Space(8);
        string newSearchFilter = GUILayout.TextField(searchFilter, tk2dEditorSkin.ToolbarSearch, GUILayout.ExpandWidth(true));

        if (newSearchFilter != searchFilter)
        {
            searchFilter = newSearchFilter;
            PopulateEntries();
        }
        if (searchFilter.Length > 0)
        {
            if (GUILayout.Button("", tk2dEditorSkin.ToolbarSearchClear, GUILayout.ExpandWidth(false)))
            {
                searchFilter = "";
                PopulateEntries();
            }
        }
        else
        {
            GUILayout.Label("", tk2dEditorSkin.ToolbarSearchRightCap);
        }
        GUILayout.EndHorizontal();

        // Label
        if (_spriteCollection != null)
        {
            GUILayout.Label(_spriteCollection.name);
        }

        // RHS
        GUILayout.FlexibleSpace();

        // Always in settings view when empty
        if (spriteCollectionProxy != null && spriteCollectionProxy.Empty)
        {
            GUILayout.Toggle(true, "Settings", EditorStyles.toolbarButton);
        }
        else
        {
            bool newSettingsView = GUILayout.Toggle(settingsView.show, "Settings", EditorStyles.toolbarButton);
            if (newSettingsView != settingsView.show)
            {
                ClearSelection();
                settingsView.show = newSettingsView;
            }
        }

        if (GUILayout.Button("Revert", EditorStyles.toolbarButton) && spriteCollectionProxy != null)
        {
            spriteCollectionProxy.CopyFromSource();
            OnSpriteCollectionChanged(false);
        }

        if (GUILayout.Button("Commit", EditorStyles.toolbarButton) && spriteCollectionProxy != null)
        {
            spriteCollectionProxy.CopyToTarget();
            tk2dSpriteCollectionBuilder.ResetCurrentBuild();
            tk2dSpriteCollectionBuilder.Rebuild(_spriteCollection);
            spriteCollectionProxy.CopyFromSource();
        }

        GUILayout.EndHorizontal();
    }