コード例 #1
0
        private void SetLanguageTypeSettings(LanguageTypeSettings settings)
        {
            var data = settings.fontAssetData;

            if (!fixedFontAsset)
            {
                Text.font = data.FontAsset;
                if (L10nManager.TryGetFontMaterial(fontMaterialType, out var fontMaterial))
                {
                    Text.fontSharedMaterial = fontMaterial;
                }
            }

            if (!fixedFontStyle)
            {
                var mask = ~FontStyles.Normal;
                if (data.SetFontStyleBoldToDisabledAsForced)
                {
                    mask &= ~FontStyles.Bold;
                }

                Text.fontStyle = defaultFontStyles & mask;
            }

            if (!fixedFontSizeOffset)
            {
                Text.fontSize = defaultFontSize + data.FontSizeOffset;
            }

            if (!fixedSpacingOption)
            {
                Text.characterSpacing = defaultCharacterSpacing + data.CharacterSpacingOffset;
                Text.wordSpacing      = defaultWordSpacing + data.WordSpacingOffset;
                Text.lineSpacing      = defaultLineSpacing + data.LineSpacingOffset;
            }
        }
コード例 #2
0
        private void Awake()
        {
            if (!fontMaterialIndexInitialized)
            {
                fontMaterialIndex = Text.fontMaterials
                                    .ToList()
                                    .IndexOf(Text.fontMaterial);
                fontMaterialIndexInitialized = true;
            }

            if (!defaultFontStylesInitialized)
            {
                defaultFontStyles            = Text.fontStyle;
                defaultFontStylesInitialized = true;
            }

            if (!defaultFontSizeInitialized)
            {
                defaultFontSize            = Text.fontSize;
                defaultFontSizeInitialized = true;
            }

            if (!defaultCharacterSpacingInitialized)
            {
                defaultCharacterSpacing            = Text.characterSpacing;
                defaultCharacterSpacingInitialized = true;
            }

            if (!defaultWordSpacingInitialized)
            {
                defaultWordSpacing            = Text.wordSpacing;
                defaultWordSpacingInitialized = true;
            }

            if (!defaultLineSpacingInitialized)
            {
                defaultLineSpacing            = Text.lineSpacing;
                defaultWordSpacingInitialized = true;
            }

            if (L10nManager.CurrentState == L10nManager.State.Initialized)
            {
                SetLanguageTypeSettings(L10nManager.CurrentLanguageTypeSettings);
                SubscribeLanguageChange();
            }
            else
            {
                L10nManager.OnInitialize
                .Subscribe(_ =>
                {
                    SetLanguageTypeSettings(L10nManager.CurrentLanguageTypeSettings);
                    SubscribeLanguageChange();
                })
                .AddTo(gameObject);
            }

            if (!string.IsNullOrEmpty(l10nKey))
            {
                Text.text = L10nManager.Localize(l10nKey);
            }
        }