Skip to content

Commit c1adaf3

Browse files
authored
Merge pull request #387 from Unity-Technologies/UT-111-update-DLL-to-source-code
Ut 111 update dll to source code
2 parents 955d861 + 030e629 commit c1adaf3

File tree

2 files changed

+50
-30
lines changed

2 files changed

+50
-30
lines changed

Assets/com.unity.formats.fbx/Editor/Scripts/FbxExportSettings.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,8 @@ public override void OnInspectorGUI() {
124124

125125
var repairMissingScripts = new GUIContent (
126126
"Run Component Updater",
127-
"If the forum package 1.1.0b1 was previously installed, then links to the FbxPrefab component " +
128-
"in assets created with the FBX exporter will need updating.\n" +
129-
"Run this button to update all FbxPrefab references in text serialized prefabs and scene files.");
127+
"If FBX exporter version 1.3.0f1 or earlier was previously installed, then links to the FbxPrefab component will need updating.\n" +
128+
"Run this to update all FbxPrefab references in text serialized prefabs and scene files.");
130129

131130
if (GUILayout.Button (repairMissingScripts)) {
132131
var componentUpdater = new FbxExporters.Editor.RepairMissingScripts ();

Assets/com.unity.formats.fbx/Editor/Scripts/FbxExporterRepairMissingScripts.cs

Lines changed: 48 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,25 @@ namespace FbxExporters.Editor
99
public class RepairMissingScripts
1010
{
1111
private const string m_forumPackageGUID = "2d81c55c4d9d85146b1d2de96e084b63";
12-
private const string m_currentPackageGUID = "628ffbda3fdf4df4588770785d91a698";
12+
private const string m_assetStorePackageGUID = "628ffbda3fdf4df4588770785d91a698";
1313

1414
private const string m_fbxPrefabDLLFileId = "69888640";
1515

1616
private const string m_idFormat = "{{fileID: {0}, guid: {1}, type:";
1717

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+
};
3529
}
36-
return m_currentPackageSearchID;
30+
return m_searchIDsToReplace;
3731
}
3832
}
3933

@@ -47,6 +41,19 @@ private string[] AssetsToRepair{
4741
}
4842
}
4943

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+
5057
public int GetAssetsToRepairCount(){
5158
return AssetsToRepair.Length;
5259
}
@@ -91,7 +98,8 @@ private static bool AssetNeedsRepair(string filePath)
9198
}
9299

93100
var contents = sr.ReadToEnd();
94-
if(contents.Contains(ForumPackageSearchID)){
101+
if (SearchIDsToReplace.Exists(searchId => contents.Contains(searchId)))
102+
{
95103
sr.Close();
96104
return true;
97105
}
@@ -105,17 +113,32 @@ private static bool AssetNeedsRepair(string filePath)
105113

106114
public bool ReplaceGUIDInTextAssets ()
107115
{
116+
string sourceCodeSearchID = GetSourceCodeSearchID();
117+
if(string.IsNullOrEmpty(sourceCodeSearchID))
118+
{
119+
return false;
120+
}
108121
bool replacedGUID = false;
109122
foreach (string file in AssetsToRepair) {
110-
replacedGUID |= ReplaceGUIDInFile (file);
123+
replacedGUID |= ReplaceGUIDInFile (file, sourceCodeSearchID);
111124
}
112125
if (replacedGUID) {
113126
AssetDatabase.Refresh ();
114127
}
115128
return replacedGUID;
116129
}
117130

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)
119142
{
120143
// try to read file, assume it's a text file for now
121144
bool modified = false;
@@ -144,11 +167,9 @@ private static bool ReplaceGUIDInFile (string path)
144167

145168
while (sr.Peek () > -1) {
146169
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+
);
152173

153174
sw.WriteLine (line);
154175
}

0 commit comments

Comments
 (0)