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

104 lines
2.9 KiB
C#

using System;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using asap.core;
public class FishMapItem : PanelItemBase<FishMapItemData>
{
Transform root;
Image img_map;
private GameObject mask;
Image bar;
private TMP_Text text_bar;
GameObject newGo;
private GameObject redpoint;
Button btn_item;
private GameObject mask_empty;
private TMP_Text text_require;
private void Awake()
{
root = transform.Find("p_icon_item/icon_item1/btn_green");
img_map = root.Find("mask_map/img_map").GetComponent<Image>();
bar = root.Find("mask_empty/bg_bar/bar").GetComponent<Image>();
text_bar = root.Find("mask_empty/bg_bar/text_progress").GetComponent<TMP_Text>();
newGo = root.Find("new").gameObject;
redpoint = root.Find("redpoint").gameObject;
btn_item = root.GetComponent<Button>();
mask_empty = root.Find("mask_empty").gameObject;
text_require = root.Find("mask_empty/text_require").GetComponent<TMP_Text>();
}
private void Start()
{
btn_item.onClick.AddListener(OnBtnItem);
}
public override void OffsetX(float _offsetX, float width)
{
transform.localScale = Vector3.one * Mathf.Clamp(1 - Mathf.Abs(_offsetX) / width * 0.2f, 0.75f, 1);
float offset;
if (transform.localScale.x < 0.8f)
{
offset = (0.8f - transform.localScale.x) * width * 3;
}
else
{
offset = 0;
}
transform.GetChild(0).localPosition = _offsetX > 0 ? Vector3.left * offset : Vector3.right * offset;
if (Mathf.Abs(_offsetX) < width / 2)
{
//即将选中
OnCenter();
}
}
//当靠近中心时回调
public void OnCenter()
{
data.ChangeMapName(data.index, data.name);
}
public void SetRed()
{
redpoint.SetActive(data.isRedPoint);
}
public override void OnInit()
{
transform.localScale = Vector3.one * 0.75f;
SetRed();
SetIsNew();
bar.fillAmount = data.progress;
text_bar.text = data.progressText;
// img_map.material = data.unLock ? null : AssetManager.LoadAsset<Material>("ImageGrayMaskMat");
mask_empty.SetActive(!data.unLock);
text_require.text = data.levelRequired.ToString();
GContext.container.Resolve<IUIService>().SetImageSprite(img_map, data.icon);
}
public void SetIsNew()
{
newGo.SetActive(data.isNew);
}
}
public class FishMapItemData
{
public int ID;
public List<int> fishList;
public string name;
public float progress;
public string icon;
public string progressText;
public bool unLock;
public bool isNew;
public bool isRedPoint;
public int index;
public Action<int, string> ChangeMapName;
public int levelRequired;
}