简体   繁体   中英

unity how to load image from streamingassets on ios

I put some png files into /Assets/StreamingAssets, what i want to do is load a image's texture from that floder.

here is my c# code below:

string path = "file://" + Application.streamingAssetsPath + "/sunny.png";

private IEnumerator GetMatByWWW(string url)
{
    WWW www = new WWW(url);
    yield return www;



    RawImage rawImage = gameObject.GetComponent<RawImage>();
    rawImage.texture = www.texture;
}

On OSX, the code working perfect. But i need to make it working on IOS. So i remove the prefix of "file://" and the path is :

string path = Application.streamingAssetsPath + "/sunny.png";

It just showed a red question-mark after build and run at my iPhone. And i also tried

string path = "file:/" + Application.streamingAssetsPath + "/sunny.png";

Who can tell me how to do it correctly?

string ab_path = Application.streamingAssetsPath + "/" + "bundlename";
AssetBundle ab = AssetBundle.LoadFromFile(ab_path);

if(ab == null)
{
    Debug.Log("ab is null");
}

Gameobject prefab =  ab.LoadAsset<GameObject>("prefab_name");
Gameobject go = GameObject.Instantiate(prefab);

please check this link. https://docs.unity3d.com/ScriptReference/AssetBundle.LoadFromFile.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM