75 lines
2.0 KiB
C#
75 lines
2.0 KiB
C#
using GameCore;
|
|
using System;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UnityNative.Sharing;
|
|
|
|
public class FishingRewardPhoto : MonoBehaviour
|
|
{
|
|
Image icon_photo;
|
|
Button btn_share;
|
|
Button btn_back;
|
|
public Action OnBackClick; // 用于通知外部点击返回按钮
|
|
GameObject clickMask;
|
|
byte[] bytes;
|
|
IUnityNativeSharing adapter;
|
|
string imageName = "TravelFish.png";
|
|
string savePath;
|
|
private void Awake()
|
|
{
|
|
btn_back = transform.Find("btn_back/btn_green").GetComponent<Button>();
|
|
clickMask = transform.Find("clickMask").gameObject;
|
|
btn_share = transform.Find("btn_share/btn_green").GetComponent<Button>();
|
|
icon_photo = transform.Find("photo/icon_photo").GetComponent<Image>();
|
|
clickMask.SetActive(false);
|
|
btn_share.onClick.AddListener(OnClickInviteLink);
|
|
btn_back.onClick.AddListener(OnClickBack);
|
|
}
|
|
|
|
public void SetData(Sprite sprite, byte[] bytes)
|
|
{
|
|
icon_photo.sprite = sprite;
|
|
this.bytes = bytes;
|
|
}
|
|
|
|
void OnClickBack()
|
|
{
|
|
OnBackClick?.Invoke(); // 调用外部传入的回调方法
|
|
if (!string.IsNullOrEmpty(savePath))
|
|
{
|
|
CaptureImageSaver.DeleteImagePersistent(savePath);
|
|
}
|
|
}
|
|
|
|
void OnClickInviteLink()
|
|
{
|
|
//存图片
|
|
clickMask.SetActive(true);
|
|
CaptureImageSaver.SaveImagePersistent(bytes, imageName, MediaSaveCallback);
|
|
clickMask.SetActive(false);
|
|
|
|
if (string.IsNullOrEmpty(savePath))
|
|
{
|
|
return;
|
|
}
|
|
if (adapter == null)
|
|
{
|
|
adapter = UnityNativeSharing.Create();
|
|
}
|
|
string invite = LocalizationMgr.GetText("UI_FishingSocialPanel_44");
|
|
adapter.ShareScreenshotAndText(invite, savePath);
|
|
}
|
|
void MediaSaveCallback(bool success, string path)
|
|
{
|
|
if (success)
|
|
{
|
|
savePath = path;
|
|
Debug.Log("Image saved to: " + path);
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError("Failed to save image.");
|
|
}
|
|
}
|
|
}
|