docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    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.

    Inheritance
    object
    PublisherUtils
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Unity.Play.Publisher.Editor
    Assembly: Unity.Play.Publisher.Editor.dll
    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
    int

    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
    bool

    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
    bool

    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
    bool

    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(ulong)

    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
    ulong 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
    ulong

    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
    bool

    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.

    In This Article
    Back to top
    Copyright © 2025 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)