拼ui 一些业务逻辑x实现

This commit is contained in:
FloatGaming
2026-03-19 06:15:09 +08:00
parent f5c6f143c0
commit 49e45ac464
1118 changed files with 246518 additions and 5368 deletions
@@ -9,6 +9,8 @@ public sealed class AllyHeroDeployLedger : MonoBehaviour
public static AllyHeroDeployLedger Instance { get; private set; }
private readonly Dictionary<int, int> deployCountsByHeroId = new Dictionary<int, int>();
private readonly Dictionary<int, int> finishCountsByHeroId = new Dictionary<int, int>();
private readonly Dictionary<int, int> mvpCountsByHeroId = new Dictionary<int, int>();
private bool initialized;
private bool loadedFromSave;
@@ -69,7 +71,6 @@ public sealed class AllyHeroDeployLedger : MonoBehaviour
loadedFromSave = AllyHeroDeployLedgerStorage.TryLoad(out payload);
RebuildFromPayload(payload);
initialized = true;
SeedFromHeroAssetsIfNeeded();
SyncAllMirrorFlags();
SaveNow();
}
@@ -81,6 +82,20 @@ public sealed class AllyHeroDeployLedger : MonoBehaviour
return deployCountsByHeroId.TryGetValue(heroId, out count) ? count : 0;
}
public int GetFinishCount(int heroId)
{
InitializeIfNeeded();
int count;
return finishCountsByHeroId.TryGetValue(heroId, out count) ? count : 0;
}
public int GetMvpCount(int heroId)
{
InitializeIfNeeded();
int count;
return mvpCountsByHeroId.TryGetValue(heroId, out count) ? count : 0;
}
public void IncrementDeployCount(AllyHero_SO hero, int amount = 1)
{
if (hero == null || hero.ally_heroID <= 0 || amount <= 0)
@@ -97,6 +112,38 @@ public sealed class AllyHeroDeployLedger : MonoBehaviour
SaveNow();
}
public void IncrementFinishCount(AllyHero_SO hero, int amount = 1)
{
if (hero == null || hero.ally_heroID <= 0 || amount <= 0)
{
return;
}
InitializeIfNeeded();
int current = GetFinishCount(hero.ally_heroID);
long next = (long)current + amount;
finishCountsByHeroId[hero.ally_heroID] = next > int.MaxValue ? int.MaxValue : (int)next;
hero.ally_finishCount = finishCountsByHeroId[hero.ally_heroID];
MarkDirty(hero);
SaveNow();
}
public void IncrementMvpCount(AllyHero_SO hero, int amount = 1)
{
if (hero == null || hero.ally_heroID <= 0 || amount <= 0)
{
return;
}
InitializeIfNeeded();
int current = GetMvpCount(hero.ally_heroID);
long next = (long)current + amount;
mvpCountsByHeroId[hero.ally_heroID] = next > int.MaxValue ? int.MaxValue : (int)next;
hero.ally_mvpCount = mvpCountsByHeroId[hero.ally_heroID];
MarkDirty(hero);
SaveNow();
}
public void SaveNow()
{
if (!initialized)
@@ -111,6 +158,8 @@ public sealed class AllyHeroDeployLedger : MonoBehaviour
private void RebuildFromPayload(AllyHeroDeployLedgerPayload payload)
{
deployCountsByHeroId.Clear();
finishCountsByHeroId.Clear();
mvpCountsByHeroId.Clear();
if (payload == null || payload.entries == null)
{
return;
@@ -125,39 +174,8 @@ public sealed class AllyHeroDeployLedger : MonoBehaviour
}
deployCountsByHeroId[entry.heroId] = Mathf.Max(0, entry.deployCount);
}
}
private void SeedFromHeroAssetsIfNeeded()
{
AllyHero_SO[] heroes = Resources.LoadAll<AllyHero_SO>(string.Empty);
bool changed = false;
for (int i = 0; i < heroes.Length; i++)
{
AllyHero_SO hero = heroes[i];
if (hero == null || hero.ally_heroID <= 0)
{
continue;
}
if (deployCountsByHeroId.ContainsKey(hero.ally_heroID))
{
continue;
}
if (hero.ally_battleDeployCount <= 0)
{
continue;
}
deployCountsByHeroId[hero.ally_heroID] = Mathf.Max(0, hero.ally_battleDeployCount);
changed = true;
}
if (changed && !loadedFromSave)
{
SaveNow();
finishCountsByHeroId[entry.heroId] = Mathf.Max(0, entry.finishCount);
mvpCountsByHeroId[entry.heroId] = Mathf.Max(0, entry.mvpCount);
}
}
@@ -178,25 +196,71 @@ public sealed class AllyHeroDeployLedger : MonoBehaviour
count = 0;
}
if (hero.ally_battleDeployCount == count)
int finishCount;
if (!finishCountsByHeroId.TryGetValue(hero.ally_heroID, out finishCount))
{
continue;
finishCount = 0;
}
hero.ally_battleDeployCount = count;
MarkDirty(hero);
int mvpCount;
if (!mvpCountsByHeroId.TryGetValue(hero.ally_heroID, out mvpCount))
{
mvpCount = 0;
}
bool changed = false;
if (hero.ally_battleDeployCount != count)
{
hero.ally_battleDeployCount = count;
changed = true;
}
if (hero.ally_finishCount != finishCount)
{
hero.ally_finishCount = finishCount;
changed = true;
}
if (hero.ally_mvpCount != mvpCount)
{
hero.ally_mvpCount = mvpCount;
changed = true;
}
if (changed)
{
MarkDirty(hero);
}
}
}
private AllyHeroDeployLedgerPayload BuildPayload()
{
AllyHeroDeployLedgerPayload payload = AllyHeroDeployLedgerStorage.CreateDefaultPayload();
HashSet<int> allHeroIds = new HashSet<int>();
foreach (KeyValuePair<int, int> pair in deployCountsByHeroId)
{
allHeroIds.Add(pair.Key);
}
foreach (KeyValuePair<int, int> pair in finishCountsByHeroId)
{
allHeroIds.Add(pair.Key);
}
foreach (KeyValuePair<int, int> pair in mvpCountsByHeroId)
{
allHeroIds.Add(pair.Key);
}
foreach (int heroId in allHeroIds)
{
payload.entries.Add(new AllyHeroDeployEntry
{
heroId = pair.Key,
deployCount = Mathf.Max(0, pair.Value)
heroId = heroId,
deployCount = Mathf.Max(0, GetDeployCount(heroId)),
finishCount = Mathf.Max(0, GetFinishCount(heroId)),
mvpCount = Mathf.Max(0, GetMvpCount(heroId))
});
}
@@ -206,7 +270,7 @@ public sealed class AllyHeroDeployLedger : MonoBehaviour
private static void MarkDirty(AllyHero_SO hero)
{
#if UNITY_EDITOR
if (hero != null)
if (!Application.isPlaying && hero != null)
{
EditorUtility.SetDirty(hero);
}