You've already forked Commercialization.topon
79 lines
1.8 KiB
C#
79 lines
1.8 KiB
C#
#if UNITY_EDITOR
|
|
using System;
|
|
using System.IO;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
|
|
[InitializeOnLoad]
|
|
public static class IAABatchBuildBootstrap
|
|
{
|
|
private const string TaskFilePath = "Temp/iaa-batch-task.txt";
|
|
private static bool _subscribed;
|
|
private static bool _taskRunning;
|
|
|
|
static IAABatchBuildBootstrap()
|
|
{
|
|
if (!Application.isBatchMode)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (_subscribed)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_subscribed = true;
|
|
EditorApplication.update += ExecutePendingTaskWhenReady;
|
|
}
|
|
|
|
private static void ExecutePendingTaskWhenReady()
|
|
{
|
|
if (!Application.isBatchMode || _taskRunning)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var fullPath = Path.GetFullPath(TaskFilePath);
|
|
if (!File.Exists(fullPath))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (EditorApplication.isCompiling || EditorApplication.isUpdating)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_taskRunning = true;
|
|
EditorApplication.update -= ExecutePendingTaskWhenReady;
|
|
|
|
var task = File.ReadAllText(fullPath).Trim();
|
|
File.Delete(fullPath);
|
|
|
|
try
|
|
{
|
|
switch (task)
|
|
{
|
|
case "create-sample":
|
|
IAAAdDebugSampleCreator.CreateOrUpdateSample();
|
|
break;
|
|
case "build-apk":
|
|
IAAAdAndroidBuild.BuildAndroidTestApk();
|
|
break;
|
|
default:
|
|
Debug.LogWarning($"[IAA Batch] Unknown task: {task}");
|
|
break;
|
|
}
|
|
|
|
EditorApplication.Exit(0);
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
Debug.LogException(exception);
|
|
EditorApplication.Exit(1);
|
|
}
|
|
}
|
|
}
|
|
#endif
|