207 lines
7.8 KiB
C#
207 lines
7.8 KiB
C#
using System.Threading.Tasks;
|
|
using cfg;
|
|
using asap.core;
|
|
using GameCore;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.AddressableAssets;
|
|
using UnityEngine.UI;
|
|
|
|
public class AquariumReportPhoto : MonoBehaviour
|
|
{
|
|
SpriteRenderer bg_photo;
|
|
Transform fishIconRT;
|
|
RawImage rawImage;
|
|
RenderTexture rt;
|
|
Camera rtCamera;
|
|
Transform avatarCapture;
|
|
Vector3 startPosition;
|
|
int fieldOfView = 60;
|
|
int fishPosZ = 20;
|
|
|
|
GameObject kuang_mutated;
|
|
GameObject kuang_nml;
|
|
GameObject fx_photo_show_nml;
|
|
GameObject fx_photo_show_mutated;
|
|
GameObject bg_mutated;
|
|
GameObject bg_nml;
|
|
|
|
TMP_Text text_num_level;
|
|
Image tag_fish_settlement;
|
|
TMP_Text text_fish_name_settlement;
|
|
|
|
GameObject fishGo;
|
|
int loadIndex = -1;
|
|
|
|
public void Init(Transform iconFishRoot)
|
|
{
|
|
fishIconRT = iconFishRoot != null ? iconFishRoot : transform.Find("mask_bg2/icon_fish");
|
|
kuang_mutated = transform.Find("kuang_mutated").gameObject;
|
|
kuang_nml = transform.Find("kuang_nml").gameObject;
|
|
var fxNml = kuang_nml.transform.Find("fx_ui_fishingsettlement_hunt_photo_show");
|
|
if (fxNml != null) fx_photo_show_nml = fxNml.gameObject;
|
|
var fxMutated = kuang_mutated.transform.Find("fx_ui_fishingsettlement_hunt_photo_show");
|
|
if (fxMutated != null) fx_photo_show_mutated = fxMutated.gameObject;
|
|
bg_mutated = transform.Find("level/bg_mutated").gameObject;
|
|
bg_nml = transform.Find("level/bg_nml").gameObject;
|
|
bg_photo = fishIconRT.Find("Camera/bg_photo").GetComponent<SpriteRenderer>();
|
|
avatarCapture = fishIconRT.Find("avatarCapture");
|
|
rtCamera = fishIconRT.Find("Camera").GetComponent<Camera>();
|
|
rawImage = transform.Find("mask_bg2/RawImage").GetComponent<RawImage>();
|
|
text_num_level = transform.Find("level/text_level_num").GetComponent<TMP_Text>();
|
|
tag_fish_settlement = transform.Find("icon_rate").GetComponent<Image>();
|
|
text_fish_name_settlement = transform.Find("text_name").GetComponent<TMP_Text>();
|
|
startPosition = avatarCapture.localPosition;
|
|
}
|
|
|
|
public async Task ShowFish(AquariumSlotData data, Item fishItem, FishingAquariumAct act)
|
|
{
|
|
CleanupFish();
|
|
|
|
Tables tables = GContext.container.Resolve<Tables>();
|
|
var fishData = tables.TbFishData.GetOrDefault(fishItem.RedirectID);
|
|
|
|
if (rt == null)
|
|
SetRT();
|
|
var TankPosition = fishData.TankPosition;
|
|
Vector3 pos = new Vector3(TankPosition[0], TankPosition[1], TankPosition[2] + fishPosZ);
|
|
pos += startPosition;
|
|
avatarCapture.localPosition = pos;
|
|
|
|
int curLoadIndex = ++loadIndex;
|
|
var prefab = await Addressables.InstantiateAsync(fishData.Fbx, avatarCapture).Task;
|
|
if (loadIndex != curLoadIndex || avatarCapture == null)
|
|
{
|
|
Addressables.ReleaseInstance(prefab);
|
|
return;
|
|
}
|
|
fishGo = prefab;
|
|
|
|
var fish = fishGo.GetComponent<Fish>();
|
|
fish.animator.transform.localPosition = Vector3.zero;
|
|
fish.EnableCollider();
|
|
fish.animator.Play("Swim01", 0, Random.Range(0, 0.8f));
|
|
fish.animator.transform.localPosition = Vector3.zero;
|
|
fishGo.transform.localPosition = Vector3.zero;
|
|
fishGo.transform.localScale = Vector3.one * fishData.TankScale;
|
|
var TankRotation = fishData.TankRotation;
|
|
fishGo.transform.localRotation = Quaternion.Euler(TankRotation[0], TankRotation[1], TankRotation[2]);
|
|
|
|
if (data.mutants > 0)
|
|
{
|
|
var fishMutant = tables.TbFishMutant;
|
|
Material mutantMat = act != null ? act.MutantMaterial : await Addressables.LoadAssetAsync<Material>(fishMutant.Material).Task;
|
|
GameObject fxLeftEyePrefab = act != null ? act.FxLeftEyePrefab : await Addressables.LoadAssetAsync<GameObject>(fishMutant.FxLeftEye).Task;
|
|
GameObject fxRightEyePrefab = act != null ? act.FxRightEyePrefab : await Addressables.LoadAssetAsync<GameObject>(fishMutant.FxRightEye).Task;
|
|
|
|
if (fishGo == null) return;
|
|
|
|
float eyeScale = fishMutant.FxAquariumScale[fishData.Quality - 1];
|
|
if (fish.LeftEye != null && fxLeftEyePrefab != null)
|
|
{
|
|
var leftEye = Object.Instantiate(fxLeftEyePrefab);
|
|
leftEye.transform.localScale = Vector3.one * eyeScale;
|
|
leftEye.transform.parent = fish.LeftEye;
|
|
leftEye.transform.localPosition = Vector3.zero;
|
|
leftEye.transform.localRotation = Quaternion.identity;
|
|
}
|
|
if (fish.RightEye != null && fxRightEyePrefab != null)
|
|
{
|
|
var rightEye = Object.Instantiate(fxRightEyePrefab);
|
|
rightEye.transform.localScale = Vector3.one * eyeScale;
|
|
rightEye.transform.parent = fish.RightEye;
|
|
rightEye.transform.localPosition = Vector3.zero;
|
|
rightEye.transform.localRotation = Quaternion.identity;
|
|
}
|
|
Renderer[] renderers = fishGo.GetComponentsInChildren<Renderer>();
|
|
if (renderers != null && renderers.Length > 0)
|
|
{
|
|
var render = renderers[0];
|
|
var materials = render.materials;
|
|
for (int i = 0; i < materials.Length; i++)
|
|
{
|
|
var mat = materials[i];
|
|
var matP = new Material(mutantMat);
|
|
matP.SetTexture("_BaseMap", mat.GetTexture("_BaseMap"));
|
|
matP.SetTexture("_BumpMap", mat.GetTexture("_BumpMap"));
|
|
materials[i] = matP;
|
|
}
|
|
render.materials = materials;
|
|
}
|
|
}
|
|
|
|
PlayerFishData playerFishData = GContext.container.Resolve<PlayerFishData>();
|
|
int cardLv;
|
|
if (fishItem.Quality < 6)
|
|
cardLv = playerFishData.GetDataLevel(fishItem.RedirectID);
|
|
else
|
|
cardLv = GContext.container.Resolve<PlayerData>().benefitsLevel[4];
|
|
text_num_level.text = cardLv.ToString();
|
|
|
|
await GContext.container.Resolve<IUIService>().SetImageSprite(tag_fish_settlement, "icon_fish_rate_tag_" + fishItem.Quality);
|
|
text_fish_name_settlement.text = LocalizationMgr.GetText(fishItem.Name_l10n_key);
|
|
|
|
bool isMutated = data.mutants > 0;
|
|
kuang_mutated.SetActive(isMutated);
|
|
bg_mutated.SetActive(isMutated);
|
|
kuang_nml.SetActive(!isMutated);
|
|
bg_nml.SetActive(!isMutated);
|
|
}
|
|
|
|
void SetRT()
|
|
{
|
|
RectTransform raw = rawImage.GetComponent<RectTransform>();
|
|
rt = new RenderTexture((int)raw.rect.width, (int)raw.rect.height, 24, RenderTextureFormat.ARGB32);
|
|
rtCamera.fieldOfView = fieldOfView;
|
|
rtCamera.enabled = true;
|
|
rtCamera.targetTexture = rt;
|
|
rawImage.texture = rt;
|
|
rtCamera.Render();
|
|
}
|
|
|
|
public void ReplayPhotoShowFx()
|
|
{
|
|
GameObject fx = kuang_nml.activeSelf ? fx_photo_show_nml : fx_photo_show_mutated;
|
|
if (fx != null)
|
|
{
|
|
fx.SetActive(false);
|
|
fx.SetActive(true);
|
|
}
|
|
}
|
|
|
|
public void SetBackground(int mapId)
|
|
{
|
|
var mapData = GContext.container.Resolve<Tables>().TbMapData.DataMap[mapId];
|
|
string prefabName = mapData.AquariumPrefab;
|
|
Transform bg = transform.Find($"bg_{prefabName}");
|
|
if (bg != null)
|
|
{
|
|
bg_photo.sprite = bg.GetComponent<Image>().sprite;
|
|
}
|
|
}
|
|
|
|
public void CleanupFish()
|
|
{
|
|
if (fishGo != null)
|
|
{
|
|
Addressables.ReleaseInstance(fishGo);
|
|
fishGo = null;
|
|
}
|
|
}
|
|
|
|
public void Cleanup()
|
|
{
|
|
CleanupFish();
|
|
if (rt != null)
|
|
{
|
|
rt.Release();
|
|
Destroy(rt);
|
|
rt = null;
|
|
}
|
|
if (rtCamera != null)
|
|
{
|
|
rtCamera.targetTexture = null;
|
|
}
|
|
}
|
|
}
|