@@ -46,6 +46,7 @@ public LongGuid GUID
4646 public virtual bool ShouldProtectItemOrder => false ;
4747
4848 private Dictionary < string , ScriptableObject > itemNameToScriptableObject = new ( ) ;
49+ private Dictionary < LongGuid , ScriptableObject > itemGuidToScriptableObject = new ( ) ;
4950
5051 public ScriptableObject this [ int index ]
5152 {
@@ -444,7 +445,7 @@ public void RefreshCollection()
444445 Clear ( ) ;
445446 }
446447
447- if ( ! CollectionsRegistry . Instance . IsKnowCollection ( this ) )
448+ if ( ! CollectionsRegistry . Instance . IsKnownCollection ( this ) )
448449 {
449450 CollectionsRegistry . Instance . RegisterCollection ( this ) ;
450451 }
@@ -468,10 +469,13 @@ public void RefreshCollection()
468469 public void CacheItemNames ( )
469470 {
470471 itemNameToScriptableObject . Clear ( ) ;
472+ itemGuidToScriptableObject . Clear ( ) ;
471473 for ( int i = 0 ; i < items . Count ; i ++ )
472474 {
473475 ScriptableObject item = items [ i ] ;
474476 itemNameToScriptableObject . TryAdd ( item . name , item ) ;
477+ if ( item is ISOCItem socItem && socItem . GUID . IsValid ( ) )
478+ itemGuidToScriptableObject . TryAdd ( socItem . GUID , item ) ;
475479 }
476480 }
477481
@@ -499,16 +503,23 @@ public bool TryGetItemByGUID<T>(LongGuid itemGUID, out T scriptableObjectCollect
499503 {
500504 if ( itemGUID . IsValid ( ) )
501505 {
506+ if ( itemGuidToScriptableObject . TryGetValue ( itemGUID , out ScriptableObject cached ) )
507+ {
508+ scriptableObjectCollectionItem = cached as T ;
509+ return scriptableObjectCollectionItem != null ;
510+ }
511+
502512 for ( int i = 0 ; i < items . Count ; i ++ )
503513 {
504514 ScriptableObject item = items [ i ] ;
505515 ISOCItem socItem = item as ISOCItem ;
506516 if ( socItem == null )
507517 continue ;
508-
518+
509519 if ( socItem . GUID == itemGUID )
510520 {
511521 scriptableObjectCollectionItem = item as T ;
522+ itemGuidToScriptableObject [ itemGUID ] = item ;
512523 return scriptableObjectCollectionItem != null ;
513524 }
514525 }
@@ -524,6 +535,8 @@ public bool TryGetItemByGUID(LongGuid itemGUID, out ScriptableObject scriptableO
524535
525536 protected virtual void ClearCachedValues ( )
526537 {
538+ itemGuidToScriptableObject . Clear ( ) ;
539+ itemNameToScriptableObject . Clear ( ) ;
527540 }
528541 }
529542
@@ -546,8 +559,6 @@ public static IReadOnlyList<TObjectType> Values
546559 get => ( TObjectType ) base [ index ] ;
547560 set => base [ index ] = value ;
548561 }
549-
550- private readonly Dictionary < Type , List < TObjectType > > typeToItems = new ( ) ;
551562
552563
553564 public new IEnumerator < TObjectType > GetEnumerator ( )
0 commit comments