拼ui 一些业务逻辑x实现
This commit is contained in:
@@ -14,6 +14,7 @@ public sealed class StoreOwnershipLedger : MonoBehaviour
|
||||
private readonly Dictionary<int, StoreOwnershipEntry> entriesByItemId = new Dictionary<int, StoreOwnershipEntry>();
|
||||
private readonly List<storeItemSO> cachedStoreItems = new List<storeItemSO>();
|
||||
private bool initialized;
|
||||
private int lastSaveFrame = -1;
|
||||
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
|
||||
private static void Bootstrap()
|
||||
@@ -68,13 +69,12 @@ public sealed class StoreOwnershipLedger : MonoBehaviour
|
||||
return;
|
||||
}
|
||||
|
||||
initialized = true;
|
||||
StoreOwnershipPayload payload;
|
||||
StoreOwnershipStorage.TryLoad(out payload);
|
||||
RebuildFromPayload(payload);
|
||||
LoadStoreItems();
|
||||
SeedFromCurrentMirrorFlags();
|
||||
SyncAllMirrorFlags();
|
||||
initialized = true;
|
||||
SaveNow();
|
||||
}
|
||||
|
||||
@@ -137,6 +137,7 @@ public sealed class StoreOwnershipLedger : MonoBehaviour
|
||||
}
|
||||
|
||||
ApplyEntryToItem(itemSO, entry);
|
||||
GlobalAchievementService.EnsureInstance().RefreshDerivedMetrics();
|
||||
SaveNow();
|
||||
return true;
|
||||
}
|
||||
@@ -154,6 +155,12 @@ public sealed class StoreOwnershipLedger : MonoBehaviour
|
||||
return;
|
||||
}
|
||||
|
||||
if (Application.isPlaying && lastSaveFrame == Time.frameCount)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
lastSaveFrame = Application.isPlaying ? Time.frameCount : -1;
|
||||
StoreOwnershipStorage.TrySave(CreatePayload());
|
||||
}
|
||||
|
||||
@@ -314,6 +321,8 @@ public sealed class StoreOwnershipLedger : MonoBehaviour
|
||||
|
||||
private void SyncAllMirrorFlags()
|
||||
{
|
||||
ResetAllMirrorFlags();
|
||||
|
||||
for (int i = 0; i < cachedStoreItems.Count; i++)
|
||||
{
|
||||
var item = cachedStoreItems[i];
|
||||
@@ -332,6 +341,68 @@ public sealed class StoreOwnershipLedger : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
private void ResetAllMirrorFlags()
|
||||
{
|
||||
var seenHeroIds = new HashSet<int>();
|
||||
var seenSongIds = new HashSet<int>();
|
||||
var seenStoryIds = new HashSet<int>();
|
||||
|
||||
for (int i = 0; i < cachedStoreItems.Count; i++)
|
||||
{
|
||||
var item = cachedStoreItems[i];
|
||||
if (item == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (item.itemType == storeItemSO.ItemType.character && item.associatedAllyHero != null && seenHeroIds.Add(item.associatedAllyHero.ally_heroID))
|
||||
{
|
||||
if (item.associatedAllyHero.isUnlocked)
|
||||
{
|
||||
item.associatedAllyHero.isUnlocked = false;
|
||||
MarkDirty(item.associatedAllyHero);
|
||||
}
|
||||
}
|
||||
else if (item.itemType == storeItemSO.ItemType.song && item.associatedSong != null && seenSongIds.Add(item.associatedSong.songID))
|
||||
{
|
||||
if (item.associatedSong.isUnlocked)
|
||||
{
|
||||
item.associatedSong.isUnlocked = false;
|
||||
MarkDirty(item.associatedSong);
|
||||
}
|
||||
}
|
||||
else if (item.itemType == storeItemSO.ItemType.storyPassage && item.associatedStoryPassage != null && seenStoryIds.Add(item.associatedStoryPassage.class_id))
|
||||
{
|
||||
var story = item.associatedStoryPassage;
|
||||
bool changed = false;
|
||||
|
||||
if (story.isUnlocked)
|
||||
{
|
||||
story.isUnlocked = false;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if (story.sonList != null)
|
||||
{
|
||||
for (int sonIndex = 0; sonIndex < story.sonList.Count; sonIndex++)
|
||||
{
|
||||
var son = story.sonList[sonIndex];
|
||||
if (son != null && son.son_isUnlocked)
|
||||
{
|
||||
son.son_isUnlocked = false;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (changed)
|
||||
{
|
||||
MarkDirty(story);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool ValidateGrantTarget(storeItemSO itemSO, out string failureMessage)
|
||||
{
|
||||
failureMessage = string.Empty;
|
||||
@@ -647,7 +718,7 @@ public sealed class StoreOwnershipLedger : MonoBehaviour
|
||||
private static void MarkDirty(UnityEngine.Object target)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (target != null)
|
||||
if (!Application.isPlaying && target != null)
|
||||
{
|
||||
EditorUtility.SetDirty(target);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user