长音符再修复 加入了关卡连接 优化了一些默认加载

This commit is contained in:
FloatGaming
2026-01-13 11:22:39 +08:00
parent 2738089af1
commit 2f9d4aae0c
426 changed files with 299413 additions and 1050 deletions
+75 -5
View File
@@ -19,7 +19,25 @@ public class SkillBuilder : MonoBehaviour
private void Awake()
{
if (Instance == null) Instance = this;
else Destroy(gameObject);
else
{
Destroy(gameObject);
return;
}
}
private void Start()
{
// Prewarm expensive Resources.LoadAll<AllyHero_SO>("") so first note hit doesn't hitch.
// This keeps behavior the same, just moves the cost into loading time.
try
{
PrewarmAllyHeroSOIndex();
}
catch (System.Exception ex)
{
Debug.LogWarning($"[SkillBuilder] PrewarmAllyHeroSOIndex failed: {ex}");
}
}
// ----------------------------- 基础参数模板 -----------------------------
@@ -41,6 +59,36 @@ public class SkillBuilder : MonoBehaviour
[Tooltip("(Fallback) Base HP loss on Miss will be (missHpLossBase * (1 - damageResistance)) if SO level value not present")] public float missHpLossBase = 10f;
// --------- Caches to avoid first-hit hitch (Resources.LoadAll) ---------
private AllyHero_SO[] _allAllyHeroSOs;
private Dictionary<int, AllyHero_SO> _allyHeroSoById;
private Dictionary<int, AllyHero_SO> _allyHeroSoBySlotCache;
private void PrewarmAllyHeroSOIndex()
{
if (_allAllyHeroSOs != null && _allAllyHeroSOs.Length > 0) return;
_allAllyHeroSOs = Resources.LoadAll<AllyHero_SO>("");
_allyHeroSoById = new Dictionary<int, AllyHero_SO>(_allAllyHeroSOs != null ? _allAllyHeroSOs.Length : 0);
_allyHeroSoBySlotCache = new Dictionary<int, AllyHero_SO>(8);
if (_allAllyHeroSOs != null)
{
foreach (var so in _allAllyHeroSOs)
{
if (so == null) continue;
if (so.ally_heroID <= 0) continue;
if (!_allyHeroSoById.ContainsKey(so.ally_heroID))
_allyHeroSoById.Add(so.ally_heroID, so);
}
}
if (GameConfig.verboseLogs)
{
Debug.Log($"[SkillBuilder] PrewarmAllyHeroSOIndex: loaded {_allAllyHeroSOs?.Length ?? 0} AllyHero_SO assets, indexed {_allyHeroSoById.Count}");
}
}
// Placeholder: if you want to route damage through EffectSystem later, use this.
public void DealDamageFromAllyToEnemies(int slotIndex, float amount)
{
@@ -429,17 +477,39 @@ public class SkillBuilder : MonoBehaviour
// 根据槽位解析 AllyHero_SO(运行时从 Resources 中查找 ally_heroID
public AllyHero_SO GetAllyHeroSOBySlot(int slotIndex)
{
// slot-based cache (depends on team selection)
if (_allyHeroSoBySlotCache != null && _allyHeroSoBySlotCache.TryGetValue(slotIndex, out var cached) && cached != null)
return cached;
if (teamUIController.Instance == null || teamUIController.Instance.allySlotIds == null) return null;
if (slotIndex < 0 || slotIndex >= teamUIController.Instance.allySlotIds.Count) return null;
int id = teamUIController.Instance.allySlotIds[slotIndex];
if (id <= 0) return null;
var all = Resources.LoadAll<AllyHero_SO>("");
foreach (var a in all)
// Ensure index is built
if (_allAllyHeroSOs == null || _allAllyHeroSOs.Length == 0) PrewarmAllyHeroSOIndex();
AllyHero_SO result = null;
if (_allyHeroSoById != null && _allyHeroSoById.TryGetValue(id, out var so) && so != null)
{
if (a != null && a.ally_heroID == id) return a;
result = so;
}
return null;
else
{
// fallback to previous behavior if index missing
var all = Resources.LoadAll<AllyHero_SO>("");
foreach (var a in all)
{
if (a != null && a.ally_heroID == id) { result = a; break; }
}
}
if (result != null)
{
if (_allyHeroSoBySlotCache == null) _allyHeroSoBySlotCache = new Dictionary<int, AllyHero_SO>(8);
_allyHeroSoBySlotCache[slotIndex] = result;
}
return result;
}
// 根据当前经验选择生效的等级信息(返回 null 表示未找到)