-
Notifications
You must be signed in to change notification settings - Fork 12
/
Builder.cs
87 lines (77 loc) · 2.65 KB
/
Builder.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using System;
using System.Collections.Generic;
using System.IO;
using Nordeus.Build.Reporters;
using UnityEditor;
using UnityEngine;
using System.Collections;
namespace Nordeus.Build
{
public static class Builder
{
/// <summary>
/// Builds an APK at the specified path with the specified texture compression.
/// </summary>
/// <param name="buildPath">Path for the output APK.</param>
/// <param name="textureCompression">If not null, will override the texture compression subtarget.</param>
public static void BuildAndroid(string buildPath, MobileTextureSubtarget? textureCompression = null)
{
if (textureCompression != null)
{
EditorUserBuildSettings.androidBuildSubtarget = textureCompression.Value;
}
string buildMessage = BuildPipeline.BuildPlayer(GetEnabledScenePaths().ToArray(), buildPath, BuildTarget.Android, BuildOptions.None);
if (string.IsNullOrEmpty(buildMessage)) BuildReporter.Current.IndicateSuccessfulBuild();
else
{
BuildReporter.Current.Log(buildMessage, BuildReporter.MessageSeverity.Error);
}
}
/// <summary>
/// Builds an XCode project at the specified path.
/// </summary>
/// <param name="buildPath">Path for the XCode project.</param>
public static void BuildIos(string buildPath)
{
string buildMessage = BuildPipeline.BuildPlayer(GetEnabledScenePaths().ToArray(), buildPath, BuildTarget.iOS, BuildOptions.None);
if (string.IsNullOrEmpty(buildMessage)) BuildReporter.Current.IndicateSuccessfulBuild();
else
{
BuildReporter.Current.Log(buildMessage, BuildReporter.MessageSeverity.Error);
}
}
/// <summary>
/// Returns a list of all the enabled scenes.
/// </summary>
private static List<string> GetEnabledScenePaths()
{
List<string> scenePaths = new List<string>();
foreach (var scene in EditorBuildSettings.scenes)
{
scenePaths.Add(scene.path);
}
return scenePaths;
}
/// <summary>
/// Builds the specified build target.
/// </summary>
/// <param name="parsedBuildTarget">Build target to build.</param>
/// <param name="buildPath">Output path for the build.</param>
/// <param name="parsedTextureSubtarget">Texture compression subtarget for Android.</param>
public static void Build(BuildTarget parsedBuildTarget, string buildPath, MobileTextureSubtarget? parsedTextureSubtarget = null)
{
Directory.CreateDirectory(buildPath);
switch (parsedBuildTarget)
{
case BuildTarget.Android:
BuildAndroid(buildPath, parsedTextureSubtarget);
break;
case BuildTarget.iOS:
BuildIos(buildPath);
break;
default:
throw new ArgumentException(parsedBuildTarget + " is not a supported build target.");
}
}
}
}