using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Giant.Res {
    public static class AssetUtily
    {
        /// <summary>
        /// 类型比较
        /// </summary>
        /// <param name="t1"></param>
        /// <param name="t2"></param>
        /// <returns></returns>
        public static bool IsCompatible(Type t1, Type t2)
        {
            return t1 == t2 || t1.IsSubclassOf(t2) || t1.IsAssignableFrom(t2);
        }

        /// <summary>
        /// 通过类型获取文件扩展名
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public static string DefaultType2SuffixFunc(Type t)
        {

            if (IsCompatible(t, typeof(GameObject)))
            {
                return ".prefab";
            }

            if (IsCompatible(t, typeof(ScriptableObject)))
                return ".asset";

            if (IsCompatible(t, typeof(Texture)) || IsCompatible(t, typeof(Sprite)))
            {
                return ".png";
            }
            if (IsCompatible(t, typeof(Material)))
            {
                return ".mat";
            }

            else if (IsCompatible(t, typeof(TextAsset)))
            {
                return ".bytes";
            }
            else if (IsCompatible(t, typeof(RuntimeAnimatorController)))
            {
                return ".controller";
            }

            return "";
        }
    }
}

