Unity截屏分享朋友圈(微信)


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-INF\CERT.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:Assets\Plugins\Android\ShareSDK\libs

代碼:

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);
    }
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM