Skip to content

Commit 2735921

Browse files
committed
update file ids and guids from DLL to source code
- get the file id and guid of the source code asset from the project - check against the old forum package id and asset store id
1 parent 0597da2 commit 2735921

File tree

1 file changed

+35
-12
lines changed

1 file changed

+35
-12
lines changed

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

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@ 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

1818
private static string m_forumPackageSearchID;
19-
2019
private static string ForumPackageSearchID {
2120
get {
2221
if (string.IsNullOrEmpty (m_forumPackageSearchID)) {
@@ -26,14 +25,13 @@ private static string ForumPackageSearchID {
2625
}
2726
}
2827

29-
private static string m_currentPackageSearchID;
30-
31-
private static string CurrentPackageSearchID {
28+
private static string m_assetStorePackageSearchID;
29+
private static string AssetStorePackageSearchID {
3230
get {
33-
if (string.IsNullOrEmpty (m_currentPackageSearchID)) {
34-
m_currentPackageSearchID = string.Format (m_idFormat, m_fbxPrefabDLLFileId, m_currentPackageGUID);
31+
if (string.IsNullOrEmpty (m_assetStorePackageSearchID)) {
32+
m_assetStorePackageSearchID = string.Format (m_idFormat, m_fbxPrefabDLLFileId, m_assetStorePackageGUID);
3533
}
36-
return m_currentPackageSearchID;
34+
return m_assetStorePackageSearchID;
3735
}
3836
}
3937

@@ -47,6 +45,20 @@ private string[] AssetsToRepair{
4745
}
4846
}
4947

48+
public static bool TryGetSourceCodeSearchID(out string searchID)
49+
{
50+
var fbxPrefabObj = AssetDatabase.LoadMainAssetAtPath(FbxExporters.FbxPrefabAutoUpdater.FindFbxPrefabAssetPath());
51+
searchID = null;
52+
string guid;
53+
long fileId;
54+
if(AssetDatabase.TryGetGUIDAndLocalFileIdentifier(fbxPrefabObj, out guid, out fileId))
55+
{
56+
searchID = string.Format(m_idFormat, fileId, guid);
57+
return true;
58+
}
59+
return false;
60+
}
61+
5062
public int GetAssetsToRepairCount(){
5163
return AssetsToRepair.Length;
5264
}
@@ -91,7 +103,7 @@ private static bool AssetNeedsRepair(string filePath)
91103
}
92104

93105
var contents = sr.ReadToEnd();
94-
if(contents.Contains(ForumPackageSearchID)){
106+
if(contents.Contains(ForumPackageSearchID) || contents.Contains(AssetStorePackageSearchID)){
95107
sr.Close();
96108
return true;
97109
}
@@ -105,17 +117,22 @@ private static bool AssetNeedsRepair(string filePath)
105117

106118
public bool ReplaceGUIDInTextAssets ()
107119
{
120+
string sourceCodeSearchID;
121+
if(!TryGetSourceCodeSearchID(out sourceCodeSearchID))
122+
{
123+
return false;
124+
}
108125
bool replacedGUID = false;
109126
foreach (string file in AssetsToRepair) {
110-
replacedGUID |= ReplaceGUIDInFile (file);
127+
replacedGUID |= ReplaceGUIDInFile (file, sourceCodeSearchID);
111128
}
112129
if (replacedGUID) {
113130
AssetDatabase.Refresh ();
114131
}
115132
return replacedGUID;
116133
}
117134

118-
private static bool ReplaceGUIDInFile (string path)
135+
private static bool ReplaceGUIDInFile (string path, string replacementSearchID)
119136
{
120137
// try to read file, assume it's a text file for now
121138
bool modified = false;
@@ -146,7 +163,13 @@ private static bool ReplaceGUIDInFile (string path)
146163
var line = sr.ReadLine ();
147164

148165
if (line.Contains (ForumPackageSearchID)) {
149-
line = line.Replace (ForumPackageSearchID, CurrentPackageSearchID);
166+
line = line.Replace (ForumPackageSearchID, replacementSearchID);
167+
modified = true;
168+
}
169+
170+
if (line.Contains(AssetStorePackageSearchID))
171+
{
172+
line = line.Replace (AssetStorePackageSearchID, replacementSearchID);
150173
modified = true;
151174
}
152175

0 commit comments

Comments
 (0)