Class PublisherUtils
Provides a collection of utility methods. These methods are used by the WebGL Publisher and by other tools that need information about existing builds.
Inherited Members
Namespace: Unity.Play.Publisher.Editor
Syntax
public static class PublisherUtils
Fields
DefaultGameName
the default name of every uploaded game
Declaration
public const string DefaultGameName = "Untitled"
Field Value
| Type | Description |
|---|---|
| String |
MaxDisplayedBuilds
The max number of builds that can be displayed in the UI at the same time
Declaration
public const int MaxDisplayedBuilds = 10
Field Value
| Type | Description |
|---|---|
| Int32 |
Methods
AddBuildDirectory(String)
Adds a directory to the list of tracked build directories
Declaration
public static void AddBuildDirectory(string buildPath)
Parameters
| Type | Name | Description |
|---|---|---|
| String | buildPath | The absolute path to a build |
Remarks
if there are already MaxDisplayedBuilds elements in the list, the oldest element will be removed to make room for the new build directory.
Examples
class AddBuildDirectoryExample
{
void Start()
{
string buildPath = "C://Builds/MyAwesomeBuild";
PublisherUtils.AddBuildDirectory(buildPath);
PrintAllBuildsDirectories(); //will also display buildPath
}
void PrintAllBuildsDirectories()
{
List<string> existingBuildsPaths = PublisherUtils.GetAllBuildsDirectories();
foreach (string path in existingBuildsPaths)
{
if (path == string.Empty) { continue; }
Debug.Log(path);
}
}
}
BuildIsCompatibleFor2019_3(String, String)
Determines whether a build is valid or not, according to Unity 2019.3 WebGL build standard output
Declaration
public static bool BuildIsCompatibleFor2019_3(string buildPath, string descriptorFileName)
Parameters
| Type | Name | Description |
|---|---|---|
| String | buildPath | The path to a build |
| String | descriptorFileName |
Returns
| Type | Description |
|---|---|
| Boolean | Returns True if the build follows the standard for a supported Unity version, otherwise returns false |
BuildIsCompatibleFor2020_2(String, String)
Determines whether a build is valid or not, according to Unity 2020.2 WebGL build standard output
Declaration
public static bool BuildIsCompatibleFor2020_2(string buildPath, string descriptorFileName)
Parameters
| Type | Name | Description |
|---|---|---|
| String | buildPath | The path to a build |
| String | descriptorFileName |
Returns
| Type | Description |
|---|---|
| Boolean | Returns True if the build follows the standard for a supported Unity version, otherwise returns false |
BuildIsValid(String)
Determines whether a build is valid or not
Declaration
public static bool BuildIsValid(string buildPath)
Parameters
| Type | Name | Description |
|---|---|---|
| String | buildPath | The path to a build |
Returns
| Type | Description |
|---|---|
| Boolean | Returns True if the build follows the standard for a supported Unity version, otherwise returns false |
Remarks
A build is considered valid if its folders contain all files that are typically created for WebGL builds, specific to its Unity version.
FormatBytes(UInt64)
Formats an amount of bytes so it is represented in one of its multiples. Supports GB, MB, KB, or B
Declaration
public static string FormatBytes(ulong bytes)
Parameters
| Type | Name | Description |
|---|---|---|
| UInt64 | bytes | The amount of bytes to represent |
Returns
| Type | Description |
|---|---|
| String | Returns a string representing multiples of Bytes with two decimals and Bytes with zero decimals |
Examples
class FormatBytesExample
{
void Start()
{
string size = PublisherUtils.FormatBytes(5ul); //returns "5 B"
size = PublisherUtils.FormatBytes(5 * 1024ul); //returns "5 KB"
size = PublisherUtils.FormatBytes(15 * 1024ul * 1024ul); //returns "15 MB"
size = PublisherUtils.FormatBytes(999 * 1024ul * 1024ul * 1024ul); //returns "999 MB"
}
}
GetAllBuildsDirectories()
Retrieves a list of build directories.
Declaration
public static List<string> GetAllBuildsDirectories()
Returns
| Type | Description |
|---|---|
| List<String> | Returns a list of build directories |
Remarks
The list always contains MaxDisplayedBuilds elements. If not enough build paths are retrieved, the missing elements will just contain empty paths.
Examples
class GetAllBuildsDirectoriesExample
{
void Start()
{
PrintAllBuildsDirectories();
}
void PrintAllBuildsDirectories()
{
List<string> existingBuildsPaths = PublisherUtils.GetAllBuildsDirectories();
foreach (string path in existingBuildsPaths)
{
if (path == string.Empty) { continue; }
Debug.Log(path);
}
}
}
GetCurrentPublisherState(PublisherWindow)
Gets the current PublisherState of a PublisherWindow instance
Declaration
public static PublisherState GetCurrentPublisherState(PublisherWindow instance)
Parameters
| Type | Name | Description |
|---|---|---|
| PublisherWindow | instance | The instance of an open PublisherWindow |
Returns
| Type | Description |
|---|---|
| PublisherState | Returns the current PublisherState of a PublisherWindow instance |
Remarks
Use this to detect a change in the current step and react accordingly (I.E: use it to understand if the user started the publishing process)
Examples
class GetCurrentPublisherStateExample
{
void Start()
{
PublisherState currentStep = PublisherUtils.GetCurrentPublisherState(PublisherWindow.FindInstance());
Debug.Log(currentStep);
switch (currentStep)
{
case PublisherState.Idle:
//your code here
break;
case PublisherState.Login:
//your code here
break;
case PublisherState.Zip:
//your code here
break;
case PublisherState.Upload:
//your code here
break;
case PublisherState.Process:
//your code here
break;
default:
break;
}
}
}
GetEditorPreference(String)
Gets an editor preference for the project, using the PublisherSettingsManager
Declaration
public static string GetEditorPreference(string key)
Parameters
| Type | Name | Description |
|---|---|---|
| String | key | ID of the preference |
Returns
| Type | Description |
|---|---|
| String | Returns the value stored for that preference ID |
GetFilteredGameTitle(String)
Filters the name of the game, ensuring it contains something more than just spaces.
Declaration
public static string GetFilteredGameTitle(string currentGameTitle)
Parameters
| Type | Name | Description |
|---|---|---|
| String | currentGameTitle | The original name of the game |
Returns
| Type | Description |
|---|---|
| String | Returns the name of the game if it contains something different than just spaces, or a default name in case the original one only contains spaces. |
Examples
class GetFilteredGameTitleExample
{
void Start()
{
string filteredTitle = PublisherUtils.GetFilteredGameTitle("A title with spaces"); //returns "A title with spaces"
filteredTitle = PublisherUtils.GetFilteredGameTitle(" "); //returns "Untitled" (the value of PublisherUtils.DefaultGameName)
}
}
GetFirstValidBuildPath()
Returns the first valid build path among all builds tracked
Declaration
public static string GetFirstValidBuildPath()
Returns
| Type | Description |
|---|---|
| String | Returns the first valid build path among all builds tracked, if any. Otherwise, returns an empty string |
Examples
class GetFirstValidBuildPathExample
{
void Start()
{
string buildPath = PublisherUtils.GetFirstValidBuildPath();
if (string.IsNullOrEmpty(buildPath))
{
Debug.LogError("There are no valid builds");
return;
}
Debug.Log("Your most recent valid build is located at: " + buildPath);
}
}
GetFolderSize(String)
Gets the size of a folder, in bytes
Declaration
public static ulong GetFolderSize(string folder)
Parameters
| Type | Name | Description |
|---|---|---|
| String | folder | The folder to analyze |
Returns
| Type | Description |
|---|---|
| UInt64 | Returns the size of the folder, in bytes |
GetUnityVersionOfBuild(String)
Gets the Unity version with which a WebGL build was made
Declaration
public static string GetUnityVersionOfBuild(string buildPath)
Parameters
| Type | Name | Description |
|---|---|---|
| String | buildPath | The path to a build |
Returns
| Type | Description |
|---|---|
| String | Returns the Unity version with which a WebGL build was made, if the build contains that information. Otherwise, returns an empty string |
GetUrlOfLastPublishedBuild(PublisherWindow)
Gets the URL of the last build that was published during the current session. Only valid as long as the PublisherWindow stays open.
Declaration
public static string GetUrlOfLastPublishedBuild(PublisherWindow instance)
Parameters
| Type | Name | Description |
|---|---|---|
| PublisherWindow | instance | The instance of an open PublisherWindow |
Returns
| Type | Description |
|---|---|
| String | Returns the URL of the last build that was published during the current session. |
Remarks
If this is empty, no build has been published.
Examples
class GetUrlOfLastPublishedBuildExample
{
void Start()
{
string latestBuildURL = PublisherUtils.GetUrlOfLastPublishedBuild(PublisherWindow.FindInstance());
Debug.Log(latestBuildURL);
}
}
RemoveBuildDirectory(String)
Removes a directory from the list of tracked builds
Declaration
public static void RemoveBuildDirectory(string buildPath)
Parameters
| Type | Name | Description |
|---|---|---|
| String | buildPath | The absolute path to a build |
Remarks
The removed element will be replaced with an empty string.
Examples
class RemoveBuildDirectoryExample
{
void Start()
{
string buildPath = "C://Builds/MyAwesomeBuild";
PublisherUtils.AddBuildDirectory(buildPath);
PrintAllBuildsDirectories(); //will also display buildPath
PublisherUtils.RemoveBuildDirectory(buildPath);
PrintAllBuildsDirectories(); //will not display buildPath
}
void PrintAllBuildsDirectories()
{
List<string> existingBuildsPaths = PublisherUtils.GetAllBuildsDirectories();
foreach (string path in existingBuildsPaths)
{
if (path == string.Empty) { continue; }
Debug.Log(path);
}
}
}
SetEditorPreference(String, String)
Sets an editor preference for the project, using the PublisherSettingsManager
Declaration
public static void SetEditorPreference(string key, string value)
Parameters
| Type | Name | Description |
|---|---|---|
| String | key | ID of the preference |
| String | value | New value |
ValidBuildExists()
Determines whether a valid build is tracked
Declaration
public static bool ValidBuildExists()
Returns
| Type | Description |
|---|---|
| Boolean | Returns True if a non-corrupted build is tracked |
Remarks
A build is considered valid if its folders contain all files that are typically created for WebGL builds, specific to its Unity version.