Skip to content

Instantly share code, notes, and snippets.

@jinwoo-lee-github
Last active December 26, 2015 07:59
Show Gist options
  • Save jinwoo-lee-github/7118468 to your computer and use it in GitHub Desktop.
Save jinwoo-lee-github/7118468 to your computer and use it in GitHub Desktop.
unity build menu
using UnityEngine;
using UnityEditor;
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
public class WhdvlBuilder {
static string[] Scenes = FindEnableEditorScenes();
[MenuItem ("whdvl/Build/iOS")]
static void PerformiOSBuild() {
if(ExistFolder("../Builds") == false) {
//Debug.Log("Create Builds Folder ");
CreateFolder("../Builds");
}
if(ExistFolder("../Builds/project_ios")) {
//Debug.Log("Exist project_ios Folder");
GenericBuild(Scenes, "Builds/project_ios", BuildTarget.iPhone, BuildOptions.AcceptExternalModificationsToPlayer);
} else {
//Debug.Log("Create project_ios Folder");
GenericBuild(Scenes, "Builds/project_ios", BuildTarget.iPhone, BuildOptions.None);
}
}
private static string[] FindEnableEditorScenes() {
List<String> editorScenes = new List<String>();
foreach(EditorBuildSettingsScene scene in EditorBuildSettings.scenes) {
if(!scene.enabled) continue;
editorScenes.Add(scene.path);
}
return editorScenes.ToArray();
}
static void GenericBuild(string[] scenes, string target_filename, BuildTarget build_target, BuildOptions build_options)
{
EditorUserBuildSettings.SwitchActiveBuildTarget(build_target);
string res = BuildPipeline.BuildPlayer(scenes, target_filename, build_target, build_options);
if (res.Length > 0) {
throw new Exception("[whdvl] BuildPlayer failure: " + res);
}
}
private static bool ExistFolder(string name) {
//Debug.Log( string.Format("{0}/{1}", Application.dataPath, name));
return Directory.Exists(string.Format("{0}/{1}", Application.dataPath, name));
}
private static void CreateFolder(string name) {
//Debug.Log( string.Format("{0}/{1}", Application.dataPath, name));
Directory.CreateDirectory(string.Format("{0}/{1}", Application.dataPath, name));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment