Unity2017.1 ShareSDK GalleryScreenshot.unitypackage
一、SharSDK注册产品
后台>概括
二、微信开放平台上注册产品
2.1Unity: PlayerSettings>OtherSetting: com.wfj.snailshell
Android平台
应用下载地址:未填写
应用签名:xxxxb98a448d45e37cc7b3fa5c0fxxxx
包名:com.wfj.snailshell
2.2应用签名的获取
2.2.1修改apk后缀名为zip,解压得到其中的META-INF文件夹;
2.2.2把META-INF文件夹放到C盘根目录下;
2.2.3在dos面板中, 敲入命令: keytool -printcert -file C:META-INFCERT.RSA 命令,即可获取签名信息
2.2.4去冒号
2.3检查签名
https://open.weixin.qq.com/cgi-bin/readtemplate?t=resource/app_download_android_tmpl&lang=zh_CN 签名生成工具
安装apk后输入com.wfj.snailshell
三、Unity配置
3.1修改AndroidManifest
http://bbs.mob.com/thread-23519-1-1.html
3.2替换DemoCallback.jar
Unity:AssetsPluginsAndroidShareSDKlibs
代码:
using cn.sharesdk.unity3d; using System.Collections; using System.IO; using UnityEngine; using UnityEngine.UI; public class SharePhoto : MonoBehaviour { public Image ImagePreview; public ShareSDK Ssdk; string photoNamePrefix = "jimmy"; string albumName = "SnailShellShots"; string filePath; void Start() { ScreenshotManager.ScreenshotFinishedSaving += ScreenshotManager_ScreenshotFinishedSaving; } private void ScreenshotManager_ScreenshotFinishedSaving() { string date = System.DateTime.Now.ToString("dd-MM-yy"); string screenshotFilename = photoNamePrefix + "_" + ScreenshotManager.ScreenShotNumber + "_" + date + ".png"; #if UNITY_IPHONE filePath = Application.persistentDataPath + "/" + screenshotFilename; #elif UNITY_ANDROID filePath = Application.persistentDataPath + "/../../../../DCIM/" + albumName + "/" + screenshotFilename; #endif //创建文件读取流 FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read); fileStream.Seek(0, SeekOrigin.Begin); //创建文件长度缓冲区 byte[] bytes = new byte[fileStream.Length]; //读取文件 fileStream.Read(bytes, 0, (int)fileStream.Length); //释放文件读取流 fileStream.Close(); fileStream.Dispose(); fileStream = null; int width = 960; int height = 540; Texture2D texture = new Texture2D(width, height); texture.LoadImage(bytes); Sprite sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f)); ImagePreview.sprite = sprite; ImagePreview.gameObject.SetActive(true); //show preview panel } public void TakeShotClick() { StartCoroutine(Shot()); } IEnumerator Shot() { yield return StartCoroutine ( ScreenshotManager.Save ( photoNamePrefix, albumName, true ) ); } //After taking shot public void OnShareClick() { ShareContent content = new ShareContent(); content.SetImagePath(filePath); //本地图片路径 content.SetShareType(ContentType.Image); Ssdk.ShareContent(PlatformType.WeChatMoments, content); } }