您的位置:首页 > 移动开发 > Unity3D

【Unity3d】unity接入sharesdk分享本地图片失败记录

2015-06-10 17:30 471 查看
接入sharesdk时,即将分享的图片如果指向网络里的资源没问题;但是如果改成分享SD卡里的图片,发现分享不了;

错误提示:Texture ‘share' is not readable, the memory can not be accessed form scripts, You can make the texture
readable in the Texture Import Setting。


解决方法来自于http://tieba.baidu.com/p/2770331770;

只需将即将分享的图片放置在Resources目录下,然后按照下面图片所示修改下设置即可:



附上来自于
momo雨松的部分sharesdk for unity3d 分享源代码,需要的小伙伴自行拷贝:

//分享的本地图片处理
        private void Copy2SDpath()
        {
            //读、写的路径		
            string imagePath = Application.persistentDataPath + "/share.png";
            //如果文件不存在,把它拷贝进去。
            if (!System.IO.File.Exists(imagePath))
            {
                Texture2D o = Resources.Load("share") as Texture2D;
                if (o != null)
                {
                    System.IO.File.WriteAllBytes(imagePath, o.EncodeToPNG());
                }
            }
        }


private void ShareByAndroid()
        {
            Copy2SDpath();

            Hashtable content = new Hashtable();
            content["content"] = String.Format("周竞演得分{0},名列全球第{1}位,不服来战!来自点点那星星!", iTotalScore, iGlobleNew);

            //image的路径就可以直接写了。		
            string imagePath = Application.persistentDataPath + "/share.png";
            if (System.IO.File.Exists(imagePath))
            {
                content["image"] = imagePath;
            }
            else
            {
                content["image"] = "http://120.**.53.223:8765/icon108x108.png";
            }
            content["title"] = "点点那星星,越点越开心";
            content["description"] = String.Format("周竞演得分{0},名列全球第{1}位,不服来战!来自点点那星星!", iTotalScore, iGlobleNew);
            content["url"] = "http://120.**.53.223/";
            content["type"] = Convert.ToString((int)ContentType.News);
            content["siteUrl"] = "http://120.**.53.223/";
            content["site"] = "点点那星星";
            content["musicUrl"] = "";
            //开启,调用客户端授权
            content["disableSSOWhenAuthorize"] = false;
            content["shareTheme"] = "classic";//ShareTheme has only two value which are skyblue and classic

            ShareResultEvent evt = new ShareResultEvent(ShareResultHandler);
            ShareSDK.showShareMenu(null, content, 100, 100, MenuArrowDirection.Up, evt);
        }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: