Пример #1
0
    public static IEnumerator ShareBattleResult(string type)
    {
        int    w        = Screen.width * 50 / 640;
        int    h        = Screen.height * 57 / 360;
        Rect   rect     = new Rect(w, h, Screen.width - w * 2, Screen.height - h * 2);
        string filepath = Application.persistentDataPath + "/battleresult.png";

        Texture2D screenShot = new Texture2D((int)rect.width, (int)rect.height, TextureFormat.RGB24, false);

        //只在每一帧渲染完成后才读取屏幕信息
        yield return(new WaitForEndOfFrame());

        //读取屏幕像素信息并存储为纹理数据
        screenShot.ReadPixels(rect, 0, 0);
        screenShot.Apply();// 这一句必须有,像素信息并没有保存在2D纹理贴图中

        //读取将这些纹理数据,成一个png图片文件
        byte[] bytes = screenShot.EncodeToPNG();
        //写入文件 并且指定路径,因为使用该函数写入文件,同名的文件会被覆盖,所以,在路径中使用Time.time只是为了不出现同名文件而已, 没有什么实际的意义,只是当作个测试
        File.WriteAllBytes(filepath, bytes);

        //分享
        if (type == "wxtimeline")
        {
            PlatformDifferences.WXShareToTimeline("", "", "", filepath);
        }
        else if (type == "wxsession")
        {
            PlatformDifferences.WXShare("", "", "", filepath);
        }
        else
        {
            PlatformDifferences.QQShare("", "", "", filepath);
        }
    }
Пример #2
0
 void BtnWXShareToSessionClicked(GameObject sender)
 {
     SoundManager.Instance.PlaySound("音效/按钮");
     PlatformDifferences.WXShare("快来一起玩吧", "房间号" + BattleCode.text, "http://www.kawumei.com/", "http://www.kawumei.com/");
 }