1
This commit is contained in:
@@ -144,7 +144,10 @@ public class GameManager : MonoSingleton<GameManager>
|
||||
gameData.currUser = "123";
|
||||
//string json = Resources.Load<TextAsset>("Config/GameConfig").text;
|
||||
//gameConfig = JsonConvert.DeserializeObject<APIResponse<GameConfig>>(json).data;
|
||||
APIManager.Response<GameConfig>(APIType.GameConfig_Get, res => { gameConfig = res; var v = CreateFishManager.Instance.CreateDic;
|
||||
APIManager.Response<GameConfig>(APIType.GameConfig_Get,
|
||||
res => {
|
||||
gameConfig = res;
|
||||
var v = CreateFishManager.Instance.CreateDic;
|
||||
foreach (var item in gameConfig.fishTypeConfigs)
|
||||
{
|
||||
dic_fishTypeConfigs[item.fishNumber]=item;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Assets.Framework.Tool;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Assets.MyGame.Scripts.Net.API.GameConfig_SubClass
|
||||
@@ -10,6 +11,19 @@ namespace Assets.MyGame.Scripts.Net.API.GameConfig_SubClass
|
||||
public class PropFragmentConfig : BasePropInfo
|
||||
{
|
||||
public Sprite sprite_Icon;
|
||||
public void GetSprite(Action<Sprite> callback)
|
||||
{
|
||||
|
||||
if (sprite_Icon == null)
|
||||
{
|
||||
WebTool.DownImage(APIManager.baseURL + imageUrl, (a) => { sprite_Icon = Sprite.Create(a, new Rect(0, 0, a.width, a.height), Vector2.one * 0.5f); callback?.Invoke(sprite_Icon); });
|
||||
}
|
||||
else
|
||||
{
|
||||
callback?.Invoke(sprite_Icon);
|
||||
}
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 合成所需碎片数量
|
||||
/// </summary>
|
||||
|
||||
@@ -3066,6 +3066,10 @@ MonoBehaviour:
|
||||
btn_Wing: {fileID: 7767001353994184739}
|
||||
btn_ZS: {fileID: 6358180352555696406}
|
||||
btn_Get: {fileID: 5034870180401538498}
|
||||
btn_DuiHuan: {fileID: 4336991627547622938}
|
||||
propIcon: {fileID: 1249392386408153250}
|
||||
slider: {fileID: 701210061533139629}
|
||||
tmp_CurrSuiPian: {fileID: 8508762177392708964}
|
||||
tMP_Type: {fileID: 322712953226584951}
|
||||
toggle_TurretItemPrefab: {fileID: 3268227797923973528}
|
||||
toggle_WingItemPrefab: {fileID: 722333950919489853}
|
||||
@@ -4361,9 +4365,9 @@ RectTransform:
|
||||
- {fileID: 7474773506168572963}
|
||||
m_Father: {fileID: 8904622048228621647}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0.5, y: 0.5}
|
||||
m_AnchorMax: {x: 0.5, y: 0.5}
|
||||
m_AnchoredPosition: {x: -38.00001, y: -314}
|
||||
m_AnchorMin: {x: 0.5, y: 0}
|
||||
m_AnchorMax: {x: 0.5, y: 0}
|
||||
m_AnchoredPosition: {x: -38.00001, y: 61}
|
||||
m_SizeDelta: {x: 272, y: 64}
|
||||
m_Pivot: {x: 0.5, y: 0.5}
|
||||
--- !u!222 &8907184129529078447
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Assets.MyGame.Scripts.Net;
|
||||
using Assets.MyGame.Scripts.Net.API;
|
||||
using Assets.MyGame.Scripts.Net.API.GameConfig_SubClass;
|
||||
using Assets.MyGame.Scripts.Net.API.UserData_SubClass;
|
||||
using Assets.MyGame.Scripts.Net.APIRequest.Params;
|
||||
using TMPro;
|
||||
@@ -78,6 +79,7 @@ public class UIHome_BY_ItemListPanels : SubUIBase
|
||||
btn_ZS.onClick.AddListener(() => UpdateSelectType(ItemPanelSelect.ZS));
|
||||
|
||||
btn_Get.onClick.AddListener(OnClickGet);
|
||||
btn_DuiHuan.onClick.AddListener(OnClickDuiHuan);
|
||||
|
||||
if (tMP_Type != null)
|
||||
tMP_Type.onValueChanged.AddListener(OnDropdownChanged);
|
||||
@@ -420,6 +422,11 @@ public class UIHome_BY_ItemListPanels : SubUIBase
|
||||
? $"编号: {resData.turretNumber}\n类型: {TypeName(resData.turretType)}"
|
||||
: "";
|
||||
|
||||
// 3. 按钮显隐 & 兑换 UI
|
||||
bool isOwned = turretNumber > 0 && IsItemOwned(turretNumber);
|
||||
RefreshButtonsVisibility(isOwned);
|
||||
RefreshDuiHuanUI(turretNumber);
|
||||
|
||||
// 3. 缩略图(翅膀/战神使用相机渲染,不动 texture)
|
||||
|
||||
// 5. 炮台分类隐藏 rawImg_DetailPreview,翅膀/战神分类显示
|
||||
@@ -584,6 +591,126 @@ public class UIHome_BY_ItemListPanels : SubUIBase
|
||||
RebuildItemList();
|
||||
}
|
||||
|
||||
// ==================== 兑换系统 ====================
|
||||
|
||||
/// <summary>兑换 UI 的父节点(btn_DuiHuan / propIcon / slider / tmp_CurrSuiPian 共用一个父对象)。</summary>
|
||||
private GameObject _duiHuanParent;
|
||||
|
||||
/// <summary>根据是否已拥有,切换装备按钮的显隐。</summary>
|
||||
private void RefreshButtonsVisibility(bool isOwned)
|
||||
{
|
||||
if (btn_Get != null)
|
||||
btn_Get.gameObject.SetActive(isOwned);
|
||||
}
|
||||
|
||||
/// <summary>刷新兑换相关的 UI:碎片图标、进度条、文本。兑换 UI 父节点统一控制显隐。</summary>
|
||||
private void RefreshDuiHuanUI(int turretNumber)
|
||||
{
|
||||
if (_duiHuanParent == null && btn_DuiHuan != null)
|
||||
_duiHuanParent = btn_DuiHuan.transform.parent.gameObject;
|
||||
|
||||
if (turretNumber <= 0)
|
||||
{
|
||||
if (_duiHuanParent != null) _duiHuanParent.SetActive(false);
|
||||
return;
|
||||
}
|
||||
|
||||
bool isOwned = IsItemOwned(turretNumber);
|
||||
var info = isOwned ? (null, 0) : GetFragmentInfo(turretNumber);
|
||||
bool hasFragment = info.config != null;
|
||||
|
||||
// 统一控制兑换 UI 父节点的显隐
|
||||
if (_duiHuanParent != null)
|
||||
_duiHuanParent.SetActive(hasFragment);
|
||||
|
||||
if (!hasFragment) return;
|
||||
|
||||
// 设置图标
|
||||
if (propIcon != null && info.config.sprite_Icon != null)
|
||||
propIcon.sprite = info.config.sprite_Icon;
|
||||
|
||||
// 进度条
|
||||
if (slider != null)
|
||||
{
|
||||
slider.maxValue = info.config.fragmentCount;
|
||||
slider.value = Mathf.Min(info.ownedCount, info.config.fragmentCount);
|
||||
slider.interactable = false; // 只读
|
||||
}
|
||||
|
||||
// 文本:"当前数量/所需数量"
|
||||
if (tmp_CurrSuiPian != null)
|
||||
{
|
||||
bool canExchange = info.ownedCount >= info.config.fragmentCount;
|
||||
string color = canExchange ? "green" : "red";
|
||||
tmp_CurrSuiPian.text = $"<color={color}>{info.ownedCount}</color>/{info.config.fragmentCount}";
|
||||
}
|
||||
|
||||
// 兑换按钮可用性
|
||||
if (btn_DuiHuan != null)
|
||||
btn_DuiHuan.interactable = info.ownedCount >= info.config.fragmentCount;
|
||||
}
|
||||
|
||||
/// <summary>根据道具编号查找碎片配置和拥有的碎片数量。</summary>
|
||||
private (PropFragmentConfig config, int ownedCount) GetFragmentInfo(int turretNumber)
|
||||
{
|
||||
var fragments = GameManager.Instance?.gameConfig?.propFragments;
|
||||
if (fragments == null) return (null, 0);
|
||||
|
||||
// 查找 productNumber 等于当前道具编号的碎片配置
|
||||
string targetNum = turretNumber.ToString();
|
||||
var config = fragments.Find(f => f.productNumber == targetNum);
|
||||
if (config == null) return (null, 0);
|
||||
|
||||
// 查找用户拥有的碎片数量
|
||||
var props = GameManager.Instance?.user?.props;
|
||||
int owned = 0;
|
||||
if (props != null)
|
||||
{
|
||||
var ownedProp = props.Find(p => p.number == config.number);
|
||||
if (ownedProp != null)
|
||||
owned = ownedProp.count;
|
||||
}
|
||||
|
||||
return (config, owned);
|
||||
}
|
||||
|
||||
/// <summary>兑换按钮点击。</summary>
|
||||
private void OnClickDuiHuan()
|
||||
{
|
||||
if (_selectedTurretNumber <= 0) return;
|
||||
|
||||
var info = GetFragmentInfo(_selectedTurretNumber);
|
||||
if (info.config == null)
|
||||
{
|
||||
Debug.LogWarning($"[TurretPanel] 道具 #{_selectedTurretNumber} 没有碎片配置");
|
||||
return;
|
||||
}
|
||||
|
||||
if (info.ownedCount < info.config.fragmentCount)
|
||||
{
|
||||
Debug.Log($"[TurretPanel] 碎片不足: 需要 {info.config.fragmentCount},当前 {info.ownedCount}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!int.TryParse(info.config.number, out int fragmentId))
|
||||
{
|
||||
Debug.LogError($"[TurretPanel] 碎片编号解析失败: {info.config.number}");
|
||||
return;
|
||||
}
|
||||
|
||||
APIRequestList.SynthesisFragment(new SynthesisFragmentParam
|
||||
{
|
||||
fragmentId = fragmentId,
|
||||
count = info.config.fragmentCount
|
||||
}, res =>
|
||||
{
|
||||
Debug.Log($"[TurretPanel] 兑换成功: 道具 #{_selectedTurretNumber}, propId={res.propId}");
|
||||
RefreshUserAndRebuild();
|
||||
});
|
||||
}
|
||||
|
||||
// ==================== 生命周期结束 ====================
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
ClearItemList();
|
||||
|
||||
Reference in New Issue
Block a user