@@ -16,17 +16,18 @@ public class RepairMissingScripts
16
16
private const string m_idFormat = "{{fileID: {0}, guid: {1}, type:" ;
17
17
18
18
private static List < string > m_searchIDsToReplace ;
19
- private static string [ ] SearchIDsToReplace
19
+ private static List < string > SearchIDsToReplace
20
20
{
21
21
get
22
22
{
23
- if ( m_searchIDsToReplace == null || m_searchIDsToReplace . Count <= 0 )
23
+ if ( m_searchIDsToReplace == null || m_searchIDsToReplace . Count <= 0 )
24
24
{
25
- m_searchIDsToReplace = new List < string > ( ) ;
26
- m_searchIDsToReplace . Add ( string . Format ( m_idFormat , m_fbxPrefabDLLFileId , m_forumPackageGUID ) ) ;
27
- m_searchIDsToReplace . Add ( string . Format ( m_idFormat , m_fbxPrefabDLLFileId , m_assetStorePackageGUID ) ) ;
25
+ m_searchIDsToReplace = new List < string > ( ) {
26
+ string . Format ( m_idFormat , m_fbxPrefabDLLFileId , m_forumPackageGUID ) ,
27
+ string . Format ( m_idFormat , m_fbxPrefabDLLFileId , m_assetStorePackageGUID )
28
+ } ;
28
29
}
29
- return m_searchIDsToReplace . ToArray ( ) ;
30
+ return m_searchIDsToReplace ;
30
31
}
31
32
}
32
33
@@ -40,18 +41,17 @@ private string[] AssetsToRepair{
40
41
}
41
42
}
42
43
43
- public static bool TryGetSourceCodeSearchID ( out string searchID )
44
+ public static string GetSourceCodeSearchID ( )
44
45
{
45
46
var fbxPrefabObj = AssetDatabase . LoadMainAssetAtPath ( FbxExporters . FbxPrefabAutoUpdater . FindFbxPrefabAssetPath ( ) ) ;
46
- searchID = null ;
47
+ string searchID = null ;
47
48
string guid ;
48
49
long fileId ;
49
50
if ( AssetDatabase . TryGetGUIDAndLocalFileIdentifier ( fbxPrefabObj , out guid , out fileId ) )
50
51
{
51
52
searchID = string . Format ( m_idFormat , fileId , guid ) ;
52
- return true ;
53
53
}
54
- return false ;
54
+ return searchID ;
55
55
}
56
56
57
57
public int GetAssetsToRepairCount ( ) {
@@ -98,13 +98,10 @@ private static bool AssetNeedsRepair(string filePath)
98
98
}
99
99
100
100
var contents = sr . ReadToEnd ( ) ;
101
- foreach ( var searchId in SearchIDsToReplace )
101
+ if ( SearchIDsToReplace . Exists ( searchId => contents . Contains ( searchId ) ) )
102
102
{
103
- if ( contents . Contains ( searchId ) )
104
- {
105
- sr . Close ( ) ;
106
- return true ;
107
- }
103
+ sr . Close ( ) ;
104
+ return true ;
108
105
}
109
106
}
110
107
}
@@ -116,8 +113,8 @@ private static bool AssetNeedsRepair(string filePath)
116
113
117
114
public bool ReplaceGUIDInTextAssets ( )
118
115
{
119
- string sourceCodeSearchID ;
120
- if ( ! TryGetSourceCodeSearchID ( out sourceCodeSearchID ) )
116
+ string sourceCodeSearchID = GetSourceCodeSearchID ( ) ;
117
+ if ( string . IsNullOrEmpty ( sourceCodeSearchID ) )
121
118
{
122
119
return false ;
123
120
}
@@ -131,6 +128,16 @@ public bool ReplaceGUIDInTextAssets ()
131
128
return replacedGUID ;
132
129
}
133
130
131
+ private static bool ReplaceID ( string searchId , string replacementId , ref string line )
132
+ {
133
+ if ( line . Contains ( searchId ) )
134
+ {
135
+ line = line . Replace ( searchId , replacementId ) ;
136
+ return true ;
137
+ }
138
+ return false ;
139
+ }
140
+
134
141
private static bool ReplaceGUIDInFile ( string path , string replacementSearchID )
135
142
{
136
143
// try to read file, assume it's a text file for now
@@ -160,15 +167,9 @@ private static bool ReplaceGUIDInFile (string path, string replacementSearchID)
160
167
161
168
while ( sr . Peek ( ) > - 1 ) {
162
169
var line = sr . ReadLine ( ) ;
163
-
164
- foreach ( var searchId in SearchIDsToReplace )
165
- {
166
- if ( line . Contains ( searchId ) )
167
- {
168
- line = line . Replace ( searchId , replacementSearchID ) ;
169
- modified = true ;
170
- }
171
- }
170
+ SearchIDsToReplace . ForEach ( searchId =>
171
+ modified |= ReplaceID ( searchId , replacementSearchID , ref line )
172
+ ) ;
172
173
173
174
sw . WriteLine ( line ) ;
174
175
}
0 commit comments