using System; using I2.Loc; using UnityEngine; using UnityEngine.Events; [DisallowMultipleComponent] [RequireComponent(typeof(Localize))] [RequireComponent(typeof(UILabel))] public class NGUILabelLocalizeSupport : MonoBehaviour { public NGUILabelLocalizeSupport() { NGUILabelLocalizeSupport.OverRideProperty overRideProperty = default(NGUILabelLocalizeSupport.OverRideProperty); overRideProperty.overFlow.enabled = true; overRideProperty.overFlow.value = UILabel.Overflow.ShrinkContent; overRideProperty.SpacingX.enabled = true; overRideProperty.SpacingY.enabled = true; this.overRidePropertys = overRideProperty; base..ctor(); } private void Awake() { if (this.callAwake) { return; } this.callAwake = true; this.localize = base.GetComponent(); this.label = base.GetComponent(); if (this.localize != null && this.label != null) { this.localize.LocalizeEvent.AddListener(new UnityAction(this.OnLocalize)); this.holdOverflow = this.label.overflowMethod; this.holdAlignment = this.label.alignment; this.holdFontSize = this.label.fontSize; if (this.label.useFloatSpacing) { this.holdSpacingX = this.label.floatSpacingX; this.holdSpacingY = this.label.floatSpacingY; } else { this.holdSpacingX = (float)this.label.spacingX; this.holdSpacingY = (float)this.label.spacingY; } this.holdWidgetSizeX = this.label.width; this.holdWidgetSizeY = this.label.height; this.holdMaxLines = this.label.maxLineCount; this.updateReq = true; this.OnLocalize(); } } public void OnLocalize() { if (!this.callAwake) { this.Awake(); } if (!this.updateReq) { return; } if (LocalizationManager.CurrentLanguageCode == "ja") { if (this.holdOverflow != UILabel.Overflow.ResizeFreely) { this.label.width = this.holdWidgetSizeX; } if (this.holdOverflow != UILabel.Overflow.ResizeHeight) { this.label.height = this.holdWidgetSizeY; } this.label.fontSize = this.holdFontSize; if (this.label.useFloatSpacing) { this.label.floatSpacingX = this.holdSpacingX; this.label.floatSpacingY = this.holdSpacingY; } else { this.label.spacingX = (int)this.holdSpacingX; this.label.spacingY = (int)this.holdSpacingY; } this.label.maxLineCount = this.holdMaxLines; this.label.alignment = this.holdAlignment; this.label.overflowMethod = this.holdOverflow; } else { this.Apply(this.overRidePropertys); if (this.languageOverRidePropertys != null) { foreach (NGUILabelLocalizeSupport.LanguageOverRideProperty languageOverRideProperty in this.languageOverRidePropertys) { if (languageOverRideProperty.LanguageCode == LocalizationManager.CurrentLanguageCode) { this.Apply(languageOverRideProperty.Property); break; } } } } } public void Apply(NGUILabelLocalizeSupport.OverRideProperty property) { UILabel.Overflow overflow = (!property.overFlow.enabled) ? this.holdOverflow : property.overFlow.value; if (overflow != UILabel.Overflow.ResizeFreely) { this.label.width = ((!property.widgetSizeX.enabled) ? this.holdWidgetSizeX : property.widgetSizeX.value); } if (overflow != UILabel.Overflow.ResizeHeight) { this.label.height = ((!property.widgetSizeY.enabled) ? this.holdWidgetSizeY : property.widgetSizeY.value); } this.label.fontSize = ((!property.fontSize.enabled) ? this.holdFontSize : property.fontSize.value); if (property.SpacingX.enabled) { if (this.label.useFloatSpacing) { this.label.floatSpacingX = (float)property.SpacingX.value; } else { this.label.spacingX = property.SpacingX.value; } } else if (this.label.useFloatSpacing) { this.label.floatSpacingX = this.holdSpacingX; } else { this.label.spacingX = (int)this.holdSpacingX; } if (property.SpacingY.enabled) { if (this.label.useFloatSpacing) { this.label.floatSpacingY = (float)property.SpacingY.value; } else { this.label.spacingY = property.SpacingY.value; } } else if (this.label.useFloatSpacing) { this.label.floatSpacingY = this.holdSpacingY; } else { this.label.spacingY = (int)this.holdSpacingY; } this.label.maxLineCount = ((!property.maxLines.enabled) ? this.holdMaxLines : property.maxLines.value); this.label.alignment = ((!property.alignment.enabled) ? this.holdAlignment : property.alignment.value); this.label.overflowMethod = overflow; } [SerializeField] public NGUILabelLocalizeSupport.OverRideProperty overRidePropertys; [SerializeField] public NGUILabelLocalizeSupport.LanguageOverRideProperty[] languageOverRidePropertys; private UILabel.Overflow holdOverflow; private NGUIText.Alignment holdAlignment; private int holdFontSize; private float holdSpacingX; private float holdSpacingY; private int holdWidgetSizeX; private int holdWidgetSizeY; private int holdMaxLines; private bool updateReq; private bool callAwake; private Localize localize; private UILabel label; [Serializable] public struct OverRideProperty { public NGUILabelLocalizeSupport.OverRideProperty.OverflowValue overFlow; public NGUILabelLocalizeSupport.OverRideProperty.AlignmentValue alignment; public NGUILabelLocalizeSupport.OverRideProperty.IntValue fontSize; public NGUILabelLocalizeSupport.OverRideProperty.IntValue SpacingX; public NGUILabelLocalizeSupport.OverRideProperty.IntValue SpacingY; public NGUILabelLocalizeSupport.OverRideProperty.IntValue widgetSizeX; public NGUILabelLocalizeSupport.OverRideProperty.IntValue widgetSizeY; public NGUILabelLocalizeSupport.OverRideProperty.IntValue maxLines; [Serializable] public struct IntValue { public bool enabled; public int value; } [Serializable] public struct OverflowValue { public bool enabled; public UILabel.Overflow value; } [Serializable] public struct AlignmentValue { public bool enabled; public NGUIText.Alignment value; } } [Serializable] public struct LanguageOverRideProperty { public string LanguageCode; public NGUILabelLocalizeSupport.OverRideProperty Property; } }