コード例 #1
0
    // ------------------------------------------------------------------
    /// \param _sprites the list of sprites to rebuild
    /// rebuild the listed sprites
    // ------------------------------------------------------------------

    public static void RebuildSprites(exSpriteBase[] _sprites)
    {
        try {
            EditorUtility.DisplayProgressBar("Rebuild Scene Sprites...",
                                             "Rebuild Scene Sprites...",
                                             0.5f);

            for (int i = 0; i < _sprites.Length; ++i)
            {
                exSpriteBase spBase = _sprites[i];
                // DISABLE: it is too slow {
                // float progress = (float)i/(float)_sprites.Length;
                // EditorUtility.DisplayProgressBar( "Rebuild Scene Sprites...",
                //                                   "Build Sprite " + spBase.gameObject.name, progress );
                // } DISABLE end

                // if sprite
                if (spBase is exSprite)
                {
                    exSprite sp = spBase as exSprite;
                    exAtlasDB.ElementInfo elInfo = exAtlasDB.GetElementInfo(sp.textureGUID);
                    exSpriteEditor.UpdateAtlas(sp, elInfo);

                    Texture2D texture = null;
                    if (sp.useAtlas == false)
                    {
                        texture = exEditorHelper.LoadAssetFromGUID <Texture2D>(sp.textureGUID);
                    }
                    sp.Build(texture);
                }

#if !(EX2D_EVALUATE)
                // if sprite font
                if (spBase is exSpriteFont)
                {
                    exSpriteFont spFont = spBase as exSpriteFont;
                    spFont.Build();
                }

                // if sprite border
                if (spBase is exSpriteBorder)
                {
                    exSpriteBorder spBorder = spBase as exSpriteBorder;

                    Texture2D texture = null;
                    if (spBorder.guiBorder)
                    {
                        exAtlasDB.ElementInfo elInfo = exAtlasDB.GetElementInfo(spBorder.guiBorder.textureGUID);
                        exSpriteBorderEditor.UpdateAtlas(spBorder, elInfo);

                        if (spBorder.useAtlas == false)
                        {
                            texture = exEditorHelper.LoadAssetFromGUID <Texture2D>(spBorder.guiBorder.textureGUID);
                        }
                    }
                    spBorder.Build(texture);
                }
#endif // EX2D_EVALUATE
            }
            EditorUtility.ClearProgressBar();
        }
        catch (System.Exception) {
            EditorUtility.ClearProgressBar();
            throw;
        }
    }
コード例 #2
0
    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------

    public static void Rebuild(this exSpriteFont _spriteFont)
    {
        _spriteFont.Build();
    }
コード例 #3
0
    // ------------------------------------------------------------------
    /// \param _atlasInfoGUIDs the list of atlas info guid
    /// update sprites in current scene and in prefab by atlas info list
    // ------------------------------------------------------------------

    public static void UpdateSprites(List <string> _atlasInfoGUIDs)
    {
        if (_atlasInfoGUIDs.Count == 0)
        {
            return;
        }

        try {
            EditorUtility.DisplayProgressBar("Update Scene Sprites With Changed Atlas...", "Scanning...", 0.0f);
            // exSpriteBase[] sprites = GameObject.FindObjectsOfType(typeof(exSpriteBase)) as exSpriteBase[];
            exSpriteBase[] sprites = Resources.FindObjectsOfTypeAll(typeof(exSpriteBase)) as exSpriteBase[];
            for (int i = 0; i < sprites.Length; ++i)
            {
                exSpriteBase spBase = sprites[i];

                // ========================================================
                // exSprite
                // ========================================================

                if (spBase is exSprite)
                {
                    exSprite sp = spBase as exSprite;
                    exAtlasDB.ElementInfo elInfo = exAtlasDB.GetElementInfo(sp.textureGUID);
                    bool needRebuild             = false;

                    // NOTE: we test sp.index is -1 or not instead of test atlas is null, because it is possible we delete an atlas and it will always be null
                    if (elInfo != null)
                    {
                        if (sp.index == -1)
                        {
                            needRebuild = true;
                        }
                        else
                        {
                            // find if the sp's atalsInfo need rebuild
                            foreach (string guidAtlasInfo in _atlasInfoGUIDs)
                            {
                                if (elInfo.guidAtlasInfo == guidAtlasInfo)
                                {
                                    needRebuild = true;
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        if (sp.index != -1)
                        {
                            needRebuild = true;
                        }
                    }

                    //
                    if (needRebuild)
                    {
                        exSpriteEditor.UpdateAtlas(sp, elInfo);
#if UNITY_3_4
                        bool isPrefab = (EditorUtility.GetPrefabType(spBase) == PrefabType.Prefab);
#else
                        bool isPrefab = (PrefabUtility.GetPrefabType(spBase) == PrefabType.Prefab);
#endif
                        if (isPrefab == false)
                        {
                            Texture2D texture = null;
                            if (sp.index == -1)
                            {
                                texture = exEditorHelper.LoadAssetFromGUID <Texture2D>(sp.textureGUID);
                            }
                            sp.Build(texture);
                        }
                        EditorUtility.SetDirty(sp);
                    }
                }

#if !(EX2D_EVALUATE)
                // ========================================================
                // exSpriteFont
                // ========================================================

                if (spBase is exSpriteFont)
                {
                    exSpriteFont spFont = spBase as exSpriteFont;

                    //
                    bool needRebuild = false;
                    if (spFont.fontInfo == null)
                    {
                        needRebuild = true;
                    }
                    else
                    {
                        foreach (string guidAtlasInfo in _atlasInfoGUIDs)
                        {
                            exAtlasInfo atlasInfo = exEditorHelper.LoadAssetFromGUID <exAtlasInfo>(guidAtlasInfo);
                            // NOTE: it is possible we process this in delete stage
                            if (atlasInfo == null)
                            {
                                continue;
                            }

                            foreach (exBitmapFont bmfont in atlasInfo.bitmapFonts)
                            {
                                if (spFont.fontInfo == bmfont)
                                {
                                    needRebuild = true;
                                    break;
                                }
                            }
                        }
                    }

                    //
                    if (needRebuild)
                    {
                        spFont.Build();
                    }
                }

                // ========================================================
                // exSpriteBorder
                // ========================================================

                if (spBase is exSpriteBorder)
                {
                    exSpriteBorder spBorder = spBase as exSpriteBorder;
                    if (spBorder.guiBorder != null)
                    {
                        exAtlasDB.ElementInfo elInfo = exAtlasDB.GetElementInfo(spBorder.guiBorder.textureGUID);
                        bool needRebuild             = false;

                        // NOTE: we test spBorder.index is -1 or not instead of test atlas is null, because it is possible we delete an atlas and it will always be null
                        if (elInfo != null)
                        {
                            if (spBorder.index == -1)
                            {
                                needRebuild = true;
                            }
                            else
                            {
                                // find if the spBorder's atalsInfo need rebuild
                                foreach (string guidAtlasInfo in _atlasInfoGUIDs)
                                {
                                    if (elInfo.guidAtlasInfo == guidAtlasInfo)
                                    {
                                        needRebuild = true;
                                        break;
                                    }
                                }
                            }
                        }
                        else
                        {
                            if (spBorder.index != -1)
                            {
                                needRebuild = true;
                            }
                        }

                        //
                        if (needRebuild)
                        {
                            exSpriteBorderEditor.UpdateAtlas(spBorder, elInfo);
#if UNITY_3_4
                            bool isPrefab = (EditorUtility.GetPrefabType(spBase) == PrefabType.Prefab);
#else
                            bool isPrefab = (PrefabUtility.GetPrefabType(spBase) == PrefabType.Prefab);
#endif
                            if (isPrefab == false)
                            {
                                Texture2D texture = null;
                                if (spBorder.index == -1)
                                {
                                    texture = exEditorHelper.LoadAssetFromGUID <Texture2D>(spBorder.guiBorder.textureGUID);
                                }
                                spBorder.Build(texture);
                            }
                            EditorUtility.SetDirty(spBorder);
                        }
                    }
                }
#endif // !(EX2D_EVALUATE)

                // DISABLE: it is too slow {
                // float progress = (float)i/(float)sprites.Length;
                // EditorUtility.DisplayProgressBar( "Update Scene Sprites...",
                //                                   "Update Sprite " + spBase.gameObject.name, progress );
                // } DISABLE end
            }
            EditorUtility.ClearProgressBar();
        }
        catch (System.Exception) {
            EditorUtility.ClearProgressBar();
            throw;
        }
    }