602 坐骑优化-客户端 战马列表修复第一次进入界面因为时序问题没成功初始化的问题,属性改为显示当前选中的坐骑的,不是当前装备的
3个文件已修改
93 ■■■■■ 已修改文件
Main/System/Horse/HorseCarouselView.cs 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Main/System/Horse/HorseManager.cs 58 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Main/System/Horse/HorseWin.cs 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Main/System/Horse/HorseCarouselView.cs
@@ -1,10 +1,7 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.UI;
using System;
using System.Linq;
public class HorseCarouselView : MonoBehaviour, IDragHandler, IEndDragHandler, IBeginDragHandler
{
@@ -46,8 +43,13 @@
        }
    }
    void Start()
    /// <summary>
    /// 初始化池子(由外部调用)
    /// </summary>
    public void InitPool()
    {
        if (items.Count > 0)
            return;
        // 初始化池子:为了保证左右滑动不穿帮,视野内显示5个,池子可以建7个 (5 + 左右各多1个缓冲)
        int poolSize = 7;
        for (int i = 0; i < poolSize; i++)
@@ -56,16 +58,17 @@
            HorseItem item = go.GetComponent<HorseItem>();
            items.Add(item);
        }
        // 使用排序缓存
        horseConfigs = HorseManager.GetSortedHorseConfigs();
        // 获取当前骑乘坐骑的索引
        int currentHorseID = HorseManager.Instance.horseID;
        int index = horseConfigs.FindIndex(c => c.HorseID == currentHorseID);
        InitWithHorse(index >= 0 ? index : 0);
    }
    // 界面打开时调用,传入当前骑乘的坐骑ID或序号
    /// <summary>
    /// 初始化坐骑配置(由外部调用)
    /// </summary>
    public void InitHorseConfigs(List<HorseIDConfig> configs)
    {
        horseConfigs = configs;
    }
    // 界面打开时调用,传入当前骑乘的坐骑序号
    public void InitWithHorse(int horseIndex)
    {
        currentSelectedIndex = horseIndex;
Main/System/Horse/HorseManager.cs
@@ -571,24 +571,30 @@
        }
    }
    private long AccumulateAttrValues(int attrID, int[] attrIDList, int[] attrValueList)
    {
        long result = 0;
        if (attrIDList == null || attrIDList.Length == 0)
            return result;
        for (int i = 0; i < attrIDList.Length; i++)
        {
            if (attrIDList[i] == attrID)
            {
                result += attrValueList[i];
            }
        }
        return result;
    }
    public bool GetNowRiderAttrInfo(out int attrID, out long value, out PlayerPropertyConfig playerPropertyConfig)
    {
        value = 0;
        HorseIDConfig horseIDConfig = HorseIDConfig.Get(horseID);
        attrID = horseIDConfig.AttrID;
        for (int lv = 0; lv <= classLV; lv++)
        {
            var config = HorseClassConfig.Get(lv);
            if (config.HorseEffAttrIDList.IsNullOrEmpty())
                continue;
            for (int i = 0; i < config.HorseEffAttrIDList.Length; i++)
            {
                if (config.HorseEffAttrIDList[i] == attrID)
                {
                    value += config.HorseEffAttrValueList[i];
                }
            }
            value += AccumulateAttrValues(attrID, config.HorseEffAttrIDList, config.HorseEffAttrValueList);
        }
        playerPropertyConfig = PlayerPropertyConfig.Get(attrID);
        return playerPropertyConfig != null;
@@ -597,23 +603,35 @@
    public bool GetNowRiderTotalAttrInfo(out int attrID, out long value, out PlayerPropertyConfig playerPropertyConfig)
    {
        GetNowRiderAttrInfo(out attrID, out value, out playerPropertyConfig);
        for (int lv = 0; lv <= classLV; lv++)
        {
            var config = HorseClassConfig.Get(lv);
            if (config.ClassSpecAttrIDList.IsNullOrEmpty())
                continue;
            for (int i = 0; i < config.ClassSpecAttrIDList.Length; i++)
            {
                if (config.ClassSpecAttrIDList[i] == attrID)
                {
                    value += config.ClassSpecAttrValueList[i];
                }
            }
            value += AccumulateAttrValues(attrID, config.ClassSpecAttrIDList, config.ClassSpecAttrValueList);
        }
        return playerPropertyConfig != null;
    }
    public bool GetRiderTotalAttrInfoByHorseID(int horseID, out int attrID, out long value, out PlayerPropertyConfig playerPropertyConfig)
    {
        value = 0;
        HorseIDConfig horseIDConfig = HorseIDConfig.Get(horseID);
        if (horseIDConfig == null)
        {
            attrID = 0;
            playerPropertyConfig = null;
            return false;
        }
        attrID = horseIDConfig.AttrID;
        for (int lv = 0; lv <= classLV; lv++)
        {
            var config = HorseClassConfig.Get(lv);
            value += AccumulateAttrValues(attrID, config.HorseEffAttrIDList, config.HorseEffAttrValueList);
            value += AccumulateAttrValues(attrID, config.ClassSpecAttrIDList, config.ClassSpecAttrValueList);
        }
        playerPropertyConfig = PlayerPropertyConfig.Get(attrID);
        return playerPropertyConfig != null;
    }
    Dictionary<int, long> mergedResultDic = new Dictionary<int, long>();
    public Dictionary<int, long> GetMergedAttrDic()
Main/System/Horse/HorseWin.cs
@@ -126,13 +126,13 @@
        carouselView.OnSelectedIndexChanged += OnSelectedIndexChanged;
        HorseManager.Instance.OnHorseUnlockedEvent += OnHorseUnlockedEvent;
        // 每次打开时,恢复到当前骑乘的坐骑
        // 外部初始化
        if (carouselView != null)
        {
            carouselView.InitPool();
            int currentHorseID = HorseManager.Instance.horseID;
            // 使用排序缓存
            var horseConfigs = HorseManager.GetSortedHorseConfigs();
            carouselView.InitHorseConfigs(horseConfigs);
            int index = horseConfigs.FindIndex(c => c.HorseID == currentHorseID);
            carouselView.InitWithHorse(index >= 0 ? index : 0);
        }
@@ -231,7 +231,7 @@
        nameText.text = isChangeState ? HorseSkinConfig.Get(nowSkinID).Name : horseIdSkinConfig.Name;
        HorseIDConfig horseIDConfig = HorseIDConfig.Get(showHorseID);
        bool hasAttr = HorseManager.Instance.GetNowRiderTotalAttrInfo(out int attrID, out long value, out PlayerPropertyConfig playerPropertyConfig);
        bool hasAttr = HorseManager.Instance.GetRiderTotalAttrInfoByHorseID(showHorseID, out int attrID, out long value, out PlayerPropertyConfig playerPropertyConfig);
        attrImg.SetActive(hasAttr);
        noAttrTxt.SetActive(!hasAttr);
        if (hasAttr)