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.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using UnityBuilderAction.Input;
|
||||
using UnityBuilderAction.Reporting;
|
||||
using UnityBuilderAction.Versioning;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Build.Reporting;
|
||||
|
||||
#if USE_ADDRESSABLES
|
||||
using UnityEditor.AddressableAssets.Settings;
|
||||
#endif
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityBuilderAction
|
||||
{
|
||||
@ -48,11 +45,28 @@ namespace UnityBuilderAction
|
||||
if (buildPlayerOptions.target == BuildTarget.Android)
|
||||
AndroidSettings.Apply(options);
|
||||
|
||||
// Execute default AddressableAsset content build, if the package is installed
|
||||
#if USE_ADDRESSABLES
|
||||
AddressableAssetSettings.CleanPlayerContent();
|
||||
AddressableAssetSettings.BuildPlayerContent();
|
||||
#endif
|
||||
// Execute default AddressableAsset content build, if the package is installed.
|
||||
// Version defines would be the best solution here, but Unity 2018 doesn't support that,
|
||||
// so we fall back to using reflection instead.
|
||||
var addressableAssetSettingsType = Type.GetType(
|
||||
"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
|
||||
BuildReport buildReport = BuildPipeline.BuildPlayer(buildPlayerOptions);
|
||||
|
@ -1,8 +1,6 @@
|
||||
{
|
||||
"name": "UnityBuilderAction",
|
||||
"references": [
|
||||
"Unity.Addressables.Editor"
|
||||
],
|
||||
"references": [],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
@ -12,12 +10,6 @@
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [
|
||||
{
|
||||
"name": "com.unity.addressables",
|
||||
"expression": "1.0.0",
|
||||
"define": "USE_ADDRESSABLES"
|
||||
}
|
||||
],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
Loading…
Reference in New Issue
Block a user