Files
MinFt/Client/Assets/Scripts/UI/Item/FishCardItem.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

265 lines
9.5 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using asap.core;
using cfg;
using GameCore;
using MH.WaterCausticsModules;
using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UniRx;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class FishCardItem : PanelItemBase<FishCardItemData>
{
WaterCausticsEffect waterCausticsEffect;
Coroutine coroutine;
private Image bg_quality;
TMP_Text text_name;
private Image icon_fish;
private GameObject icon_fish_empty;
private TMP_Text text_info;
public TMP_Text text_weight;
public Button btn_rank;
private List<GameObject> stars = new List<GameObject>();
private Image bar;
private GameObject bar_max;
public TMP_Text text_bar;
public TMP_Text text_level;
//模型存放节点
public Transform avatar;
GameObject currentFish;
GameObject loading;
public RawImage rawImageFish;
public Camera _camera;
public UIDrag uiDrag;
//血量
public TMP_Text text_hp;
//重量
public TMP_Text text_weight2;
//额外加成
public TMP_Text text_extra;
private List<string[]> colorStr = new List<string[]>()
{
new[] { "#021d5f", "#021d5f" },
new[] { "#a7caf8", "#e1ecff" },
new[] { "#f5a6f8", "#f6d2fe" },
new[] { "#ffe7a7", "#ffffeb" },
};
private int ID;
private string fishingName;
IDisposable disposable;
RenderTexture rt;
void Awake()
{
disposable = GContext.OnEvent<OnFishLoadEvent>().Subscribe(SetFishAsync);
text_weight = transform.Find("text_num").GetComponent<TMP_Text>();
btn_rank = transform.Find("text_record/btn_rank/btn_green_c").GetComponent<Button>();
text_bar = transform.Find("text_progress").GetComponent<TMP_Text>();
text_level = transform.Find("bg_grade/text_grade").GetComponent<TMP_Text>();
avatar = transform.Find("icon_fish/Avatar").GetComponent<Transform>();
_camera = transform.Find("icon_fish/Camera").GetComponent<Camera>();
rawImageFish = transform.Find("RawImageFish").GetComponent<RawImage>();
uiDrag = rawImageFish.transform.GetComponent<UIDrag>();
text_hp = transform.Find("bg_attribute/blood/text_strength").GetComponent<TMP_Text>();
text_weight2 = transform.Find("bg_attribute/weight/text_strength").GetComponent<TMP_Text>();
text_extra = transform.Find("bg_attribute/addition/text_strength").GetComponent<TMP_Text>();
loading = transform.Find("loading").gameObject;
bg_quality = transform.Find("bg_quality").GetComponent<Image>();
text_name = transform.Find("text_name").GetComponent<TMP_Text>();
icon_fish_empty = transform.Find("icon_fish_empty").gameObject;
text_info = transform.Find("text_info").GetComponent<TMP_Text>();
Transform star = transform.Find("star/star");
for (int i = 1; i < 6; i++)
{
stars.Add(star.Find("star" + i).gameObject);
}
bar = transform.Find("bg_bar/bar").GetComponent<Image>();
bar_max = transform.Find("bg_bar/bar_max").gameObject;
waterCausticsEffect = transform.Find("icon_fish/Avatar/WaterCausticsEffect").GetComponent<WaterCausticsEffect>();
rt = new RenderTexture(1024, 512, 24, RenderTextureFormat.ARGB32);
_camera.targetTexture = rt;
_camera.Render();
rawImageFish.texture = rt;
uiDrag.OnDragCall += OnDragFishing;
}
private void OnEnable()
{
ID = 0;
fishingName = "";
}
IEnumerator Start()
{
btn_rank.onClick.AddListener(OnClickRank);
yield return new WaitForSeconds(1);
waterCausticsEffect.surfaceY = waterCausticsEffect.transform.position.y + 2;
}
void OnDragFishing(PointerEventData eventData)
{
avatar.Rotate(Vector3.up, -eventData.delta.x * data.speed);
}
void SetFishAsync(OnFishLoadEvent fishData)
{
if (fishingName == fishData.fishName)
{
if (currentFish != null && currentFish.transform.parent == avatar)
{
currentFish.SetActive(false);
}
if (fishData.fish != null)
{
currentFish = fishData.fish;
currentFish.transform.SetParent(avatar);
currentFish.transform.localPosition = Vector3.zero;
currentFish.SetActive(true);
avatar.localEulerAngles = Vector3.up * -90;
//鱼加载完成
rawImageFish.gameObject.SetActive(true);
loading.SetActive(false);
}
}
}
public void SetFish(FishData fishData)
{
if (fishData != null)
{
if (fishData.ID == ID)
{
return;
}
//鱼加载过程中
rawImageFish.gameObject.SetActive(false);
loading.SetActive(true);
fishingName = fishData.Fbx;
data.action(this);
ID = fishData.ID;
text_name.text = LocalizationMgr.GetText(fishData.Name_l10n_key);
//Color[] colors = new Color[2];
//ColorUtility.TryParseHtmlString(colorStr[fishData.Quality - 1][0], out colors[0]);
//ColorUtility.TryParseHtmlString(colorStr[fishData.Quality - 1][1], out colors[1]);
//VertexGradient vertexGradient = text_name.colorGradient;
//vertexGradient.topLeft = colors[0];
//vertexGradient.topRight = colors[0];
//vertexGradient.bottomRight = colors[1];
//vertexGradient.bottomLeft = colors[1];
//text_name.colorGradient = vertexGradient;
text_info.text = LocalizationMgr.GetText(fishData.Story_l10n_key);
//GContext.container.Resolve<IUIService>().SetImageSprite(bg_quality, Define.FishCardReviewCard[fishData.Quality - 1], BasePanel.PanelName);
cfg.FishCard fishCard = GContext.container.Resolve<Tables>().TbFishCard[fishData.FishCardID];
int curProficiency = GContext.container.Resolve<PlayerFishData>().GetCardDataProficiency(fishData.FishCardID);
rawImageFish.color = curProficiency < 0.01f && data.isMask ? Color.black : Color.white;
text_weight.text = curProficiency > 0 ? curProficiency.ToString() : "--";
int level = GContext.container.Resolve<PlayerFishData>().GetDataLevel(fishData.ID);
text_level.text = level.ToString();
if (level < fishCard.MaxLevel)
{
int endWeight = fishCard.CardsRequiredList[level];
int startWeight = level > 0 ? fishCard.CardsRequiredList[level - 1] : 0;
bar.fillAmount = (curProficiency - startWeight) / (endWeight - startWeight);
bar_max.SetActive(false);
text_bar.text = $"<color=#4675e4>{curProficiency - startWeight}</color>/{endWeight - startWeight}";
}
else
{
bar_max.SetActive(true);
text_bar.text = LocalizationMgr.GetText("UI_FishingPanel_101007");
}
if (curProficiency < 0)
{
text_level.text = "";
text_bar.text = "未被发现";
}
float weightIncEvent = 0;
if (level > 0)
{
weightIncEvent = fishCard.WeightMagList[level - 1]; //重量加成参数 = 针对特定鱼的重量加成 + 基于基础重量的重量加成 + 总体重量加成初始为0
}
// float weightIncEvent = fishCard.WeightMagList[level] * (Random.Range(1 - data.WeightRandom, 1 + data.WeightRandom));
int starNum = (int)Mathf.Round(weightIncEvent / fishData.WeightMagPerStar);
starNum = Mathf.Clamp(starNum, 1, fishData.MaxStar);
for (int i = 0; i < stars.Count; i++)
{
stars[i].SetActive(i < starNum);
}
text_hp.text = fishData.HP.ToString();
text_weight2.text = LocalizationMgr.GetWeight(fishData.AverageWeight);
text_extra.text = Mathf.Round(weightIncEvent * 100) + "%";
}
}
//public override void OffsetX(float _offsetX, float width)
//{
// if (Mathf.Abs(_offsetX) < width / 2)
// {
// //即将选中
// }
// else
// {
// }
//}
public async void OnClickRank()
{
//btn_rank.onClick.RemoveAllListeners();
//(await UIManager.Instance.ShowUI(UITypes.FishingRankPanel)).GetComponent<FishingRankPanel>().SetFish(index, FishCardReviewPopupPanel.Instance.fishDatas);
//btn_rank.onClick.AddListener(OnClickRank);
}
//private void OnDisable()
//{
// if (currentFish != null)
// {
// currentFish.SetActive(false);
// }
//}
private void OnDestroy()
{
if (disposable != null)
{
disposable.Dispose();
disposable = null;
}
//释放 rawImageFish.texture
if (rt != null)
{
rt.Release();
Destroy(rt);
rt = null;
}
}
override public void OnInit()
{
SetFish(data.fishData);
}
}
public class FishCardItemData
{
public FishData fishData;
public Action<FishCardItem> action;
public float speed;
public bool isMask;
public FishCardItemData(FishData fishData, Action<FishCardItem> action, float speed, bool isMask)
{
this.fishData = fishData;
this.action = action;
this.speed = speed;
this.isMask = isMask;
}
}