图像不能';t在unity中从ios设备加载
我正在使用unity加载保存在设备中的facebook个人资料图片。该代码在安卓系统中运行良好,但在IOS系统中运行不好。我受这个问题困扰了好几天。这是我的密码,请帮帮我图像不能';t在unity中从ios设备加载,ios,unity3d,Ios,Unity3d,我正在使用unity加载保存在设备中的facebook个人资料图片。该代码在安卓系统中运行良好,但在IOS系统中运行不好。我受这个问题困扰了好几天。这是我的密码,请帮帮我 using UnityEngine; using System.Collections; using System.IO; using UnityEngine.UI; public class UserProfilePicture : MonoBehaviour { public RawImage profilePictur
using UnityEngine;
using System.Collections;
using System.IO;
using UnityEngine.UI;
public class UserProfilePicture : MonoBehaviour {
public RawImage profilePicture, testProfile;
private Texture2D texture,text;
void FixedUpdate(){
if (FbSetup.userInfoLoaded) {
if(SPFacebook.instance.userInfo.GetProfileImage(FacebookProfileImageSize.square) != null) {
text = SPFacebook.instance.userInfo.GetProfileImage(FacebookProfileImageSize.square);
}
}
testProfile.texture = text as Texture;
byte[] textureByte = text.EncodeToPNG ();
File.WriteAllBytes (Path.Combine(Application.persistentDataPath,"profilePicture.png"),textureByte);
Debug.Log("Save path: " + Application.persistentDataPath + Path.DirectorySeparatorChar + "profilePicture.png");
if(File.Exists(Application.persistentDataPath + Path.DirectorySeparatorChar + "profilePicture.png")){
Debug.Log("Texture saved");
}
}
void Update(){
StartCoroutine (Control ());
profilePicture.texture = texture as Texture;
}
IEnumerator Control(){
WWW pictureUrl;
pictureUrl = new WWW(System.Uri.EscapeUriString("file://" + Path.Combine(Application.persistentDataPath,"profilePicture.png")));
yield return new WaitForEndOfFrame();
texture = pictureUrl.texture;
Debug.Log("Loaded path: " + Path.Combine(Application.persistentDataPath,"profilePicture.png"));
}
void OnEnable(){
if (GLobal.playAsGuest) {
this.gameObject.SetActive(false);
}
else{
this.gameObject.SetActive(true);
}
}
谢谢你的帮助,谢谢 原来问题出在下面这行
yield return new WaitForEndOfFrame();
显然,一帧不足以从磁盘加载文件。你很幸运,在你的android设备上已经足够了。所以你应该把这行改成
yield return pictureUrl;
因此,它将等待加载完成。您确定
“file://”+Path.Combine(Application.persistentDataPath,“profilePicture.png”
是对的?是的,它在android上工作。这个脚本在ios上不工作吗?我的意思是,好吧,这个路径不应该在ios上工作。在没有文件的情况下尝试://
部分。刚刚尝试过,它甚至在android上也不工作。有没有其他方法来解决这个问题?嗯,让我们澄清一下。纹理文件是创建的,并且不能读取吗?或者根本没有t创建?啊…我明白了,谢谢你,我的朋友。真的感谢你的帮助!永远欢迎你。顺便说一句,如果答案解决了你的问题,你应该通过点击答案左侧的箭头来“接受”它。哦,好吧~对不起,我是这个论坛的新成员。谢谢!哈,没关系:我从SO那里获得了一次很好的体验。