Skip to content

Commit a38d360

Browse files
authored
Merge pull request #251 from Unity-Technologies/UNI-32579-package-upgrade-breaks-component-links
Uni 32579 package upgrade breaks component links
2 parents 16e190e + 88363ae commit a38d360

36 files changed

+562
-2
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
**/.idea/
2121

2222
## Unity ##
23-
*.meta
23+
[Aa]ssets/**/*.meta
24+
![Aa]ssets/FbxExporters/**/*.meta
2425
[Pp]rojectSettings/*.asset
2526
[Pp]rojectSettings/*.txt
2627

Assets/FbxExporters/Editor.meta

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/FbxExporters/Editor/ConvertToModel.cs.meta

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/FbxExporters/Editor/EditorRotate.cs.meta

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/FbxExporters/Editor/FbxExportSettings.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,30 @@ public override void OnInspectorGUI() {
180180
}
181181
EditorGUI.EndDisabledGroup ();
182182

183+
if (!HideRepairMissingScripts ()) {
184+
EditorGUILayout.Space ();
185+
186+
EditorGUI.indentLevel--;
187+
EditorGUILayout.LabelField ("Repair Missing Scripts", EditorStyles.boldLabel);
188+
EditorGUI.indentLevel++;
189+
190+
EditorGUILayout.Space ();
191+
192+
var repairMissingScripts = new GUIContent (
193+
"Repair Missing Scripts",
194+
"Repair missing FbxPrefab scripts in text assets");
195+
if (GUILayout.Button (repairMissingScripts)) {
196+
bool result = FbxExporters.Editor.RepairMissingScripts.ReplaceGUIDInTextAssets ();
197+
if (result) {
198+
UnityEditor.EditorUtility.DisplayDialog ("Finished Repairing Scripts",
199+
"Repaired missing scripts in text serialized assets", "Ok");
200+
} else {
201+
UnityEditor.EditorUtility.DisplayDialog ("Finished Repairing Scripts",
202+
"Couldn't find any assets needing repair", "Ok");
203+
}
204+
}
205+
}
206+
183207
GUILayout.FlexibleSpace ();
184208
GUILayout.EndScrollView ();
185209
GUILayout.EndVertical();
@@ -190,6 +214,11 @@ public override void OnInspectorGUI() {
190214
}
191215
}
192216

217+
private static bool HideRepairMissingScripts(){
218+
var docPath = Application.dataPath + "/FbxExporters/FBX_Exporter_User_Guide_v1.1.0b1.pdf";
219+
return File.Exists(docPath)? false : true;
220+
}
221+
193222
private static string TryFindDCC(string dccPath, string ext, ExportSettings.DCCType dccType){
194223
string dccName = "";
195224
switch (dccType) {

Assets/FbxExporters/Editor/FbxExportSettings.cs.meta

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/FbxExporters/Editor/FbxExporter.cs.meta

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
using UnityEditor;
5+
using System.IO;
6+
7+
namespace FbxExporters.Editor
8+
{
9+
public class RepairMissingScripts
10+
{
11+
private const string m_forumPackageGUID = "2d81c55c4d9d85146b1d2de96e084b63";
12+
private const string m_currentPackageGUID = "628ffbda3fdf4df4588770785d91a698";
13+
14+
private const string m_fbxPrefabDLLFileId = "69888640";
15+
16+
private const string m_idFormat = "{{fileID: {0}, guid: {1}, type:";
17+
18+
19+
private static string m_forumPackageSearchID;
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+
}
29+
30+
private static string m_currentPackageSearchID;
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+
}
40+
41+
public static bool ReplaceGUIDInTextAssets ()
42+
{
43+
// search project for assets containing old GUID
44+
45+
// ignore if forced binary
46+
if (UnityEditor.EditorSettings.serializationMode == SerializationMode.ForceBinary) {
47+
return false;
48+
}
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 tmpFile = Path.GetTempFileName();
72+
if(string.IsNullOrEmpty(tmpFile)){
73+
return false;
74+
}
75+
76+
using(var sr = new StreamReader (path)){
77+
// verify that this is a text file
78+
var firstLine = "";
79+
if (sr.Peek () > -1) {
80+
firstLine = sr.ReadLine ();
81+
if (!firstLine.StartsWith ("%YAML")) {
82+
sr.Close ();
83+
return false;
84+
}
85+
}
86+
87+
using(var sw = new StreamWriter (tmpFile, false)){
88+
if (!string.IsNullOrEmpty (firstLine)) {
89+
sw.WriteLine (firstLine);
90+
}
91+
92+
while (sr.Peek () > -1) {
93+
var line = sr.ReadLine ();
94+
95+
if (line.Contains (ForumPackageSearchID)) {
96+
line = line.Replace (ForumPackageSearchID, CurrentPackageSearchID);
97+
modified = true;
98+
}
99+
100+
sw.WriteLine (line);
101+
}
102+
}
103+
}
104+
105+
if (modified) {
106+
File.Delete (path);
107+
File.Move (tmpFile, path);
108+
return true;
109+
} else {
110+
File.Delete (tmpFile);
111+
}
112+
} catch (IOException e) {
113+
Debug.LogError (string.Format ("Failed to replace GUID in file {0} (error={1})", path, e));
114+
}
115+
116+
return false;
117+
}
118+
}
119+
}

Assets/FbxExporters/Editor/FbxExporterRepairMissingScripts.cs.meta

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/FbxExporters/Editor/FbxPrefabAutoUpdater.cs.meta

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)