Custom build systems

If you're using a custom build system for making builds in Unity, this is for you.

πŸ“˜

This article is only relevant to you if you are using a custom solution for making builds in Unity. It is not a required step for getting started with Trail.

Integrating a custom build system with Trail

You can use this to trigger your own build system when pressing any of the "Build" buttons in the Trail Editor Extension.

This is not a requirement for making builds for Trail, it's simply a convenience.

Events

Description

TrailBuild.CustomBuild

The event that can be used to override the default build pipeline used by Trail. The method provided needs to return a BuildReport, so Trail can store information about the build for easier uploading.

TrailBuild.OnPreBuild

The event that that can be used to run any custom code before a build.

Example:

[InitializeOnLoadMethod]
private static void SetupBuildPipeline()
{
   Trail.TrailBuild.CustomBuild += MyBuildPipeline;
}

private static BuildReport MyBuildPipeline()
{
   BuildPlayerOptions options = new BuildPlayerOptions();

   options.scenes = EditorBuildSettings.scenes
       .Where(x => x.enabled)
       .Select(x => x.path)
       .ToArray();

   options.target = BuildTarget.WebGL;
   options.targetGroup = BuildTargetGroup.WebGL;
   options.options = BuildOptions.ShowBuiltPlayer;
   options.locationPathName = "Builds/WebGL";

   return UnityEditor.BuildPipeline.BuildPlayer(options);
}

Triggering builds and uploads programmatically

Useful for example if you want to finish your scripted build process with uploading the build to Trail.

Method

Description

TrailBuild.RunFullReport();

This method will run through all the reports in Report Window to verify how many required issues exist. Returns the number of problems that need to be fixed before uploading to Trail.

TrailBuild.Build();

This method will run the same operation as the Build button provided in the Trail SDK Editor. This will further update the Trail SDK Editor build-cache so you can upload the build without providing a path. Returns BuildReport if the build was not canceled.

TrailBuild.Upload(string description);

This method will attempt to upload the latest build, with a description, to Trail if any build exists.

TrailBuild.Upload(string path, string description);

This method will attempt to upload a build, with a description, on the provided path to Trail.

TrailBuild.HasBuild();

A convenient method to verify if the build cache exists and the directory of the build exists.
This method does not check if all files exist in the build.

Example:

private static void ExampleBuildAndUpload()
{
   var requiredIssues = Trail.TrailBuild.RunFullReport();
  if (requiredIssues > 0)
  {
        Debug.LogError($"You have {requiredIssues} that needs to be fixed before building for Trail.");
        return;
  }
   var report = Trail.TrailBuild.Build();
   if (report.summary.result == BuildResult.Succeeded)
   {
       Trail.TrailBuild.Upload();
   }
}