Files
back_cantanBuilding/Assets/Scripts/Aquarium/UI/EventFishHuntingPanel.cs
2026-05-26 16:15:54 +08:00

407 lines
15 KiB
C#

using asap.core;
using cfg;
using DG.Tweening;
using game;
using GameCore;
using TMPro;
using UniRx;
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class EventFishHuntingPanel : MonoBehaviour
{
Tables _tables;
Head head;
Button switchbtn;
GameObject exchange;
GameObject title;
Button btn_aim;
TMP_Text text_name;
GameObject fish_info;
Image tag_fish;
TMP_Text text_fish_name;
GameObject mutated;
GameObject mutated_settlement;
GameObject root_settlement;
GameObject kill;
GameObject hurt;
Button btn_close;
Transform photo;
SpriteRenderer bg_photo;
Transform fishIconRT;
RawImage rawImage;
RenderTexture rt;
GameObject fishGo;
Camera rtCamera;
Transform avatarCapture;
Transform avatarEscape;
int fieldOfView = 60;
//鱼距离相机的位置
int fishPosZ = 20;
SmallGameData smallGameData;
string playFabId;
OpponentItemData opponentItemData;
bool isClick = false;
AquariumShooterFishManager AM;
int multiple;
[HideInInspector]
public ShooterFishAct shooterFishAct;
EventFishHuntingAim eventFishHuntingAim;
FishMovement fishMovement;
FishMovement curTarget;
int changeTargetCount = 0;
UIDownUp uIDownUp;
protected CompositeDisposable disposables = new CompositeDisposable();
private void Awake()
{
multiple = GContext.container.Resolve<PlayerData>().GetMagnification();
AM = GContext.container.Resolve<AquariumShooterFishManager>();
smallGameData = GContext.container.Resolve<SmallGameData>();
_tables = GContext.container.Resolve<Tables>();
text_name = transform.Find("root/title/bg/text_name").GetComponent<TMP_Text>();
head = transform.Find("root/title/btn_head").GetComponent<Head>();
switchbtn = transform.Find("root/switch/btn_switch/btn_green").GetComponent<Button>();
exchange = transform.Find("root/switch").gameObject;
title = transform.Find("root/title").gameObject;
btn_aim = transform.Find("root/btn_hunt").GetComponent<Button>();
kill = transform.Find("root/root_settlement/kill").gameObject;
hurt = transform.Find("root/root_settlement/hurt").gameObject;
root_settlement = transform.Find("root/root_settlement").gameObject;
btn_close = transform.Find("root/root_settlement/btn_play/btn_green").GetComponent<Button>();
fish_info = transform.Find("root/fish_info").gameObject;
tag_fish = fish_info.transform.Find("text_name/tag_fish").GetComponent<Image>();
text_fish_name = fish_info.transform.Find("text_name").GetComponent<TMP_Text>();
mutated = fish_info.transform.Find("mutated").gameObject;
mutated_settlement = transform.Find("root/root_settlement/photo/mutated").gameObject;
photo = transform.Find("root/root_settlement/photo");
bg_photo = photo.Find("mask_bg2/icon_fish/Camera/bg_photo").GetComponent<SpriteRenderer>();
fishIconRT = transform.Find("root/root_settlement/photo/mask_bg2/icon_fish");
avatarCapture = fishIconRT.Find("avatarCapture");
avatarEscape = fishIconRT.Find("avatarEscape");
rtCamera = fishIconRT.Find("Camera").GetComponent<Camera>();
rawImage = transform.Find("root/root_settlement/photo/mask_bg2/RawImage").GetComponent<RawImage>();
text_num = transform.Find("root/root_settlement/photo/reward/text_num").GetComponent<TMP_Text>();
text_num_buff = transform.Find("root/root_settlement/photo/reward/text_num/text_num_buff").GetComponent<TMP_Text>();
fx_ui_eventbankheistreward_money_01 = transform.Find("root/root_settlement/particle/fx_ui_eventbankheistreward_money_01").gameObject;
btn_close = transform.Find("root/root_settlement/btn_play/btn_green").GetComponent<Button>();
bg_extra = transform.Find("root/root_settlement/photo/bonus").gameObject;
reward_extra = transform.Find("root/root_settlement/photo/bonus/reward").GetComponent<RewardItemNew>();
tag_fish_settlement = transform.Find("root/root_settlement/photo/icon_rate").GetComponent<Image>();
text_fish_name_settlement = transform.Find("root/root_settlement/photo/text_name").GetComponent<TMP_Text>();
uIDownUp = transform.Find("root/OpenHuntingAim").GetComponent<UIDownUp>();
eventFishHuntingAim = transform.Find("root/EventFishHuntingAim").GetComponent<EventFishHuntingAim>();
eventFishHuntingAim.eventFishHuntingPanel = this;
}
private void Start()
{
GContext.OnEvent<ChangeSmallGameTargetEvent>().Subscribe(ChangeSmallGameTarget).AddTo(disposables);
opponentItemData = smallGameData.opponentData;
playFabId = smallGameData.opponentData.playFabID;
GContext.OnEvent<GetClubPlayInfoEvent>().Where(x => x.id == playFabId).Subscribe(SetAvatar).AddTo(disposables);
IUserService userService = GContext.container.Resolve<IUserService>();
PlayInfo clubPlayInfo = userService.GetPlayInfo(playFabId);
SetAvatar(clubPlayInfo);
if (GContext.container.Resolve<LeadboardData>().IsOpenleaderboard)
{
switchbtn.onClick.AddListener(OnClickHead);
}
else
{
exchange.SetActive(false);
switchbtn.enabled = false;
//exchange.SetActive(false);
}
btn_aim.onClick.AddListener(OnClickAni);
btn_close.onClick.AddListener(OnClickClose);
uIDownUp.onDown.AddListener(OnDownAim);
Debug.Log($"target_source Start isRobot: {opponentItemData.isRobot} target_group: {opponentItemData.target_group} target_source {opponentItemData.target_source}");
}
void OnClickClose()
{
GContext.Publish(new UnloadActToNextAct());
}
bool opening = false;
IEnumerator aniCameraMoveCoroutine;
void OnDownAim()
{
opening = true;
aniCameraMoveCoroutine = shooterFishAct.AniCameraMove();
StartCoroutine(FishHuntingAim());
//计时UP
uIDownUp.onUp.AddListener(OnUpAim);
}
IEnumerator FishHuntingAim()
{
yield return StartCoroutine(aniCameraMoveCoroutine);
if (!opening)
{
yield break;
}
eventFishHuntingAim.gameObject.SetActive(true);
float aimTime = eventFishHuntingAim.AimTime;
yield return new WaitForSeconds(aimTime);
ChangeTarget(null);
OnUpAim();
}
public async void OnUpAim()
{
if (!opening)
{
return;
}
uIDownUp.onUp.RemoveAllListeners();
OnClickAni();
eventFishHuntingAim.isFinish = true;
StopAllCoroutines();
opening = false;
uIDownUp.gameObject.SetActive(false);
eventFishHuntingAim.Trigger("Aim");
if (fishMovement == null)
{
await StartCoroutine(shooterFishAct.OnBack());
eventFishHuntingAim.isFinish = false;
eventFishHuntingAim.gameObject.SetActive(false);
await Awaiters.Seconds(shooterFishAct.AimBlockTime);
uIDownUp.gameObject.SetActive(true);
}
else
{
await Awaiters.Seconds(2);
eventFishHuntingAim.gameObject.SetActive(false);
}
}
async void OnClickAni()
{
isClick = true;
fishMovement = shooterFishAct.Target();
if (fishMovement != null)
{
eventFishHuntingAim.Trigger("Shoot");
int getGlodCount = (int)AM.RobFishRequest(changeTargetCount, multiple, playFabId, fishMovement.index, fishMovement.groupId, opponentItemData, out bool isRob, out int addRankCount);
await shooterFishAct.OnShoot(isRob);
title.SetActive(false);
exchange.SetActive(false);
btn_aim.gameObject.SetActive(false);
UIManager.Instance.DestroyUI(UITypes.EventBankHeistOpponentPopupPanel);
ShowFish(isRob);
await Awaiters.Seconds(shooterFishAct.ShootTime);
tag_fish_settlement.sprite = tag_fish.sprite;
text_fish_name_settlement.text = text_fish_name.text;
mutated_settlement.SetActive(fishMovement.index < fishMovement.slotData.mutants);
GContext.Publish(new VibrationData(HapticTypes.MediumImpact));
hurt.SetActive(!isRob);
kill.SetActive(isRob);
fx_ui_eventbankheistreward_money_01.SetActive(isRob);
await shooterFishAct.OnShooted(isRob);
SetData(getGlodCount, addRankCount);
var mapData = _tables.TbMapData.DataMap[AM.MapId];
string prefabName = mapData.AquariumPrefab;
Transform bg = photo.Find($"bg_{prefabName}");
if (bg != null)
{
bg_photo.sprite = bg.GetComponent<Image>().sprite;
}
root_settlement.SetActive(true);
fish_info.SetActive(false);
}
else
{
eventFishHuntingAim.Trigger("Back");
ToastPanel.Show(LocalizationMgr.GetText("UI_AquariumPanel_46"));
}
//exchange.SetActive(false);
}
async void OnClickHead()
{
//选择对象
await UIManager.Instance.ShowUI(UITypes.EventBankHeistOpponentPopupPanel);
}
public void ChangeTarget(FishMovement fish)
{
if (shooterFishAct == null)
{
return;
}
shooterFishAct.OnTargetChange(fish);
if (fish != curTarget)
{
fish_info.SetActive(fish != null);
curTarget = fish;
if (curTarget != null)
{
var item = _tables.TbItem.GetOrDefault(curTarget.slotData.fishItemID);
mutated.SetActive(curTarget.slotData.mutants > curTarget.index);
text_fish_name.text = LocalizationMgr.GetText(item.Name_l10n_key);
GContext.container.Resolve<IUIService>().SetImageSprite(tag_fish, "icon_fish_rate_tag_" + item.Quality);
}
}
}
async void ChangeSmallGameTarget(ChangeSmallGameTargetEvent data)
{
//exchange.SetActive(false);
switchbtn.enabled = false;
if (await data.ts.Task)
{
changeTargetCount++;
opponentItemData = data.opponentItemData;
playFabId = data.opponentItemData.playFabID;
IUserService userService = GContext.container.Resolve<IUserService>();
PlayInfo clubPlayInfo = userService.GetPlayInfo(playFabId);
SetAvatar(clubPlayInfo);
fish_info.SetActive(false);
}
//exchange.SetActive(true);
switchbtn.enabled = true;
}
public void SetAvatar(PlayInfo clubPlayInfo)
{
if (clubPlayInfo != null)
{
text_name.text = LocalizationMgr.GetFormatTextValue("UI_AquariumPanel_29", clubPlayInfo.name);
head.SetData(clubPlayInfo.avatarUrl);
}
}
void SetAvatar(GetClubPlayInfoEvent getClubPlayInfoEvent)
{
if (getClubPlayInfoEvent.id == playFabId)
{
text_name.text = LocalizationMgr.GetFormatTextValue("UI_AquariumPanel_29", getClubPlayInfoEvent.name);
head.SetData(getClubPlayInfoEvent.avatarUrl);
}
}
private void OnDisable()
{
if (rt != null)
{
rt.Release();
Destroy(rt);
rt = null;
}
if (fishGo != null)
{
Destroy(fishGo);
}
rtCamera.targetTexture = null;
disposables?.Dispose();
disposables = null;
}
GameObject fx_ui_eventbankheistreward_money_01;
TMP_Text text_num;
TMP_Text text_num_buff;
RewardItemNew reward_extra;
GameObject bg_extra;
int add = 0;
Image tag_fish_settlement;
TMP_Text text_fish_name_settlement;
void ShowFish(bool isRob)
{
if (fishMovement != null)
{
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;
var TankPosition = fishMovement.fishData.TankPosition;
Vector3 pos = new Vector3(TankPosition[0], TankPosition[1], TankPosition[2] + fishPosZ);
Transform avatar = isRob ? avatarCapture : avatarEscape;
//rawImage.color = isRob ? Color.white : Color.black;
pos += avatar.localPosition;
avatar.localPosition = pos;
//fishMovement.RemoveEye();
fishGo = Instantiate(fishMovement.fish.gameObject, avatar);
Fish fish = fishGo.GetComponent<Fish>();
fish.animator.transform.localPosition = Vector3.zero;
var TankRotation = fishMovement.fishData.TankRotation;
fish.transform.localRotation = Quaternion.Euler(TankRotation[0], TankRotation[1], TankRotation[2]);
fish.transform.localScale = Vector3.one * fishMovement.fishData.TankScale * fishMovement.mutantScale;
//fish.transform.localPosition = pos;
rtCamera.targetTexture = rt;
rawImage.texture = rt;
rtCamera.Render();
}
//var mapData = _tables.TbMapData.DataMap[AM.MapId];
//var AquariumBg = transform.Find($"root/root_settlement/photo/mask_bg2/{mapData.AquariumBg}");
//if (AquariumBg != null)
//{
// AquariumBg.gameObject.SetActive(true);
//}
}
void SetData(int glod, int addRankCount)
{
//superCashBonus = 0.5f;
FishingEventData _fishingEventData = GContext.container.Resolve<FishingEventData>();
bool isRankInit = _fishingEventData.rankInit != null;
if (isRankInit && addRankCount > 0)
{
reward_extra.SetData(new ItemData() { id = _fishingEventData.rankInit.TokenID, count = addRankCount });
//GContext.container.Resolve<SmallGameData>().image_extra_pos = bg_extra.transform.position;
bg_extra.SetActive(true);
}
else
{
bg_extra.SetActive(false);
}
//this.multiple = multiple;
add = glod;
GContext.Publish(new TargetAddData(1002, 0, add));
StartCoroutine(ShowMoney());
}
IEnumerator ShowMoney()
{
text_num.text = "";
text_num_buff.text = "";
SuperHunt superHunt = GContext.container.Resolve<BuffDataCenter>().GetWeelyBuffTimeData<SuperHunt>(true);
float superCashBonus = 0;
if (superHunt != null)
{
superCashBonus = superHunt.CashBonus;
}
if (superCashBonus > 0.001f)
{
text_num.color = Color.black;
text_num_buff.color = Color.white;
}
yield return new WaitForSeconds(1.2f);
int gold = 0;
DOTween.To(() => gold, x => gold = x, add, 1f).OnUpdate(() =>
{
text_num.text = ConvertTools.GetNumberString2(gold);
text_num_buff.text = text_num.text;
});
}
}