using System; using UnityEngine; namespace I2.Loc { public class LocalizeTarget_UnityStandard_GUIText : LocalizeTarget { static LocalizeTarget_UnityStandard_GUIText() { LocalizeTarget_UnityStandard_GUIText.AutoRegister(); } [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] private static void AutoRegister() { LocalizationManager.RegisterTarget(new LocalizeTargetDesc_Type { Name = "GUIText", Priority = 100 }); } public override eTermType GetPrimaryTermType(Localize cmp) { return eTermType.Text; } public override eTermType GetSecondaryTermType(Localize cmp) { return eTermType.Font; } public override bool CanUseSecondaryTerm() { return true; } public override bool AllowMainTermToBeRTL() { return true; } public override bool AllowSecondTermToBeRTL() { return false; } public override void GetFinalTerms(Localize cmp, string Main, string Secondary, out string primaryTerm, out string secondaryTerm) { primaryTerm = ((!this.mTarget) ? null : this.mTarget.text); secondaryTerm = ((!string.IsNullOrEmpty(Secondary) || !(this.mTarget.font != null)) ? null : this.mTarget.font.name); } public override void DoLocalize(Localize cmp, string mainTranslation, string secondaryTranslation) { Font secondaryTranslatedObj = cmp.GetSecondaryTranslatedObj(ref mainTranslation, ref secondaryTranslation); if (secondaryTranslatedObj != null && this.mTarget.font != secondaryTranslatedObj) { this.mTarget.font = secondaryTranslatedObj; } if (this.mInitializeAlignment) { this.mInitializeAlignment = false; this.mAlignment_LTR = (this.mAlignment_RTL = this.mTarget.alignment); if (LocalizationManager.IsRight2Left && this.mAlignment_RTL == TextAlignment.Right) { this.mAlignment_LTR = TextAlignment.Left; } if (!LocalizationManager.IsRight2Left && this.mAlignment_LTR == TextAlignment.Left) { this.mAlignment_RTL = TextAlignment.Right; } } if (mainTranslation != null && this.mTarget.text != mainTranslation) { if (cmp.CorrectAlignmentForRTL && this.mTarget.alignment != TextAlignment.Center) { this.mTarget.alignment = ((!LocalizationManager.IsRight2Left) ? this.mAlignment_LTR : this.mAlignment_RTL); } this.mTarget.text = mainTranslation; } } private TextAlignment mAlignment_RTL = TextAlignment.Right; private TextAlignment mAlignment_LTR; private bool mAlignmentWasRTL; private bool mInitializeAlignment = true; } }