| | |
| | | |
| | | 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.Concat(name, SPRITE_EXTENSION))) |
| | | { |
| | | var path = StringUtility.Concat("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 |
| | | { |
| | | //if (sprite == null) |
| | | { |
| | | // US1: Route through YooAssetService sync wrapper |
| | | var path = StringUtility.Concat("Assets/ResourcesOut/BuiltIn/Sprites/", name, SPRITE_EXTENSION); |
| | | #pragma warning disable CS0612 |
| | | sprite = YooAssetService.Instance.LoadAssetSync<Sprite>(path); |
| | | #pragma warning restore CS0612 |
| | | } |
| | | } |
| | | |
| | | 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.Concat("Assets/ResourcesOut/BuiltIn/Prefabs/", name, PREFAB_EXTENSION); |
| | | prefab = UnityEditor.AssetDatabase.LoadAssetAtPath<GameObject>(path); |
| | | #endif |
| | | } |
| | | else |
| | | { |
| | | // US1: Route through YooAssetService sync wrapper |
| | | var path = StringUtility.Concat("Assets/ResourcesOut/BuiltIn/Prefabs/", name, PREFAB_EXTENSION); |
| | | #pragma warning disable CS0612 |
| | | prefab = YooAssetService.Instance.LoadAssetSync<GameObject>(path); |
| | | #pragma warning restore CS0612 |
| | | } |
| | | |
| | | if (prefab == null) |
| | | { |
| | | Debug.LogErrorFormat("BuiltInLoader.LoadPrefab() => 加载不到资源: {0}.", name); |
| | | } |
| | | |
| | | return prefab; |
| | | } |
| | | |
| | | public static void UnLoadPrefab(string name) |
| | | { |
| | | // US1: No-op. YooAsset manages asset lifecycle via handle-based release. |
| | | } |
| | | |
| | | public static AudioClip LoadMusic(string name) |
| | | { |
| | | AudioClip audioClip = null; |
| | | if (!AssetSource.isUseAssetBundle) |
| | | { |
| | | #if UNITY_EDITOR |
| | | var path = StringUtility.Concat("Assets/ResourcesOut/BuiltIn/Musics/", name, ".mp3"); |
| | | audioClip = UnityEditor.AssetDatabase.LoadAssetAtPath<AudioClip>(path); |
| | | #endif |
| | | } |
| | | else |
| | | { |
| | | // US1: Route through YooAssetService sync wrapper |
| | | var path = StringUtility.Concat("Assets/ResourcesOut/BuiltIn/Musics/", name, ".mp3"); |
| | | #pragma warning disable CS0612 |
| | | audioClip = YooAssetService.Instance.LoadAssetSync<AudioClip>(path); |
| | | #pragma warning restore CS0612 |
| | | } |
| | | |
| | | 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.Concat("Assets/ResourcesOut/BuiltIn/AnimationClips/", name, ".anim"); |
| | | clip = UnityEditor.AssetDatabase.LoadAssetAtPath<AnimationClip>(path); |
| | | #endif |
| | | } |
| | | else |
| | | { |
| | | // US1: Route through YooAssetService sync wrapper |
| | | var path = StringUtility.Concat("Assets/ResourcesOut/BuiltIn/AnimationClips/", name, ".anim"); |
| | | #pragma warning disable CS0612 |
| | | clip = YooAssetService.Instance.LoadAssetSync<AnimationClip>(path); |
| | | #pragma warning restore CS0612 |
| | | } |
| | | |
| | | 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.Concat("Assets/ResourcesOut/BuiltIn/Materials/", name, ".mat"); |
| | | material = UnityEditor.AssetDatabase.LoadAssetAtPath<Material>(path); |
| | | #endif |
| | | } |
| | | else |
| | | { |
| | | // US1: Route through YooAssetService sync wrapper |
| | | var path = StringUtility.Concat("Assets/ResourcesOut/BuiltIn/Materials/", name, ".mat"); |
| | | #pragma warning disable CS0612 |
| | | material = YooAssetService.Instance.LoadAssetSync<Material>(path); |
| | | #pragma warning restore CS0612 |
| | | } |
| | | |
| | | 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.Concat(ResourcesPath.ResourcesOutAssetPath, |
| | | "BuiltIn/ScriptableObjects/", name, ".asset"); |
| | | |
| | | config = UnityEditor.AssetDatabase.LoadAssetAtPath<T>(resourcePath); |
| | | #endif |
| | | } |
| | | else |
| | | { |
| | | // US1: Route through YooAssetService sync wrapper |
| | | var path = StringUtility.Concat(ResourcesPath.ResourcesOutAssetPath, |
| | | "BuiltIn/ScriptableObjects/", name, ".asset"); |
| | | #pragma warning disable CS0612 |
| | | config = YooAssetService.Instance.LoadAssetSync<T>(path); |
| | | #pragma warning restore CS0612 |
| | | } |
| | | |
| | | 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.Concat(ResourcesPath.ResourcesOutAssetPath, |
| | | "Font/", fontName, ".ttf"); |
| | | font = UnityEditor.AssetDatabase.LoadAssetAtPath<Font>(path); |
| | | #endif |
| | | } |
| | | else |
| | | { |
| | | // US1: Route through YooAssetService sync wrapper |
| | | var path = StringUtility.Concat(ResourcesPath.ResourcesOutAssetPath, |
| | | "Font/", fontName, ".ttf"); |
| | | #pragma warning disable CS0612 |
| | | font = YooAssetService.Instance.LoadAssetSync<Font>(path); |
| | | #pragma warning restore CS0612 |
| | | } |
| | | |
| | | if (font == null) |
| | | { |
| | | Debug.LogErrorFormat("BuiltInLoader.LoadFont() => 加载不到资源: {0}.", fontName); |
| | | } |
| | | |
| | | return font; |
| | | } |
| | | |
| | | // ==================================================================== |
| | | // US2: Async UniTask variants |
| | | // ==================================================================== |
| | | // ...existing code... |
| | | |
| | | public static async UniTask<Sprite> LoadSpriteAsync(string name, CancellationToken ct = default) |
| | | { |