Last active
March 22, 2021 16:12
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Git class is here https://gist.github.com/edwardrowe/fdec706fe53bfff0671e063f263ada63