66using System . Text ;
77using System . Text . RegularExpressions ;
88using Ink . UnityIntegration ;
9+ using UnityEditor . Compilation ;
910using UnityEngine . Networking ;
1011
1112// Should be run to update files in the package folder from the root of the repo, and to create demo and release packages.
@@ -103,40 +104,49 @@ public static void CreatePackage () {
103104 // AssetDatabase.DisallowAutoRefresh();
104105 // #endif
105106 var assetsInkPath = Path . Combine ( Application . dataPath , "Ink" ) ;
106- List < KeyValuePair < DirectoryInfo , DirectoryInfo > > rootPaths = new List < KeyValuePair < DirectoryInfo , DirectoryInfo > > ( ) ;
107- // Copy the plugin into assets, make a package
107+ var copiedFiles = new List < ( string packagesFile , string assetsFile ) > ( ) ;
108+ var copiedDirectories = new List < ( DirectoryInfo packagesDirectory , DirectoryInfo assetsDirectory ) > ( ) ;
109+
110+ // Work out which files need to be copied into Assets for the Package
111+ var files = Directory . GetFiles ( IntegrationPath ) ;
112+ foreach ( var filePath in files ) {
113+ var fileExtension = Path . GetExtension ( filePath ) ;
114+ if ( fileExtension == ".meta" || fileExtension == ".DS_Store" ) continue ;
115+ var fileName = Path . GetFileName ( filePath ) ;
116+ if ( fileName == "package.json" ) continue ;
117+ copiedFiles . Add ( ( filePath , Path . Combine ( assetsInkPath , fileName ) ) ) ;
118+ }
119+
108120 var integrationDirs = Directory . GetDirectories ( IntegrationPath ) ;
109121 foreach ( var dir in integrationDirs ) {
110122 var dirName = Path . GetFileName ( dir ) ;
111123 if ( dirName == "Demos" ) continue ;
112- rootPaths . Add ( new KeyValuePair < DirectoryInfo , DirectoryInfo > ( new DirectoryInfo ( dir ) , new DirectoryInfo ( Path . Combine ( assetsInkPath , dirName ) ) ) ) ;
124+ copiedDirectories . Add ( ( new DirectoryInfo ( dir ) , new DirectoryInfo ( Path . Combine ( assetsInkPath , dirName ) ) ) ) ;
113125 }
114126
115127 // Move files from Packages into Assets
116- foreach ( var rootPath in rootPaths ) {
117- MoveFilesRecursively ( rootPath . Key , rootPath . Value ) ;
118- }
119- // TODO - when we switch to 2019.4, get this working!
120- // This refresh causes errors until you alt-tab and back because it forces a script recompile but the files are moved back before it's done.
121- // To fix it, we can block recompilation (I dont think you can do this, or even if it'd work) or need to wait until compilation is done before copying the files back.
128+ foreach ( var rootPath in copiedFiles )
129+ new FileInfo ( rootPath . packagesFile ) . MoveTo ( rootPath . assetsFile ) ;
130+ foreach ( var rootPath in copiedDirectories )
131+ MoveFilesRecursively ( rootPath . packagesDirectory , rootPath . assetsDirectory ) ;
132+
133+ // I believe this creates meta files but I can't recall!
122134 AssetDatabase . Refresh ( ) ;
123- // We can use this callback to achieve this.
124- // CompilationPipeline.compilationFinished += (object sender) => {
125- // CompilationPipeline.RequestScriptCompilation();
126- // }
127135
128136 // Create a .unitypackage
129137 var version = InkLibrary . unityIntegrationVersionCurrent ;
130138 var packageExportPath = string . Format ( "../Ink Unity Integration {0}.{1}.{2}.unitypackage" , version . Major , version . Minor , version . Build ) ;
131139 AssetDatabase . ExportPackage ( "Assets/Ink" , packageExportPath , ExportPackageOptions . Recurse ) ;
132140
133141 // Move files back to Packages
134- foreach ( var rootPath in rootPaths ) {
135- MoveFilesRecursively ( rootPath . Value , rootPath . Key ) ;
136- }
142+ foreach ( var rootPath in copiedFiles )
143+ new FileInfo ( rootPath . assetsFile ) . MoveTo ( rootPath . packagesFile ) ;
144+ foreach ( var rootPath in copiedDirectories )
145+ MoveFilesRecursively ( rootPath . assetsDirectory , rootPath . packagesDirectory ) ;
137146
138147 EditorApplication . UnlockReloadAssemblies ( ) ;
139-
148+ AssetDatabase . Refresh ( ) ;
149+ CompilationPipeline . RequestScriptCompilation ( ) ;
140150 Debug . Log ( "PublishingTools.CreatePackage: Created .unitypackage at " + Path . GetFullPath ( Path . Combine ( Application . dataPath , packageExportPath ) ) ) ;
141151 }
142152
@@ -158,8 +168,9 @@ void OnGUI () {
158168 EditorGUILayout . BeginVertical ( ) ;
159169 EditorGUILayout . LabelField ( "Version " + InkLibrary . unityIntegrationVersionCurrent , EditorStyles . centeredGreyMiniLabel ) ;
160170
161- // Editor
162- //
171+ if ( GUILayout . Button ( "Unlock" ) ) {
172+ EditorApplication . UnlockReloadAssemblies ( ) ;
173+ }
163174 if ( GUILayout . Button ( "Prepare for publishing (run all tasks)" ) ) {
164175 PreparePublish ( ) ;
165176 }
0 commit comments