using System; using System.Collections.Generic; using UnityEngine; namespace I2.Loc { public class LocalizeTarget_NGUI_Label : LocalizeTarget { static LocalizeTarget_NGUI_Label() { LocalizeTarget_NGUI_Label.AutoRegister(); } [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] private static void AutoRegister() { LocalizationManager.RegisterTarget(new LocalizeTargetDesc_Type { Name = "NGUI Label", Priority = 100 }); } public override eTermType GetPrimaryTermType(Localize cmp) { return eTermType.Text; } public override eTermType GetSecondaryTermType(Localize cmp) { return eTermType.UIFont; } 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 = ((!(this.mTarget.ambigiousFont != null)) ? string.Empty : this.mTarget.ambigiousFont.name); } public override void DoLocalize(Localize cmp, string mainTranslation, string secondaryTranslation) { Font secondaryTranslatedObj = cmp.GetSecondaryTranslatedObj(ref mainTranslation, ref secondaryTranslation); if (secondaryTranslatedObj != null) { if (secondaryTranslatedObj != this.mTarget.ambigiousFont) { this.mTarget.ambigiousFont = secondaryTranslatedObj; } } else { UIFont secondaryTranslatedObj2 = cmp.GetSecondaryTranslatedObj(ref mainTranslation, ref secondaryTranslation); if (secondaryTranslatedObj2 != null && this.mTarget.ambigiousFont != secondaryTranslatedObj2) { this.mTarget.ambigiousFont = secondaryTranslatedObj2; } } if (this.mInitializeAlignment) { this.mInitializeAlignment = false; this.mAlignment_LTR = (this.mAlignment_RTL = this.mTarget.alignment); if (LocalizationManager.IsRight2Left && this.mAlignment_RTL == NGUIText.Alignment.Right) { this.mAlignment_LTR = NGUIText.Alignment.Left; } if (!LocalizationManager.IsRight2Left && this.mAlignment_LTR == NGUIText.Alignment.Left) { this.mAlignment_RTL = NGUIText.Alignment.Right; } } UIInput uiinput = NGUITools.FindInParents(this.mTarget.gameObject); if (uiinput != null && uiinput.label == this.mTarget) { if (mainTranslation != null && uiinput.defaultText != mainTranslation) { if (cmp.CorrectAlignmentForRTL && (uiinput.label.alignment == NGUIText.Alignment.Left || uiinput.label.alignment == NGUIText.Alignment.Right)) { uiinput.label.alignment = ((!LocalizationManager.IsRight2Left) ? this.mAlignment_LTR : this.mAlignment_RTL); } uiinput.defaultText = mainTranslation; } } else if (mainTranslation != null && this.mTarget.text != mainTranslation) { if (cmp.CorrectAlignmentForRTL && (this.mTarget.alignment == NGUIText.Alignment.Left || this.mTarget.alignment == NGUIText.Alignment.Right)) { this.mTarget.alignment = ((!LocalizationManager.IsRight2Left) ? this.mAlignment_LTR : this.mAlignment_RTL); } if (((!this.mTarget.useFloatSpacing && (this.mTarget.spacingX != 0 || this.mTarget.spacingY != 0)) || (this.mTarget.useFloatSpacing && (this.mTarget.floatSpacingX != 0f || this.mTarget.floatSpacingY != 0f))) && cmp.gameObject.GetComponent() == null) { NGUILabelLocalizeSupport nguilabelLocalizeSupport = cmp.gameObject.AddComponent(); if (!cmp.ForceOverFlowShrink) { nguilabelLocalizeSupport.overRidePropertys.overFlow.enabled = false; } } if (cmp.ForceOverFlowShrink && cmp.gameObject.GetComponent() == null) { cmp.gameObject.AddComponent(); } if (!string.IsNullOrEmpty(mainTranslation) && cmp.mTermArgs != null && 0 < cmp.mTermArgs.Length) { List list = new List(); for (int i = 0; i < cmp.mTermArgs.Length; i++) { string text = cmp.mTermArgs[i].text; if (!cmp.mTermArgs[i].isTerm) { if (text.IndexOf('{') != -1 && text.IndexOf('}') != -1) { mainTranslation += text; } else { list.Add(text); } } else { list.Add((text == null) ? string.Empty : LocalizationManager.GetTranslation(text, false, 0, true, false, null, null)); } } mainTranslation = string.Format(mainTranslation, list.ToArray()); } this.mTarget.text = mainTranslation; } } private NGUIText.Alignment mAlignment_RTL = NGUIText.Alignment.Right; private NGUIText.Alignment mAlignment_LTR = NGUIText.Alignment.Left; private bool mAlignmentWasRTL; private bool mInitializeAlignment = true; } }