docs.unity3d.com
    Show / Hide Table of Contents

    Class GroupResolver

    Provides support for placing assets into different AddressableAssetGroups.

    Inheritance
    Object
    GroupResolver
    Namespace: UnityEditor.Localization.Addressables
    Syntax
    [Serializable]
    public class GroupResolver
    Examples

    This example places all English assets into a local group and all other languages into a remote group which could then be downloaded after the game is released.

    using System.Collections.Generic;
    using UnityEditor;
    using UnityEditor.AddressableAssets.Settings;
    using UnityEditor.Localization.Addressables;
    using UnityEngine;
    using UnityEngine.Localization;
    
    /// <summary>
    /// Places all English assets into a local group and all other languages into a remote group which could be downloaded after the game is released.
    /// </summary>
    [System.Serializable]
    public class GroupResolverExample : GroupResolver
    {
    public string localAssetsGroup = "Localization-Local";
    public string remoteAssetsGroup = "Localization-Remote";
    
    [MenuItem("Localization Samples/Create Group Resolver")]
    static void CreateAsset()
    {
        var path = EditorUtility.SaveFilePanelInProject("Create Addressable Rules", "Localization Addressable Group Rules.asset", "asset", "");
        if (string.IsNullOrEmpty(path))
            return;
    
        var instance = ScriptableObject.CreateInstance<AddressableGroupRules>();
        var resolver = new GroupResolverExample();
    
        // Apply our custom group resolver to everything
        instance.LocaleResolver = resolver;
        instance.AssetTablesResolver = resolver;
        instance.AssetResolver = resolver;
        instance.StringTablesResolver = resolver;
    
        // Make this our new AddressableGroupRules
        AssetDatabase.CreateAsset(instance, path);
        AddressableGroupRules.Instance = instance;
    }
    
    public override string GetExpectedGroupName(IList<LocaleIdentifier> locales, Object asset, AddressableAssetSettings aaSettings)
    {
        // Use default behaviour for shared assets
        if (locales == null || locales.Count == 0)
            return base.GetExpectedGroupName(locales, asset, aaSettings);
    
        var locale = locales[0];
        if (locale.Code == "en")
            return localAssetsGroup;
        return remoteAssetsGroup;
    }
    }

    Constructors

    GroupResolver()

    Creates a new default instance of GroupResolver.

    Declaration
    public GroupResolver()

    GroupResolver(String)

    Creates a new instance which will store all assets into a single group.

    Declaration
    public GroupResolver(string groupName)
    Parameters
    Type Name Description
    String groupName

    The name to use when creating a new group.

    GroupResolver(String, String)

    Creates an instance using custom group names for each Locale.

    Declaration
    public GroupResolver(string localeGroupNamePattern, string sharedGroupName)
    Parameters
    Type Name Description
    String localeGroupNamePattern

    The name to use when creating a new Group for a selected LocaleIdentifier. The name is formatted using Smart where the argument passed will be the LocaleIdentifier. The default is "Localization-Assets-{Code}"."

    String sharedGroupName

    The name of the group to use when an asset is shared by multiple Locales that do not all use the same group.

    GroupResolver(AddressableAssetGroup)

    Creates a new instance which will store all assets into a single group;

    Declaration
    public GroupResolver(AddressableAssetGroup group)
    Parameters
    Type Name Description
    AddressableAssetGroup group

    The group to use.

    Properties

    LocaleGroupNamePattern

    The name to use when generating a new AddressableAssetGroup for a Locale.

    Declaration
    public string LocaleGroupNamePattern { get; set; }
    Property Value
    Type Description
    String

    MarkEntriesReadOnly

    Should new Entries be marked as read only? This will prevent editing them in the Addressables window.

    Declaration
    public bool MarkEntriesReadOnly { get; set; }
    Property Value
    Type Description
    Boolean

    SharedGroup

    The group to use for shared assets. If null then a new group will be created using SharedGroupName.

    Declaration
    public AddressableAssetGroup SharedGroup { get; set; }
    Property Value
    Type Description
    AddressableAssetGroup

    SharedGroupName

    The name to use when creating a new group.

    Declaration
    public string SharedGroupName { get; set; }
    Property Value
    Type Description
    String

    Methods

    AddLocaleGroup(LocaleIdentifier, AddressableAssetGroup)

    Add a group for the LocaleIdentifier. If a Group is already assigned it will be replaced with the new group.

    Declaration
    public void AddLocaleGroup(LocaleIdentifier identifier, AddressableAssetGroup group)
    Parameters
    Type Name Description
    LocaleIdentifier identifier

    The Locale Id to use for the selected group.

    AddressableAssetGroup group

    The group to add for the selected Locale Id, must not be null.

    AddToGroup(Object, IList<LocaleIdentifier>, AddressableAssetSettings, Boolean)

    Add an asset to an AddressableAssetGroup. The asset will be moved into a group which either matches SharedGroup or SharedGroupName.

    Declaration
    public virtual AddressableAssetEntry AddToGroup(Object asset, IList<LocaleIdentifier> locales, AddressableAssetSettings aaSettings, bool createUndo)
    Parameters
    Type Name Description
    Object asset

    The asset to be added to a group.

    IList<LocaleIdentifier> locales

    List of locales that depend on this asset or null if the asset is used by all.

    AddressableAssetSettings aaSettings

    The Addressables setting that will be used if a new group should be added.

    Boolean createUndo

    Should an Undo record be created?

    Returns
    Type Description
    AddressableAssetEntry

    The asset entry for the added asset.

    GetExpectedGroupName(IList<LocaleIdentifier>, Object, AddressableAssetSettings)

    Returns the name of the group that the asset will be moved to when calling AddToGroup(Object, IList<LocaleIdentifier>, AddressableAssetSettings, Boolean).

    Declaration
    public virtual string GetExpectedGroupName(IList<LocaleIdentifier> locales, Object asset, AddressableAssetSettings aaSettings)
    Parameters
    Type Name Description
    IList<LocaleIdentifier> locales
    Object asset
    AddressableAssetSettings aaSettings
    Returns
    Type Description
    String

    GetExpectedSharedGroupName(IList<LocaleIdentifier>, Object, AddressableAssetSettings)

    Returns the name that the Shared group is expected to have.

    Declaration
    protected virtual string GetExpectedSharedGroupName(IList<LocaleIdentifier> locales, Object asset, AddressableAssetSettings aaSettings)
    Parameters
    Type Name Description
    IList<LocaleIdentifier> locales
    Object asset
    AddressableAssetSettings aaSettings
    Returns
    Type Description
    String

    GetGroup(IList<LocaleIdentifier>, Object, AddressableAssetSettings, Boolean)

    Returns the Addressable group for the asset.

    Declaration
    protected virtual AddressableAssetGroup GetGroup(IList<LocaleIdentifier> locales, Object asset, AddressableAssetSettings aaSettings, bool createUndo)
    Parameters
    Type Name Description
    IList<LocaleIdentifier> locales

    The locales that depend on the asset.

    Object asset

    The asset that is to be added to an Addressable group.

    AddressableAssetSettings aaSettings

    The Addressable asset settings.

    Boolean createUndo

    Should an Undo record be created if changes are made?

    Returns
    Type Description
    AddressableAssetGroup

    GetLocaleGroup(LocaleIdentifier)

    Returns the active group assigned to the LocaleIdentifier or null if one has not been assigned.

    Declaration
    public AddressableAssetGroup GetLocaleGroup(LocaleIdentifier identifier)
    Parameters
    Type Name Description
    LocaleIdentifier identifier

    The Locale Id to search for.

    Returns
    Type Description
    AddressableAssetGroup

    RemoveLocaleGroup(LocaleIdentifier)

    Removes the group for the chosen Locale Id.

    Declaration
    public bool RemoveLocaleGroup(LocaleIdentifier identifier)
    Parameters
    Type Name Description
    LocaleIdentifier identifier

    The Locale Id to be removed.

    Returns
    Type Description
    Boolean

    Returns true if an item was removed.

    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023