/// <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 curely braces, attempt to extract the value
        /// from a custom variable.
        /// </remarks>
        public string GetDisplayName(string characterId)
        {
            if (string.IsNullOrWhiteSpace(characterId))
            {
                return(null);
            }

            var displayName = default(string);

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

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

            if (!string.IsNullOrEmpty(displayName) && displayName.StartsWithFast("{") && displayName.EndsWithFast("}"))
            {
                var customVarName = displayName.GetAfterFirst("{").GetBeforeLast("}");
                if (!customVariableManager.VariableExists(customVarName))
                {
                    Debug.LogWarning($"Failed to retrieve `{customVarName}` custom variable binded to `{characterId}` character display name.");
                    return(null);
                }
                displayName = customVariableManager.GetVariableValue(customVarName);
            }

            return(string.IsNullOrEmpty(displayName) ? null : displayName);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Attempts to retrieve value of a variable with the provided name and type. Variable names are case-insensitive.
        /// When no variables of the provided name are found or when the string value can't be parsed to the requested type, will return false.
        /// </summary>
        public static bool TryGetVariableValue <TValue> (this ICustomVariableManager manager, string name, out TValue value)
        {
            value = default;
            var stringValue = manager.GetVariableValue(name);

            if (stringValue is null)
            {
                return(false);
            }

            var objValue = CustomVariablesConfiguration.ParseVariableValue(stringValue);

            if (objValue is TValue)
            {
                value = (TValue)objValue;
                return(true);
            }

            return(false);
        }
Exemplo n.º 3
0
 private void ConvertDate() => convertedDate = DateTime.Parse(varMan.GetVariableValue(date));