-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathPopCommandLineBuild.cs
More file actions
73 lines (61 loc) · 2 KB
/
PopCommandLineBuild.cs
File metadata and controls
73 lines (61 loc) · 2 KB
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
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Linq;
using System;
/*
* gr: this is being deprecated, for "PopBuild" a more complete build solution, but keeping this here temporarily until all funcitonality is replaced.
* so PopBuild has been renamed to PopCommandLineBuild
*/
public class PopCommandLineBuild : MonoBehaviour {
private static string BuildPathArg = "-BuildPath=";
//private static string PathSuffixIos = "/";
private static string PathSuffixIos = null;
private static string PathSuffixAndroid = ".apk";
private static string[] GetLevels()
{
return (from scene in EditorBuildSettings.scenes where scene.enabled select scene.path).ToArray();
}
public static string GetCommandLineBuildPath(string RequiredSuffix)
{
string[] Args = Environment.GetCommandLineArgs ();
try
{
string BuildPath = Args.Where( Element => Element.StartsWith(BuildPathArg)).Single();
// strip predicate
BuildPath = BuildPath.Replace(BuildPathArg, "");
BuildPath = BuildPath.Replace("\"", "" );
BuildPath = BuildPath.Trim();
Debug.Log("Build path found as: " + BuildPath );
if ( RequiredSuffix != null )
if ( !BuildPath.EndsWith(RequiredSuffix) )
return null;
return BuildPath;
}
catch(System.Exception e)
{
Debug.Log("failed to get BuildPath arg: " + e.Message );
return null;
}
}
public static void Build(BuildTarget Target,string RequiredBuildPathSuffix)
{
string Path = GetCommandLineBuildPath (RequiredBuildPathSuffix);
if ( Path==null )
{
string Error = "No path (ending in "+RequiredBuildPathSuffix+") supplied on commandline. use " + BuildPathArg + "\"yourpath/filename" + RequiredBuildPathSuffix + "\"";
throw new UnityException(Error);
}
BuildPipeline.BuildPlayer (GetLevels(), Path, Target, BuildOptions.None);
}
public static void BuildAndroid()
{
Build (BuildTarget.Android, PathSuffixAndroid);
}
public static void BuildIos()
{
Build (BuildTarget.iOS, PathSuffixIos);
}
}
#endif//UNITY_EDITOR