CreateSprites() static private method

Create a list of sprites using the specified list of textures.
static private CreateSprites ( List textures ) : List
textures List
return List
コード例 #1
0
    private static Texture2D UpdateUIAtlas(UIAtlas atlas, List <Texture2D> textures, ref int?size, out int minSize, UITexturePacker.FreeRectChoiceHeuristic heuristic)
    {
        Debug.Log("***************** Updating atlas " + atlas.name + " - " + DateTime.Now);
        Rect[]    texRects;
        Texture2D newTexture = CreateTexture(textures.ToArray(), ref size, 1, out texRects, out minSize, heuristic);
        List <UIAtlasMaker.SpriteEntry> sprites = UIAtlasMaker.CreateSprites(textures.Cast <Texture>().ToList());

        for (int i = 0; i < sprites.Count; i++)
        {
            Rect rect = NGUIMath.ConvertToPixels(texRects[i], newTexture.width, newTexture.height, true);

            UIAtlasMaker.SpriteEntry se = sprites[i];
            se.x      = Mathf.RoundToInt(rect.x);
            se.y      = Mathf.RoundToInt(rect.y);
            se.width  = Mathf.RoundToInt(rect.width);
            se.height = Mathf.RoundToInt(rect.height);
        }

        // Replace the sprites within the atlas
        UIAtlasMaker.ReplaceSprites(atlas, sprites);

        // Release the temporary textures
        UIAtlasMaker.ReleaseSprites(sprites);

        return(newTexture);
    }
コード例 #2
0
    /// <summary>
    /// Update the sprites within the texture atlas, preserving the sprites that have not been selected.
    /// </summary>

    void UpdateAtlas(UIAtlas atlas, List <Texture> textures, bool keepSprites)
    {
        // Create a list of sprites using the collected textures
        List <UIAtlasMaker.SpriteEntry> sprites = UIAtlasMaker.CreateSprites(textures);

        if (sprites.Count > 0)
        {
            // Extract sprites from the atlas, filling in the missing pieces
            if (keepSprites)
            {
                UIAtlasMaker.ExtractSprites(atlas, sprites);
            }

            // NOTE: It doesn't seem to be possible to undo writing to disk, and there also seems to be no way of
            // detecting an Undo event. Without either of these it's not possible to restore the texture saved to disk,
            // so the undo process doesn't work right. Because of this I'd rather disable it altogether until a solution is found.

            // The ability to undo this action is always useful
            //NGUIEditorTools.RegisterUndo("Update Atlas", UISettings.atlas, UISettings.atlas.texture, UISettings.atlas.material);

            // Update the atlas
            UIAtlasMaker.UpdateAtlas(atlas, sprites);
        }
        else if (!keepSprites)
        {
            UIAtlasMaker.UpdateAtlas(atlas, sprites);
        }
    }
コード例 #3
0
    /* public - [Event] Function
     * 프랜드 객체가 호출(For Friend class call)*/

    // ========================================================================== //

    #region Protected

    /* protected - [abstract & virtual]         */

    /* protected - [Event] Function
     * 자식 객체가 호출(For Child class call)		*/

    /* protected - Override & Unity API         */

    #endregion Protected

    // ========================================================================== //

    #region Private

    /* private - [Proc] Function
     * 로직을 처리(Process Local logic)           */

    static private void MakeAtlas(string strPath)
    {
        string     strPath_Mat    = strPath + ".mat";
        string     strPath_Prefab = strPath + ".prefab";
        GameObject pObjectAtlas   = AssetDatabase.LoadAssetAtPath(strPath_Prefab, typeof(GameObject)) as GameObject;
        Texture    pTextureAtlas  = null;

        if (pObjectAtlas == null)
        {
            Material mat = null;

            Shader shader = Shader.Find(NGUISettings.atlasPMA ? "Unlit/Premultiplied Colored" : "Unlit/Transparent Colored");
            mat = new Material(shader);

            // Save the material
            AssetDatabase.CreateAsset(mat, strPath_Mat);
            AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport);

            // Load the material so it's usable
            mat = AssetDatabase.LoadAssetAtPath(strPath_Mat, typeof(Material)) as Material;

            // Create a new prefab for the atlas
            Object prefab = PrefabUtility.CreateEmptyPrefab(strPath_Prefab);

            // Create a new game object for the atlas
            string atlasName = strPath_Prefab.Replace(".prefab", "");
            atlasName    = atlasName.Substring(strPath.LastIndexOfAny(new char[] { '/', '\\' }) + 1);
            pObjectAtlas = new GameObject(atlasName);
            pObjectAtlas.AddComponent <UIAtlas>().spriteMaterial = mat;

            // Update the prefab
            PrefabUtility.ReplacePrefab(pObjectAtlas, prefab);

            UnityEngine.GameObject.DestroyImmediate(pObjectAtlas);
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport);

            // Select the atlas
            pObjectAtlas       = AssetDatabase.LoadAssetAtPath(strPath_Prefab, typeof(GameObject)) as GameObject;
            NGUISettings.atlas = pObjectAtlas.GetComponent <UIAtlas>();
        }
        else
        {
            pTextureAtlas = pObjectAtlas.GetComponent <UIAtlas>().texture;
        }

        List <Texture> listTexture = GetAllTextureInFolder(strPath, pTextureAtlas);
        List <UIAtlasMaker.SpriteEntry> listSprite = UIAtlasMaker.CreateSprites(listTexture);

        UIAtlasMaker.ExtractSprites(NGUISettings.atlas, listSprite);
        UIAtlasMaker.UpdateAtlas(NGUISettings.atlas, listSprite);

        //for (int i = 0; i < listTexture.Count; i++)
        //	Debug.Log( listTexture[i].name );
    }
コード例 #4
0
    private bool DrawAdvancedMenu()
    {
        if (Application.isPlaying == true)
        {
            return(true);
        }

        if (NGUIEditorTools.DrawHeader("Advanced menu") == false)
        {
            return(true);
        }

        NGUIEditorTools.BeginContents();
        GUILayout.BeginVertical();

        GUILayout.BeginHorizontal();
        _texToSprite = EditorGUILayout.ObjectField(_texToSprite, typeof(Texture), false) as Texture;

        if (GUILayout.Button("Add", GUILayout.Width(40f)))
        {
            if (_texToSprite == null)
            {
                Debug.LogError("Select a texture first.");
                return(false);
            }

            UIAtlas curAtlas = GetAtlas();

            if (curAtlas == null)
            {
                if (CreateOwnAtlas() == false)
                {
                    return(false);
                }

                curAtlas = GetAtlas();
            }

            List <UIAtlasMaker.SpriteEntry> entries = UIAtlasMaker.CreateSprites(new List <Texture>()
            {
                _texToSprite
            });
            UIAtlasMaker.ExtractSprites(curAtlas, entries);
            UIAtlasMaker.UpdateAtlas(curAtlas, entries);

            SelectSprite(_texToSprite.name);

            return(false);
        }

        if (GUILayout.Button("New") == true)
        {
            if (_texToSprite == null)
            {
                Debug.LogError("Select a texture first.");
                return(false);
            }

            if (CreateOwnAtlas() == false)
            {
                return(false);
            }

            UIAtlas curAtlas = GetAtlas();

            List <UIAtlasMaker.SpriteEntry> entries = UIAtlasMaker.CreateSprites(new List <Texture>()
            {
                _texToSprite
            });
            UIAtlasMaker.ExtractSprites(curAtlas, entries);
            UIAtlasMaker.UpdateAtlas(curAtlas, entries);

            SelectSprite(_texToSprite.name);

            return(false);
        }

        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        if (GUILayout.Button("Delete sprite") == true)
        {
            UIAtlas curAtlas   = GetAtlas();
            string  curSprName = GetSpriteName();

            if (curAtlas == null)
            {
                Debug.LogError("No atlas in this UISprite");
                return(false);
            }

            if (string.IsNullOrEmpty(curSprName) == true)
            {
                Debug.LogError("No sprite in this UISprite");
                return(false);
            }

            List <UIAtlasMaker.SpriteEntry> lstSprites = new List <UIAtlasMaker.SpriteEntry>();
            UIAtlasMaker.ExtractSprites(curAtlas, lstSprites);

            for (int i = lstSprites.Count; i > 0;)
            {
                UIAtlasMaker.SpriteEntry entry = lstSprites[--i];

                if (entry.name == curSprName)
                {
                    lstSprites.RemoveAt(i);
                }
            }
            UIAtlasMaker.UpdateAtlas(curAtlas, lstSprites);
            NGUIEditorTools.RepaintSprites();

            return(false);
        }

        if (GUILayout.Button("Atlas Maker") == true)
        {
            EditorWindow.GetWindow <UIAtlasMaker>(false, "Atlas Maker", true).Show();

            return(false);
        }

        GUILayout.EndHorizontal();

        GUILayout.EndVertical();
        NGUIEditorTools.EndContents();

        return(true);
    }
コード例 #5
0
    protected override bool ShouldDrawProperties()
    {
        if (target == null)
        {
            return(false);
        }

        if (Application.isPlaying == false && NGUIEditorTools.DrawHeader("Tex to Spr"))
        {
            NGUIEditorTools.BeginContents();
            GUILayout.BeginHorizontal();

            if (NGUIEditorTools.DrawPrefixButton("Atlas"))
            {
                ComponentSelector.Show <UIAtlas>(OnSelectAtlas);
            }

            UIAtlas curAtlas = NGUISettings.atlas;

            if (curAtlas != null)
            {
                GUILayout.Label(curAtlas.name, "HelpBox", GUILayout.Height(18f));
            }
            else
            {
                GUILayout.Label("No Atlas", "HelpBox", GUILayout.Height(18f));
            }

            GUILayout.FlexibleSpace();

            if (GUILayout.Button("ToS", GUILayout.Width(40f)))
            {
                if (curAtlas == null)
                {
                    CreateOwnAtlas();

                    curAtlas = NGUISettings.atlas;
                }

                List <UIAtlasMaker.SpriteEntry> entries = UIAtlasMaker.CreateSprites(new List <Texture>()
                {
                    mTex.mainTexture
                });
                UIAtlasMaker.ExtractSprites(curAtlas, entries);
                UIAtlasMaker.UpdateAtlas(curAtlas, entries);

                UISprite sprite = mTex.gameObject.AddComponent <UISprite>();
                sprite.atlas      = curAtlas;
                sprite.spriteName = mTex.mainTexture.name;

                sprite.type = mTex.type;

                UISpriteData data = sprite.GetAtlasSprite();
                data.SetBorder((int)mTex.border.w, (int)mTex.border.y, (int)mTex.border.x, (int)mTex.border.z);

                sprite.depth  = mTex.depth;
                sprite.width  = mTex.width;
                sprite.height = mTex.height;

                UITexture.DestroyImmediate(mTex);

                EditorGUIUtility.ExitGUI();

                return(false);
            }

            GUILayout.EndHorizontal();
            NGUIEditorTools.EndContents();
        }

        SerializedProperty sp = NGUIEditorTools.DrawProperty("Texture", serializedObject, "mTexture");

        NGUIEditorTools.DrawProperty("Material", serializedObject, "mMat");

        if (sp != null)
        {
            NGUISettings.texture = sp.objectReferenceValue as Texture;
        }

        if (mTex != null && (mTex.material == null || serializedObject.isEditingMultipleObjects))
        {
            NGUIEditorTools.DrawProperty("Shader", serializedObject, "mShader");
        }

        EditorGUI.BeginDisabledGroup(mTex == null || mTex.mainTexture == null || serializedObject.isEditingMultipleObjects);

        NGUIEditorTools.DrawRectProperty("UV Rect", serializedObject, "mRect");

        sp = serializedObject.FindProperty("mFixedAspect");
        bool before = sp.boolValue;

        NGUIEditorTools.DrawProperty("Fixed Aspect", sp);
        if (sp.boolValue != before)
        {
            (target as UIWidget).drawRegion = new Vector4(0f, 0f, 1f, 1f);
        }

        if (sp.boolValue)
        {
            EditorGUILayout.HelpBox("Note that Fixed Aspect mode is not compatible with Draw Region modifications done by sliders and progress bars.", MessageType.Info);
        }

        EditorGUI.EndDisabledGroup();

        return(true);
    }
コード例 #6
0
    public static UIAtlas CreateAtlas(string atlasName, Device device, AtlasType atlasType)
    {
        List <UISpriteData> oldSpriteData;

#if RSATLASHELPER_DEBUG
        Debug.Log(string.Format("AddNewAtlas; atlasName = {0}, device = {1}, atlasType = {2}", atlasName, device, atlasType));
#endif

        string texturesDir = GetAtlasTexturesDirectory(atlasName, device, atlasType);

        DirectoryInfo dirInfo = new DirectoryInfo("Assets/" + texturesDir);
        if (dirInfo == null || !dirInfo.Exists)
        {
            Debug.LogWarning("Directory does not exist; " + atlasName + ", for device: " + device + " " + texturesDir);
            return(null);
        }
        List <FileInfo> fis;
        GetTextureAssets(dirInfo, out fis);

        if (fis == null && fis.Count == 0)
        {
            Debug.LogWarning("Directory empty; " + atlasName + ", for device: " + device);
            return(null);
        }

        UIAtlas newAtlas = CreateAtlasInternal(atlasName, device, atlasType, out oldSpriteData);
        if (newAtlas == null)
        {
            Debug.LogWarning("Could not create atlas for " + atlasName + ", device = " + device);
            return(null);
        }

        NGUISettings.atlas            = newAtlas;
        NGUISettings.atlasPadding     = 2;
        NGUISettings.atlasTrimming    = false;
        NGUISettings.forceSquareAtlas = true;
        NGUISettings.allow4096        = (atlasType == AtlasType.HD);
        NGUISettings.fontTexture      = null;
        NGUISettings.unityPacking     = false;

        if (device == Device.Tablet || device == Device.Standalone)
        {
            newAtlas.pixelSize = (atlasType == AtlasType.HD) ? 1f : 2f;
        }
        else
        {
            newAtlas.pixelSize = 1f;
        }

        EditorUtility.SetDirty(newAtlas.gameObject);

        List <Texture> textures = new List <Texture>();

        foreach (FileInfo fi in fis)
        {
            string textureName = "Assets" + texturesDir + fi.Name;

            Texture2D tex = AssetDatabase.LoadAssetAtPath(textureName, typeof(Texture2D)) as Texture2D;

            TextureImporter texImporter = AssetImporter.GetAtPath(textureName) as TextureImporter;
            texImporter.textureType         = TextureImporterType.Default;
            texImporter.npotScale           = TextureImporterNPOTScale.None;
            texImporter.generateCubemap     = TextureImporterGenerateCubemap.None;
            texImporter.normalmap           = false;
            texImporter.linearTexture       = true;
            texImporter.alphaIsTransparency = true;
            texImporter.convertToNormalmap  = false;
            texImporter.grayscaleToAlpha    = false;
            texImporter.lightmap            = false;
            texImporter.npotScale           = TextureImporterNPOTScale.None;
            texImporter.filterMode          = FilterMode.Point;
            texImporter.wrapMode            = TextureWrapMode.Clamp;
            texImporter.maxTextureSize      = 4096;
            texImporter.mipmapEnabled       = false;
            texImporter.textureFormat       = TextureImporterFormat.AutomaticTruecolor;
            AssetDatabase.ImportAsset(textureName, ImportAssetOptions.ForceUpdate);

            tex.filterMode = FilterMode.Bilinear;
            tex.wrapMode   = TextureWrapMode.Clamp;

            textures.Add(tex);

#if RSATLASHELPER_DEBUG
            Debug.Log("- added tex: " + textureName);
#endif
        }

        List <UIAtlasMaker.SpriteEntry> sprites = UIAtlasMaker.CreateSprites(textures);
        UIAtlasMaker.ExtractSprites(newAtlas, sprites);
        UIAtlasMaker.UpdateAtlas(newAtlas, sprites);
        AssetDatabase.SaveAssets();

        {
            string resourceDir = GetAtlasResourceFolder(device, atlasType);
            string atlasName2  = GetAtlasName(atlasName, device, atlasType);
            string newTex      = "Assets" + resourceDir + atlasName2 + ".png";

            TextureImporter texImporter    = AssetImporter.GetAtPath(newTex) as TextureImporter;
            int             maxTextureSize = atlasType == AtlasType.HD ? 4096 : 2048;
            texImporter.maxTextureSize = maxTextureSize;
            texImporter.textureFormat  = TextureImporterFormat.AutomaticCompressed;
            if (device == Device.Phone)
            {
                texImporter.mipmapEnabled = true;
                texImporter.borderMipmap  = true;
                texImporter.mipmapFilter  = TextureImporterMipFilter.BoxFilter;
            }
            else
            {
                texImporter.mipmapEnabled = false;
            }
            texImporter.alphaIsTransparency = true;
            texImporter.filterMode          = FilterMode.Bilinear;
            texImporter.wrapMode            = TextureWrapMode.Clamp;
            texImporter.anisoLevel          = 1;
            texImporter.SetPlatformTextureSettings("iPhone", maxTextureSize, TextureImporterFormat.PVRTC_RGBA4);
            texImporter.SetPlatformTextureSettings("Android", maxTextureSize, TextureImporterFormat.PVRTC_RGBA4);
            AssetDatabase.ImportAsset(newTex, ImportAssetOptions.ForceUpdate);
        }

        UpdateAtlasSpriteData(ref newAtlas, ref oldSpriteData);

#if RSATLASHELPER_DEBUG
        DebugAtlasSpriteData(ref newAtlas);
#endif

        newAtlas.MarkAsChanged();
        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();

        return(newAtlas);
    }
コード例 #7
0
    void OnInspectorUpdate()
    {
        bool refresh = false;

        switch (retinaProState.state)
        {
        default:
        case retinaProState.rpState.kWaiting:
            break;

        case retinaProState.rpState.kGen:
        {
            deviceIndex    = 0;
            fileIndex      = 0;
            progressPeriod = 0.0f;
            progressString = "Atlas " + genAtlasItem.atlasName;

#if RETINAPRO_DEBUGLOG
            Debug.Log(progressString);
#endif

            if (genAtlasItem.isFont)
            {
                retinaProState.state = retinaProState.rpState.kFont;
            }
            else
            {
                // create atlas that will be used as the reference for the device specific atlas
                UIAtlas atlasRef = retinaProNGTools.createAtlas(genAtlasItem.atlasName, null, out oldSpriteData);
                oldSpriteData = null;
                if (atlasRef == null)
                {
                    Debug.LogWarning("Could not create atlas reference for " + genAtlasItem.atlasName);
                    retinaProState.state = retinaProState.rpState.kDone;
                    break;
                }

                retinaProParent parent = atlasRef.gameObject.GetComponent <retinaProParent>();
                if (parent == null)
                {
                    atlasRef.gameObject.AddComponent <retinaProParent>();
                }

                EditorUtility.SetDirty(atlasRef.gameObject);
                retinaProState.state = retinaProState.rpState.kAtlas;
            }

            break;
        }


        case retinaProState.rpState.kAtlas: {
            retinaProDevice deviceItem = retinaProDataSerialize.sharedInstance.deviceList[deviceIndex];
            progressString       = "Atlas " + genAtlasItem.atlasName + " / " + deviceItem.name + " - Processing images";
            retinaProState.state = retinaProState.rpState.kAtlasProcess;
            break;
        }


        case retinaProState.rpState.kAtlasProcess: {
            retinaProDevice deviceItem = retinaProDataSerialize.sharedInstance.deviceList[deviceIndex];

#if RETINAPRO_DEBUGLOG
            Debug.Log("addNewAtlas; " + genAtlasItem.atlasName + ", for device: " + deviceItem.name + ", pixelSize = " + deviceItem.pixelSize);
#endif
            // gather textures for this atlas / device
            DirectoryInfo dinfo = new DirectoryInfo(retinaProFileLock.baseDataPath + retinaProConfig.atlasTextureFolder + deviceItem.name + "/" + genAtlasItem.atlasName);
            if (dinfo == null || !dinfo.Exists)
            {
                Debug.LogWarning("Folder does not exist; " + genAtlasItem.atlasName + ", for device: " + deviceItem.name + ", pixelSize = " + deviceItem.pixelSize);
            }
            else
            {
                List <FileInfo> fis;
                retinaProConfig.getValidArtFiles(dinfo, out fis);

                if (fis != null && fis.Count > 0)
                {
                    genAtlas = retinaProNGTools.createAtlas(genAtlasItem.atlasName, deviceItem.name, out oldSpriteData);
                    if (genAtlas == null)
                    {
                        Debug.LogWarning("Could not create atlas for " + genAtlasItem.atlasName + ", device = " + deviceItem.name);
                        retinaProState.state = retinaProState.rpState.kDone;
                        break;
                    }

                    NGUISettings.atlas         = genAtlas;
                    NGUISettings.atlasPadding  = genAtlasItem.atlasPadding;
                    NGUISettings.atlasTrimming = false;
                    NGUISettings.allow4096     = true;
                    NGUISettings.fontTexture   = null;
                    NGUISettings.unityPacking  = true;

                    genAtlas.pixelSize = deviceItem.pixelSize;
                    EditorUtility.SetDirty(genAtlas.gameObject);

                    // add all art files into the atlas (one-pass)
                    List <Texture> textures = new List <Texture>();

                    foreach (FileInfo fi in fis)
                    {
                        // check to see if this file has a corresponding .txt file (i.e. it's a font)
                        bool isFont = false;
                        {
                            string fontName = Path.GetFileNameWithoutExtension(fi.Name);
                            if (dinfo != null && dinfo.Exists)
                            {
                                FileInfo [] fontTextFile = dinfo.GetFiles(fontName + ".txt");
                                if (fontTextFile != null && fontTextFile.Length == 1)
                                {
                                    isFont = true;
                                }
                            }
                        }

                        if (isFont)
                        {
                            progressString = "Atlas " + genAtlasItem.atlasName + " / " + deviceItem.name + " - Fonts in a sprite atlas are not supported!";
                            string fontName = Path.GetFileNameWithoutExtension(fi.Name);
                            Debug.LogWarning("Fonts (" + fontName + ") in a sprite atlas is not supported. Use a font atlas instead, see the example scene.");
                        }
                        else
                        {
                            {
                                string textureName = "Assets" + retinaProConfig.atlasTextureFolder + deviceItem.name + "/" + genAtlasItem.atlasName + "/" + fi.Name;

                                // source texture
                                Texture2D tex = AssetDatabase.LoadAssetAtPath(textureName, typeof(Texture2D)) as Texture2D;
                                if (retinaProDataSerialize.sharedInstance.getUtilityRefreshSourceTextures())                                            // refresh importer settings on source texture?
                                // update texture importer settings on source artwork
                                // this ensures that we don't bring in assets into the atlas that are too small (for their given size)
                                {
                                    TextureImporter tImporter = AssetImporter.GetAtPath(textureName) as TextureImporter;
                                    if (tImporter != null)
                                    {
                                        tImporter.textureType         = TextureImporterType.Advanced;
                                        tImporter.normalmap           = false;
                                        tImporter.linearTexture       = true;
                                        tImporter.alphaIsTransparency = true;
                                        tImporter.convertToNormalmap  = false;
                                        tImporter.grayscaleToAlpha    = false;
                                        tImporter.lightmap            = false;
                                        tImporter.npotScale           = TextureImporterNPOTScale.None;
                                        tImporter.filterMode          = FilterMode.Point;
                                        tImporter.maxTextureSize      = 4096;
                                        tImporter.mipmapEnabled       = false;
                                        tImporter.textureFormat       = TextureImporterFormat.AutomaticTruecolor;
                                        AssetDatabase.ImportAsset(textureName, ImportAssetOptions.ForceUpdate);
                                    }
                                }

                                tex.filterMode = genAtlasItem.atlasFilterMode;
                                tex.wrapMode   = TextureWrapMode.Clamp;
                                textures.Add(tex);

#if RETINAPRO_DEBUGLOG
                                Debug.Log("- added tex: " + textureName);
#endif
                            }
                        }
                    }

                    List <UIAtlasMaker.SpriteEntry> sprites = UIAtlasMaker.CreateSprites(textures);
                    UIAtlasMaker.ExtractSprites(genAtlas, sprites);
                    UIAtlasMaker.UpdateAtlas(genAtlas, sprites);
                    AssetDatabase.SaveAssets();

                    // set texture filter mode
                    {
                        string          newTex    = "Assets" + retinaProConfig.atlasResourceFolder + deviceItem.name + "/" + genAtlasItem.atlasName + "~" + deviceItem.name + ".png";
                        TextureImporter tImporter = AssetImporter.GetAtPath(newTex) as TextureImporter;

                        if (tImporter != null)
                        {
                            tImporter.filterMode    = genAtlasItem.atlasFilterMode;
                            tImporter.textureFormat = genAtlasItem.atlasTextureFormat;
                            AssetDatabase.ImportAsset(newTex, ImportAssetOptions.ForceUpdate);
                        }
                    }

                    // restore the sprite data within the atlas
                    // update the new atlas with the old sprite data
                    retinaProNGTools.updateAtlasSpriteData(ref genAtlas, ref oldSpriteData);
#if RETINAPRO_DEBUGLOG
                    retinaProNGTools.debugAtlasSpriteData(ref genAtlas);
#endif

                    genAtlas.MarkAsChanged();
                    AssetDatabase.SaveAssets();
                    AssetDatabase.Refresh();


                    // continue with next device
                    deviceIndex++;
                    if (deviceIndex >= retinaProDataSerialize.sharedInstance.deviceList.Count)
                    {
                        retinaProState.state = retinaProState.rpState.kDone;
                        break;
                    }
                    else
                    {
                        retinaProState.state = retinaProState.rpState.kAtlas;
                    }

                    progressPortion = 0.0f;
                    break;
                }
            }
            break;
        }

        case retinaProState.rpState.kFont:
        {
            retinaProDevice deviceItem = retinaProDataSerialize.sharedInstance.deviceList[deviceIndex];

            DirectoryInfo dinfo = new DirectoryInfo(retinaProFileLock.baseDataPath + retinaProConfig.atlasTextureFolder + deviceItem.name + "/" + genAtlasItem.atlasName);
            if (dinfo == null || !dinfo.Exists)
            {
                Debug.LogWarning("Folder does not exist; " + genAtlasItem.atlasName + ", for device: " + deviceItem.name + ", pixelSize = " + deviceItem.pixelSize);
                retinaProState.state = retinaProState.rpState.kDone;
                break;
            }

            FileInfo [] fis    = dinfo.GetFiles("*.png");
            FileInfo [] fisTxt = dinfo.GetFiles("*.txt");

            if (fis == null || fis.Length != 1 || fisTxt == null || fisTxt.Length != 1)
            {
                Debug.LogWarning("Font atlases should contain two files; thefont.png / thefont.txt");
                fileIndex            = fis.Length;
                retinaProState.state = retinaProState.rpState.kDone;
                break;
            }

            FileInfo fi = fis[fileIndex];

            {
                string fontName = Path.GetFileNameWithoutExtension(fi.Name);
                progressString = "Atlas " + genAtlasItem.atlasName + " / " + deviceItem.name + " / " + fontName;

#if RETINAPRO_DEBUGLOG
                Debug.Log("addNewFont; " + fontName + ", for device: " + deviceItem.name + ", pixelSize = " + deviceItem.pixelSize);
#endif

                UIFont font = retinaProNGTools.createFont(genAtlasItem.atlasName, fontName, deviceItem.name);
                //font.pixelSize = deviceItem.pixelSize;
                EditorUtility.SetDirty(font.gameObject);

                // create the reference font version
                UIFont fontRef = retinaProNGTools.createFont(genAtlasItem.atlasName, fontName, null);
                fontRef.replacement = font;
                //fontRef.pixelSize = deviceItem.pixelSize;

                retinaProParent parent = fontRef.gameObject.GetComponent <retinaProParent>();
                if (parent == null)
                {
                    fontRef.gameObject.AddComponent <retinaProParent>();
                }

                EditorUtility.SetDirty(fontRef.gameObject);
            }

            // set texture filter mode
            {
                string          newTex    = "Assets" + retinaProConfig.atlasTextureFolder + deviceItem.name + "/" + genAtlasItem.atlasName + "/" + fis[0].Name;
                TextureImporter tImporter = AssetImporter.GetAtPath(newTex) as TextureImporter;

                if (tImporter != null)
                {
                    tImporter.filterMode    = genAtlasItem.atlasFilterMode;
                    tImporter.textureFormat = genAtlasItem.atlasTextureFormat;
                    AssetDatabase.ImportAsset(newTex, ImportAssetOptions.ForceUpdate);
                }
            }


            fileIndex++;
            if (fileIndex >= fis.Length)
            {
                fileIndex = 0;

                deviceIndex++;
                if (deviceIndex >= retinaProDataSerialize.sharedInstance.deviceList.Count)
                {
                    fileIndex            = fis.Length;
                    retinaProState.state = retinaProState.rpState.kDone;
                }
            }
            progressPortion = (((float)(fileIndex + 1)) / ((float)fis.Length));
            progressPortion = Mathf.Clamp01(progressPortion);
            break;
        }

        case retinaProState.rpState.kDone:
        {
            EditorUtility.ClearProgressBar();
            refresh = true;
            retinaProState.state = retinaProState.rpState.kWaiting;
            Repaint();
            break;
        }
        }

        if (refresh)
        {
#if RETINAPRO_DEBUGLOG
            Debug.Log("refresh called");
#endif
            int             idx = retinaProDataSerialize.sharedInstance.getPreviewDeviceIdx();
            retinaProDevice di  = retinaProDataSerialize.sharedInstance.deviceList[idx];
            if (di.isDeviceValid())
            {
                retinaProNGTools.refreshReferencesForDevice(di, retinaProDataSerialize.sharedInstance.getPreviewScreenIdx(), retinaProDataSerialize.sharedInstance.getPreviewGameViewIdx());
                retinaProNGTools.refresh();
            }
        }

        if (retinaProState.state != retinaProState.rpState.kWaiting)
        {
            Repaint();
        }
    }
コード例 #8
0
    private static void UpdateAtlas(DirectoryInfo dir)
    {
        FileInfo[] infos = dir.GetFiles();

        bool haveInfo = false;

        List <string> list = new List <string>();

        foreach (var item in infos)
        {
            if (item.FullName.Contains(".png") && !item.FullName.Contains(".png.meta"))
            {
                haveInfo = true;
                string str = "";
                str = item.FullName;
                str = str.Replace(@"\", @"/");
                str = str.Replace(Application.dataPath, "Assets");

                list.Add(str);
            }
        }

        if (!haveInfo)
        {
            DirectoryInfo[] infos1 = dir.GetDirectories();
            for (int i = 0; i < infos1.Length; i++)
            {
                GetNewAtlas(infos1[i]);
            }
            return;
        }


        List <Texture> texTures = new List <Texture>();

        for (int i = 0; i < list.Count; i++)
        {
            UnityEngine.Object obj = AssetDatabase.LoadAssetAtPath(list[i], typeof(Texture));
            FileImporterSetting.SetFileImporterSetting(EFileImporterSettingType.TextureForRGBA32, 1024, AssetDatabase.GetAssetPath(obj));
            texTures.Add(obj as Texture);
        }

        string dirPath = dir.FullName.Replace(@"\", @"/");

        dirPath = dirPath.Replace(Application.dataPath + "/BreakAtlasPic/", "Assets/TGameResources/");


        string[] dirPaths = dirPath.Split('/');

        dirPath = "Assets";
        for (int i = 1; i < dirPaths.Length - 1; i++)
        {
            dirPath += "/";
            dirPath += dirPaths[i];
        }


        UnityEngine.Object obj1 = AssetDatabase.LoadAssetAtPath(dirPath + "/" + dirPaths[dirPaths.Length - 1] + ".prefab", typeof(UIAtlas));
        ua = obj1 as UIAtlas;

        UIAtlasUtil.UncompressAtlas(dirPath + "/" + dirPaths[dirPaths.Length - 1] + ".prefab");

        FileImporterSetting.SetFileImporterSetting(EFileImporterSettingType.TextureForRGBA32, 1024, AssetDatabase.GetAssetPath(ua.spriteMaterial.mainTexture));


        spriteList = ua.spriteList;
        List <UIAtlasMaker.SpriteEntry> ui = UIAtlasMaker.CreateSprites(texTures);

        for (int i = 0; i < ui.Count; i++)
        {
            for (int j = 0; j < spriteList.Count; j++)
            {
                if (ui[i].name == spriteList[j].name)
                {
                    ui[i].borderLeft   = spriteList[j].borderLeft;
                    ui[i].borderRight  = spriteList[j].borderRight;
                    ui[i].borderBottom = spriteList[j].borderBottom;
                    ui[i].borderTop    = spriteList[j].borderTop;
                }
            }
        }

        for (int i = 0; i < ui.Count; i++)
        {
            UIAtlasMaker.AddOrUpdate(ua, ui[i]);
        }

        UIAtlasUtil.CompressAtlas(dirPath + "/" + dirPaths[dirPaths.Length - 1] + ".prefab");

        AssetDatabase.Refresh();
    }