Version: Unity 6.7 Beta (6000.7)
LanguageEnglish
  • C#

VariantSelectorMetadata

class in Unity.Localization


Implements interfaces:IMetadata

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Description

Makes a key variant-driven by attaching the selector that chooses its current variant.

Attach it to a shared key's metadata for a per-key IVariantSelector, or to the SharedTableData for a default that every key in the collection inherits. The selector lives on the shared data, not the per-locale entry, so it stays the same across locales. Variant values themselves are stored per locale; add them with ResourceTable.AddStringVariant, which registers the variant keys here.

Additional resources: IVariantSelector, SharedTableData

Attach a selector and add a variant value from script.

namespace Unity.Localization.Samples
{
    public static class AddVariantByScriptExample
    {
        public static void MakeWishlistVaryByStorefront(ResourceTable table)
        {
            // The default value, used wherever no variant matches.
            table.AddStringEntry("wishlist", "Add to wishlist");

// The selector lives on the shared key, so every locale resolves the same way. var key = table.SharedData.GetEntry("wishlist"); if (key.Metadata.GetMetadata<VariantSelectorMetadata>() == null) key.Metadata.AddMetadata(new VariantSelectorMetadata(new StorefrontVariantSelector()));

// The value this locale shows when the selector reports "GOG". table.AddStringVariant("wishlist", "GOG", "Add to GOG wishlist"); }

public static void RemoveTheVariant(ResourceTable table) { table.RemoveVariant("wishlist", "GOG"); } } }

Properties

Property Description
Keys The variant keys authored for this scope, used by the editor to lay out variant rows.
Selector The selector that chooses the current variant key.

Constructors

Constructor Description
VariantSelectorMetadata Creates empty variant metadata.

Public Methods

Method Description
AddKey Adds key to the authored variant keys if absent.
RemoveKey Removes key from the authored variant keys.