Skip to content

Instantly share code, notes, and snippets.

@edwardrowe
Last active March 22, 2021 16:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edwardrowe/1c67fb72bbd54454bc76495530fd8096 to your computer and use it in GitHub Desktop.
Save edwardrowe/1c67fb72bbd54454bc76495530fd8096 to your computer and use it in GitHub Desktop.
An example of a Build Tool, used to accompany my blog post on Versioning with git in Unity.
/* MIT License
Copyright (c) 2016 RedBlueGames
*/
using UnityEditor;
using UnityEngine;
using UnityEditor.Build.Reporting;
public class BuildToolExample : MonoBehaviour
{
[MenuItem("Build/Build with Version")]
public static void MyBuild()
{
// This gets the Build Version from Git via the `git describe` command
PlayerSettings.bundleVersion = Git.BuildVersion;
// ===== This sample is taken from the Unity scripting API here:
// https://docs.unity3d.com/ScriptReference/BuildPipeline.BuildPlayer.html
BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions();
buildPlayerOptions.scenes = new[] { "Assets/Scene1.unity", "Assets/Scene2.unity" };
buildPlayerOptions.locationPathName = "Builds";
buildPlayerOptions.target = BuildTarget.StandaloneWindows;
buildPlayerOptions.options = BuildOptions.None;
BuildReport report = BuildPipeline.BuildPlayer(buildPlayerOptions);
BuildSummary summary = report.summary;
if (summary.result == BuildResult.Succeeded)
{
Debug.Log("Build succeeded: " + summary.totalSize + " bytes");
}
if (summary.result == BuildResult.Failed)
{
Debug.Log("Build failed");
}
}
}
@dimmduh
Copy link

dimmduh commented Aug 19, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment