Files
MinFt/Client/Assets/Scripts/UI/FishCardReviewPopupPanel.cs
Liubing\LB 3d8d4d18f3 first commit
先修复一下,错误的场景

删除不必要的钓场资产

修复into场景

update:更新meta文件,修复报错

update:修复资源

修复第一章节建造

修复建造第三章

update:删除多余内容

update:更新README.md

update:还原图标

update:更新README

update:更新配置
2026-04-28 02:17:22 +08:00

193 lines
6.4 KiB
C#

using System.Collections.Generic;
using cfg;
using UnityEngine;
using UnityEngine.UI;
using GameCore;
using UnityEngine.AddressableAssets;
using asap.core;
using Game;
public class OnFishLoadEvent
{
public OnFishLoadEvent(GameObject fish, string fishName)
{
this.fish = fish;
this.fishName = fishName;
}
public GameObject fish;
public string fishName;
}
public class FishCardReviewPopupPanel : MonoBehaviour
{
public Button btn_mask;
public Button btn_close;
private RectTransform content;
public PanelScroll panelScroll;
public GameObject cardItem;
public Button btn_left;
public Button btn_right;
public GameObject btn_left_icon;
public GameObject btn_left_icon_gray;
public GameObject btn_right_icon;
public GameObject btn_right_icon_gray;
public float speed = 0.5f;
public List<FishCardItemData> fishCardItemData = new List<FishCardItemData>();
private Dictionary<string, GameObject> fishAvatar = new Dictionary<string, GameObject>();
private Dictionary<string, GameObject> fishPrefabs = new Dictionary<string, GameObject>();
List<string> fishNameList = new List<string>();
float itemWidth;
bool isShow = false;
int index = 0;
public List<FishData> fishDatas;
//创建一个实例
public static FishCardReviewPopupPanel Instance;
void Awake()
{
btn_mask = transform.Find("mask").GetComponent<Button>();
btn_close = transform.Find("btn_close").GetComponent<Button>();
panelScroll = transform.Find("root").GetComponent<PanelScroll>();
cardItem = transform.Find("root/Viewport/Content/root").gameObject;
content = transform.Find("root/Viewport/Content").GetComponent<RectTransform>();
btn_left = transform.Find("btn_close/btn_arrow_left").GetComponent<Button>();
btn_right = transform.Find("btn_close/btn_arrow_right").GetComponent<Button>();
btn_left_icon = transform.Find("btn_close/btn_arrow_left/icon").gameObject;
btn_left_icon_gray = transform.Find("btn_close/btn_arrow_left/icon_gray").gameObject;
btn_right_icon = transform.Find("btn_close/btn_arrow_right/icon").gameObject;
btn_right_icon_gray = transform.Find("btn_close/btn_arrow_right/icon_gray").gameObject;
Instance = this;
}
//private void OnEnable()
//{
// FishingSystem.Instance.HideFishenv();
//}
void Start()
{
itemWidth = cardItem.GetComponent<RectTransform>().sizeDelta.x;
btn_close.onClick.AddListener(() => { UIManager.Instance.HideUI(UITypes.FishCardReviewPopupPanel); });
btn_mask.onClick.AddListener(() => { UIManager.Instance.HideUI(UITypes.FishCardReviewPopupPanel); });
btn_left.onClick.AddListener(OnLeftClick);
btn_right.onClick.AddListener(OnRightClick);
panelScroll.loop = false;
isShow = true;
ScrollInit();
}
public void SetFish(int _index, List<FishData> _fishDatas, bool isMask = true)
{
index = _index;
fishCardItemData.Clear();
fishDatas = _fishDatas;
for (int i = 0; i < _fishDatas.Count; i++)
{
fishCardItemData.Add(new FishCardItemData(_fishDatas[i], SetFishAsync, speed, isMask));
}
if (isShow)
{
ScrollInit();
}
}
async void SetFishAsync(FishCardItem fishCardItem)
{
FishData fishData = fishCardItem.data.fishData;
//fishAvatar是否包含data.Fbx,包含则取出来,不包含则加载
if (!fishAvatar.ContainsKey(fishData.Fbx))
{
if (fishNameList.Contains(fishData.Fbx))
{
return;
}
fishNameList.Add(fishData.Fbx);
var fishPrefab = await Addressables.LoadAssetAsync<GameObject>(fishData.Fbx).Task;
if (fishPrefab != null)
{
if (this == null)
{
Addressables.Release(fishPrefab);
return;
}
if (fishPrefabs.ContainsKey(fishData.Fbx))
{
Addressables.Release(fishPrefab);
}
else
{
fishPrefabs.Add(fishData.Fbx, fishPrefab);
var go = Instantiate(fishPrefab, fishCardItem.avatar);
go.SetActive(false);
fishAvatar.Add(fishData.Fbx, go);
go.transform.localRotation = Quaternion.Euler(fishData.TankRotation[0], fishData.TankRotation[1], fishData.TankRotation[2]);
go.transform.localScale = Vector3.one * fishData.TankScale;
}
}
}
GameObject fish = fishAvatar.GetValueOrDefault(fishData.Fbx);
GContext.Publish(new OnFishLoadEvent(fish, fishData.Fbx));
}
public void SetFish(int _index)
{
index = _index;
if (isShow)
{
ScrollInit();
}
}
void ScrollInit()
{
panelScroll.Init<FishCardItem, FishCardItemData>(itemWidth, cardItem, OnClickItem, fishCardItemData, true, index);
OnLeftOrRight();
}
void OnClickItem(FishCardItem item)
{
GContext.Publish(new EventUISound(SoundType.audio_ui_fishingmap_btn_detail));
index = panelScroll.currentIndex;
btn_left.interactable = true;
btn_right.interactable = true;
OnLeftOrRight();
}
void OnLeftClick()
{
if (index > 0)
{
btn_left.interactable = false;
index--;
panelScroll.JumpToTarget(index);
OnLeftOrRight();
}
}
void OnRightClick()
{
if (index < fishCardItemData.Count - 1)
{
btn_right.interactable = false;
index++;
panelScroll.JumpToTarget(index);
OnLeftOrRight();
}
}
void OnLeftOrRight()
{
btn_left_icon.SetActive(index > 0);
btn_left_icon_gray.SetActive(index <= 0);
btn_right_icon.SetActive(index < fishCardItemData.Count - 1);
btn_right_icon_gray.SetActive(index >= fishCardItemData.Count - 1);
}
//private void OnDisable()
//{
// FishingSystem.Instance.ShowFishenv();
//}
private void OnDestroy()
{
foreach (KeyValuePair<string, GameObject> v in fishPrefabs)
{
Addressables.Release(v.Value);
}
fishPrefabs.Clear();
fishAvatar.Clear();
}
}