123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- using System.Collections.Generic;
- using System.Diagnostics;
- namespace XGame.Framework.Asset.Monitor
- {
- public sealed partial class AssetsMonitor
- {
- private static AssetsMonitor _instance;
- private static AssetsMonitor Instance
- {
- get
- {
- if (_instance == null)
- {
- _instance = new AssetsMonitor();
- }
- return _instance;
- }
- }
- /// <summary>
- /// 记录加载数据
- /// </summary>
- /// <param name="addressableName"></param>
- /// <param name="obj"></param>
- [Conditional(MacroDefine.UNITY_EDITOR)]
- [Conditional(MacroDefine.UNITY_STANDALONE)]
- [Conditional(MacroDefine.UNITY_STANDALONE_WIN)]
- public static void RecordAsset(string addressableName, object obj)
- {
- #if UNITY_EDITOR || UNITY_STANDALONE || UNITY_STANDALONE_WIN
- Instance.RecordAssetInternal(addressableName, obj);
- #endif
- }
- /// <summary>
- /// 获取所有已加载过的资源数据
- /// </summary>
- /// <returns></returns>
- public static AssetLoadingRecord[] GetRecords()
- {
- #if UNITY_EDITOR || UNITY_STANDALONE || UNITY_STANDALONE_WIN
- return Instance.GetRecordsInternal();
- #else
- return null;
- #endif
- }
- [Conditional(MacroDefine.UNITY_EDITOR)]
- public static void Write()
- {
- #if UNITY_EDITOR || UNITY_STANDALONE || UNITY_STANDALONE_WIN
- Instance.WriteInternal();
- #endif
- }
- [Conditional(MacroDefine.UNITY_EDITOR)]
- public static void Dispose()
- {
- #if UNITY_EDITOR || UNITY_STANDALONE || UNITY_STANDALONE_WIN
- if (_instance != null)
- {
- //Write();
- _instance._assetInfoMap.Clear();
- _instance._assetInfoMap = null;
- }
- _instance = null;
- #endif
- }
- #region AssetModule
- /// <summary>
- /// 返回指定AssetModule的实例数据
- /// </summary>
- /// <param name="assetModule"></param>
- /// <returns></returns>
- public static AssetInstanceCopy[] GetAssetInstances(IAssetModule assetModule)
- {
- #if UNITY_EDITOR || UNITY_STANDALONE || UNITY_STANDALONE_WIN
- if (assetModule is AssetModule impl)
- {
- var field = impl.GetType().GetField("assetMap", System.Reflection.BindingFlags.NonPublic |
- System.Reflection.BindingFlags.Instance);
- if (field != null)
- {
- var assetMap = field.GetValue(impl) as Dictionary<long, AssetInstance>;
- var instances = new AssetInstanceCopy[assetMap.Count];
- var index = 0;
- foreach(var item in assetMap)
- {
- var instance = item.Value;
- instances[index++] = new AssetInstanceCopy()
- {
- asset = instance.Asset,
- reference = instance.Reference,
- hashcode = instance.Hashcode,
- name = instance.Name
- };
- }
- return instances;
- }
- }
- #endif
- return null;
- }
- #endregion
- }
- }
|