コード例 #1
0
        private IEnumerator StartShare(int offset)
        {
            yield return(new WaitForEndOfFrame());

            var texture       = TextureHelper.CaptureByRect(new Rect(0, 0, Screen.width, Screen.height));
            var inGameConmfig = _inGameConfig.Read();

            if (inGameConmfig == null)
            {
                _dialogManager.ShowToast("数据发生错误,无法分享T_T", 2, true);
                _analyticManager.Event("game_wx_share_capture_screen_fail");
                yield break;
            }

            var inviteUrl = inGameConmfig.wx_invite_url;

            if (string.IsNullOrEmpty(inviteUrl))
            {
                _dialogManager.ShowToast("数据发生错误,无法分享T_T", 2, true);
                _analyticManager.Event("game_wx_share_capture_screen_fail");
                yield break;
            }

            var qrCodeTexture = GenerateQRCode.GenerateQRCodeTexture2DFromUrl(inviteUrl);

            var startX = Screen.width - offset;
            var startY = Screen.height - offset;

            //融合图片
            TextureHelper.ComposeTwoTexture(texture, qrCodeTexture, startX, startY);

            var bytes = texture.EncodeToPNG();
            var path  = _filePicManager.SavePic(bytes, WechatShareFile);

            if (!string.IsNullOrEmpty(path))
            {
                _dialogManager.ShowDialog <WeChatShareDialog>(DialogName.WeChatShareDialog, false, true,
                                                              (dialog) =>
                {
                    dialog.ApplyData("截图分享", null, null, path, null, null, null);
                    dialog.Show();
                });

                _analyticManager.Event("game_wx_share");
            }
            else
            {
                _dialogManager.ShowToast("截屏失败了T_T", 2, true);
                _analyticManager.Event("game_wx_share_capture_screen_fail");
            }
        }
コード例 #2
0
        private void DownloadFinish(DownloadTask task)
        {
            if (task == null)
            {
                return;
            }

            var www = task.Downloader;

            if (www == null)
            {
                return;
            }

            if (!string.IsNullOrEmpty(www.error))
            {
                MyLog.ErrorWithFrame(name, string.Format("Download failed! url: {0}, error: {1}", task.Url, www.error));
                return;
            }

            try
            {
                var type = task.Type;
                if (type == ContentType.Image)
                {
                    // 将下载的图片保存到路径中。
                    if (!www.texture)
                    {
                        return;
                    }

                    if (string.IsNullOrEmpty(task.FileName))
                    {
                        return;
                    }

                    var bytes = www.texture.EncodeToPNG();
                    _filePicManager.SavePic(bytes, task.FileName);
                }
                else if (type == ContentType.Bytes)
                {
                    if (!Directory.Exists(FilePath.BinaryFilePath()))
                    {
                        Directory.CreateDirectory(FilePath.BinaryFilePath());
                    }

                    var path = FilePath.BinaryFilePath() + task.FileName;
                    File.WriteAllBytes(path, www.bytes);
                }
                else if (type == ContentType.Text)
                {
                    if (!Directory.Exists(FilePath.TextPath()))
                    {
                        Directory.CreateDirectory(FilePath.TextPath());
                    }

                    var path = FilePath.TextPath() + task.FileName;
                    File.WriteAllBytes(path, www.bytes);
                }

                MyLog.InfoWithFrame(name, string.Format("Finish download: {0}", task.FileName));
            }
            catch (Exception e)
            {
                MyLog.ErrorWithFrame(name, e.Message);
            }
        }