天天看点

unity android读取本地图片,unity+Android+PC加载本地图片

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class LoadImage : MonoBehaviour { Texture2D tempImage; private RawImage RawImageRef; // Use this for initialization void Start () { RawImageRef = gameObject.GetComponent(); StartCoroutine(OnLoadImage("uploadFile/projectImg/22.jpg", RawImageRef)); } // Update is called once per frame void Update () { } IEnumerator OnLoadImage(string path, RawImage image) { string filePath = "file://" + Application.persistentDataPath + "/document/" + path; //string filePath = "file://" + "/sdcard/TKData/SaveData/" + "document/" + path;//手机 WWW www = new WWW(filePath); yield return www; if (www.error != null) { Debug.LogError(filePath + www.error); image.gameObject.SetActive(false); } else { Debug.LogError(filePath); image.gameObject.SetActive(true); tempImage = www.texture; image.texture = tempImage; } } }

将图片放入本地指定文件夹即可

unity设置如下

unity android读取本地图片,unity+Android+PC加载本地图片