-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathBuildScript.cs
More file actions
126 lines (100 loc) · 4.67 KB
/
BuildScript.cs
File metadata and controls
126 lines (100 loc) · 4.67 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Linq;
// Sources:
// http://jonathanpeppers.com/Blog/automating-unity3d-builds-with-fake
// http://www.thegameengineer.com/blog/2013/07/23/unity-3-building-the-project/
// http://ralphbarbagallo.com/2015/05/26/how-to-support-gear-vr-and-google-cardboard-in-one-unity3d-project/
public class BuildScript : MonoBehaviour {
// Generated file info
private static string companyName = "MyCompany";
private static string productName = "TestScene";
private static string bundleIdentifier = String.Format("com.{0}.{1}", companyName, productName);
private static string outputFolder = "bin/";
private static string outputFilenameAndroidCardboard = outputFolder + productName + "Cardboard.apk";
private static string outputFilenameAndroidGearVR = outputFolder + productName + "GearVR.apk";
// Folders that contains the manifest, GearVR keys, ...
// Copy the content of imported files from the Cardboard and GearVR SDK in this news folders (manifest, phone keys, ...)
private static string androidFolderDestination = Application.dataPath + "/Plugins/Android/";
private static string androidFolderCardboard = Application.dataPath + "/Platforms/.AndroidCardboard/"; //Unity must ignore it (plugin conflits)
private static string androidFolderGearVR = Application.dataPath + "/Platforms/AndroidGearVR/";
// Keystore path, username and password (set it in Player Settings or here if you want to give in raw text)
//private static string keystorePath;
//private static string username;
//private static string password;
// If you release multiple time on store in one day increment this (Version number as: YYYYMMDDB)
private static int buildNumber = 0;
[MenuItem("Build/Cardboard")]
public static void BuildCardboard()
{
Init ();
SwapAndroidPluginFolder (androidFolderCardboard);
PlayerSettings.virtualRealitySupported = false;
PlayerSettings.SetScriptingDefineSymbolsForGroup (BuildTargetGroup.Android, "");
Build(BuildTarget.Android, outputFilenameAndroidCardboard);
}
[MenuItem("Build/GearVR")]
public static void BuildGearVR()
{
Init ();
SwapAndroidPluginFolder (androidFolderGearVR);
PlayerSettings.virtualRealitySupported = true;
PlayerSettings.SetScriptingDefineSymbolsForGroup (BuildTargetGroup.Android, "NATIVE_VR_SUPPORTED"); // Add a precompilation sympol to disable the cardboard SDK
Build(BuildTarget.Android, outputFilenameAndroidGearVR);
}
private static void Init()
{
var now = DateTime.Now;
var versionNumber = now.Year.ToString("D4") + now.Month.ToString("D2") + now.Day.ToString("D2") + buildNumber.ToString("D2"); //Version number: YYYYMMDDB
PlayerSettings.companyName = companyName;
PlayerSettings.productName = productName;
PlayerSettings.bundleIdentifier = bundleIdentifier;
PlayerSettings.bundleVersion = versionNumber;
PlayerSettings.Android.bundleVersionCode = int.Parse(versionNumber);
//PlayerSettings.Android.keystoreName = keystorePath;
//PlayerSettings.Android.keyaliasName = username;
//PlayerSettings.Android.keyaliasPass = password;
}
static void SwapAndroidPluginFolder(string folderSource) {
if (Directory.Exists (androidFolderDestination))
Directory.Delete (androidFolderDestination, true);
if (Directory.Exists (folderSource)) {
FileUtil.CopyFileOrDirectory (folderSource, androidFolderDestination);
AssetDatabase.Refresh ();
} else {
Debug.LogError("Source folder: " + folderSource + " Doesn't exist");
}
}
private static void Build(BuildTarget target, string output){
var outputDirectory = output.Remove (output.LastIndexOf ("/"));
if (!Directory.Exists(outputDirectory))
Directory.CreateDirectory(outputDirectory);
// Get all the scenes
string[] levelList = EditorBuildSettings.scenes.Where(s => s.enabled).Select(s => s.path).ToArray();
string scenesNames = "(";
foreach( string s in levelList)
scenesNames += s.Remove( s.IndexOf(".unity") ) + ", ";
if (scenesNames.Length <= 1) {
Debug.LogError("No scenes found! Please add scenes (Files -> Build Settings -> Scenes in build");
return;
}
scenesNames = scenesNames.Remove (scenesNames.Length - 2) + ")";
Debug.Log("Building Platform: " + target.ToString() );
Debug.Log("Building Target: " + output);
Debug.Log("Scenes Processed: " + levelList.Length );
Debug.Log("Scenes Names: " + scenesNames);
// Build the project
string results = BuildPipeline.BuildPlayer( levelList, output, target, BuildOptions.AutoRunPlayer );
if ( results.Length == 0 )
Debug.Log("No Build Errors" );
else
Debug.LogError("Build Error:" + results);
}
}
#endif