public void OnLanguageChanged(string inNewLanguage) { if (m_Widget == null) { return; } string font_name = m_FontName; if (m_FontName == "Default") { font_name = "NewFont"; } GUIBase_FontEx newFont = null; if ("English.Old" == inNewLanguage) { newFont = MFFontManager.GetFont(m_FontName, SystemLanguage.English) as GUIBase_FontEx; } else { newFont = MFFontManager.GetFont(font_name) as GUIBase_FontEx; } if (newFont != m_Font) { m_Font = newFont; m_Widget.ChangeMaterial(m_Font.fontMaterial); } SetRegenerationNeeded(); }
public void OnLanguageChanged(string inNewLanguage) { if (m_Widget == null) { return; } if ("English.Old" == inNewLanguage) { ChangeFont(MFFontManager.GetFont("Default")); } else { string font_name = m_FontName; if (m_FontName == "Default") { font_name = "NewFont"; } ChangeFont(MFFontManager.GetFont(font_name)); } }
// ================================================================================================== // === Default MoneBehaviour interface ============================================================== #region MoneBehaviourInterface public void Start() { m_Widget = GetComponent <GUIBase_Widget>(); m_Widget.RegisterUpdateDelegate(RegenerateSprites); m_Widget.RegisterCallback(this, (int)E_CallbackType.E_CT_INIT); m_Widget.m_TextScaleFix_HACK = true; if (m_TextID <= 0 && string.IsNullOrEmpty(m_Text)) { m_Text = "This-is-temporary-test-for-testing-TextArea-auto-wrap. This is tooooooo long line. \n\n" + "This is temporary test for testing TextArea auto wrap. This is tooooooo long line. " + "This is temporary test for testing TextArea auto wrap. This is tooooooo long line."; //m_Text = "Test"; } if (m_Font == null) { //m_Font = MFGuiManager.Instance.GetFontForLanguage(SystemLanguage.English); m_Font = MFFontManager.GetFont(m_FontName) as GUIBase_FontEx; } SetRegenerationNeeded(); }
//--------------------------------------------------------- void RegenerateSprites() { if (m_RegenerateSprites == false || m_Widget.IsVisible() == false) { return; } if (m_Font == null) { m_Font = MFFontManager.GetFont(m_FontName) as GUIBase_FontEx; if (m_Font == null) { Debug.LogError(gameObject.GetFullName() + " Can't load font with name " + m_FontName); return; } } if (m_TextID > 0) { m_Text = TextDatabase.instance[m_TextID]; } // destroy old text if any exist... int maxSprites = text != null && text.Length > 0 ? Mathf.CeilToInt(text.Length * 0.1f) * 10 : 0; m_Widget.PrepareSprites(maxSprites); if (text != null && text.Length > 0) { Vector3 scale = transform.lossyScale; scale = Vector3.one; // setup cursor ... Vector2 leftUpPos = new Vector2(m_Widget.GetOrigPos().x - m_Widget.GetWidth() * 0.5f * scale.x, m_Widget.GetOrigPos().y - m_Widget.GetHeight() * 0.5f * scale.y); Vector2 cursor = leftUpPos; float maxLineSize = m_Widget.GetWidth() * scale.x; scale.x = m_TextScale.x; scale.y = m_TextScale.y; List <TextLine> textLines = GetLines(text, m_Font, alignment, maxLineSize, scale, lineSpace, IsForTextField); if (textLines == null || textLines.Count <= 0) { return; } float fontHeight = m_Font.GetFontHeight(); m_TextSize = new Vector2(m_Widget.GetWidth(), textLines.Count * fontHeight * scale.y + (textLines.Count - 1) * lineSpace * fontHeight * scale.y); float width; Rect spriteRect, texRect; int spriteIdx = 0; foreach (TextLine line in textLines) { cursor = leftUpPos + line.m_Offset; for (int i = line.m_StartIndex; i < line.m_EndIndex; ++i) { int character = text[i]; if (!IsForTextField && character == ' ') { cursor.x += line.m_SpaceWidth; continue; } switch (character) { case '\n': Debug.LogWarning("function GetLines doesn't work correctly"); break; default: { if (m_Font.GetCharDescription(text[i], out width, out spriteRect, out texRect, false, false, false)) { Vector2 inCharSize = new Vector2(spriteRect.width * scale.x, spriteRect.height * scale.y); Vector2 inCharCenter = cursor + new Vector2(spriteRect.center.x * scale.x, 0.0f); m_Widget.SetTextureCoords(spriteIdx, (int)texRect.x, (int)texRect.y, (int)texRect.width, (int)texRect.height); m_Widget.UpdateSpritePosAndSize(spriteIdx, inCharCenter.x, inCharCenter.y, inCharSize.x, inCharSize.y); m_Widget.ShowSprite(spriteIdx, true); cursor.x += width * scale.x; spriteIdx++; } break; } } } } // hide all unused sprites while (spriteIdx < maxSprites) { m_Widget.SetTextureCoords(spriteIdx, 0.0f, 0.0f, 0.0f, 0.0f); m_Widget.UpdateSpritePosAndSize(spriteIdx, 0.0f, -Screen.height, 1.0f, 1.0f); m_Widget.ShowSprite(spriteIdx, false); spriteIdx++; } } // we have to force widget update. m_RegenerateSprites = false; m_Widget.SetModify(); }