예제 #1
0
        public override void DoLocalize(Localize cmp, string mainTranslation, string secondaryTranslation)
        {
            //--[ Localize Font Object ]----------
            {
                TMPro.TMP_FontAsset newFont = cmp.GetSecondaryTranslatedObj <TMPro.TMP_FontAsset>(ref mainTranslation, ref secondaryTranslation);

                if (newFont != null)
                {
                    if (mTarget.font != newFont)
                    {
                        mTarget.font = newFont;
                    }
                }
                else
                {
                    //--[ Localize Font Material ]----------
                    Material newMat = cmp.GetSecondaryTranslatedObj <Material>(ref mainTranslation, ref secondaryTranslation);
                    if (newMat != null && mTarget.fontMaterial != newMat)
                    {
                        if (!newMat.name.StartsWith(mTarget.font.name, StringComparison.Ordinal))
                        {
                            newFont = GetTMPFontFromMaterial(cmp, secondaryTranslation.EndsWith(newMat.name, StringComparison.Ordinal) ? secondaryTranslation : newMat.name);
                            if (newFont != null)
                            {
                                mTarget.font = newFont;
                            }
                        }

                        mTarget.fontSharedMaterial /* fontMaterial*/ = newMat;
                    }
                }
            }
            if (mInitializeAlignment)
            {
                mInitializeAlignment = false;
                mAlignmentWasRTL     = LocalizationManager.IsRight2Left;
                InitAlignment_TMPro(mAlignmentWasRTL, mTarget.alignment, out mAlignment_LTR, out mAlignment_RTL);
            }
            else
            {
                TMPro.TextAlignmentOptions alignRTL, alignLTR;
                InitAlignment_TMPro(mAlignmentWasRTL, mTarget.alignment, out alignLTR, out alignRTL);

                if ((mAlignmentWasRTL && mAlignment_RTL != alignRTL) ||
                    (!mAlignmentWasRTL && mAlignment_LTR != alignLTR))
                {
                    mAlignment_LTR = alignLTR;
                    mAlignment_RTL = alignRTL;
                }
                mAlignmentWasRTL = LocalizationManager.IsRight2Left;
            }

            if (mainTranslation != null && mTarget.text != mainTranslation)
            {
                if (mainTranslation != null && cmp.CorrectAlignmentForRTL)
                {
                    mTarget.alignment         = (LocalizationManager.IsRight2Left ? mAlignment_RTL : mAlignment_LTR);
                    mTarget.isRightToLeftText = LocalizationManager.IsRight2Left;
                    if (LocalizationManager.IsRight2Left)
                    {
                        mainTranslation = I2Utils.ReverseText(mainTranslation);
                    }
                }

                mTarget.text = mainTranslation;
            }
        }
예제 #2
0
 /// <summary>
 /// for adding an TMP_FontAsset directly
 /// </summary>
 /// <param name="fontAsset">The loaded fontasset</param>
 public static void Add(TMPro.TMP_FontAsset fontAsset)
 {
     fontAssets.Add(fontAsset);
 }
예제 #3
0
        public void DoLocalize_TMPLabel(string MainTranslation, string SecondaryTranslation)
        {
            // there its a problem with TMPro that disables and renables the inspector when changing fonts, and that breaks the current preview flow
            if (!Application.isPlaying)
            {
                                #if UNITY_EDITOR
                if (UnityEditor.Selection.activeGameObject == gameObject)
                {
                    if (string.IsNullOrEmpty(TMP_previewLanguage))
                    {
                        TMP_previewLanguage = LocalizationManager.CurrentLanguage;
                    }
                }
                                #endif
            }

            //--[ Localize Font Object ]----------
            {
                                #if TextMeshPro_Pre53
                TMPro.TextMeshProFont newFont = GetSecondaryTranslatedObj <TMPro.TextMeshProFont>(ref MainTranslation, ref SecondaryTranslation);
                                #else
                TMPro.TMP_FontAsset newFont = GetSecondaryTranslatedObj <TMPro.TMP_FontAsset>(ref MainTranslation, ref SecondaryTranslation);
                                #endif


                if (newFont != null)
                {
                    if (mTarget_TMPLabel.font != newFont)
                    {
                        mTarget_TMPLabel.font = newFont;
                    }
                }
                else
                {
                    //--[ Localize Font Material ]----------
                    Material newMat = GetSecondaryTranslatedObj <Material>(ref MainTranslation, ref SecondaryTranslation);
                    if (newMat != null && mTarget_TMPLabel.fontMaterial != newMat)
                    {
                        mTarget_TMPLabel.fontMaterial = newMat;
                    }
                }
            }
            if (mInitializeAlignment)
            {
                mInitializeAlignment    = false;
                mOriginalAlignmentTMPro = mTarget_TMPLabel.alignment;
            }

            if (!string.IsNullOrEmpty(MainTranslation) && mTarget_TMPLabel.text != MainTranslation)
            {
                if (Localize.CurrentLocalizeComponent.CorrectAlignmentForRTL)
                {
                    if (mTarget_TMPLabel.alignment <= TMPro.TextAlignmentOptions.TopJustified)
                    {
                        mTarget_TMPLabel.alignment = LocalizationManager.IsRight2Left ? TMPro.TextAlignmentOptions.TopRight : mOriginalAlignmentTMPro;
                    }
                    else
                    if (mTarget_TMPLabel.alignment <= TMPro.TextAlignmentOptions.Justified)
                    {
                        mTarget_TMPLabel.alignment = LocalizationManager.IsRight2Left ? TMPro.TextAlignmentOptions.Right : mOriginalAlignmentTMPro;
                    }
                    else
                    {
                        mTarget_TMPLabel.alignment = LocalizationManager.IsRight2Left ? TMPro.TextAlignmentOptions.BottomRight : mOriginalAlignmentTMPro;
                    }
                }

                mTarget_TMPLabel.text = MainTranslation;
                mTarget_TMPLabel.ForceMeshUpdate();
            }
        }
예제 #4
0
        public void DoLocalize_TMPLabel(string MainTranslation, string SecondaryTranslation)
        {
            // there its a problem with TMPro that disables and renables the inspector when changing fonts, and that breaks the current preview flow
            if (!Application.isPlaying)
            {
                                #if UNITY_EDITOR
                if (UnityEditor.Selection.activeGameObject == gameObject)
                {
                    if (string.IsNullOrEmpty(TMP_previewLanguage))
                    {
                        TMP_previewLanguage = LocalizationManager.CurrentLanguage;
                    }
                }
                                #endif
            }

            //--[ Localize Font Object ]----------
            {
                                #if TextMeshPro_Pre53
                TMPro.TextMeshProFont newFont = GetSecondaryTranslatedObj <TMPro.TextMeshProFont>(ref MainTranslation, ref SecondaryTranslation);
                                #else
                TMPro.TMP_FontAsset newFont = GetSecondaryTranslatedObj <TMPro.TMP_FontAsset>(ref MainTranslation, ref SecondaryTranslation);
                                #endif


                if (newFont != null)
                {
                    if (mTarget_TMPLabel.font != newFont)
                    {
                        mTarget_TMPLabel.font = newFont;
                    }
                }
                else
                {
                    //--[ Localize Font Material ]----------
                    Material newMat = GetSecondaryTranslatedObj <Material>(ref MainTranslation, ref SecondaryTranslation);
                    if (newMat != null && mTarget_TMPLabel.fontMaterial != newMat)
                    {
                        if (!newMat.name.StartsWith(mTarget_TMPLabel.font.name))
                        {
                            newFont = GetTMPFontFromMaterial(newMat.name);
                            if (newFont != null)
                            {
                                mTarget_TMPLabel.font = newFont;
                            }
                        }

                        mTarget_TMPLabel.fontSharedMaterial /* fontMaterial*/ = newMat;
                    }
                }
            }
            if (mInitializeAlignment)
            {
                mInitializeAlignment = false;
                InitAlignment_TMPro(mTarget_TMPLabel.alignment, out mAlignmentTMPro_LTR, out mAlignmentTMPro_RTL);
            }

            if (!string.IsNullOrEmpty(MainTranslation) && mTarget_TMPLabel.text != MainTranslation)
            {
                if (Localize.CurrentLocalizeComponent.CorrectAlignmentForRTL)
                {
                    mTarget_TMPLabel.alignment = LocalizationManager.IsRight2Left ? mAlignmentTMPro_RTL : mAlignmentTMPro_LTR;
                }

                mTarget_TMPLabel.text = MainTranslation;
                //mTarget_TMPLabel.SetText( MainTranslation, 0 );
            }
        }
예제 #5
0
        public void DoLocalize_TMPUGUILabel(string MainTranslation, string SecondaryTranslation)
        {
            {
                //--[ Localize Font Object ]----------
                                #if TextMeshPro_Pre53
                TMPro.TextMeshProFont newFont = GetSecondaryTranslatedObj <TMPro.TextMeshProFont>(ref MainTranslation, ref SecondaryTranslation);
                                #else
                TMPro.TMP_FontAsset newFont = GetSecondaryTranslatedObj <TMPro.TMP_FontAsset>(ref MainTranslation, ref SecondaryTranslation);
                                #endif

                if (newFont != null)
                {
                    if (mTarget_TMPUGUILabel.font != newFont)
                    {
                        mTarget_TMPUGUILabel.font = newFont;
                    }
                }
                else
                {
                    //--[ Localize Font Material ]----------
                    Material newMat = GetSecondaryTranslatedObj <Material>(ref MainTranslation, ref SecondaryTranslation);
                    if (newMat != null && mTarget_TMPUGUILabel.fontMaterial != newMat)
                    {
                        if (!newMat.name.StartsWith(mTarget_TMPUGUILabel.font.name))
                        {
                            newFont = GetTMPFontFromMaterial(newMat.name);
                            if (newFont != null)
                            {
                                mTarget_TMPUGUILabel.font = newFont;
                            }
                        }
                        mTarget_TMPUGUILabel.fontSharedMaterial = newMat;
                    }
                }
            }
            if (mInitializeAlignment)
            {
                mInitializeAlignment    = false;
                mOriginalAlignmentTMPro = mTarget_TMPUGUILabel.alignment;
            }
            if (!string.IsNullOrEmpty(MainTranslation) && mTarget_TMPUGUILabel.text != MainTranslation)
            {
                if (Localize.CurrentLocalizeComponent.CorrectAlignmentForRTL)
                {
                    if (mTarget_TMPUGUILabel.alignment <= TMPro.TextAlignmentOptions.TopJustified)
                    {
                        mTarget_TMPUGUILabel.alignment = LocalizationManager.IsRight2Left ? TMPro.TextAlignmentOptions.TopRight : mOriginalAlignmentTMPro;
                    }
                    else
                    if (mTarget_TMPUGUILabel.alignment <= TMPro.TextAlignmentOptions.Justified)
                    {
                        mTarget_TMPUGUILabel.alignment = LocalizationManager.IsRight2Left ? TMPro.TextAlignmentOptions.Right : mOriginalAlignmentTMPro;
                    }
                    else
                    {
                        mTarget_TMPUGUILabel.alignment = LocalizationManager.IsRight2Left ? TMPro.TextAlignmentOptions.BottomRight : mOriginalAlignmentTMPro;
                    }
                }
                mTarget_TMPUGUILabel.text = MainTranslation;
                //mTarget_TMPUGUILabel.SetText(MainTranslation, 0);
            }
        }
예제 #6
0
        public void SetupButton(eButtonType buttonType, ConversationNode node, TMPro.TMP_FontAsset continueFont = null, TMPro.TMP_FontAsset endFont = null)
        {
            m_buttonType = buttonType;
            m_node       = node;

            switch (m_buttonType)
            {
            case eButtonType.Option:
            {
                TextMesh.text = node.Text;
                TextMesh.font = node.TMPFont;
            }
            break;

            case eButtonType.Speech:
            {
                TextMesh.text = "Continue.";
                TextMesh.font = continueFont;
            }
            break;

            case eButtonType.End:
            {
                TextMesh.text = "End.";
                TextMesh.font = endFont;
            }
            break;
            }
        }
예제 #7
0
        public void DoLocalize_TMPLabel(string mainTranslation, string secondaryTranslation)
        {
            // there its a problem with TMPro that disables and renables the inspector when changing fonts, and that breaks the current preview flow
            if (!Application.isPlaying)
            {
                                #if UNITY_EDITOR
                if (UnityEditor.Selection.activeGameObject == gameObject)
                {
                    if (string.IsNullOrEmpty(TMP_previewLanguage))
                    {
                        TMP_previewLanguage = LocalizationManager.CurrentLanguage;
                    }
                }
                                #endif
            }

            //--[ Localize Font Object ]----------
            {
                                #if TextMeshPro_Pre53
                TMPro.TextMeshProFont newFont = GetSecondaryTranslatedObj <TMPro.TextMeshProFont>(ref mainTranslation, ref secondaryTranslation);
                                #else
                TMPro.TMP_FontAsset newFont = GetSecondaryTranslatedObj <TMPro.TMP_FontAsset>(ref mainTranslation, ref secondaryTranslation);
                                #endif


                if (newFont != null)
                {
                    if (mTarget_TMPLabel.font != newFont)
                    {
                        mTarget_TMPLabel.font = newFont;
                    }
                }
                else
                {
                    //--[ Localize Font Material ]----------
                    Material newMat = GetSecondaryTranslatedObj <Material>(ref mainTranslation, ref secondaryTranslation);
                    if (newMat != null && mTarget_TMPLabel.fontMaterial != newMat)
                    {
                        if (!newMat.name.StartsWith(mTarget_TMPLabel.font.name, StringComparison.Ordinal))
                        {
                            newFont = GetTMPFontFromMaterial(secondaryTranslation.EndsWith(newMat.name, StringComparison.Ordinal) ? secondaryTranslation : newMat.name);
                            if (newFont != null)
                            {
                                mTarget_TMPLabel.font = newFont;
                            }
                        }

                        mTarget_TMPLabel.fontSharedMaterial = newMat;
                    }
                }
            }
            if (mInitializeAlignment)
            {
                mInitializeAlignment = false;
                mAlignmentTMPwasRTL  = LocalizationManager.IsRight2Left;
                InitAlignment_TMPro(mAlignmentTMPwasRTL, mTarget_TMPLabel.alignment, out mAlignmentTMPro_LTR, out mAlignmentTMPro_RTL);
            }
            else
            {
                TMPro.TextAlignmentOptions alignRTL, alignLTR;
                InitAlignment_TMPro(mAlignmentTMPwasRTL, mTarget_TMPLabel.alignment, out alignLTR, out alignRTL);

                if ((mAlignmentTMPwasRTL && mAlignmentTMPro_RTL != alignRTL) ||
                    (!mAlignmentTMPwasRTL && mAlignmentTMPro_LTR != alignLTR))
                {
                    mAlignmentTMPro_LTR = alignLTR;
                    mAlignmentTMPro_RTL = alignRTL;
                }
                mAlignmentTMPwasRTL = LocalizationManager.IsRight2Left;
            }

            if (mainTranslation != null && mTarget_TMPLabel.text != mainTranslation)
            {
                if (CurrentLocalizeComponent.CorrectAlignmentForRTL)
                {
                    mTarget_TMPLabel.alignment         = LocalizationManager.IsRight2Left ? mAlignmentTMPro_RTL : mAlignmentTMPro_LTR;
                    mTarget_TMPLabel.isRightToLeftText = LocalizationManager.IsRight2Left;
                    if (LocalizationManager.IsRight2Left)
                    {
                        mainTranslation = ReverseText(mainTranslation);
                    }
                }

                mTarget_TMPLabel.text = mainTranslation;
                //mTarget_TMPLabel.SetText( mainTranslation, 0 );
            }
        }
예제 #8
0
        public void DoLocalize_TMPUGUILabel(string mainTranslation, string secondaryTranslation)
        {
            {
                //--[ Localize Font Object ]----------
                                #if TextMeshPro_Pre53
                TMPro.TextMeshProFont newFont = GetSecondaryTranslatedObj <TMPro.TextMeshProFont>(ref mainTranslation, ref secondaryTranslation);
                                #else
                TMPro.TMP_FontAsset newFont = GetSecondaryTranslatedObj <TMPro.TMP_FontAsset>(ref mainTranslation, ref secondaryTranslation);
                                #endif

                if (newFont != null)
                {
                    if (mTarget_TMPUGUILabel.font != newFont)
                    {
                        mTarget_TMPUGUILabel.font = newFont;
                    }
                }
                else
                {
                    //--[ Localize Font Material ]----------
                    Material newMat = GetSecondaryTranslatedObj <Material>(ref mainTranslation, ref secondaryTranslation);
                    if (newMat != null && mTarget_TMPUGUILabel.fontMaterial != newMat)
                    {
                        if (!newMat.name.StartsWith(mTarget_TMPUGUILabel.font.name, StringComparison.Ordinal))
                        {
                            newFont = GetTMPFontFromMaterial(secondaryTranslation.EndsWith(newMat.name, StringComparison.Ordinal) ? secondaryTranslation : newMat.name);
                            if (newFont != null)
                            {
                                mTarget_TMPUGUILabel.font = newFont;
                            }
                        }
                        mTarget_TMPUGUILabel.fontSharedMaterial = newMat;
                    }
                }
            }

            if (mInitializeAlignment)
            {
                mInitializeAlignment = false;
                mAlignmentTMPwasRTL  = LocalizationManager.IsRight2Left;
                InitAlignment_TMPro(mAlignmentTMPwasRTL, mTarget_TMPUGUILabel.alignment, out mAlignmentTMPro_LTR, out mAlignmentTMPro_RTL);
            }
            else
            {
                TMPro.TextAlignmentOptions alignRTL, alignLTR;
                InitAlignment_TMPro(mAlignmentTMPwasRTL, mTarget_TMPUGUILabel.alignment, out alignLTR, out alignRTL);

                if ((mAlignmentTMPwasRTL && mAlignmentTMPro_RTL != alignRTL) ||
                    (!mAlignmentTMPwasRTL && mAlignmentTMPro_LTR != alignLTR))
                {
                    mAlignmentTMPro_LTR = alignLTR;
                    mAlignmentTMPro_RTL = alignRTL;
                }
                mAlignmentTMPwasRTL = LocalizationManager.IsRight2Left;
            }

            if (mainTranslation != null && mTarget_TMPUGUILabel.text != mainTranslation)
            {
                if (CurrentLocalizeComponent.CorrectAlignmentForRTL)
                {
                    mTarget_TMPUGUILabel.alignment         = LocalizationManager.IsRight2Left ? mAlignmentTMPro_RTL : mAlignmentTMPro_LTR;
                    mTarget_TMPUGUILabel.isRightToLeftText = LocalizationManager.IsRight2Left;
                    if (LocalizationManager.IsRight2Left)
                    {
                        mainTranslation = ReverseText(mainTranslation);
                    }
                }

                mTarget_TMPUGUILabel.text = mainTranslation;
                //mTarget_TMPUGUILabel.SetText(mainTranslation, 0);
            }
        }