先修复一下,错误的场景 删除不必要的钓场资产 修复into场景 update:更新meta文件,修复报错 update:修复资源 修复第一章节建造 修复建造第三章 update:删除多余内容 update:更新README.md update:还原图标 update:更新README update:更新配置
192 lines
5.9 KiB
C#
192 lines
5.9 KiB
C#
using asap.core;
|
|
using cfg;
|
|
using game;
|
|
using GameCore;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UnityNative.Sharing;
|
|
|
|
public class TravelMapPhotoPanel : MonoBehaviour
|
|
{
|
|
Image icon_photo;
|
|
TMP_Text text_map;
|
|
Button btn_share;
|
|
IUnityNativeSharing adapter;
|
|
Button btn_next;
|
|
public GameObject photo_camera_go;
|
|
Camera photo_camera;
|
|
GameObject clickMask;
|
|
CampDataMM campData;
|
|
PlayerData playerData;
|
|
Tables tables;
|
|
byte[] bytes;
|
|
string imageName;
|
|
string savePath;
|
|
private void Awake()
|
|
{
|
|
playerData = GContext.container.Resolve<PlayerData>();
|
|
campData = GContext.container.Resolve<CampDataMM>();
|
|
tables = GContext.container.Resolve<Tables>();
|
|
|
|
btn_share = transform.Find("root/btn_share/btn_green").GetComponent<Button>();
|
|
btn_next = transform.Find("root/btn_next/btn_green").GetComponent<Button>();
|
|
icon_photo = transform.Find("root/photo/icon_photo").GetComponent<Image>();
|
|
text_map = transform.Find("root/text_map").GetComponent<TMP_Text>();
|
|
clickMask = transform.Find("root/clickMask").gameObject;
|
|
}
|
|
private void Start()
|
|
{
|
|
var go = Instantiate(photo_camera_go);
|
|
photo_camera = go.GetComponent<Camera>();
|
|
clickMask.SetActive(true);
|
|
int PreID = campData.PreID;
|
|
savePath = "";
|
|
Construction data = tables.TbConstruction.DataMap[PreID];
|
|
imageName = $"TravelMap.png";
|
|
|
|
string mapname = LocalizationMgr.GetText(campData.GetMMTString(data.Name_l10n_key));
|
|
text_map.text = $"{data.ID % 100}.{mapname}";
|
|
|
|
btn_next.onClick.AddListener(OnNextClick);
|
|
btn_share.onClick.AddListener(OnClickInviteLink);
|
|
OnCaptureFishPhoto();
|
|
}
|
|
async void OnCaptureFishPhoto()
|
|
{
|
|
Rect rect = icon_photo.rectTransform.rect;
|
|
var _rt = new RenderTexture((int)rect.width, (int)rect.height, 24);
|
|
photo_camera.targetTexture = _rt;
|
|
photo_camera.transform.position = Camera.main.transform.position;
|
|
photo_camera.transform.rotation = Camera.main.transform.rotation;
|
|
await Awaiters.NextFrame;
|
|
photo_camera.Render();
|
|
photo_camera.targetTexture = null;
|
|
//Capture By Camera
|
|
Texture2D texture2D = new Texture2D(_rt.width, _rt.height, TextureFormat.RGB24, false);
|
|
var currentRt = RenderTexture.active;
|
|
RenderTexture.active = _rt;
|
|
texture2D.ReadPixels(new Rect(0, 0, _rt.width, _rt.height), 0, 0);
|
|
texture2D.Apply();
|
|
icon_photo.sprite = Sprite.Create(texture2D, new Rect(0, 0, _rt.width, _rt.height), new Vector2(0.5f, 0.5f));
|
|
|
|
bytes = texture2D.EncodeToPNG();
|
|
//ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_65"));
|
|
RenderTexture.active = currentRt;
|
|
_rt.Release();
|
|
clickMask.SetActive(false);
|
|
Destroy(photo_camera.gameObject);
|
|
}
|
|
|
|
void MediaSaveCallback(bool success, string path)
|
|
{
|
|
if (success)
|
|
{
|
|
savePath = path;
|
|
Debug.Log("Image saved to: " + path);
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError("Failed to save image.");
|
|
}
|
|
}
|
|
|
|
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 OnNextClick()
|
|
{
|
|
if (!string.IsNullOrEmpty(savePath))
|
|
{
|
|
CaptureImageSaver.DeleteImagePersistent(savePath);
|
|
}
|
|
if (campData.IsCanSkyscraper)
|
|
{
|
|
InfiniteBuildingAct();
|
|
}
|
|
else
|
|
{
|
|
OnGoto();
|
|
}
|
|
}
|
|
|
|
async void OnGoto()
|
|
{
|
|
var mapData = tables.TbMapData.DataMap[playerData.lastMapId];
|
|
|
|
ILoadResourceService loadResourceService = GContext.container.Resolve<ILoadResourceService>();
|
|
bool isCanEnter = await loadResourceService.Load(mapData.EnvName);
|
|
if (isCanEnter)
|
|
{
|
|
EnterMap();
|
|
}
|
|
else
|
|
{
|
|
var panel = await UIManager.Instance.ShowUI(UITypes.CloudTransitionPanel);
|
|
panel.GetComponent<CloudTransitionPanel>().SetBtn(true, EnterMap, OnCloseClick, false);
|
|
}
|
|
}
|
|
void EnterMap()
|
|
{
|
|
if (campData.NextMapID != -1)
|
|
{
|
|
campData.ChangeNextCampID();
|
|
GContext.Publish(new ConditionTypeEvent(ConditionType.MapUnlocked, campData.Id));
|
|
}
|
|
playerData.SetCurrentMapId(playerData.lastMapId);
|
|
//打开旅行地图
|
|
//OnCloseClick();
|
|
OpenTravelMap();
|
|
}
|
|
void OpenTravelMap()
|
|
{
|
|
HomeintoEvent homeintoEvent = new HomeintoEvent();
|
|
GContext.Publish(homeintoEvent);
|
|
}
|
|
public void OnCloseClick()
|
|
{
|
|
GContext.Publish(new UnloadActToNextAct());
|
|
UIManager.Instance.DestroyUI(UITypes.TravelMapCampPhotoPanel);
|
|
}
|
|
|
|
async void InfiniteBuildingAct()
|
|
{
|
|
ILoadResourceService loadResourceService = GContext.container.Resolve<ILoadResourceService>();
|
|
bool isCanEnter = await loadResourceService.Load("InfiniteBuildingAct");
|
|
if (isCanEnter)
|
|
{
|
|
ToCampSkyscraper();
|
|
}
|
|
else
|
|
{
|
|
var panel = await UIManager.Instance.ShowUI(UITypes.CloudTransitionPanel);
|
|
panel.GetComponent<CloudTransitionPanel>().SetBtn(true, ToCampSkyscraper, OnCloseClick, false);
|
|
}
|
|
}
|
|
|
|
void ToCampSkyscraper()
|
|
{
|
|
GContext.Publish(new UnloadActToNextAct("InfiniteBuildingAct"));
|
|
UIManager.Instance.DestroyUI(UITypes.TravelMapCampPhotoPanel);
|
|
}
|
|
}
|
|
public class HomeintoEvent
|
|
{
|
|
}
|