@@ -9,31 +9,25 @@ namespace FbxExporters.Editor
9
9
public class RepairMissingScripts
10
10
{
11
11
private const string m_forumPackageGUID = "2d81c55c4d9d85146b1d2de96e084b63" ;
12
- private const string m_currentPackageGUID = "628ffbda3fdf4df4588770785d91a698" ;
12
+ private const string m_assetStorePackageGUID = "628ffbda3fdf4df4588770785d91a698" ;
13
13
14
14
private const string m_fbxPrefabDLLFileId = "69888640" ;
15
15
16
16
private const string m_idFormat = "{{fileID: {0}, guid: {1}, type:" ;
17
17
18
- private static string m_forumPackageSearchID ;
19
-
20
- private static string ForumPackageSearchID {
21
- get {
22
- if ( string . IsNullOrEmpty ( m_forumPackageSearchID ) ) {
23
- m_forumPackageSearchID = string . Format ( m_idFormat , m_fbxPrefabDLLFileId , m_forumPackageGUID ) ;
24
- }
25
- return m_forumPackageSearchID ;
26
- }
27
- }
28
-
29
- private static string m_currentPackageSearchID ;
30
-
31
- private static string CurrentPackageSearchID {
32
- get {
33
- if ( string . IsNullOrEmpty ( m_currentPackageSearchID ) ) {
34
- m_currentPackageSearchID = string . Format ( m_idFormat , m_fbxPrefabDLLFileId , m_currentPackageGUID ) ;
18
+ private static List < string > m_searchIDsToReplace ;
19
+ private static List < string > SearchIDsToReplace
20
+ {
21
+ get
22
+ {
23
+ if ( m_searchIDsToReplace == null || m_searchIDsToReplace . Count <= 0 )
24
+ {
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
+ } ;
35
29
}
36
- return m_currentPackageSearchID ;
30
+ return m_searchIDsToReplace ;
37
31
}
38
32
}
39
33
@@ -47,6 +41,19 @@ private string[] AssetsToRepair{
47
41
}
48
42
}
49
43
44
+ public static string GetSourceCodeSearchID ( )
45
+ {
46
+ var fbxPrefabObj = AssetDatabase . LoadMainAssetAtPath ( FbxExporters . FbxPrefabAutoUpdater . FindFbxPrefabAssetPath ( ) ) ;
47
+ string searchID = null ;
48
+ string guid ;
49
+ long fileId ;
50
+ if ( AssetDatabase . TryGetGUIDAndLocalFileIdentifier ( fbxPrefabObj , out guid , out fileId ) )
51
+ {
52
+ searchID = string . Format ( m_idFormat , fileId , guid ) ;
53
+ }
54
+ return searchID ;
55
+ }
56
+
50
57
public int GetAssetsToRepairCount ( ) {
51
58
return AssetsToRepair . Length ;
52
59
}
@@ -91,7 +98,8 @@ private static bool AssetNeedsRepair(string filePath)
91
98
}
92
99
93
100
var contents = sr . ReadToEnd ( ) ;
94
- if ( contents . Contains ( ForumPackageSearchID ) ) {
101
+ if ( SearchIDsToReplace . Exists ( searchId => contents . Contains ( searchId ) ) )
102
+ {
95
103
sr . Close ( ) ;
96
104
return true ;
97
105
}
@@ -105,17 +113,32 @@ private static bool AssetNeedsRepair(string filePath)
105
113
106
114
public bool ReplaceGUIDInTextAssets ( )
107
115
{
116
+ string sourceCodeSearchID = GetSourceCodeSearchID ( ) ;
117
+ if ( string . IsNullOrEmpty ( sourceCodeSearchID ) )
118
+ {
119
+ return false ;
120
+ }
108
121
bool replacedGUID = false ;
109
122
foreach ( string file in AssetsToRepair ) {
110
- replacedGUID |= ReplaceGUIDInFile ( file ) ;
123
+ replacedGUID |= ReplaceGUIDInFile ( file , sourceCodeSearchID ) ;
111
124
}
112
125
if ( replacedGUID ) {
113
126
AssetDatabase . Refresh ( ) ;
114
127
}
115
128
return replacedGUID ;
116
129
}
117
130
118
- private static bool ReplaceGUIDInFile ( string path )
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
+
141
+ private static bool ReplaceGUIDInFile ( string path , string replacementSearchID )
119
142
{
120
143
// try to read file, assume it's a text file for now
121
144
bool modified = false ;
@@ -144,11 +167,9 @@ private static bool ReplaceGUIDInFile (string path)
144
167
145
168
while ( sr . Peek ( ) > - 1 ) {
146
169
var line = sr . ReadLine ( ) ;
147
-
148
- if ( line . Contains ( ForumPackageSearchID ) ) {
149
- line = line . Replace ( ForumPackageSearchID , CurrentPackageSearchID ) ;
150
- modified = true ;
151
- }
170
+ SearchIDsToReplace . ForEach ( searchId =>
171
+ modified |= ReplaceID ( searchId , replacementSearchID , ref line )
172
+ ) ;
152
173
153
174
sw . WriteLine ( line ) ;
154
175
}
0 commit comments