M
M
MishkaVNorky2019-02-07 09:24:24
C++ / C#
MishkaVNorky, 2019-02-07 09:24:24

How to prevent the editor from calling "readonly static" while editing?

A bit of a tautology in the title.
Maybe someone in the know.
Let's say there is a script, it has static fields, for example:

readonly static string TEST = Localization.Localize("Test");

But just sitting in the editor, these fields are initialized (and an error is generated that it cannot get the data of the Localization class, obviously because the class is initialized when the game starts).
I want to cache the translation and add it to static. But there are many problems with this and it is possible that it will not work out beautifully (further it will swear at Application.dataPath, which is called when the field is initialized)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman, 2019-02-07
@WNeZRoS

Can't be banned.
A simple option is to add a stub to the Localize method:

#if UNITY_EDITOR // Кода внутри этого #if не будет в собранной версии игры
if (isLocalizationInitialized == false)
    return localicationKey;
#endif

D
Denis Gaydak, 2019-02-07
@MrMureno

see examples of localization plugins. in the same asset store.
this is a lousy way to cache - storing hardcode in static fields.
usually a localization plugin has a separate resource file. where are all localizations.
needed at the start pulled out. stuffed into the RAM / scene and use it.
this is caching itself. from the fact that you stuff all this into readonly static variables it will not get any better))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question