ididdidi

Cogito, ergo sum

^

Unity: Easy Assets Localize

Pic. 1. View The package for easy localization of assets in Unity3d.

1. Setup

Select from the top menu: Window -> Localization Storage.

Pic. 2. Settings button

In the Localization Storage window, click on the ⚙ button near the search field.

Pic. 3. Settings

In the tab, you can add the languages and resource types needed for localization.

Pic. 4. Add language

Click on the + at the bottom of the list and select it from the list of Unity's base system languages to add a language.

Pic. 5. Add resource type

Click the + at the end of the list with types, to add a new type of assets for localization.

Pic. 6. Settings

Drag the default asset sample into the field that appears. Wait for the code generation to finish.

Pic. 7. New resource type

A new item of the corresponding type will appear in the list of localizations. When you click on it, a list of localizations of this type will open.

Pic. 8. Default localization

The list of localizations of this type will contain the default localization.

You can edit the default localization by selecting it and clicking on the tools icon in the upper right corner of the localization window.

Pic. 9. Edit default localization

This unlocks the resources of the languages used to change.

2. Applying localization to an object

Select the object that needs localization. Add a resource localization component to it: Add component -> Localize -> [Resource type]Localization. Pic. 10. Add Localization Component

Pic. 11. Localization Component

Add the object to the list of handlers and select the property corresponding to the resource type (usually they are at the top of the drop-down list)

Pic. 12. Add handler

The new localization will link to the same resources as the standard one.

3. Change localization

You can change the localization directly on the object. To do this, click the Change Localization button in the inspector window of the localization component.

Pic. 13. Change localization

In the list that appears, you can select an existing localization or add a new one.

The new localization will link to the same resources as the standard one. They can be changed directly on the component.

Attention! When editing a localization used by several objects, the changes will affect all objects using an instance of this localization.

4. Managing localizations in Runtime

To control localization in Runtime, you need to add the LocalizationController component to the stage.

Pic. 14. LocalizationController

Scriptable Object of type LocalizationStorage must be added to the Localization Storage field. In the On Chage Language event field you can add a handler that receives a string with the name of the language.

To interact with an object of type LocalizationController in code, you can use the following methods:

Method Description
GetInstance The static method that creates or returns a ready-made instance from the scene. Accepts a dontDestroy argument which allows you to save the object instance when changing scenes. Returns an instance of LocalizationController.
Subscribe Allows an instance of a LocalizationComponent derived type, passed as an argument, to subscribe to localization changes.
Unsubscribe Allows an instance of a LocalizationComponent derived type, passed as an argument, to subscribe to localization changes.
SetNextLanguage Changes the language to the next one in the localization list.
SetPrevLanguage Changes the language to the previous one in the localization list.
SetLanguage Sets the current language and loads localized resources. Takes an object of type Language as an argument

If you have any questions or suggestions, do not hesitate to send them to the email indicated on the Contacts page!

tags: c# - unity3d - work

2023-09-10