using System.Collections; 
 | 
using System.Collections.Generic; 
 | 
using UnityEngine; 
 | 
using UnityEngine.U2D; 
 | 
  
 | 
public class BuiltInLoader 
 | 
{ 
 | 
    readonly static string PREFAB_EXTENSION = ".prefab"; 
 | 
    readonly static string SPRITE_EXTENSION = ".png"; 
 | 
    readonly static string AUDIO_EXTENSION = ".wav"; 
 | 
  
 | 
    readonly static List<string> excludePngs = new List<string>() { "Launch_1.png", "Launch_2.png", "Launch_3.png", "LoginBackGround.png", "TB_DL_Logo.png" }; 
 | 
  
 | 
    public static Sprite LoadSprite(string name) 
 | 
    { 
 | 
        Sprite sprite = null; 
 | 
        if (!AssetSource.isUseAssetBundle) 
 | 
        { 
 | 
#if UNITY_EDITOR 
 | 
            if (excludePngs.Contains(StringUtility.Contact(name, SPRITE_EXTENSION))) 
 | 
            { 
 | 
                var path = StringUtility.Contact("Assets/ResourcesOut/BuiltIn/Sprites/", name, SPRITE_EXTENSION); 
 | 
                path = System.Text.RegularExpressions.Regex.Replace(path, @"[\p{C}]", ""); 
 | 
                sprite = UnityEditor.AssetDatabase.LoadAssetAtPath<Sprite>(path); 
 | 
            } 
 | 
            else 
 | 
            { 
 | 
                var spriteAtlas = UnityEditor.AssetDatabase.LoadAssetAtPath<SpriteAtlas>("Assets/ResourcesOut/BuiltIn/Sprites/sprites.spriteatlasv2"); 
 | 
                sprite = spriteAtlas.GetSprite(name); 
 | 
            } 
 | 
#endif 
 | 
        } 
 | 
        else 
 | 
        { 
 | 
            //var assetInfo = new AssetInfo("builtin/sprites", "sprites"); 
 | 
            //var spriteAtlas = AssetBundleUtility.Instance.Sync_LoadAsset(assetInfo, typeof(SpriteAtlas)) as SpriteAtlas; 
 | 
            //sprite = spriteAtlas?.GetSprite(name); 
 | 
            //if (sprite == null) 
 | 
            { 
 | 
                var assetInfo = new AssetInfo("builtin/sprites", name); 
 | 
                sprite = AssetBundleUtility.Instance.Sync_LoadAsset(assetInfo, typeof(Sprite)) as Sprite; 
 | 
            } 
 | 
        } 
 | 
  
 | 
        if (sprite == null) 
 | 
        { 
 | 
            Debug.LogErrorFormat("BuiltInLoader.LoadSprite() => 加载不到资源: {0}.", name); 
 | 
        } 
 | 
  
 | 
        return sprite; 
 | 
    } 
 | 
  
 | 
    public static GameObject LoadPrefab(string name) 
 | 
    { 
 | 
        GameObject prefab = null; 
 | 
        if (!AssetSource.isUseAssetBundle) 
 | 
        { 
 | 
#if UNITY_EDITOR 
 | 
            var path = StringUtility.Contact("Assets/ResourcesOut/BuiltIn/Prefabs/", name, PREFAB_EXTENSION); 
 | 
            prefab = UnityEditor.AssetDatabase.LoadAssetAtPath<GameObject>(path); 
 | 
#endif 
 | 
        } 
 | 
        else 
 | 
        { 
 | 
            var assetInfo = new AssetInfo("builtin/prefabs", name); 
 | 
            prefab = AssetBundleUtility.Instance.Sync_LoadAsset(assetInfo) as GameObject; 
 | 
        } 
 | 
  
 | 
        if (prefab == null) 
 | 
        { 
 | 
            Debug.LogErrorFormat("BuiltInLoader.LoadPrefab() => 加载不到资源: {0}.", name); 
 | 
        } 
 | 
  
 | 
        return prefab; 
 | 
    } 
 | 
  
 | 
    public static void UnLoadPrefab(string name) 
 | 
    { 
 | 
        if (AssetSource.isUseAssetBundle) 
 | 
        { 
 | 
            AssetBundleUtility.Instance.UnloadAsset("builtin/prefabs", name); 
 | 
        } 
 | 
    } 
 | 
  
 | 
    public static AudioClip LoadMusic(string name) 
 | 
    { 
 | 
        AudioClip audioClip = null; 
 | 
        if (!AssetSource.isUseAssetBundle) 
 | 
        { 
 | 
#if UNITY_EDITOR 
 | 
            var path = StringUtility.Contact("Assets/ResourcesOut/BuiltIn/Musics/", name, AUDIO_EXTENSION); 
 | 
            audioClip = UnityEditor.AssetDatabase.LoadAssetAtPath<AudioClip>(path); 
 | 
#endif 
 | 
        } 
 | 
        else 
 | 
        { 
 | 
            var assetInfo = new AssetInfo("builtin/musics", name); 
 | 
            audioClip = AssetBundleUtility.Instance.Sync_LoadAsset(assetInfo) as AudioClip; 
 | 
        } 
 | 
  
 | 
        if (audioClip == null) 
 | 
        { 
 | 
            Debug.LogErrorFormat("BuiltInLoader.LoadMusic() => 加载不到资源: {0}.", name); 
 | 
        } 
 | 
  
 | 
        return audioClip; 
 | 
    } 
 | 
  
 | 
    public static AnimationClip LoadAnimationClip(string name) 
 | 
    { 
 | 
        AnimationClip clip = null; 
 | 
        if (!AssetSource.isUseAssetBundle) 
 | 
        { 
 | 
#if UNITY_EDITOR 
 | 
            var path = StringUtility.Contact("Assets/ResourcesOut/BuiltIn/AnimationClips/", name, ".anim"); 
 | 
            clip = UnityEditor.AssetDatabase.LoadAssetAtPath<AnimationClip>(path); 
 | 
#endif 
 | 
        } 
 | 
        else 
 | 
        { 
 | 
            var assetInfo = new AssetInfo("builtin/animationclips", name); 
 | 
            clip = AssetBundleUtility.Instance.Sync_LoadAsset(assetInfo) as AnimationClip; 
 | 
        } 
 | 
  
 | 
        if (clip == null) 
 | 
        { 
 | 
            Debug.LogErrorFormat("BuiltInLoader.LoadAnimationClip() => 加载不到资源: {0}.", name); 
 | 
        } 
 | 
  
 | 
        return clip; 
 | 
    } 
 | 
  
 | 
    public static Material LoadMaterial(string name) 
 | 
    { 
 | 
        Material material = null; 
 | 
        if (!AssetSource.isUseAssetBundle) 
 | 
        { 
 | 
#if UNITY_EDITOR 
 | 
            var path = StringUtility.Contact("Assets/ResourcesOut/BuiltIn/Materials/", name, ".mat"); 
 | 
            material = UnityEditor.AssetDatabase.LoadAssetAtPath<Material>(path); 
 | 
#endif 
 | 
        } 
 | 
        else 
 | 
        { 
 | 
            var assetInfo = new AssetInfo("builtin/materials", name); 
 | 
            material = AssetBundleUtility.Instance.Sync_LoadAsset(assetInfo) as Material; 
 | 
        } 
 | 
  
 | 
        if (material == null) 
 | 
        { 
 | 
            Debug.LogErrorFormat("BuiltInLoader.LoadMaterial() => 加载不到资源: {0}.", name); 
 | 
        } 
 | 
  
 | 
        return material; 
 | 
    } 
 | 
  
 | 
    public static T LoadScriptableObject<T>(string name) where T : ScriptableObject 
 | 
    { 
 | 
  
 | 
        T config = null; 
 | 
        if (!AssetSource.isUseAssetBundle) 
 | 
        { 
 | 
#if UNITY_EDITOR 
 | 
            var resourcePath = StringUtility.Contact(ResourcesPath.ResourcesOutAssetPath, 
 | 
                                                   "BuiltIn/ScriptableObjects/", name, ".asset"); 
 | 
  
 | 
            config = UnityEditor.AssetDatabase.LoadAssetAtPath<T>(resourcePath); 
 | 
#endif 
 | 
        } 
 | 
        else 
 | 
        { 
 | 
            var assetInfo = new AssetInfo("builtin/scriptableobjects", name); 
 | 
            config = AssetBundleUtility.Instance.Sync_LoadAsset(assetInfo) as T; 
 | 
        } 
 | 
  
 | 
        if (config == null) 
 | 
        { 
 | 
            Debug.LogErrorFormat("BuiltIn.LoadScriptableObject() => 加载不到资源: {0}.", name); 
 | 
        } 
 | 
  
 | 
        return config; 
 | 
    } 
 | 
  
 | 
    public static Font LoadFont(string fontName) 
 | 
    { 
 | 
        Font font = null; 
 | 
        if (!AssetSource.isUseAssetBundle) 
 | 
        { 
 | 
#if UNITY_EDITOR 
 | 
            var path = StringUtility.Contact(ResourcesPath.ResourcesOutAssetPath, 
 | 
                                       "BuiltIn/Font/", fontName, ".ttf"); 
 | 
            font = UnityEditor.AssetDatabase.LoadAssetAtPath<Font>(path); 
 | 
#endif 
 | 
        } 
 | 
        else 
 | 
        { 
 | 
            var assetInfo = new AssetInfo("builtin/font", fontName); 
 | 
            font = AssetBundleUtility.Instance.Sync_LoadAsset(assetInfo, typeof(Font)) as Font; 
 | 
        } 
 | 
  
 | 
        if (font == null) 
 | 
        { 
 | 
            Debug.LogErrorFormat("BuiltInLoader.LoadFont() => 加载不到资源: {0}.", fontName); 
 | 
        } 
 | 
  
 | 
        return font; 
 | 
    } 
 | 
  
 | 
  
 | 
} 
 |