我将一些png文件放入/ Assets / StreamingAssets,我想要做的是从该floder加载图像的纹理。
这是我的c#代码:
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;
}
在OSX上,代码运行完美。但我需要让它在IOS上工作。所以我删除&#34; file://&#34;的前缀路径是:
string path = Application.streamingAssetsPath + "/sunny.png";
它只是在构建并在我的iPhone上运行后显示一个红色问号。我也试过
string path = "file:/" + Application.streamingAssetsPath + "/sunny.png";
谁能告诉我如何正确地做到这一点?
答案 0 :(得分:0)
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);
请检查此链接。 https://docs.unity3d.com/ScriptReference/AssetBundle.LoadFromFile.html