7502018d20
There is an asset in the store I grabbed. the coding is WAY above my head, I got about half of it and integrated and adapted what I can to it. im going as far as I can with it and ill come back in a few month when I understand t better.
77 lines
2.9 KiB
C#
77 lines
2.9 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
namespace UnityEditor.AddressableAssets.Build
|
|
{
|
|
/// <summary>
|
|
/// Entry point to set callbacks for builds.
|
|
/// </summary>
|
|
public static class BuildScript
|
|
{
|
|
/// <summary>
|
|
/// Global delegate for handling the result of AddressableAssets builds. This will get called for player builds and when entering play mode.
|
|
/// </summary>
|
|
public static Action<AddressableAssetBuildResult> buildCompleted;
|
|
}
|
|
|
|
static class AddressablesBuildScriptHooks
|
|
{
|
|
[InitializeOnLoadMethod]
|
|
static void Init()
|
|
{
|
|
EditorApplication.playModeStateChanged += OnEditorPlayModeChanged;
|
|
}
|
|
|
|
static void OnEditorPlayModeChanged(PlayModeStateChange state)
|
|
{
|
|
var settings = AddressableAssetSettingsDefaultObject.Settings;
|
|
if (settings == null)
|
|
return;
|
|
if (state == PlayModeStateChange.ExitingEditMode)
|
|
{
|
|
if (settings.ActivePlayModeDataBuilder == null)
|
|
{
|
|
var err = "Active play mode build script is null.";
|
|
Debug.LogError(err);
|
|
|
|
if (BuildScript.buildCompleted != null)
|
|
{
|
|
var result = AddressableAssetBuildResult.CreateResult<AddressableAssetBuildResult>(null, 0, err);
|
|
BuildScript.buildCompleted(result);
|
|
}
|
|
return;
|
|
}
|
|
|
|
if (!settings.ActivePlayModeDataBuilder.CanBuildData<AddressablesPlayModeBuildResult>())
|
|
{
|
|
var err = string.Format("Active build script {0} cannot build AddressablesPlayModeBuildResult.", settings.ActivePlayModeDataBuilder);
|
|
Debug.LogError(err);
|
|
if (BuildScript.buildCompleted != null)
|
|
{
|
|
var result = AddressableAssetBuildResult.CreateResult<AddressableAssetBuildResult>(null, 0, err);
|
|
BuildScript.buildCompleted(result);
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
var res = settings.ActivePlayModeDataBuilder.BuildData<AddressablesPlayModeBuildResult>(new AddressablesDataBuilderInput(settings));
|
|
if (!string.IsNullOrEmpty(res.Error))
|
|
{
|
|
Debug.LogError(res.Error);
|
|
EditorApplication.isPlaying = false;
|
|
}
|
|
else
|
|
{
|
|
if (BuildScript.buildCompleted != null)
|
|
BuildScript.buildCompleted(res);
|
|
settings.DataBuilderCompleted(settings.ActivePlayModeDataBuilder, res);
|
|
settings.HostingServicesManager.exitingEditMode = true;
|
|
}
|
|
}
|
|
else
|
|
settings.HostingServicesManager.exitingEditMode = false;
|
|
}
|
|
}
|
|
}
|