FairyGUI.UIPackage.Dispose C# (CSharp) Method

Dispose() private method

private Dispose ( bool allowDestroyingAssets ) : void
allowDestroyingAssets bool
return void
        void Dispose(bool allowDestroyingAssets)
        {
            int cnt = _items.Count;
            for (int i = 0; i < cnt; i++)
            {
                PackageItem pi = _items[i];
                if (pi.texture != null)
                {
                    if (pi.texture.alphaTexture != null)
                    {
                        pi.texture.alphaTexture.Dispose(allowDestroyingAssets);
                        pi.texture.alphaTexture = null;
                    }

                    if (pi.texture != NTexture.Empty)
                        pi.texture.Dispose(allowDestroyingAssets);
                    else
                        pi.texture.DestroyMaterials();
                    pi.texture = null;
                }
                else if (pi.audioClip != null)
                {
                    if (allowDestroyingAssets)
                    {
                        if (_fromBundle)
                            AudioClip.DestroyImmediate(pi.audioClip, true);
                        else
                            Resources.UnloadAsset(pi.audioClip);
                    }
                    pi.audioClip = null;
                }
                else if (pi.bitmapFont != null)
                    FontManager.UnregisterFont(pi.bitmapFont);
            }
            _items.Clear();

            if (_resBundle != null)
                _resBundle.Unload(true);
        }

Usage Example

Example #1
0
        /// <summary>
        /// Remove a package. All resources in this package will be disposed.
        /// </summary>
        /// <param name="packageIdOrName"></param>
        /// <param name="allowDestroyingAssets"></param>
        public static void RemovePackage(string packageIdOrName)
        {
            UIPackage pkg = null;

            if (!_packageInstById.TryGetValue(packageIdOrName, out pkg))
            {
                if (!_packageInstByName.TryGetValue(packageIdOrName, out pkg))
                {
                    // LLWANT: 不抛异常,只输出日志提示
                    Debug.Log("FairyGUI: '" + packageIdOrName + "' is not a valid package id or name. maybe removed");
                    return;
                }
            }
            pkg.Dispose();
            _packageInstById.Remove(pkg.id);
            if (pkg._customId != null)
            {
                _packageInstById.Remove(pkg._customId);
            }
            if (pkg.assetPath != null)
            {
                _packageInstById.Remove(pkg.assetPath);
            }
            _packageInstByName.Remove(pkg.name);
            _packageList.Remove(pkg);
        }
All Usage Examples Of FairyGUI.UIPackage::Dispose