Esempio n. 1
0
        private void DrawExportAdvancedOptions()
        {
            bool wasEnabled = GUI.enabled;

            if (exportPreset == ExportPreset.Custom)
            {
                GUI.enabled = true;
            }
            else
            {
                GUI.enabled = false;
            }

            EditorGUILayout.BeginVertical(EditorStyles.helpBox);

            GUILayout.Label("Models:", EditorStyles.miniBoldLabel);
            modelFormat = (ModelFormat)EditorGUILayout.EnumPopup("ModelFormat:", modelFormat);

            GUILayout.Label("Textures:", EditorStyles.miniBoldLabel);
            textureFormat    = (TextureFormat)EditorGUILayout.EnumPopup("TextureFormat:", textureFormat);
            textureType      = (TextureType)EditorGUILayout.EnumPopup("TextureType:", textureType);
            textureScaleMode = (MA_TextureUtils.TextureScaleMode)EditorGUILayout.EnumPopup("TextureScaleMode:", textureScaleMode);

            EditorGUILayout.EndVertical();

            GUI.enabled = wasEnabled;
        }
        private static void ExportAtlasPNG(MA_TextureAtlasserProAtlas atlas, TextureType textureType, MA_TextureUtils.TextureScaleMode scaleMode, string savePath = EXPORTASSETPATH)
        {
            if (atlas == null || atlas.textureQuads == null || atlas.textureGroupRegistration == null)
            {
                return;
            }

            //Foreach texture group
            for (int i = 0; i < atlas.textureGroupRegistration.Count; i++)
            {
                //Create new Texture Atlas
                Texture2D newTexture = new Texture2D((int)atlas.textureAtlasSize.x, (int)atlas.textureAtlasSize.y);
                newTexture.name = atlas.name + "_" + atlas.textureGroupRegistration[i].name;

                foreach (MA_TextureAtlasserProQuad q in atlas.textureQuads)
                {
                    if (q.textureGroups != null && q.textureGroups[i].texture != null)
                    {
                        //Create new texture part
                        Texture2D newTexturePart = (Texture2D)MA_Texture.MA_TextureUtils.ConvertToReadableTexture(q.textureGroups[i].texture);
                        //Scale it
                        newTexturePart = newTexturePart.MA_Scale2D((int)q.guiRect.width, (int)q.guiRect.height, scaleMode);
                        //Add it
                        newTexture = newTexture.MA_Combine2D(newTexturePart, (int)q.guiRect.x, (int)q.guiRect.y);
                    }
                }

                //Save it
                newTexture.MA_Save2D(newTexture.name, savePath);

                TextureImporter textureImporter = (TextureImporter)AssetImporter.GetAtPath(savePath + newTexture.name + ".png");
                textureImporter.textureType = TextureImporterType.Default;
                textureImporter.SaveAndReimport();
            }

            switch (textureType)
            {
            case TextureType.Default:
                break;

            case TextureType.Sprite:
                SetAtlasPNGSpriteSettings(atlas, textureType, savePath);
                break;

            case TextureType.SpriteSliced:
                SetAtlasPNGSpriteSettings(atlas, textureType, savePath);
                break;

            default:
                break;
            }

            //Refresh
            AssetDatabase.Refresh();
        }
        public static void ExportAtlasTextures(MA_TextureAtlasserProAtlas atlas, TextureFormat textureFormat, TextureType textureType, MA_TextureUtils.TextureScaleMode scaleMode, string savePath = EXPORTASSETPATH)
        {
            switch (textureFormat)
            {
            case TextureFormat.None:
                break;

            case TextureFormat.Png:
                ExportAtlasPNG(atlas, textureType, scaleMode, savePath);
                break;

            default:
                break;
            }
        }
Esempio n. 4
0
        private void OnGUI()
        {
            if (thisWindow == null)
            {
                GetCurrentWindow();
                return;
            }

            //Get current event
            Event e = ProcessEvents();

            if (isLoaded)
            {
                GUILayout.BeginArea(new Rect(MA_TextureAtlasserProUtils.VIEWOFFSET, MA_TextureAtlasserProUtils.VIEWOFFSET, position.width - (MA_TextureAtlasserProUtils.VIEWOFFSET * 2), position.height - (MA_TextureAtlasserProUtils.VIEWOFFSET * 2)));
                GUILayout.BeginVertical();


                if (curWindow != null && curWindow.textureAtlas != null)
                {
                    //Export
                    GUILayout.BeginVertical();

                    DrawExportPresetMenu();
                    DrawExportAdvancedOptions();

                    GUILayout.BeginHorizontal(EditorStyles.helpBox);

                    switch (exportPreset)
                    {
                    case ExportPreset.Custom:
                        break;

                    case ExportPreset.Default:
                        modelFormat      = ModelFormat.Obj;
                        textureFormat    = TextureFormat.Png;
                        textureType      = TextureType.Default;
                        textureScaleMode = MA_TextureUtils.TextureScaleMode.Bilinear;
                        break;

                    case ExportPreset.Sprites:
                        modelFormat      = ModelFormat.None;
                        textureFormat    = TextureFormat.Png;
                        textureType      = TextureType.SpriteSliced;
                        textureScaleMode = MA_TextureUtils.TextureScaleMode.Bilinear;
                        break;

                    case ExportPreset.ReplaceObjMeshes:
                        modelFormat      = ModelFormat.ReplaceObj;
                        textureFormat    = TextureFormat.Png;
                        textureType      = TextureType.Default;
                        textureScaleMode = MA_TextureUtils.TextureScaleMode.Bilinear;
                        break;

                    default:
                        break;
                    }

                    if (GUILayout.Button("Export", GUILayout.ExpandWidth(true), GUILayout.Height(37)))
                    {
                        MA_TextureAtlasserProUtils.ExportAtlasModels(curWindow.textureAtlas, modelFormat);
                        MA_TextureAtlasserProUtils.ExportAtlasTextures(curWindow.textureAtlas, textureFormat, textureType, textureScaleMode);
                    }

                    GUILayout.EndHorizontal();
                    GUILayout.EndVertical();
                }
                else if (curWindow == null)
                {
                    GUI.backgroundColor = Color.red;
                    GUILayout.Box("Error: Link with the Texture Atlas Editor lost!", EditorStyles.helpBox);
                    if (GUILayout.Button("Link Atlas Editor", GUILayout.ExpandWidth(true), GUILayout.Height(37)))
                    {
                        curWindow = (MA_TextureAtlasserProWindow)EditorWindow.GetWindow <MA_TextureAtlasserProWindow>();
                    }
                    GUI.backgroundColor = Color.white;
                }
                else if (curWindow.textureAtlas == null)
                {
                    GUI.backgroundColor = Color.red;
                    GUILayout.Box("Error: No Texture Atlas found make sure to open one!", EditorStyles.helpBox);
                    GUI.backgroundColor = Color.white;
                }

                GUILayout.EndVertical();
                GUILayout.EndArea();
            }

            if (e.type == EventType.Repaint)
            {
                isLoaded = true;
            }
        }