我正在使用统一加载保存在设备中的 facebook 个人资料图片。该代码在 Android 中运行良好,但在 IOS 中运行良好。我被这个问题困扰了很多天。所以这是我的代码,请帮助我。
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();
显然,一帧不足以从磁盘加载文件。你很幸运,在你的安卓设备上已经足够了。所以你应该把那行改成
yield return pictureUrl;
所以它会等到加载完成。
关于ios - 图像无法从 ios 设备统一加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31175566/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |