Skip to content

Instantly share code, notes, and snippets.

@TheMikina
Created August 15, 2021 21:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheMikina/84e97c228015000ec3b46d8bb53e8ff6 to your computer and use it in GitHub Desktop.
Save TheMikina/84e97c228015000ec3b46d8bb53e8ff6 to your computer and use it in GitHub Desktop.
/*
AutoBuilder.cs
Automatically changes the target platform and creates a build.
Installation
Place in an Editor folder.
Usage
Go to File > AutoBuilder and select a platform. These methods can also be run from the Unity command line using -executeMethod AutoBuilder.MethodName.
License
Copyright (C) 2011 by Thinksquirrel Software, LLC
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
using System;
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
public static class AutoBuilder
{
private static string defaultScenes =
"Assets/Scenes/Prototypes/MixCostComponentSelection.unity;Assets/Scenes/Others/IntroScreen.unity;Assets/Scenes/Stories/Tutorial/TutorialStart.unity;Assets/Scenes/Stories/Tutorial/Level0-1.unity;Assets/Scenes/Stories/Tutorial/Level0-2 1.unity;Assets/Scenes/Stories/Tutorial/TutorialMid.unity;Assets/Scenes/Stories/Tutorial/Level0-3.unity;Assets/Scenes/Stories/Tutorial/TutorialFinish.unity;Assets/Scenes/Others/ModeSelectScreen.unity;Assets/Scenes/Stories/1 - Run for Retrolandia/Level1.unity;Assets/Scenes/Others/ComponentsTutorialScreen.unity;Assets/Scenes/Others/FixedDefectsComponentSelection.unity;Assets/Scenes/Others/Controls.unity;Assets/Scenes/Others/ControlsTutorial.unity;Assets/Scenes/Others/Credits.unity;Assets/Scenes/Others/LanguageScreen.unity;Assets/Scenes/Others/MainMenu.unity;Assets/Scenes/Others/PartsSwapTutorial.unity;Assets/Scenes/Others/SaveSelection.unity;Assets/Scenes/Others/StorySelection.unity;Assets/Scenes/Stories/5 - Badly Lit Adventure/Briefing5-1.unity;Assets/Scenes/Stories/5 - Badly Lit Adventure/Briefing5-2.unity;Assets/Scenes/Stories/5 - Badly Lit Adventure/Briefing5-3.unity;Assets/Scenes/Stories/5 - Badly Lit Adventure/GameEnd5.unity;Assets/Scenes/Stories/1 - Run for Retrolandia/Level1-2Rework.unity;Assets/Scenes/Stories/5 - Badly Lit Adventure/Level5-1.unity;Assets/Scenes/Stories/5 - Badly Lit Adventure/Level5-2.unity;Assets/Scenes/Stories/5 - Badly Lit Adventure/Level5-3.unity;Assets/Scenes/Stories/6 - Ideal Idea/Briefing6-1.unity;Assets/Scenes/Stories/6 - Ideal Idea/Briefing6-2.unity;Assets/Scenes/Stories/6 - Ideal Idea/Briefing6-3.unity;Assets/Scenes/Stories/6 - Ideal Idea/GameEnd6.unity;Assets/Scenes/Stories/6 - Ideal Idea/Level6-1.unity;Assets/Scenes/Stories/6 - Ideal Idea/Level6-2.unity;Assets/Scenes/Stories/6 - Ideal Idea/Level6-3.unity;Assets/Scenes/Stories/6 - Ideal Idea/Level6-3ALT.unity;Assets/Scenes/Stories/TestLevel.unity;Assets/Scenes/Stories/1 - Run for Retrolandia/Briefing1.unity;Assets/Scenes/Stories/1 - Run for Retrolandia/Briefing2.unity;Assets/Scenes/Stories/1 - Run for Retrolandia/Briefing3.unity;Assets/Scenes/Stories/1 - Run for Retrolandia/GameEnd.unity;Assets/Scenes/Stories/1 - Run for Retrolandia/Level2.unity;Assets/Scenes/Stories/1 - Run for Retrolandia/Level3.unity;Assets/Scenes/Stories/2 - Day at the Office/Briefing2-1.unity;Assets/Scenes/Stories/2 - Day at the Office/Briefing2-2.unity;Assets/Scenes/Stories/2 - Day at the Office/Briefing2-3.unity;Assets/Scenes/Stories/2 - Day at the Office/GameEnd2.unity;Assets/Scenes/Stories/2 - Day at the Office/Level2-1.unity;Assets/Scenes/Stories/2 - Day at the Office/Level2-2.unity;Assets/Scenes/Stories/2 - Day at the Office/Level2-3.unity;Assets/Scenes/Stories/2 - Day at the Office/Level2-4.unity;Assets/Scenes/Stories/3 - Tramp Trouble/Briefing3-1.unity;Assets/Scenes/Stories/3 - Tramp Trouble/Briefing3-2.unity;Assets/Scenes/Stories/3 - Tramp Trouble/Briefing3-3.unity;Assets/Scenes/Stories/3 - Tramp Trouble/GameEnd3.unity;Assets/Scenes/Stories/3 - Tramp Trouble/Level3-1.unity;Assets/Scenes/Stories/3 - Tramp Trouble/Level3-2.unity;Assets/Scenes/Stories/3 - Tramp Trouble/Level3-3.unity;Assets/Scenes/Stories/4 - Lemon Heist/Briefing4-1.unity;Assets/Scenes/Stories/4 - Lemon Heist/Briefing4-2.unity;Assets/Scenes/Stories/4 - Lemon Heist/Briefing4-3.unity;Assets/Scenes/Stories/4 - Lemon Heist/GameEnd4.unity;Assets/Scenes/Stories/4 - Lemon Heist/Level4-1.unity;Assets/Scenes/Stories/4 - Lemon Heist/Level4-2.unity;Assets/Scenes/Stories/4 - Lemon Heist/Level4-3.unity;Assets/Scenes/Others/ComponentSelection.unity;Assets/Scenes/Stories/1 - Run for Retrolandia/Level1Interactable.unity;Assets/Scenes/Stories/1 - Run for Retrolandia/Level1REWORK.unity";
static string GetProjectName()
{
string[] s = Application.dataPath.Split('/');
return s[s.Length - 2];
}
static string[] GetScenePaths()
{
string[] scenes = new string[EditorBuildSettings.scenes.Length];
for(int i = 0; i < scenes.Length; i++)
{
scenes[i] = EditorBuildSettings.scenes[i].path;
}
Debug.Log("Building with scenes:");
Debug.Log(string.Join(";", scenes));
return scenes;
}
static void Win64Build(string[] withScenes)
{
PlayerSettings.bundleVersion = Git.BuildVersion;
EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.Standalone,BuildTarget.StandaloneWindows);
BuildPipeline.BuildPlayer(withScenes, "Builds/Win64/" + GetProjectName() + ".exe",BuildTarget.StandaloneWindows64,BuildOptions.None);
}
[MenuItem("File/AutoBuilder/Build-options scenes")]
static void PerformWin64Build ()
{
GetScenePaths();
Win64Build(GetScenePaths());
}
[MenuItem("File/AutoBuilder/Default Scenes (L0-3)")]
static void BuildDefaultScenes ()
{
GetScenePaths();
Win64Build(defaultScenes.Split(';'));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment