Constructor LocalizedString
LocalizedString()
Initializes and returns an empty instance of a LocalizedString.
Declaration
public LocalizedString()
LocalizedString(TableReference, TableEntryReference)
Initializes and returns an instance of a LocalizedString.
Declaration
public LocalizedString(TableReference tableReference, TableEntryReference entryReference)
Parameters
Type | Name | Description |
---|---|---|
TableReference | tableReference | Reference to the String Table Collection. This can either be the name of the collection as a string or the Collection Guid as a System.Guid. |
TableEntryReference | entryReference | Reference to the String Table Collection entry. This can either be the name of the Key as a string or the long Key Id. |
Examples
This example shows the different ways to construct a LocalizedString.
public LocalizedString usingNames = new LocalizedString("My String Table", "My Game Text");
public LocalizedString usingTableNameAndEntryId = new LocalizedString("My String Table", 4324324541);
public LocalizedString usingTableGuidAndEntryId = new LocalizedString(new System.Guid("6e79ded14bc9e0a4d9bf2b8aac246bfe"), 323453434);
public LocalizedString usingTableGuidAndEntryName = new LocalizedString(new System.Guid("6e79ded14bc9e0a4d9bf2b8aac246bfe"), "Start Game");
public LocalizedString withLocalVariables = new LocalizedString("My String Table", "My Game Text")
{
// These variables will be visible in the inspector Local Variables field.
{ "some-text", new StringVariable { Value = "Hello World" } },
{ "score", new IntVariable { Value = 100 } },
{ "player-health", new FloatVariable { Value = 0.5f } },
{ "object-reference", new ObjectVariable()}, // Set via the inspector
};
public LocalizedString withNestedTranslation = new LocalizedString("My String Table", "My Game Text")
{
{ "some-text", new StringVariable { Value = "Hello World" } },
{ "nested", new LocalizedString("My String Table", "My Nested Text")
{
{ "score", new IntVariable { Value = 100 } },
}}
};
This example shows how a LocalizedString could be set up in the Editor. By using the Guid and Id the table and entry references will not be lost if the table collection name or entry name was to be changed. Note: The performance benefits to using a Guid and Id are negligible.
public LocalizedString GenerateLocalizedStringInEditor()
{
// The main advantage to using a table Guid and entry Id is that references will not be lost when changes are made to the Table name or Entry name.
var collection = LocalizationEditorSettings.GetStringTableCollection("My String Table");
var entry = collection.SharedData.GetEntry("Start Game");
return new LocalizedString(collection.SharedData.TableCollectionNameGuid, entry.Id);
}