@@ -11,16 +11,15 @@ public static class PackageExporter
1111 [ MenuItem ( "Tools/Export Unitypackage" ) ]
1212 public static void Export ( )
1313 {
14- var version = Environment . GetEnvironmentVariable ( "UNITY_PACKAGE_VERSION" ) ;
15-
16- // configure
1714 var root = "Scripts/RandomFixtureKit" ;
18- var fileName = string . IsNullOrEmpty ( version ) ? "RandomFixtureKit.Unity.unitypackage" : $ "RandomFixtureKit.Unity.{ version } .unitypackage";
15+ var version = GetVersion ( root ) ;
16+
17+ var fileName = string . IsNullOrEmpty ( version ) ? "RandomFixtureKit.unitypackage" : $ "RandomFixtureKit.{ version } .unitypackage";
1918 var exportPath = "./" + fileName ;
2019
2120 var path = Path . Combine ( Application . dataPath , root ) ;
2221 var assets = Directory . EnumerateFiles ( path , "*" , SearchOption . AllDirectories )
23- . Where ( x => Path . GetExtension ( x ) == ".cs" || Path . GetExtension ( x ) == ".asmdef" || Path . GetExtension ( x ) == ".json" )
22+ . Where ( x => Path . GetExtension ( x ) == ".cs" || Path . GetExtension ( x ) == ".asmdef" || Path . GetExtension ( x ) == ".json" || Path . GetExtension ( x ) == ".meta" )
2423 . Select ( x => "Assets" + x . Replace ( Application . dataPath , "" ) . Replace ( @"\" , "/" ) )
2524 . ToArray ( ) ;
2625
@@ -33,6 +32,42 @@ public static void Export()
3332
3433 UnityEngine . Debug . Log ( "Export complete: " + Path . GetFullPath ( exportPath ) ) ;
3534 }
35+
36+ static string GetVersion ( string root )
37+ {
38+ var version = Environment . GetEnvironmentVariable ( "UNITY_PACKAGE_VERSION" ) ;
39+ var versionJson = Path . Combine ( Application . dataPath , root , "package.json" ) ;
40+
41+ if ( File . Exists ( versionJson ) )
42+ {
43+ var v = JsonUtility . FromJson < Version > ( File . ReadAllText ( versionJson ) ) ;
44+
45+ if ( ! string . IsNullOrEmpty ( version ) )
46+ {
47+ if ( v . version != version )
48+ {
49+ var msg = $ "package.json and env version are mismatched. UNITY_PACKAGE_VERSION:{ version } , package.json:{ v . version } ";
50+
51+ if ( Application . isBatchMode )
52+ {
53+ Console . WriteLine ( msg ) ;
54+ Application . Quit ( 1 ) ;
55+ }
56+
57+ throw new Exception ( "package.json and env version are mismatched." ) ;
58+ }
59+ }
60+
61+ version = v . version ;
62+ }
63+
64+ return version ;
65+ }
66+
67+ public class Version
68+ {
69+ public string version ;
70+ }
3671}
3772
3873#endif
0 commit comments