@@ -290,6 +290,8 @@ project.ext {
290
290
pipExe = new File (pythonBinDir, " pip3" )
291
291
// Python packages required by export_unity_package.py
292
292
exportUnityPackageRequirements = [" absl-py" , " PyYAML" ]
293
+ // Python packages required by gen_guids.py
294
+ genGuidRequirements = [" absl-py" ]
293
295
}
294
296
295
297
// Configure com.jetbrains.python.envs to bootstrap a Python install.
@@ -485,24 +487,31 @@ List<String> splitFilenameExtension(File fileObj) {
485
487
* @param fileObj File to add version to.
486
488
* @param fullVersionPrefix if true uses the "_version-" otherwise uses "_v-".
487
489
* @param postfix Optional string to add before the extensioon.
490
+ * @param useVersionDir If true, place the file to be under a folder named after
491
+ * the version number, instead of changing the filename.
488
492
*
489
493
* @returns File which includes an encoded version.
490
494
*/
491
495
File versionedAssetFile (File fileObj , Boolean fullVersionPrefix ,
492
- String postfix ) {
496
+ String postfix , Boolean useVersionDir ) {
493
497
String basename
494
498
String extension
495
499
(basename, extension) = splitFilenameExtension(fileObj)
496
500
// Encode the DLL version and target names into the DLL in the form...
497
501
// ${dllname}_version-${version}.dll
498
502
String targetName = basename
499
503
String version = project. ext. pluginVersion
504
+ File dllDir = fileObj. parent != null ? new File (fileObj. parent) :
505
+ new File ()
500
506
if (! (version == null || version. isEmpty())) {
501
- targetName + = (fullVersionPrefix ? " _version-" : " _v" ) + version
507
+ if (useVersionDir) {
508
+ dllDir = new File (dllDir, version)
509
+ } else {
510
+ targetName + = (fullVersionPrefix ? " _version-" : " _v" ) + version
511
+ }
502
512
}
503
513
String filename = targetName + postfix + extension
504
- return fileObj. parent != null ? new File (fileObj. parent, filename) :
505
- new File (filename)
514
+ return new File (dllDir, filename)
506
515
}
507
516
508
517
/*
@@ -636,7 +645,8 @@ File copyAssetMetadataFile(File sourceFile, File targetFile) {
636
645
def guidMatch = (line =~ / ^(guid:)\s +(.*)/ )
637
646
def versionLabelMatch = (line =~ versionRegEx)
638
647
def exportPathMatch = (line =~ exportPathRegEx)
639
- if (guidMatch. matches() && sourceFile. name != targetFile. name) {
648
+ if (guidMatch. matches() && (sourceFile. name != targetFile. name ||
649
+ sourceFile. parent != targetFile. parent ) ) {
640
650
// Update the metadata's GUID.
641
651
// If a file is renamed we want to make sure Unity imports it as a new
642
652
// asset with the new filename.
@@ -821,7 +831,7 @@ Task createBuildPluginDllTask(String componentName,
821
831
return [
822
832
unversionedFile. path,
823
833
versionDll ?
824
- versionedAssetFile(unversionedOutputFile, false , " " ) :
834
+ versionedAssetFile(unversionedOutputFile, false , " " , true ) :
825
835
unversionedOutputFile]
826
836
}
827
837
@@ -1320,6 +1330,30 @@ Task createExportUnityPackageTask(String taskName,
1320
1330
return exportUnityPackageTask
1321
1331
}
1322
1332
1333
+ Task createGenGuidTask (String taskName ,
1334
+ String description ,
1335
+ File guidsFile ,
1336
+ String pluginVersion ,
1337
+ Iterable<String > guidPath ) {
1338
+ File genGuidScript = new File (project. ext. exportUnityPackageDir,
1339
+ " gen_guids.py" )
1340
+ Task genGuidTask = createPythonTask(
1341
+ taskName,
1342
+ description,
1343
+ [],
1344
+ genGuidScript,
1345
+ [" --version" , pluginVersion,
1346
+ " --guids_file" , guidsFile] +
1347
+ guidPath,
1348
+ genGuidRequirements)
1349
+ genGuidTask. with {
1350
+ inputs. files ([guidsFile] +
1351
+ [genGuidScript])
1352
+ }
1353
+ return genGuidTask
1354
+ }
1355
+
1356
+
1323
1357
Task testResolverLibTests = createNUnitTask(
1324
1358
" testResolverLibTests" ,
1325
1359
" Runs the tests for the deprecated Jar Resolver library" ,
@@ -1487,9 +1521,15 @@ task generatePluginManifest(dependsOn: [preparePluginStagingAreaDir,
1487
1521
project. ext. pluginEditorDllDir. path),
1488
1522
unversionedManifestName + project. ext. unityMetadataExtension)
1489
1523
File manifestFile = versionedAssetFile(
1490
- new File (outputDir, unversionedManifestName), true , " _manifest" )
1524
+ new File (outputDir, unversionedManifestName),
1525
+ true ,
1526
+ " _manifest" ,
1527
+ false )
1491
1528
File manifestMetadataFile = versionedAssetFile(
1492
- new File (outputDir, manifestMetadataTemplateFile. name), true , " _manifest" )
1529
+ new File (outputDir, manifestMetadataTemplateFile. name),
1530
+ true ,
1531
+ " _manifest" ,
1532
+ false )
1493
1533
1494
1534
description " Generate a manifest for the files in the plug-in."
1495
1535
inputs. files files(manifestMetadataTemplateFile)
@@ -1549,10 +1589,24 @@ buildPlugin.with {
1549
1589
outputs. files project. ext. pluginExportFile. absolutePath
1550
1590
}
1551
1591
1592
+ // Guid paths for UPM package.
1593
+ File upmPluginPackageDir = new File (" com.google.external-dependency-manager" ,
1594
+ " ExternalDependencyManager" )
1595
+ File upmPluginEditorDir = new File (upmPluginPackageDir, " Editor" )
1596
+ File upmPluginDllDir = new File (upmPluginEditorDir, project. ext. pluginVersion)
1597
+
1598
+ Task genGuidUpm = createGenGuidTask(
1599
+ " genGuidUpm" ,
1600
+ " Generate GUID for .tgz packaging." ,
1601
+ new File (project. ext. scriptDirectory, " export_unity_package_guids.json" ),
1602
+ project. ext. pluginVersion,
1603
+ [upmPluginDllDir. path]
1604
+ )
1605
+
1552
1606
Task buildUpmPlugin = createExportUnityPackageTask(
1553
1607
" buildUpmPlugin" ,
1554
- " Package the .unitypackage with export_unity_package.py." ,
1555
- [generatePluginManifest],
1608
+ " Package the .tgz with export_unity_package.py." ,
1609
+ [generatePluginManifest, genGuidUpm ],
1556
1610
new File (project. ext. scriptDirectory, " export_unity_package_config.json" ),
1557
1611
new File (project. ext. scriptDirectory, " export_unity_package_guids.json" ),
1558
1612
new File (project. ext. pluginStagingAreaDir, " Assets" ),
0 commit comments