Skip to content

Commit 96ca5bf

Browse files
committed
fix: PR comments
1 parent d4eb432 commit 96ca5bf

File tree

5 files changed

+59
-18
lines changed

5 files changed

+59
-18
lines changed

Scripts/Editor/Processors/SOCItemGuidProcessor.cs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using UnityEditor;
44

@@ -66,11 +66,32 @@ private static void RemoveFromIndex(ScriptableObjectCollectionItem item)
6666
LongGuid guid = item.GUID;
6767
if (!guid.IsValid())
6868
return;
69-
69+
7070
if (PathByGuid.TryGetValue(guid, out string existing) && existing == AssetDatabase.GetAssetPath(item))
7171
PathByGuid.Remove(guid);
7272
}
7373

74+
private static void RemoveFromIndexByPath(string path)
75+
{
76+
if (!indexInitialized)
77+
return;
78+
79+
LongGuid keyToRemove = default;
80+
bool found = false;
81+
foreach (var kvp in PathByGuid)
82+
{
83+
if (string.Equals(kvp.Value, path, System.StringComparison.Ordinal))
84+
{
85+
keyToRemove = kvp.Key;
86+
found = true;
87+
break;
88+
}
89+
}
90+
91+
if (found)
92+
PathByGuid.Remove(keyToRemove);
93+
}
94+
7495
private static void OnPostprocessAllAssets(
7596
string[] importedAssets,
7697
string[] deletedAssets,
@@ -81,9 +102,7 @@ private static void OnPostprocessAllAssets(
81102

82103
foreach (string del in deletedAssets)
83104
{
84-
ScriptableObjectCollectionItem item = AssetDatabase.LoadAssetAtPath<ScriptableObjectCollectionItem>(del);
85-
if (item != null)
86-
RemoveFromIndex(item);
105+
RemoveFromIndexByPath(del);
87106
}
88107

89108
foreach (string path in importedAssets)

Scripts/Editor/Processors/SOCItemGuidProcessor.cs.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Scripts/Editor/PropertyDrawers/CollectionItemQueryPropertyDrawer.cs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -453,14 +453,25 @@ private static bool HasItemIntersection(HashSet<(long, long)> a, HashSet<(long,
453453

454454
private static bool IsCombinationImpossible(int matchA, int matchB)
455455
{
456-
// 0 = Any, 1 = All (positive) | 2 = SomeNot, 3 = None (negative)
457-
// Invalid only when the same tag is in a positive and a negative rule.
458-
bool aPositive = matchA is 0 or 1;
459-
bool bPositive = matchB is 0 or 1;
460-
bool aNegative = matchA is 2 or 3;
461-
bool bNegative = matchB is 2 or 3;
462-
463-
if ((aPositive && bNegative) || (aNegative && bPositive))
456+
// 0 = Any, 1 = All, 2 = SomeNot (forbids any), 3 = None (forbids all)
457+
// Only truly impossible when overlapping items can never satisfy both rules:
458+
// - All + SomeNot: must have all AND must have none → impossible
459+
// - Any + SomeNot: must have at least one AND must have none → impossible
460+
// - All + None: must have all AND must not have all → impossible
461+
// - Any + None: must have at least one AND must not have all → satisfiable (partial overlap ok)
462+
int lo = Mathf.Min(matchA, matchB);
463+
int hi = Mathf.Max(matchA, matchB);
464+
465+
// All(1) + SomeNot(2)
466+
if (lo == 1 && hi == 2)
467+
return true;
468+
469+
// Any(0) + SomeNot(2)
470+
if (lo == 0 && hi == 2)
471+
return true;
472+
473+
// All(1) + None(3)
474+
if (lo == 1 && hi == 3)
464475
return true;
465476

466477
return false;

Scripts/Runtime/Core/CollectionsRegistry.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,13 @@ public ScriptableObjectCollection GetCollectionByGUID(LongGuid guid)
250250
if (collectionGuidLookup.Count == 0 && collections.Count > 0)
251251
RebuildGuidLookup();
252252

253-
if (collectionGuidLookup.TryGetValue(guid, out ScriptableObjectCollection cached) && cached != null)
254-
return cached;
253+
if (collectionGuidLookup.TryGetValue(guid, out ScriptableObjectCollection cached))
254+
{
255+
if (cached != null && cached.GUID == guid)
256+
return cached;
257+
258+
collectionGuidLookup.Remove(guid);
259+
}
255260

256261
for (int i = 0; i < collections.Count; i++)
257262
{

Scripts/Runtime/Core/ScriptableObjectCollection.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,8 +505,13 @@ public bool TryGetItemByGUID<T>(LongGuid itemGUID, out T scriptableObjectCollect
505505
{
506506
if (itemGuidToScriptableObject.TryGetValue(itemGUID, out ScriptableObject cached))
507507
{
508-
scriptableObjectCollectionItem = cached as T;
509-
return scriptableObjectCollectionItem != null;
508+
if (cached != null && cached is ISOCItem cachedSocItem && cachedSocItem.GUID == itemGUID)
509+
{
510+
scriptableObjectCollectionItem = cached as T;
511+
return scriptableObjectCollectionItem != null;
512+
}
513+
514+
itemGuidToScriptableObject.Remove(itemGUID);
510515
}
511516

512517
for (int i = 0; i < items.Count; i++)
@@ -719,6 +724,7 @@ IEnumerator IEnumerable.GetEnumerator()
719724

720725
protected override void ClearCachedValues()
721726
{
727+
base.ClearCachedValues();
722728
cachedValues = null;
723729
}
724730
}

0 commit comments

Comments
 (0)