动态读取StreamingAssets目录下图片,赋值给Image的Sprite | 您所在的位置:网站首页 › img/sprite/Projector.png › 动态读取StreamingAssets目录下图片,赋值给Image的Sprite |
请先在Assets目录下面新建StreamingAssets文件夹 在StreamingAssets文件夹建立一个图片目录,把需要加载的图片拖放进该目录 path = Application.streamingAssetsPath + “/图片目录/图片1.png”; public IEnumerator TextureReader(string path, UnityAction action) { UnityWebRequest unityWebRequest = UnityWebRequestTexture.GetTexture(path); yield return unityWebRequest.SendWebRequest(); if (unityWebRequest.error != null) Debug.Log(unityWebRequest.error); else { byte[] bts = unityWebRequest.downloadHandler.data; if (action != null) { action(DownloadHandlerTexture.GetContent(unityWebRequest)); } } }使用方法 StartCoroutine(TextureReader(img_path, (t2d) => { myImage.overrideSprite = Sprite.Create(t2d, new Rect(0, 0, t2d.width, t2d.height), Vector2.zero); })); |
CopyRight 2018-2019 实验室设备网 版权所有 |