@@ -290,6 +290,8 @@ project.ext {
290290 pipExe = new File (pythonBinDir, " pip3" )
291291 // Python packages required by export_unity_package.py
292292 exportUnityPackageRequirements = [" absl-py" , " PyYAML" ]
293+ // Python packages required by gen_guids.py
294+ genGuidRequirements = [" absl-py" ]
293295}
294296
295297// Configure com.jetbrains.python.envs to bootstrap a Python install.
@@ -485,24 +487,31 @@ List<String> splitFilenameExtension(File fileObj) {
485487 * @param fileObj File to add version to.
486488 * @param fullVersionPrefix if true uses the "_version-" otherwise uses "_v-".
487489 * @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.
488492 *
489493 * @returns File which includes an encoded version.
490494 */
491495File versionedAssetFile (File fileObj , Boolean fullVersionPrefix ,
492- String postfix ) {
496+ String postfix , Boolean useVersionDir ) {
493497 String basename
494498 String extension
495499 (basename, extension) = splitFilenameExtension(fileObj)
496500 // Encode the DLL version and target names into the DLL in the form...
497501 // ${dllname}_version-${version}.dll
498502 String targetName = basename
499503 String version = project. ext. pluginVersion
504+ File dllDir = fileObj. parent != null ? new File (fileObj. parent) :
505+ new File ()
500506 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+ }
502512 }
503513 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)
506515}
507516
508517/*
@@ -636,7 +645,8 @@ File copyAssetMetadataFile(File sourceFile, File targetFile) {
636645 def guidMatch = (line =~ / ^(guid:)\s +(.*)/ )
637646 def versionLabelMatch = (line =~ versionRegEx)
638647 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 ) ) {
640650 // Update the metadata's GUID.
641651 // If a file is renamed we want to make sure Unity imports it as a new
642652 // asset with the new filename.
@@ -821,7 +831,7 @@ Task createBuildPluginDllTask(String componentName,
821831 return [
822832 unversionedFile. path,
823833 versionDll ?
824- versionedAssetFile(unversionedOutputFile, false , " " ) :
834+ versionedAssetFile(unversionedOutputFile, false , " " , true ) :
825835 unversionedOutputFile]
826836 }
827837
@@ -1320,6 +1330,30 @@ Task createExportUnityPackageTask(String taskName,
13201330 return exportUnityPackageTask
13211331}
13221332
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+
13231357Task testResolverLibTests = createNUnitTask(
13241358 " testResolverLibTests" ,
13251359 " Runs the tests for the deprecated Jar Resolver library" ,
@@ -1487,9 +1521,15 @@ task generatePluginManifest(dependsOn: [preparePluginStagingAreaDir,
14871521 project. ext. pluginEditorDllDir. path),
14881522 unversionedManifestName + project. ext. unityMetadataExtension)
14891523 File manifestFile = versionedAssetFile(
1490- new File (outputDir, unversionedManifestName), true , " _manifest" )
1524+ new File (outputDir, unversionedManifestName),
1525+ true ,
1526+ " _manifest" ,
1527+ false )
14911528 File manifestMetadataFile = versionedAssetFile(
1492- new File (outputDir, manifestMetadataTemplateFile. name), true , " _manifest" )
1529+ new File (outputDir, manifestMetadataTemplateFile. name),
1530+ true ,
1531+ " _manifest" ,
1532+ false )
14931533
14941534 description " Generate a manifest for the files in the plug-in."
14951535 inputs. files files(manifestMetadataTemplateFile)
@@ -1549,10 +1589,24 @@ buildPlugin.with {
15491589 outputs. files project. ext. pluginExportFile. absolutePath
15501590}
15511591
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+
15521606Task buildUpmPlugin = createExportUnityPackageTask(
15531607 " buildUpmPlugin" ,
1554- " Package the .unitypackage with export_unity_package.py." ,
1555- [generatePluginManifest],
1608+ " Package the .tgz with export_unity_package.py." ,
1609+ [generatePluginManifest, genGuidUpm ],
15561610 new File (project. ext. scriptDirectory, " export_unity_package_config.json" ),
15571611 new File (project. ext. scriptDirectory, " export_unity_package_guids.json" ),
15581612 new File (project. ext. pluginStagingAreaDir, " Assets" ),
0 commit comments