mirror of
https://github.com/game-ci/unity-builder.git
synced 2025-07-04 12:25:19 -04:00
Fix build script for Unity 2018, by using reflection instead of version defines (#238)
This commit is contained in:
parent
4d0b6e6db1
commit
8419046c0f
@ -1,15 +1,12 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
using UnityBuilderAction.Input;
|
using UnityBuilderAction.Input;
|
||||||
using UnityBuilderAction.Reporting;
|
using UnityBuilderAction.Reporting;
|
||||||
using UnityBuilderAction.Versioning;
|
using UnityBuilderAction.Versioning;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using UnityEditor.Build.Reporting;
|
using UnityEditor.Build.Reporting;
|
||||||
|
using UnityEngine;
|
||||||
#if USE_ADDRESSABLES
|
|
||||||
using UnityEditor.AddressableAssets.Settings;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace UnityBuilderAction
|
namespace UnityBuilderAction
|
||||||
{
|
{
|
||||||
@ -48,11 +45,28 @@ namespace UnityBuilderAction
|
|||||||
if (buildPlayerOptions.target == BuildTarget.Android)
|
if (buildPlayerOptions.target == BuildTarget.Android)
|
||||||
AndroidSettings.Apply(options);
|
AndroidSettings.Apply(options);
|
||||||
|
|
||||||
// Execute default AddressableAsset content build, if the package is installed
|
// Execute default AddressableAsset content build, if the package is installed.
|
||||||
#if USE_ADDRESSABLES
|
// Version defines would be the best solution here, but Unity 2018 doesn't support that,
|
||||||
AddressableAssetSettings.CleanPlayerContent();
|
// so we fall back to using reflection instead.
|
||||||
AddressableAssetSettings.BuildPlayerContent();
|
var addressableAssetSettingsType = Type.GetType(
|
||||||
#endif
|
"UnityEditor.AddressableAssets.Settings.AddressableAssetSettings,Unity.Addressables.Editor");
|
||||||
|
if (addressableAssetSettingsType != null)
|
||||||
|
{
|
||||||
|
// ReSharper disable once PossibleNullReferenceException, used from try-catch
|
||||||
|
void CallAddressablesMethod(string methodName, object[] args) => addressableAssetSettingsType
|
||||||
|
.GetMethod(methodName, BindingFlags.Static | BindingFlags.Public)
|
||||||
|
.Invoke(null, args);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
CallAddressablesMethod("CleanPlayerContent", new object[] { null });
|
||||||
|
CallAddressablesMethod("BuildPlayerContent", Array.Empty<object>());
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Debug.LogError($"Failed to run default addressables build:\n{e}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Perform build
|
// Perform build
|
||||||
BuildReport buildReport = BuildPipeline.BuildPlayer(buildPlayerOptions);
|
BuildReport buildReport = BuildPipeline.BuildPlayer(buildPlayerOptions);
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "UnityBuilderAction",
|
"name": "UnityBuilderAction",
|
||||||
"references": [
|
"references": [],
|
||||||
"Unity.Addressables.Editor"
|
|
||||||
],
|
|
||||||
"includePlatforms": [
|
"includePlatforms": [
|
||||||
"Editor"
|
"Editor"
|
||||||
],
|
],
|
||||||
@ -12,12 +10,6 @@
|
|||||||
"precompiledReferences": [],
|
"precompiledReferences": [],
|
||||||
"autoReferenced": true,
|
"autoReferenced": true,
|
||||||
"defineConstraints": [],
|
"defineConstraints": [],
|
||||||
"versionDefines": [
|
"versionDefines": [],
|
||||||
{
|
|
||||||
"name": "com.unity.addressables",
|
|
||||||
"expression": "1.0.0",
|
|
||||||
"define": "USE_ADDRESSABLES"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"noEngineReferences": false
|
"noEngineReferences": false
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user