@@ -30,6 +30,8 @@ public class ModelExporter : System.IDisposable
30
30
const string Comments =
31
31
@"" ;
32
32
33
+ const string ReadmeRelativePath = "FbxExporters/README.txt" ;
34
+
33
35
const string MenuItemName = "Assets/Export Model..." ;
34
36
35
37
const string FileBaseName = "Untitled" ;
@@ -80,6 +82,36 @@ public static ModelExporter Create ()
80
82
/// </summary>
81
83
const string UniqueNameFormat = "{0}_{1}" ;
82
84
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
+
83
115
/// <summary>
84
116
/// return layer for mesh
85
117
/// </summary>
@@ -845,7 +877,7 @@ public int ExportAll (IEnumerable<UnityEngine.Object> unityExportSet)
845
877
// fileFormat must be binary if we are embedding textures
846
878
int fileFormat = EditorTools . ExportSettings . instance . embedTextures ? - 1 :
847
879
fbxManager . GetIOPluginRegistry ( ) . FindWriterIDByDescription ( "FBX ascii (*.fbx)" ) ;
848
-
880
+
849
881
bool status = fbxExporter . Initialize ( LastFilePath , fileFormat , fbxManager . GetIOSettings ( ) ) ;
850
882
// Check that initialization of the fbxExporter was successful
851
883
if ( ! status )
@@ -868,6 +900,15 @@ public int ExportAll (IEnumerable<UnityEngine.Object> unityExportSet)
868
900
fbxSceneInfo . mRevision = "1.0" ;
869
901
fbxSceneInfo . mKeywords = Keywords ;
870
902
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
+ }
871
912
fbxScene . SetSceneInfo ( fbxSceneInfo ) ;
872
913
873
914
// 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)
913
954
}
914
955
}
915
956
}
916
-
917
957
// Export the scene to the file.
918
958
status = fbxExporter . Export ( fbxScene ) ;
919
959
0 commit comments