12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- using FairyGUI;
- using System.Collections.Generic;
- using System.IO;
- using UnityEngine;
- using VEngine;
- namespace GFGGame
- {
- public class GFGUIPackage
- {
- private static Dictionary<string, UIPackage> _packages = new Dictionary<string, UIPackage>();
- private static Dictionary<string, List<Asset>> _assetDic = new Dictionary<string, List<Asset>>();
- private static Dictionary<string, int> _assetCount = new Dictionary<string, int>();
- public static UIPackage AddPackage(string descFilePath)
- {
- int count = _assetCount.ContainsKey(descFilePath) ? _assetCount[descFilePath] : 0;
- if (_packages.ContainsKey(descFilePath))
- {
- _assetCount[descFilePath] = count + 1;
- return _packages[descFilePath];
- }
- var asset = Asset.Load($"{descFilePath}_fui.bytes", typeof(TextAsset));
- AddAsset(descFilePath, asset);
- var uiPackage = UIPackage.AddPackage((asset.asset as TextAsset).bytes, descFilePath, (string name, string extension, System.Type type, out DestroyMethod destroyMethod) =>
- {
- destroyMethod = DestroyMethod.Unload;
- string path = name + extension;
- if (Versions.Contains(path))
- {
- var asset = Asset.Load(path, type);
- AddAsset(descFilePath, asset);
- return asset.asset;
- }
- return null;
- });
- _assetCount.Add(descFilePath, count + 1);
- _packages.Add(descFilePath, uiPackage);
- return uiPackage;
- }
- public static void RemovePackage(string descFilePath)
- {
- UIPackage package;
- if (_packages.TryGetValue(descFilePath, out package))
- {
- int count = _assetCount[descFilePath] - 1;
- _assetCount[descFilePath] = count;
- if (count > 0) return;
- _assetCount.Remove(descFilePath);
- _packages.Remove(descFilePath);
- UIPackage.RemovePackage(package.name);
- List<Asset> list = null;
- if (_assetDic.TryGetValue(descFilePath, out list))
- {
- foreach (var asset in list)
- {
- asset.Release();
- }
- }
- }
- }
- private static void AddAsset(string key, Asset asset)
- {
- List<Asset> list = null;
- if (!_assetDic.TryGetValue(key, out list))
- {
- list = new List<Asset>();
- _assetDic.Add(key, list);
- }
- list.Add(asset);
- }
- }
- }
|