using XGame.Framework.Asset;
using XGame.Framework.Asset.Addressable.Data;
using System;
using UnityEditor;

namespace XGame.Editor.Asset
{
    public static class AddressableAssetInfoExt
    {
        /// <summary>
        /// 编辑器扩展方法
        /// </summary>
        /// <param name="assetInfo"></param>
        /// <returns></returns>
        public static string GetAssetPath(this AssetInfo assetInfo)
        {
            return AssetDatabase.GUIDToAssetPath(assetInfo.assetGUID);
        }
        /// <summary>
        /// 是否内置资源
        /// </summary>
        /// <param name="assetInfo"></param>
        /// <returns></returns>
        public static bool IsBuiltIn(this AssetInfo assetInfo)
        {
            var assetPath = assetInfo.GetAssetPath();
            if (!string.IsNullOrEmpty(assetPath) && assetPath.IndexOf(PathDefine.PackageRelative, StringComparison.Ordinal) == 0)
            {
                return true;
            }
            return false;
        }
        ///// <summary>
        ///// 编辑器扩展方法
        ///// </summary>
        ///// <param name="assetInfo"></param>
        ///// <param name="id"></param>
        //public static void SetAddressableId(this AddressableAssetInfo assetInfo, long id)
        //{
        //    var fileInfo = assetInfo.GetType().GetField("addressableId", BindingFlags.NonPublic | BindingFlags.Instance);
        //    fileInfo?.SetValue(assetInfo, id);
        //}
        ///// <summary>
        ///// 编辑器扩展方法
        ///// </summary>
        ///// <param name="assetInfo"></param>
        ///// <param name="name"></param>
        //public static void SetAddressableName(this AddressableAssetInfo assetInfo, string name)
        //{
        //    var fileInfo = assetInfo.GetType().GetField("addressableName", BindingFlags.NonPublic | BindingFlags.Instance);
        //    fileInfo?.SetValue(assetInfo, name);
        //}
        ///// <summary>
        ///// 编辑器扩展方法
        ///// </summary>
        ///// <param name="assetInfo"></param>
        ///// <param name="guid"></param>
        //public static void SetGUID(this AddressableAssetInfo assetInfo, string guid)
        //{
        //    var fileInfo = assetInfo.GetType().GetField("assetGUID", BindingFlags.NonPublic | BindingFlags.Instance);
        //    fileInfo?.SetValue(assetInfo, guid);
        //}
    }
}
