CR changes

This commit is contained in:
unknown 2018-12-27 12:56:44 -08:00
parent 65cc683f80
commit 87026a85f1
2 changed files with 22 additions and 35 deletions

View file

@ -190,28 +190,22 @@ class AvatarExporter : MonoBehaviour {
try { try {
string[] lines = File.ReadAllLines(exportFstPath); string[] lines = File.ReadAllLines(exportFstPath);
foreach (string line in lines) { foreach (string line in lines) {
if (line.StartsWith("name")) { int separatorIndex = line.IndexOf("=");
projectName = line.Substring(line.IndexOf("=") + 2); if (separatorIndex >= 0) {
string key = line.Substring(0, separatorIndex).Trim();
if (key == "name") {
projectName = line.Substring(separatorIndex + 1).Trim();
break; break;
} }
} }
}
} catch { } catch {
EditorUtility.DisplayDialog("Error", "Failed to read from existing file " + exportFstPath + EditorUtility.DisplayDialog("Error", "Failed to read from existing file " + exportFstPath +
". Please check the file and try again.", "Ok"); ". Please check the file and try again.", "Ok");
return; return;
} }
// delete existing fst file since we will write a new file string exportModelPath = Path.GetDirectoryName(exportFstPath) + "\\" + assetName + ".fbx";
// TODO: updating fst should only rewrite joint mappings and joint rotation offsets to existing file
try {
File.Delete(exportFstPath);
} catch {
EditorUtility.DisplayDialog("Error", "Failed to overwrite existing file " + exportFstPath +
". Please check the file and try again.", "Ok");
return;
}
string exportModelPath = Path.GetDirectoryName(exportFstPath) + "/" + assetName + ".fbx";
if (File.Exists(exportModelPath)) { if (File.Exists(exportModelPath)) {
// if the fbx in Unity Assets is newer than the fbx in the target export // if the fbx in Unity Assets is newer than the fbx in the target export
// folder or vice-versa then ask to replace the older fbx with the newer fbx // folder or vice-versa then ask to replace the older fbx with the newer fbx
@ -234,13 +228,8 @@ class AvatarExporter : MonoBehaviour {
if (option == 2) { // Cancel if (option == 2) { // Cancel
return; return;
} else if (option == 0) { // Yes - copy model to Unity project } else if (option == 0) { // Yes - copy model to Unity project
// delete existing fbx and associated meta file in Unity Assets // copy the fbx from the project folder to Unity Assets, overwriting the existing fbx, and re-import it
File.Delete(assetPath); File.Copy(exportModelPath, assetPath, true);
File.Delete(assetPath + ".meta");
AssetDatabase.Refresh();
// copy the fbx from the project folder to Unity Assets and import it
File.Copy(exportModelPath, assetPath);
AssetDatabase.ImportAsset(assetPath); AssetDatabase.ImportAsset(assetPath);
// set model to Humanoid animation type and force another refresh on it to process Humanoid // set model to Humanoid animation type and force another refresh on it to process Humanoid
@ -265,19 +254,10 @@ class AvatarExporter : MonoBehaviour {
copyModelToExport = option == 0; // Yes copyModelToExport = option == 0; // Yes
} }
// delete any existing fbx if we agreed to overwrite it, and copy asset fbx over // copy asset fbx over deleting any existing fbx if we agreed to overwrite it
if (copyModelToExport) { if (copyModelToExport) {
if (File.Exists(exportModelPath)) {
try { try {
File.Delete(exportModelPath); File.Copy(assetPath, exportModelPath, true);
} catch {
EditorUtility.DisplayDialog("Error", "Failed to overwrite existing file " + exportModelPath +
". Please check the file and try again.", "Ok");
return;
}
}
try {
File.Copy(assetPath, exportModelPath);
} catch { } catch {
EditorUtility.DisplayDialog("Error", "Failed to copy existing file " + assetPath + " to " + exportModelPath + EditorUtility.DisplayDialog("Error", "Failed to copy existing file " + assetPath + " to " + exportModelPath +
". Please check the location and try again.", "Ok"); ". Please check the location and try again.", "Ok");
@ -285,6 +265,16 @@ class AvatarExporter : MonoBehaviour {
} }
} }
// delete existing fst file since we will write a new file
// TODO: updating fst should only rewrite joint mappings and joint rotation offsets to existing file
try {
File.Delete(exportFstPath);
} catch {
EditorUtility.DisplayDialog("Error", "Failed to overwrite existing file " + exportFstPath +
". Please check the file and try again.", "Ok");
return;
}
// write out a new fst file in place of the old file // write out a new fst file in place of the old file
WriteFST(exportFstPath, projectName); WriteFST(exportFstPath, projectName);
} else { // Export New Avatar menu option } else { // Export New Avatar menu option
@ -326,9 +316,6 @@ class AvatarExporter : MonoBehaviour {
// instantiate a game object of the user avatar to save out bone parents then destroy it // instantiate a game object of the user avatar to save out bone parents then destroy it
UnityEngine.Object avatarResource = AssetDatabase.LoadAssetAtPath(assetPath, typeof(UnityEngine.Object)); UnityEngine.Object avatarResource = AssetDatabase.LoadAssetAtPath(assetPath, typeof(UnityEngine.Object));
if (!avatarResource) {
return false;
}
GameObject assetGameObject = (GameObject)Instantiate(avatarResource); GameObject assetGameObject = (GameObject)Instantiate(avatarResource);
SetParentNames(assetGameObject.transform, userParentNames); SetParentNames(assetGameObject.transform, userParentNames);
DestroyImmediate(assetGameObject); DestroyImmediate(assetGameObject);