Skip to content

Commit 005e2a3

Browse files
authored
Merge pull request #62 from Unity-Technologies/UNI-19109-fbx-save-application-name-and-version
UNI-19109 save application name and version to file
2 parents b99fd7b + 35a52bb commit 005e2a3

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

Assets/FbxExporters/Editor/FbxExporter.cs

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public class ModelExporter : System.IDisposable
3030
const string Comments =
3131
@"";
3232

33+
const string ReadmeRelativePath = "FbxExporters/README.txt";
34+
3335
const string MenuItemName = "Assets/Export Model...";
3436

3537
const string FileBaseName = "Untitled";
@@ -80,6 +82,36 @@ public static ModelExporter Create ()
8082
/// </summary>
8183
const string UniqueNameFormat = "{0}_{1}";
8284

85+
private string GetVersionFromReadme()
86+
{
87+
if (string.IsNullOrEmpty (ReadmeRelativePath)) {
88+
Debug.LogWarning ("Missing relative path to README");
89+
return null;
90+
}
91+
string absPath = Path.Combine (Application.dataPath, ReadmeRelativePath);
92+
if (!File.Exists (absPath)) {
93+
Debug.LogWarning (string.Format("Could not find README.txt at: {0}", absPath));
94+
return null;
95+
}
96+
97+
try{
98+
var versionHeader = "**Version**:";
99+
var lines = File.ReadAllLines (absPath);
100+
foreach (var line in lines) {
101+
if (line.StartsWith(versionHeader)) {
102+
var version = line.Replace (versionHeader, "");
103+
return version.Trim ();
104+
}
105+
}
106+
}
107+
catch(IOException e){
108+
Debug.LogWarning (string.Format("Error will reading file {0} ({1})", absPath, e));
109+
return null;
110+
}
111+
Debug.LogWarning (string.Format("Could not find version number in README.txt at: {0}", absPath));
112+
return null;
113+
}
114+
83115
/// <summary>
84116
/// return layer for mesh
85117
/// </summary>
@@ -845,7 +877,7 @@ public int ExportAll (IEnumerable<UnityEngine.Object> unityExportSet)
845877
// fileFormat must be binary if we are embedding textures
846878
int fileFormat = EditorTools.ExportSettings.instance.embedTextures? -1 :
847879
fbxManager.GetIOPluginRegistry ().FindWriterIDByDescription ("FBX ascii (*.fbx)");
848-
880+
849881
bool status = fbxExporter.Initialize (LastFilePath, fileFormat, fbxManager.GetIOSettings ());
850882
// Check that initialization of the fbxExporter was successful
851883
if (!status)
@@ -868,6 +900,15 @@ public int ExportAll (IEnumerable<UnityEngine.Object> unityExportSet)
868900
fbxSceneInfo.mRevision = "1.0";
869901
fbxSceneInfo.mKeywords = Keywords;
870902
fbxSceneInfo.mComment = Comments;
903+
fbxSceneInfo.Original_ApplicationName.Set("Unity FbxExporter Plugin");
904+
// set last saved to be the same as original, as this is a new file.
905+
fbxSceneInfo.LastSaved_ApplicationName.Set(fbxSceneInfo.Original_ApplicationName.Get());
906+
907+
var version = GetVersionFromReadme();
908+
if(version != null){
909+
fbxSceneInfo.Original_ApplicationVersion.Set(version);
910+
fbxSceneInfo.LastSaved_ApplicationVersion.Set(fbxSceneInfo.Original_ApplicationVersion.Get());
911+
}
871912
fbxScene.SetSceneInfo (fbxSceneInfo);
872913

873914
// Set up the axes (Y up, Z forward, X to the right) and units (centimeters)
@@ -913,7 +954,6 @@ public int ExportAll (IEnumerable<UnityEngine.Object> unityExportSet)
913954
}
914955
}
915956
}
916-
917957
// Export the scene to the file.
918958
status = fbxExporter.Export (fbxScene);
919959

0 commit comments

Comments
 (0)