コード例 #1
0
        /// <inheritdoc/>
        /// <remarks>
        /// When using a non-source locale, will first attempt to find a corresponding record
        /// in the managed text documents, and, if not found, check the character metadata.
        /// In case the display name is found and is wrapped in curly braces, will attempt to evaluate the value from the expression.
        /// </remarks>
        public virtual string GetDisplayName(string characterId)
        {
            if (string.IsNullOrWhiteSpace(characterId))
            {
                return(null);
            }

            var displayName = default(string);

            if (!localizationManager.IsSourceLocaleSelected())
            {
                displayName = textManager.GetRecordValue(characterId, CharactersConfiguration.DisplayNamesCategory);
            }

            if (string.IsNullOrEmpty(displayName))
            {
                displayName = Configuration.GetMetadataOrDefault(characterId).DisplayName;
            }

            if (!string.IsNullOrEmpty(displayName) && displayName.StartsWithFast("{") && displayName.EndsWithFast("}"))
            {
                var expression = displayName.GetAfterFirst("{").GetBeforeLast("}");
                displayName = ExpressionEvaluator.Evaluate <string>(expression, desc => Debug.LogError($"Failed to evaluate `{characterId}` character display name: {desc}"));
            }

            return(string.IsNullOrEmpty(displayName) ? null : displayName);
        }
コード例 #2
0
        protected UniTask InitializeProvisionSources()
        {
            UnloadAll();

            ProvisionSources.Clear();

            if (!LocalizationManager.IsSourceLocaleSelected())
            {
                var localePrefix = $"{LocalizationManager.Configuration.Loader.PathPrefix}/{LocalizationManager.SelectedLocale}/{SourcePrefix}";
                foreach (var provider in LocalizationManager.ProviderList)
                {
                    ProvisionSources.Add(new ProvisionSource(provider, localePrefix));
                }
            }

            if (FallbackToSource)
            {
                foreach (var provider in SourceProviders)
                {
                    ProvisionSources.Add(new ProvisionSource(provider, SourcePrefix));
                }
            }

            return(UniTask.CompletedTask);
        }
コード例 #3
0
 public virtual Script GetLocalizationScriptFor(Script script)
 {
     if (localizationManager.IsSourceLocaleSelected() || !localizationScripts.ContainsKey(script.Name))
     {
         return(null);
     }
     return(localizationScripts[script.Name]);
 }