装备系统完结,修复并加入很多

This commit is contained in:
2026-04-03 19:15:02 +08:00
parent 538085b64f
commit d9376833b6
378 changed files with 62464 additions and 16756 deletions
+178 -41
View File
@@ -2,6 +2,9 @@
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
#if UNITY_EDITOR
using UnityEditor;
#endif
public class eqpmtDesPrefab : MonoBehaviour
{
@@ -29,6 +32,7 @@ public class eqpmtDesPrefab : MonoBehaviour
public Text eqpmtDescription;
[Header("body")]
public Text eqpmtType;
public Text baTitle;
public Text baDetail;
public GameObject baSpace;
@@ -43,12 +47,19 @@ public class eqpmtDesPrefab : MonoBehaviour
public GameObject iaSpace;
public Text mlTitle;
public Text mlDetail;
public GameObject eqpSpace;
public GameObject whoEquipping;
public Image equipperProfile;
public Text equipperName;
[Header("objs")]
public GameObject eqpmtSkillPrefab;
public Transform sasParent;
public Transform iasParent;
public Transform mlsParent;
[Header("es description")]
public GameObject esDesPrefab;
public Vector2 esDesPrefabOffset = new Vector2(20f, 30f);
private RectTransform rectTransform;
private Canvas rootCanvas;
@@ -148,17 +159,21 @@ public class eqpmtDesPrefab : MonoBehaviour
ApplyEffectSection(taTitle, taDetail, taSpace, null, string.Empty, null, false);
ApplyEffectSection(iaTitle, iaDetail, iaSpace, iasParent, string.Empty, null, false);
ApplyEffectSection(mlTitle, mlDetail, null, mlsParent, string.Empty, null, false);
ApplyEquipperInfo(null);
return;
}
equipmentSO.EquipmentTierPresentation presentation = ResolveTierPresentation(eSO);
string displayName = presentation != null && !string.IsNullOrWhiteSpace(presentation.tierName)
? presentation.tierName
: eSO.name;
string displayName = eSO.GetDisplayTierName();
if (string.IsNullOrWhiteSpace(displayName))
{
displayName = eSO.name;
}
Sprite displaySprite = presentation != null ? presentation.equipmentSprite : null;
string description = presentation != null ? presentation.tierDescription : string.Empty;
string description = eSO.GetDisplayTierDescription();
ApplyHeader(displayName, displaySprite, GetQualityVisualIndex(eSO.level), description);
ApplyHeader(displayName, displaySprite, GetQualityVisualIndex(eSO), description);
ApplyEquipperInfo(eSO);
string basicText = BuildBasicAttributesText(eSO);
ApplyBasicSection(basicText, displayBasicAttributes && !string.IsNullOrWhiteSpace(basicText));
@@ -212,6 +227,84 @@ public class eqpmtDesPrefab : MonoBehaviour
displayMaxLevelEffects && HasSectionContent(eSO.maxLevelEffects, 0));
}
private void ApplyEquipperInfo(equipmentSO equipment)
{
AllyHero_SO equipper = FindEquipper(equipment);
bool hasEquipper = equipper != null;
if (whoEquipping != null)
{
whoEquipping.SetActive(hasEquipper);
}
if (eqpSpace != null)
{
eqpSpace.SetActive(hasEquipper);
}
if (equipperProfile != null)
{
equipperProfile.sprite = hasEquipper ? equipper.ally_hero_squareProfile : null;
equipperProfile.color = hasEquipper && equipper.ally_hero_squareProfile != null ? Color.white : new Color(1f, 1f, 1f, 0f);
}
if (equipperName != null)
{
equipperName.text = hasEquipper ? equipper.ally_heroName : string.Empty;
}
}
private AllyHero_SO FindEquipper(equipmentSO equipment)
{
if (equipment == null)
{
return null;
}
AllyHero_SO[] heroes = LoadHeroAssets();
for (int i = 0; i < heroes.Length; i++)
{
AllyHero_SO hero = heroes[i];
if (hero == null)
{
continue;
}
hero.LoadEquippedEquipmentFromLocal();
equipmentSO equipped = hero.GetEquippedEquipmentResolved();
if (equipped == equipment || (!string.IsNullOrWhiteSpace(equipped?.name) && equipped.name == equipment.name))
{
return hero;
}
}
return null;
}
private AllyHero_SO[] LoadHeroAssets()
{
#if UNITY_EDITOR
if (!Application.isPlaying)
{
string[] guids = AssetDatabase.FindAssets("t:AllyHero_SO", new[] { "Assets/Resources/so/ally" });
var heroes = new List<AllyHero_SO>(guids.Length);
for (int i = 0; i < guids.Length; i++)
{
string path = AssetDatabase.GUIDToAssetPath(guids[i]);
AllyHero_SO hero = AssetDatabase.LoadAssetAtPath<AllyHero_SO>(path);
if (hero != null)
{
heroes.Add(hero);
}
}
return heroes.ToArray();
}
#endif
return Resources.LoadAll<AllyHero_SO>("so/ally");
}
private equipmentSO.EquipmentTierPresentation ResolveTierPresentation(equipmentSO equipment)
{
if (equipment == null)
@@ -220,7 +313,7 @@ public class eqpmtDesPrefab : MonoBehaviour
}
if (equipment.tierNameConfig != null &&
equipment.tierNameConfig.TryGetStagePresentation(equipment.skillType, equipment.GetTierStageIndex(), out equipmentTierNameConfigSO.StagePresentation stage) &&
equipment.tierNameConfig.TryGetStagePresentation(equipment.skillType, equipment.GetVisualTierStageIndex(), out equipmentTierNameConfigSO.StagePresentation stage) &&
stage != null)
{
return new equipmentSO.EquipmentTierPresentation
@@ -231,7 +324,7 @@ public class eqpmtDesPrefab : MonoBehaviour
};
}
return equipment.GetCurrentTierPresentation();
return equipment.GetVisualTierPresentation();
}
private void ApplyHeader(string displayName, Sprite displaySprite, int qualityIndex, string description)
@@ -257,6 +350,11 @@ public class eqpmtDesPrefab : MonoBehaviour
eqpmtDescription.text = description;
}
if (eqpmtType != null)
{
eqpmtType.text = eSO != null ? eSO.skillType.ToString() : string.Empty;
}
if (eqpmtIcon != null)
{
eqpmtIcon.sprite = displaySprite;
@@ -333,6 +431,19 @@ public class eqpmtDesPrefab : MonoBehaviour
GameObject instance = Instantiate(eqpmtSkillPrefab, parent);
instance.name = $"eqpmtSkill_{skillId}";
SkillGroup skillGroup = EquipmentSkillGroupLibrary.ResolveSkillGroup(skillId);
string displayName = skillGroup != null && !string.IsNullOrWhiteSpace(skillGroup.groupName)
? skillGroup.groupName
: $"Skill {skillId}";
Sprite displayIcon = skillGroup != null ? skillGroup.groupIcon : null;
esPrefab legacyItem = instance.GetComponent<esPrefab>();
if (legacyItem != null)
{
legacyItem.BindSkillGroup(skillId, displayName, displayIcon, esDesPrefab, transform as RectTransform, esDesPrefabOffset);
return;
}
eqpmtSkillPrefabItem item = instance.GetComponent<eqpmtSkillPrefabItem>();
if (item != null)
@@ -346,7 +457,7 @@ public class eqpmtDesPrefab : MonoBehaviour
{
if (texts[i] != null)
{
texts[i].text = $"Skill {skillId}";
texts[i].text = displayName;
break;
}
}
@@ -454,15 +565,15 @@ public class eqpmtDesPrefab : MonoBehaviour
}
var lines = new List<string>();
AppendBasicLine(lines, "最大生命", equipment.maxHp);
AppendBasicLine(lines, "攻击力", equipment.attack);
AppendBasicLine(lines, "最大法力", equipment.maxMana);
AppendBasicLine(lines, "伤害减免", equipment.damageResistance);
AppendBasicLine(lines, "得分效率", equipment.scoreEfficiency);
AppendBasicLine(lines, "最大生命", equipment.maxHp, equipmentSO.EquipmentSpecialEffectType.MaxHp);
AppendBasicLine(lines, "攻击力", equipment.attack, equipmentSO.EquipmentSpecialEffectType.Attack);
AppendBasicLine(lines, "最大法力", equipment.maxMana, equipmentSO.EquipmentSpecialEffectType.MaxMana);
AppendBasicLine(lines, "伤害减免", equipment.damageResistance, equipmentSO.EquipmentSpecialEffectType.DamageResistance);
AppendBasicLine(lines, "得分效率", equipment.scoreEfficiency, equipmentSO.EquipmentSpecialEffectType.ScoreEfficiency);
return string.Join("\n", lines);
}
private void AppendBasicLine(List<string> lines, string label, equipmentSO.EquipmentStatTuning tuning)
private void AppendBasicLine(List<string> lines, string label, equipmentSO.EquipmentStatTuning tuning, equipmentSO.EquipmentSpecialEffectType effectType)
{
if (lines == null || tuning == null)
{
@@ -476,17 +587,27 @@ public class eqpmtDesPrefab : MonoBehaviour
}
float levelGain = eSO != null ? Mathf.Max(0, eSO.level) * tuning.cultivationInterval : 0f;
float total = baseValue + levelGain;
float finalDreamGain = GetMaxLevelBoost(effectType);
float total = baseValue + levelGain + finalDreamGain;
if (eSO == null || Mathf.Max(0, eSO.level) <= 0 || Mathf.Approximately(levelGain, 0f))
if (eSO == null || (Mathf.Max(0, eSO.level) <= 0 && Mathf.Approximately(finalDreamGain, 0f)))
{
lines.Add($"{label}{FormatTotalPercent(baseValue)}");
lines.Add($"{label}{FormatTotalPercent(baseValue + finalDreamGain)}");
return;
}
lines.Add(
$"{label}{FormatTotalPercent(total)} " +
$"(<color=#ADD8E6>{FormatComponentPercent(baseValue)}</color>+<color=#F0E68C>{FormatComponentPercent(levelGain)}</color>)");
string componentText = $"<color=#ADD8E6>{FormatComponentPercent(baseValue)}</color>";
if (!Mathf.Approximately(levelGain, 0f))
{
componentText += $"+<color=#F0E68C>{FormatComponentPercent(levelGain)}</color>";
}
if (!Mathf.Approximately(finalDreamGain, 0f))
{
componentText += $"+<color=#FF67A4>{FormatComponentPercent(finalDreamGain)}</color>";
}
lines.Add($"{label}{FormatTotalPercent(total)} ({componentText})");
}
private string BuildEffectText(equipmentSO.EquipmentSpecialEffect[] effects, out int skillId)
@@ -506,6 +627,8 @@ public class eqpmtDesPrefab : MonoBehaviour
return string.Empty;
}
bool isTypeSameEffectSection = effects == eSO?.typeSameEffects;
bool isMaxLevelEffectSection = effects == eSO?.maxLevelEffects;
var lines = new List<string>();
for (int i = 0; i < effects.Length; i++)
{
@@ -525,12 +648,36 @@ public class eqpmtDesPrefab : MonoBehaviour
continue;
}
lines.Add($"{GetEffectDisplayName(effect.effectType)}{FormatSignedValue(effect.value)}");
string valueText = (isTypeSameEffectSection || isMaxLevelEffectSection)
? FormatSignedPercent(effect.value)
: FormatSignedValue(effect.value);
lines.Add($"{GetEffectDisplayName(effect.effectType)}{valueText}");
}
return string.Join("\n", lines);
}
private float GetMaxLevelBoost(equipmentSO.EquipmentSpecialEffectType effectType)
{
if (eSO == null || eSO.maxLevelEffects == null)
{
return 0f;
}
for (int i = 0; i < eSO.maxLevelEffects.Length; i++)
{
equipmentSO.EquipmentSpecialEffect effect = eSO.maxLevelEffects[i];
if (effect == null || effect.effectType != effectType)
{
continue;
}
return effect.value;
}
return 0f;
}
private Sprite GetBottomSprite(int qualityIndex)
{
if (eqpmtBtmSprites == null || eqpmtBtmSprites.Length == 0)
@@ -553,29 +700,14 @@ public class eqpmtDesPrefab : MonoBehaviour
return profilebtmColor[safeIndex];
}
private static int GetQualityVisualIndex(int level)
private static int GetQualityVisualIndex(equipmentSO equipment)
{
if (level >= 20)
if (equipment == null)
{
return 5;
return 0;
}
if (level >= 15)
{
return 4;
}
if (level >= 10)
{
return 3;
}
if (level >= 5)
{
return 2;
}
return 1;
return equipment.GetVisualQualityColorIndex();
}
private static string GetEffectDisplayName(equipmentSO.EquipmentSpecialEffectType effectType)
@@ -612,6 +744,12 @@ public class eqpmtDesPrefab : MonoBehaviour
return $"{(value >= 0f ? "+" : string.Empty)}{value:0.####}";
}
private static string FormatSignedPercent(float value)
{
float percent = value * 100f;
return $"{(percent >= 0f ? "+" : string.Empty)}{percent:0.##}%";
}
private static string BuildDisplayEquipmentId(equipmentSO equipment)
{
if (equipment == null || string.IsNullOrWhiteSpace(equipment.name))
@@ -637,4 +775,3 @@ public class eqpmtDesPrefab : MonoBehaviour
equipment.name.Contains("(TourPreview)");
}
}