84 lines
2.9 KiB
C#
84 lines
2.9 KiB
C#
using Newtonsoft.Json;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using QRCodeShareMain;
|
|
using static Cinemachine.CinemachineBlendDefinition;
|
|
using TMPro;
|
|
|
|
public class ToFriend : Base
|
|
{
|
|
public Image Tofrienf;
|
|
private Texture2D currentQRCodeGenerate = null;
|
|
public UserInfomation14 userInfomation14;
|
|
public Button SaveButton;
|
|
// Start is called before the first frame update
|
|
async void Start()
|
|
{
|
|
Dictionary<string, string> head14 = new Dictionary<string, string>
|
|
{
|
|
{ "Authorization", Global.global.serverResponse.data.token }
|
|
};
|
|
|
|
// 异步查询玩家信息
|
|
string response14 = await web.SendRequest(web.URL + "/snail/user/queryUserInfo", "POST", "{}", head14);
|
|
Debug.Log("1.4查询玩家信息" + response14);
|
|
userInfomation14 = JsonConvert.DeserializeObject<UserInfomation14>(response14);
|
|
OnClickGenerateQRCode(userInfomation14.data.inviteCodeMy);
|
|
SaveButton.onClick.AddListener((() =>
|
|
{
|
|
StartCoroutine(TakeScreenshotAndSave());
|
|
}));
|
|
}
|
|
private IEnumerator TakeScreenshotAndSave()
|
|
{
|
|
yield return new WaitForEndOfFrame();
|
|
|
|
Texture2D ss = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);
|
|
ss.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
|
|
ss.Apply();
|
|
|
|
// Save the screenshot to Gallery/Photos
|
|
NativeGallery.Permission permission = NativeGallery.SaveImageToGallery(ss, "GalleryTest", "Image.png", (success, path) => Debug.Log("Media save result: " + path + " " + path));
|
|
|
|
Debug.Log("Permission result: " + permission);
|
|
addEventPopUp("保存成功");
|
|
// To avoid memory leaks
|
|
Destroy(ss);
|
|
}
|
|
private void OnClickGenerateQRCode(string content)
|
|
{
|
|
currentQRCodeGenerate = HelloWorldQRCode(content);
|
|
|
|
if (currentQRCodeGenerate != null)
|
|
{
|
|
ShowImage(Tofrienf, currentQRCodeGenerate);
|
|
// Enable the download image button is the texture is not null
|
|
|
|
}
|
|
|
|
}
|
|
private void ShowImage(Image showImage, Texture2D image)
|
|
{
|
|
showImage.sprite = ImageProcessing.ConvertTexture2DToSprite(image);
|
|
float imageSize = Mathf.Max(showImage.GetComponent<RectTransform>().sizeDelta.x, showImage.GetComponent<RectTransform>().sizeDelta.y);
|
|
|
|
showImage.GetComponent<RectTransform>().sizeDelta = image.width <= image.height ?
|
|
new Vector2(imageSize / image.height * image.width, imageSize) :
|
|
new Vector2(imageSize, imageSize * image.height / image.width);
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
private Texture2D HelloWorldQRCode(string content)
|
|
{
|
|
QRImageProperties properties = new QRImageProperties(500, 500, 50);
|
|
Texture2D QRCodeImage = QRCodeShare.CreateQRCodeImage(content, properties);
|
|
return QRCodeImage;
|
|
}
|
|
}
|