using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Networking; using System; using Object = UnityEngine.Object; namespace ZXKFramework { public class ResStreamingAssets : IRes { public void GetTexture(string path, Action action) where T : Object { try { Debug.Log(path); Game.Instance.StartCoroutine(TextureReader(path, action)); } catch (Exception e) { Debug.LogError(e); } } IEnumerator TextureReader(string path, Action action) where T : Object { using UnityWebRequest unityWebRequest = UnityWebRequestTexture.GetTexture(path); yield return unityWebRequest.SendWebRequest(); if (string.IsNullOrEmpty(unityWebRequest.error)) { action?.Invoke(UnityTools.ToSprite(DownloadHandlerTexture.GetContent(unityWebRequest)) as T); } } public void GetAudioClip(string path, Action action) where T : Object { try { Debug.Log(path); Game.Instance.StartCoroutine(AudioClipReader(path, action)); } catch (Exception e) { Debug.LogError(e); } } IEnumerator AudioClipReader(string path, Action action) where T : Object { using UnityWebRequest webRequest = UnityWebRequestMultimedia.GetAudioClip(path, AudioType.WAV); yield return webRequest.SendWebRequest(); if (string.IsNullOrEmpty(webRequest.error)) { action?.Invoke(DownloadHandlerAudioClip.GetContent(webRequest) as T); } } public void Load(string assetName, Action action) where T : Object { string tipType = typeof(T).Name; switch (tipType) { case "Sprite": GetTexture(Application.streamingAssetsPath + "/" + assetName + ".png", action); break; case "AudioClip": GetAudioClip(Application.streamingAssetsPath + "/" + assetName + ".wav", action); break; case "GameObject": break; } } public void UnLoadAll() { } } }