2024-12-13 16:40:14 +08:00
using Newtonsoft.Json ;
using System.Collections ;
using System.Collections.Generic ;
using UnityEngine ;
using UnityEngine.UI ;
using QRCodeShareMain ;
using static Cinemachine . CinemachineBlendDefinition ;
using TMPro ;
2024-12-14 14:46:16 +08:00
public class ToFriend : Base
2024-12-13 16:40:14 +08:00
{
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 }
} ;
// <20> 첽<EFBFBD> <ECB2BD> ѯ<EFBFBD> <D1AF> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ϣ
string response14 = await web . SendRequest ( web . URL + "/snail/user/queryUserInfo" , "POST" , "{}" , head14 ) ;
Debug . Log ( "1.4<EFBFBD> <EFBFBD> ѯ<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ϣ" + 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 ) ;
2024-12-14 14:46:16 +08:00
addEventPopUp ( "<22> <> <EFBFBD> <EFBFBD> <EFBFBD> ɹ<EFBFBD> " ) ;
2024-12-13 16:40:14 +08:00
// 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 ;
}
}