unity3d - image couldn't loaded from ios device in unity -
i using unity load facebook profile picture saved in device. code working fine in android not ios. suffering problem many days. here code, please me.
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 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 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); } }
appreciate help, thanks!
it turned out problem following line.
yield return new waitforendofframe();
obviously, 1 frame not enough load file disk. lucky enough on android device. should change line to
yield return pictureurl;
so wait until it's done loading.
Comments
Post a Comment