Sprite Packer helpers.

Beispiel #1
0
        private Rect DoToolbarGUI()
        {
            Rect toolbarRect = new Rect(0, 0, position.width, k_ToolbarHeight);

            if (Event.current.type == EventType.Repaint)
            {
                EditorStyles.toolbar.Draw(toolbarRect, false, false, false, false);
            }

            bool wasEnabled = GUI.enabled;

            GUI.enabled = m_AtlasNames.Length > 0;
            toolbarRect = DoAlphaZoomToolbarGUI(toolbarRect);
            GUI.enabled = wasEnabled;

            Rect drawRect = new Rect(EditorGUI.kSpacing, 0, 0, k_ToolbarHeight);

            toolbarRect.width -= drawRect.x;

            using (new EditorGUI.DisabledScope(Application.isPlaying))
            {
                drawRect.width = EditorStyles.toolbarButton.CalcSize(PackerWindowStyle.packLabel).x;
                DrawToolBarWidget(ref drawRect, ref toolbarRect, (adjustedDrawRect) =>
                {
                    if (GUI.Button(adjustedDrawRect, PackerWindowStyle.packLabel, EditorStyles.toolbarButton))
                    {
                        Packer.RebuildAtlasCacheIfNeededInternal(EditorUserBuildSettings.activeBuildTarget, true, Packer.Execution.Normal);
                        m_SelectedSprite = null;
                        RefreshAtlasPageList();
                        RefreshState();
                    }
                });

                using (new EditorGUI.DisabledScope(Packer.SelectedPolicy == Packer.kDefaultPolicy))
                {
                    drawRect.x    += drawRect.width;
                    drawRect.width = EditorStyles.toolbarButton.CalcSize(PackerWindowStyle.repackLabel).x;
                    DrawToolBarWidget(ref drawRect, ref toolbarRect, (adjustedDrawRect) =>
                    {
                        if (GUI.Button(adjustedDrawRect, PackerWindowStyle.repackLabel, EditorStyles.toolbarButton))
                        {
                            Packer.RebuildAtlasCacheIfNeededInternal(EditorUserBuildSettings.activeBuildTarget, true, Packer.Execution.ForceRegroup);
                            m_SelectedSprite = null;
                            RefreshAtlasPageList();
                            RefreshState();
                        }
                    });
                }
            }

            const float kAtlasNameWidth = 100;
            const float kPagesWidth     = 70;
            const float kPolicyWidth    = 100;

            float viewAtlasWidth = GUI.skin.label.CalcSize(PackerWindowStyle.viewAtlasLabel).x;
            float totalWidth     = viewAtlasWidth + kAtlasNameWidth + kPagesWidth + kPolicyWidth;

            drawRect.x        += EditorGUI.kSpacing; // leave some space from previous control for cosmetic
            toolbarRect.width -= EditorGUI.kSpacing;
            float availableWidth = toolbarRect.width;

            using (new EditorGUI.DisabledScope(m_AtlasNames.Length == 0))
            {
                drawRect.x    += drawRect.width;
                drawRect.width = viewAtlasWidth / totalWidth * availableWidth;
                DrawToolBarWidget(ref drawRect, ref toolbarRect, (adjustedDrawArea) =>
                {
                    GUI.Label(adjustedDrawArea, PackerWindowStyle.viewAtlasLabel);
                });

                EditorGUI.BeginChangeCheck();
                drawRect.x    += drawRect.width;
                drawRect.width = kAtlasNameWidth / totalWidth * availableWidth;
                DrawToolBarWidget(ref drawRect, ref toolbarRect, (adjustedDrawArea) =>
                {
                    m_SelectedAtlas = EditorGUI.Popup(adjustedDrawArea, m_SelectedAtlas, m_AtlasNames, EditorStyles.toolbarPopup);
                });
                if (EditorGUI.EndChangeCheck())
                {
                    RefreshAtlasPageList();
                    m_SelectedSprite = null;
                }

                EditorGUI.BeginChangeCheck();
                drawRect.x    += drawRect.width;
                drawRect.width = kPagesWidth / totalWidth * availableWidth;
                DrawToolBarWidget(ref drawRect, ref toolbarRect, (adjustedDrawArea) =>
                {
                    m_SelectedPage = EditorGUI.Popup(adjustedDrawArea, m_SelectedPage, m_PageNames, EditorStyles.toolbarPopup);
                });

                if (EditorGUI.EndChangeCheck())
                {
                    m_SelectedSprite = null;
                }
            }

            EditorGUI.BeginChangeCheck();
            string[] policies       = Packer.Policies;
            int      selectedPolicy = Array.IndexOf(policies, Packer.SelectedPolicy);

            drawRect.x    += drawRect.width;
            drawRect.width = kPolicyWidth / totalWidth * availableWidth;
            DrawToolBarWidget(ref drawRect, ref toolbarRect, (adjustedDrawArea) =>
            {
                selectedPolicy = EditorGUI.Popup(adjustedDrawArea, selectedPolicy, policies, EditorStyles.toolbarPopup);
            });

            if (EditorGUI.EndChangeCheck())
            {
                Packer.SelectedPolicy = policies[selectedPolicy];
            }

            return(toolbarRect);
        }
Beispiel #2
0
 public static void RebuildAtlasCacheIfNeeded(BuildTarget target, bool displayProgressBar)
 {
     Packer.Execution execution = Packer.Execution.Normal;
     Packer.RebuildAtlasCacheIfNeeded(target, displayProgressBar, execution);
 }
Beispiel #3
0
        private Rect DoToolbarGUI()
        {
            Rect rect = new Rect(0f, 0f, base.position.width, 17f);

            if (Event.current.type == EventType.Repaint)
            {
                EditorStyles.toolbar.Draw(rect, false, false, false, false);
            }
            bool enabled = GUI.enabled;

            GUI.enabled = (this.m_AtlasNames.Length > 0);
            rect        = base.DoAlphaZoomToolbarGUI(rect);
            GUI.enabled = enabled;
            Rect rect2 = new Rect(5f, 0f, 0f, 17f);

            rect.width -= rect2.x;
            using (new EditorGUI.DisabledScope(Application.isPlaying))
            {
                rect2.width = EditorStyles.toolbarButton.CalcSize(PackerWindow.PackerWindowStyle.packLabel).x;
                SpriteUtilityWindow.DrawToolBarWidget(ref rect2, ref rect, delegate(Rect adjustedDrawRect)
                {
                    if (GUI.Button(adjustedDrawRect, PackerWindow.PackerWindowStyle.packLabel, EditorStyles.toolbarButton))
                    {
                        Packer.RebuildAtlasCacheIfNeeded(EditorUserBuildSettings.activeBuildTarget, true);
                        this.m_SelectedSprite = null;
                        this.RefreshAtlasPageList();
                        this.RefreshState();
                    }
                });
                using (new EditorGUI.DisabledScope(Packer.SelectedPolicy == Packer.kDefaultPolicy))
                {
                    rect2.x    += rect2.width;
                    rect2.width = EditorStyles.toolbarButton.CalcSize(PackerWindow.PackerWindowStyle.repackLabel).x;
                    SpriteUtilityWindow.DrawToolBarWidget(ref rect2, ref rect, delegate(Rect adjustedDrawRect)
                    {
                        if (GUI.Button(adjustedDrawRect, PackerWindow.PackerWindowStyle.repackLabel, EditorStyles.toolbarButton))
                        {
                            Packer.RebuildAtlasCacheIfNeeded(EditorUserBuildSettings.activeBuildTarget, true, Packer.Execution.ForceRegroup);
                            this.m_SelectedSprite = null;
                            this.RefreshAtlasPageList();
                            this.RefreshState();
                        }
                    });
                }
            }
            float x   = GUI.skin.label.CalcSize(PackerWindow.PackerWindowStyle.viewAtlasLabel).x;
            float num = x + 100f + 70f + 100f;

            rect2.x    += 5f;
            rect.width -= 5f;
            float width = rect.width;

            using (new EditorGUI.DisabledScope(this.m_AtlasNames.Length == 0))
            {
                rect2.x    += rect2.width;
                rect2.width = x / num * width;
                SpriteUtilityWindow.DrawToolBarWidget(ref rect2, ref rect, delegate(Rect adjustedDrawArea)
                {
                    GUI.Label(adjustedDrawArea, PackerWindow.PackerWindowStyle.viewAtlasLabel);
                });
                EditorGUI.BeginChangeCheck();
                rect2.x    += rect2.width;
                rect2.width = 100f / num * width;
                SpriteUtilityWindow.DrawToolBarWidget(ref rect2, ref rect, delegate(Rect adjustedDrawArea)
                {
                    this.m_SelectedAtlas = EditorGUI.Popup(adjustedDrawArea, this.m_SelectedAtlas, this.m_AtlasNames, EditorStyles.toolbarPopup);
                });
                if (EditorGUI.EndChangeCheck())
                {
                    this.RefreshAtlasPageList();
                    this.m_SelectedSprite = null;
                }
                EditorGUI.BeginChangeCheck();
                rect2.x    += rect2.width;
                rect2.width = 70f / num * width;
                SpriteUtilityWindow.DrawToolBarWidget(ref rect2, ref rect, delegate(Rect adjustedDrawArea)
                {
                    this.m_SelectedPage = EditorGUI.Popup(adjustedDrawArea, this.m_SelectedPage, this.m_PageNames, EditorStyles.toolbarPopup);
                });
                if (EditorGUI.EndChangeCheck())
                {
                    this.m_SelectedSprite = null;
                }
            }
            EditorGUI.BeginChangeCheck();
            string[] policies       = Packer.Policies;
            int      selectedPolicy = Array.IndexOf <string>(policies, Packer.SelectedPolicy);

            rect2.x    += rect2.width;
            rect2.width = 100f / num * width;
            SpriteUtilityWindow.DrawToolBarWidget(ref rect2, ref rect, delegate(Rect adjustedDrawArea)
            {
                selectedPolicy = EditorGUI.Popup(adjustedDrawArea, selectedPolicy, policies, EditorStyles.toolbarPopup);
            });
            if (EditorGUI.EndChangeCheck())
            {
                Packer.SelectedPolicy = policies[selectedPolicy];
            }
            return(rect);
        }
Beispiel #4
0
 internal static void ExecuteSelectedPolicy(BuildTarget target, int[] textureImporterInstanceIDs)
 {
     Packer.RegenerateList();
     (Activator.CreateInstance(Packer.m_policyTypeCache[Packer.m_selectedPolicy]) as IPackerPolicy).OnGroupAtlases(target, new PackerJob(), textureImporterInstanceIDs);
 }