6
6
using System . Text ;
7
7
using System . Text . RegularExpressions ;
8
8
using Ink . UnityIntegration ;
9
+ using UnityEditor . Compilation ;
9
10
using UnityEngine . Networking ;
10
11
11
12
// 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 () {
103
104
// AssetDatabase.DisallowAutoRefresh();
104
105
// #endif
105
106
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
+
108
120
var integrationDirs = Directory . GetDirectories ( IntegrationPath ) ;
109
121
foreach ( var dir in integrationDirs ) {
110
122
var dirName = Path . GetFileName ( dir ) ;
111
123
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 ) ) ) ) ;
113
125
}
114
126
115
127
// 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!
122
134
AssetDatabase . Refresh ( ) ;
123
- // We can use this callback to achieve this.
124
- // CompilationPipeline.compilationFinished += (object sender) => {
125
- // CompilationPipeline.RequestScriptCompilation();
126
- // }
127
135
128
136
// Create a .unitypackage
129
137
var version = InkLibrary . unityIntegrationVersionCurrent ;
130
138
var packageExportPath = string . Format ( "../Ink Unity Integration {0}.{1}.{2}.unitypackage" , version . Major , version . Minor , version . Build ) ;
131
139
AssetDatabase . ExportPackage ( "Assets/Ink" , packageExportPath , ExportPackageOptions . Recurse ) ;
132
140
133
141
// 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 ) ;
137
146
138
147
EditorApplication . UnlockReloadAssemblies ( ) ;
139
-
148
+ AssetDatabase . Refresh ( ) ;
149
+ CompilationPipeline . RequestScriptCompilation ( ) ;
140
150
Debug . Log ( "PublishingTools.CreatePackage: Created .unitypackage at " + Path . GetFullPath ( Path . Combine ( Application . dataPath , packageExportPath ) ) ) ;
141
151
}
142
152
@@ -158,8 +168,9 @@ void OnGUI () {
158
168
EditorGUILayout . BeginVertical ( ) ;
159
169
EditorGUILayout . LabelField ( "Version " + InkLibrary . unityIntegrationVersionCurrent , EditorStyles . centeredGreyMiniLabel ) ;
160
170
161
- // Editor
162
- //
171
+ if ( GUILayout . Button ( "Unlock" ) ) {
172
+ EditorApplication . UnlockReloadAssemblies ( ) ;
173
+ }
163
174
if ( GUILayout . Button ( "Prepare for publishing (run all tasks)" ) ) {
164
175
PreparePublish ( ) ;
165
176
}
0 commit comments