@@ -33,8 +33,20 @@ protected TypeInfo(Type type, string typeGUID = null)
3333 _guid = typeGUID ?? GetClassGUID ( type ) ;
3434 }
3535
36+ protected TypeInfo ( Type type , string typeNameAndAssembly , string typeGUID )
37+ {
38+ Type = type ;
39+ _typeNameAndAssembly = typeNameAndAssembly ;
40+ _guid = typeGUID ?? GetClassGUID ( type ) ;
41+ }
42+
3643 private string GetClassGUID ( Type type )
3744 {
45+ string guid = GenerationDatabase < MonoBehaviour > . GetCachedGenericTypeGUID ( _typeNameAndAssembly ) ;
46+
47+ if ( guid != null )
48+ return guid ;
49+
3850 if ( TypeCannotHaveGUID ( ) )
3951 return string . Empty ;
4052
@@ -56,7 +68,7 @@ public string TypeFullName
5668 }
5769 }
5870
59- public bool RetrieveType < TObject > ( out Type type , out bool retrievedFromGUID )
71+ public bool RetrieveType < TObject > ( out Type type , out bool retrievedFromGUID , bool updateGUID = true )
6072 where TObject : Object
6173 {
6274 retrievedFromGUID = false ;
@@ -71,8 +83,10 @@ public bool RetrieveType<TObject>(out Type type, out bool retrievedFromGUID)
7183
7284 if ( Type != null )
7385 {
86+ if ( updateGUID )
87+ UpdateGUIDIfNeeded < TObject > ( ) ;
88+
7489 type = Type ;
75- UpdateGUIDIfNeeded < TObject > ( ) ;
7690 return true ;
7791 }
7892
@@ -89,10 +103,18 @@ public bool RetrieveType<TObject>(out Type type, out bool retrievedFromGUID)
89103 return Type != null ;
90104 }
91105
92- public Type RetrieveType < TObject > ( )
106+ /// <summary> Retrieves type stored in this <see cref="TypeInfo"/> instance. </summary>
107+ /// <param name="updateGUID">
108+ /// Whether to try updating GUID if the type was found using typeNameAndAssembly. It is strongly not
109+ /// recommended to use. The only case when it can be to false is after all generic types are updated, to
110+ /// improve performance. See <see cref="DictInitializer{TObject}"/>. /
111+ /// </param>
112+ /// <typeparam name="TObject"> Type derived from <see cref="UnityEngine.Object"/>. </typeparam>
113+ /// <returns> A retrieved type or <c>null</c>, if the type was not found by typeNameAndAssembly or GUID. </returns>
114+ public Type RetrieveType < TObject > ( bool updateGUID = true )
93115 where TObject : Object
94116 {
95- RetrieveType < TObject > ( out Type type , out bool _ ) ;
117+ RetrieveType < TObject > ( out Type type , out bool _ , updateGUID ) ;
96118 return type ;
97119 }
98120
@@ -106,27 +128,21 @@ public void UpdateNameAndAssembly(Type newType) =>
106128
107129 public bool Equals ( TypeInfo p )
108130 {
109- // If parameter is null, return false.
110131 if ( ReferenceEquals ( p , null ) )
111132 {
112133 return false ;
113134 }
114135
115- // Optimization for a common success case.
116136 if ( ReferenceEquals ( this , p ) )
117137 {
118138 return true ;
119139 }
120140
121- // If run-time types are not exactly the same, return false.
122141 if ( this . GetType ( ) != p . GetType ( ) )
123142 {
124143 return false ;
125144 }
126145
127- // Return true if the fields match.
128- // Note that the base class is not invoked because it is
129- // System.Object, which defines Equals as reference equality.
130146 return TypeNameAndAssembly == p . TypeNameAndAssembly && _guid == p . _guid ;
131147 }
132148
@@ -184,7 +200,7 @@ private void UpdateGUIDIfNeeded<TObject>()
184200 if ( TypeAtGUIDIsSame ( ) )
185201 return ;
186202
187- string newGUID = AssetSearcher . GetClassGUID ( Type ) ; //
203+ string newGUID = AssetSearcher . GetClassGUID ( Type ) ;
188204
189205 if ( string . IsNullOrEmpty ( newGUID ) || GUID == newGUID )
190206 return ;
@@ -199,14 +215,14 @@ private void UpdateGUIDIfNeeded<TObject>()
199215 }
200216 else
201217 {
202- throw new TypeLoadException ( $ "{ nameof ( UpdateGUIDIfNeeded ) } method doesn't know of this inheritor of { nameof ( TypeInfo ) } yet: { GetType ( ) } .") ;
218+ throw new TypeLoadException (
219+ $ "{ nameof ( UpdateGUIDIfNeeded ) } method doesn't know of this inheritor " +
220+ $ "of { nameof ( TypeInfo ) } yet: { GetType ( ) } .") ;
203221 }
204222 }
205223
206224 private bool TypeAtGUIDIsSame ( )
207225 {
208- // Check if asset at guid contains the same type
209- // If it doesn't contain the same type or no type at all, search GUID of the type elsewhere
210226 string path = AssetDatabase . GUIDToAssetPath ( GUID ) ;
211227 if ( path . Length == 0 )
212228 return false ;
0 commit comments