Scripting API

✅ Assemblies

All the code in this asset is under assembly definitions. This helps with compile times for your code. If your code is also in an assembly definition you will need reference the assembly/assemblies to access the code for this asset. The assemblies are:

For accessing the editor code of the asset.

CarterGames.BuildVersions.Editor

For accessing the runtime code of the asset.

CarterGames.BuildVersions

🚩 Namespaces

All code for this asset is under the following namespace(s):

For accessing the editor code of the asset.

CarterGames.Assets.BuildVersions.Editor

For accessing the runtime code of the asset.

CarterGames.Assets.BuildVersions

🎗️ Scripting

📗 Runtime

🟢 Build Information

See how to show this information here: How to show Build Information on Unity UI

Properties

BuildType (string)
Gets the “type” the build is set as by you.

var buildInfo = AssetAccessor.GetAsset<BuildInformation>();
Debug.Log(buildInfo.BuildType);

BuildDate (SeralizedDate)
Gets the date that the last build was made as a string.

var buildInfo = AssetAccessor.GetAsset<BuildInformation>();
Debug.Log(buildInfo.BuildDate);

BuildNumber (int)
Gets the current build number, this is the unique number not the player settings number.

var buildInfo = AssetAccessor.GetAsset<BuildInformation>();
Debug.Log(buildInfo.BuildNumber);

SemanticVersionNumber (string)
Get the current version number, this is the number in the player settings.

var buildInfo = AssetAccessor.GetAsset<BuildInformation>();
Debug.Log(buildInfo.SemanticBuildNumber);

🟢 Asset Accessor


Methods

GetAsset<T> (BuildVersionsAsset<T>)
Gets a scriptable object of the type requested. This only works with the build version assets.

public void ExampleMethod()
{
    var info = AssetAccessor.GetAsset<BuildInformation>();
}

📗 Editor


🟢 Build Handler


ℹ️ Use BuildVersionsEditorUtil.GetClassName<T>() to get the class name for the handler dialogue data class type.

Methods

Register(HandlerDialogueData) | void
Registers a class into the handler system when a build is made.

BuildHandler.Register(new HandlerDialogueData(BuildVersionsEditorUtil.GetClassName<AndroidBundleCodeUpdater>(), true));

Get<T>() | HandlerDialogueData
Gets a handler data to use.


Clear() | void
Registers a class into the handler system when a build is made.


🟢 Handler Dialogue Data


ℹ️ A struct holding data for the build handler system.

ParamTypeDescription
IdStringThe id this handler is, this should be the class name to keep it unique.
ChoiceboolThe choice the user made in the dialogue window.

🟢 Custom Updaters


ℹ️ Any custom updaters should be in an editor folder in the folder structure or in a editor ifdef.

If you want to know how to add a custom updater, see “How to make a custom build updater” in the documentation tab for more information on how to set these up!

Interfaces

IBuildUpdater
Implement to make a build updater that will increment build numbers on build.

// Defines the order that the updater runs at...
// Above 0 is after the asset updaters, below is before...
int UpdateOrder { get; }

// Runs the logic in this method when the asset tries 
// to update the build number...
public void OnBuildVersionIncremented(BuildTarget buildTarget)

ISyncable
Implement to sync version numbers when requested (systematic only)…

// Runs the logic in this method when the asset tries 
// to sync version numbers...
public void OnVersionSync(string version)

IPreBuildDialogue
Implement to make a dialogue window appear before a build is made…

// Runs the logic in this method when the asset tries 
// to sync version numbers...
public void OnPreBuildDialogue(BuildTarget target)

Example

ℹ️ Below is an example of a custom updater to update the build number in a game analytics settings asset when the number is updated by the asset & when the user manually sync’s the semantic version number.

using GameAnalyticsSDK;
using UnityEditor;

public class GameAnalyticsUpdater : IBuildUpdater, ISyncable
{
    //
    //
    //  IBuildUpdater Implementation 
    //
    //
    public int UpdateOrder => 10;
        
    public void OnBuildVersionIncremented(BuildTarget buildTarget)
    {
        for (var i = 0; i < GameAnalytics.SettingsGA.Build.Count; i++)
        {
            GameAnalytics.SettingsGA.Build[i] = PlayerSettings.bundleVersion;
        }
    }

        
    //
    //
    //  ISyncable Implementation 
    //
    //
    public void OnVersionSync(string version)
    {
        for (var i = 0; i < GameAnalytics.SettingsGA.Build.Count; i++)
        {
            GameAnalytics.SettingsGA.Build[i] = version;
        }
    }
}