zoukankan      html  css  js  c++  java
  • 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-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);
        }
    }
  • 相关阅读:
    hdu 4273 2012长春赛区网络赛 三维凸包中心到最近面距离 ***
    hdu 4272 2012长春赛区网络赛 dfs暴力 ***
    hdu 4063 福州赛区网络赛 圆 ****
    hdu 4069 福州赛区网络赛I DLC ***
    hdu 4061 福州赛区网络赛A 数学 ***
    hdu 4068 福州赛区网络赛H 排列 ***
    hdu 4070 福州赛区网络赛J 贪心 ***
    hdu 5366 组合数 *
    linux的rsync工具的常用选项及ssh同步介绍
    从U盘安装CentOS7.3教程
  • 原文地址:https://www.cnblogs.com/JimmyCode/p/7737159.html
Copyright © 2011-2022 走看看