6
6
7
7
namespace FbxExporters . Editor
8
8
{
9
- public class RepairMissingScripts
10
- {
11
- private const string m_forumPackageGUID = "2d81c55c4d9d85146b1d2de96e084b63" ;
12
- private const string m_currentPackageGUID = "628ffbda3fdf4df4588770785d91a698" ;
9
+ public class RepairMissingScripts
10
+ {
11
+ private const string m_forumPackageGUID = "2d81c55c4d9d85146b1d2de96e084b63" ;
12
+ private const string m_currentPackageGUID = "628ffbda3fdf4df4588770785d91a698" ;
13
13
14
- private const string m_fbxPrefabDLLFileId = "69888640" ;
14
+ private const string m_fbxPrefabDLLFileId = "69888640" ;
15
15
16
- private const string m_idFormat = "{{fileID: {0}, guid: {1}, type:" ;
16
+ private const string m_idFormat = "{{fileID: {0}, guid: {1}, type:" ;
17
17
18
18
19
- private static string m_forumPackageSearchID ;
19
+ private static string m_forumPackageSearchID ;
20
20
21
- private static string ForumPackageSearchID {
22
- get {
23
- if ( string . IsNullOrEmpty ( m_forumPackageSearchID ) ) {
24
- m_forumPackageSearchID = string . Format ( m_idFormat , m_fbxPrefabDLLFileId , m_forumPackageGUID ) ;
25
- }
26
- return m_forumPackageSearchID ;
27
- }
28
- }
21
+ private static string ForumPackageSearchID {
22
+ get {
23
+ if ( string . IsNullOrEmpty ( m_forumPackageSearchID ) ) {
24
+ m_forumPackageSearchID = string . Format ( m_idFormat , m_fbxPrefabDLLFileId , m_forumPackageGUID ) ;
25
+ }
26
+ return m_forumPackageSearchID ;
27
+ }
28
+ }
29
29
30
- private static string m_currentPackageSearchID ;
30
+ private static string m_currentPackageSearchID ;
31
31
32
- private static string CurrentPackageSearchID {
33
- get {
34
- if ( string . IsNullOrEmpty ( m_currentPackageSearchID ) ) {
35
- m_currentPackageSearchID = string . Format ( m_idFormat , m_fbxPrefabDLLFileId , m_currentPackageGUID ) ;
36
- }
37
- return m_currentPackageSearchID ;
38
- }
39
- }
32
+ private static string CurrentPackageSearchID {
33
+ get {
34
+ if ( string . IsNullOrEmpty ( m_currentPackageSearchID ) ) {
35
+ m_currentPackageSearchID = string . Format ( m_idFormat , m_fbxPrefabDLLFileId , m_currentPackageGUID ) ;
36
+ }
37
+ return m_currentPackageSearchID ;
38
+ }
39
+ }
40
40
41
- public static bool ReplaceGUIDInTextAssets ( )
42
- {
43
- // search project for assets containing old GUID
41
+ public static bool ReplaceGUIDInTextAssets ( )
42
+ {
43
+ // search project for assets containing old GUID
44
44
45
45
// ignore if forced binary
46
46
if ( UnityEditor . EditorSettings . serializationMode == SerializationMode . ForceBinary ) {
47
47
return false ;
48
48
}
49
49
50
- // check all scenes and prefabs
51
- string [ ] searchFilePatterns = new string [ ] { "*.prefab" , "*.unity" } ;
52
-
53
- bool replacedGUID = false ;
54
- foreach ( string searchPattern in searchFilePatterns ) {
55
- foreach ( string file in Directory . GetFiles ( Application . dataPath , searchPattern , SearchOption . AllDirectories ) ) {
56
- replacedGUID |= ReplaceGUIDInFile ( file ) ;
57
- }
58
- }
59
- if ( replacedGUID ) {
60
- AssetDatabase . Refresh ( ) ;
61
- }
62
- return replacedGUID ;
63
- }
64
-
65
- private static bool ReplaceGUIDInFile ( string path )
66
- {
67
- // try to read file, assume it's a text file for now
68
- bool modified = false ;
69
-
70
- try {
71
- var sr = new StreamReader ( path ) ;
50
+ // check all scenes and prefabs
51
+ string [ ] searchFilePatterns = new string [ ] { "*.prefab" , "*.unity" } ;
52
+
53
+ bool replacedGUID = false ;
54
+ foreach ( string searchPattern in searchFilePatterns ) {
55
+ foreach ( string file in Directory . GetFiles ( Application . dataPath , searchPattern , SearchOption . AllDirectories ) ) {
56
+ replacedGUID |= ReplaceGUIDInFile ( file ) ;
57
+ }
58
+ }
59
+ if ( replacedGUID ) {
60
+ AssetDatabase . Refresh ( ) ;
61
+ }
62
+ return replacedGUID ;
63
+ }
64
+
65
+ private static bool ReplaceGUIDInFile ( string path )
66
+ {
67
+ // try to read file, assume it's a text file for now
68
+ bool modified = false ;
69
+
70
+ try {
71
+ var sr = new StreamReader ( path ) ;
72
72
73
73
// verify that this is a text file
74
74
var firstLine = "" ;
75
- if ( sr . Peek ( ) > - 1 ) {
76
- firstLine = sr . ReadLine ( ) ;
77
- if ( ! firstLine . StartsWith ( "%YAML" ) ) {
75
+ if ( sr . Peek ( ) > - 1 ) {
76
+ firstLine = sr . ReadLine ( ) ;
77
+ if ( ! firstLine . StartsWith ( "%YAML" ) ) {
78
78
sr . Close ( ) ;
79
79
return false ;
80
80
}
81
81
}
82
82
83
- var sw = new StreamWriter ( path + ".remap" , false ) ;
83
+ var sw = new StreamWriter ( path + ".remap" , false ) ;
84
84
85
- if ( ! string . IsNullOrEmpty ( firstLine ) ) {
86
- sw . WriteLine ( firstLine ) ;
85
+ if ( ! string . IsNullOrEmpty ( firstLine ) ) {
86
+ sw . WriteLine ( firstLine ) ;
87
87
}
88
88
89
- while ( sr . Peek ( ) > - 1 ) {
90
- var line = sr . ReadLine ( ) ;
89
+ while ( sr . Peek ( ) > - 1 ) {
90
+ var line = sr . ReadLine ( ) ;
91
91
92
- if ( line . Contains ( ForumPackageSearchID ) ) {
93
- line = line . Replace ( ForumPackageSearchID , CurrentPackageSearchID ) ;
92
+ if ( line . Contains ( ForumPackageSearchID ) ) {
93
+ line = line . Replace ( ForumPackageSearchID , CurrentPackageSearchID ) ;
94
94
modified |= true ;
95
- }
96
-
97
- sw . WriteLine ( line ) ;
98
- }
99
-
100
- sr . Close ( ) ;
101
- sw . Close ( ) ;
102
-
103
- if ( modified ) {
104
- File . Delete ( path ) ;
105
- File . Move ( path + ".remap" , path ) ;
106
- return true ;
107
- } else {
108
- File . Delete ( path + ".remap" ) ;
109
- }
110
- } catch ( IOException e ) {
111
- Debug . LogError ( string . Format ( "Failed to replace GUID in file {0} (error={1})" , path , e ) ) ;
112
- }
113
-
114
- return false ;
115
- }
116
- }
95
+ }
96
+
97
+ sw . WriteLine ( line ) ;
98
+ }
99
+
100
+ sr . Close ( ) ;
101
+ sw . Close ( ) ;
102
+
103
+ if ( modified ) {
104
+ File . Delete ( path ) ;
105
+ File . Move ( path + ".remap" , path ) ;
106
+ return true ;
107
+ } else {
108
+ File . Delete ( path + ".remap" ) ;
109
+ }
110
+ } catch ( IOException e ) {
111
+ Debug . LogError ( string . Format ( "Failed to replace GUID in file {0} (error={1})" , path , e ) ) ;
112
+ }
113
+
114
+ return false ;
115
+ }
116
+ }
117
117
}
0 commit comments