示例#1
0
        public GUIBase_FontBase GetFont(SystemLanguage inLanguage)
        {
            GUIBase_FontBase font = m_Default.m_Font;

            switch (inLanguage)
            {
            case SystemLanguage.English:
                break;                 // english is default...

            case SystemLanguage.German:
                font = m_German.m_Font;
                break;

            case SystemLanguage.French:
                font = m_French.m_Font;
                break;

            case SystemLanguage.Italian:
                font = m_Italian.m_Font;
                break;

            case SystemLanguage.Spanish:
                font = m_Spanish.m_Font;
                break;

            case SystemLanguage.Russian:
                font = m_Russian.m_Font;
                break;

            case SystemLanguage.Chinese:
                font = m_Chinese.m_Font;
                break;

            case SystemLanguage.Japanese:
                font = m_Japanese.m_Font;
                break;

            case SystemLanguage.Korean:
                font = m_Korean.m_Font;
                break;

            default:
                break;
            }

            if (font == null)
            {
                font = m_Default.m_Font;
            }

            return(font);
        }
示例#2
0
    void ChangeFont(GUIBase_FontBase inNewFont)
    {
        // destroy old text if any exist...
        m_FontXXX = inNewFont;
        SetRegenerationNeeded();

#if UNITY_EDITOR
        // this code can be only in editor. In real game m_Widget property has to be setup in start function...
        m_Widget = m_Widget ?? GetComponent <GUIBase_Widget>();
#endif

        m_Widget.ChangeMaterial(m_FontXXX.fontMaterial);
    }
示例#3
0
    public static Vector3 SetupCursorForTextAlign(Vector3 inCursor,
                                                  string inText,
                                                  int inStartIndex,
                                                  TextAlignment inAlignment,
                                                  GUIBase_FontBase inFont,
                                                  float inLineBegin,
                                                  float inMaxlineWidth,
                                                  float inScale)
    {
        Vector3 cursor = inCursor;

        cursor.x = inLineBegin;

        if (inAlignment != TextAlignment.Left)
        {
            float curLineWidth = GetCurentTextLineWidth(inText, inStartIndex, inFont);
            float span         = (inMaxlineWidth - curLineWidth) * inScale;

            if (inAlignment == TextAlignment.Center)
            {
                cursor.x += span * 0.5f;
            }
            else if (inAlignment == TextAlignment.Right)
            {
                cursor.x += span;
            }
        }

        /*
         * switch (inAlignment)
         * {
         *      case TextAlignment.Left:
         *              cursor.x = inLineBegin;
         *              break;
         *      case TextAlignment.Center:
         *      {
         *              float curLineWidth = GetCurentTextLineWidth(inText, inStartIndex, m_Font);
         *              cursor.x = inLineBegin + (inMaxlineWidth - curLineWidth)*0.5f*inScale;
         *              break;
         *      }
         *      case TextAlignment.Right:
         *      {
         *              float curLineWidth = GetCurentTextLineWidth(inText, inStartIndex, m_Font);
         *              cursor.x = inLineBegin + (inMaxlineWidth - curLineWidth)*inScale;
         *              break;
         *      }
         * }*/

        return(cursor);
    }
示例#4
0
    static float GetCurentTextLineWidth(string inText, int inStartIndex, GUIBase_FontBase inFont)
    {
        // Get current line....
        int index = inText.IndexOf('\n', inStartIndex);
        int count = (index == -1) ? inText.Length - inStartIndex : index - inStartIndex;

        if (count <= 0)
        {
            return(-1);
        }

        string subString = inText.Substring(inStartIndex, count);

        // compute size of line...
        return(GetLineWidth(subString, inFont));
    }
示例#5
0
    // =========================================================================================================================
    // === internals ===========================================================================================================
    GUIBase_FontBase _GetFont(string inFontName, SystemLanguage inLanguage)
    {
        GUIBase_FontBase font = null;

        foreach (FontSetup setup in m_Fonts)
        {
            if (setup.m_FontName == inFontName)
            {
                font = setup.GetFont(inLanguage);
                break;
            }
        }

        if (font == null)
        {
            font = m_DefaultFont;
        }

        return(font);
    }
示例#6
0
    static float GetLineWidth(string subString, GUIBase_FontBase inFont)
    {
        float          lineWidth = 0;
        GUIBase_FontEx fontEx    = inFont as GUIBase_FontEx;
        GUIBase_Font   font      = inFont as GUIBase_Font;

        if (fontEx != null)
        {
            for (int i = 0; i < subString.Length; ++i)
            {
                lineWidth += fontEx.GetCharWidth((int)subString[i]);
            }
        }
        else
        {
            for (int i = 0; i < subString.Length; ++i)
            {
                lineWidth += font.GetCharWidth((int)subString[i]);
            }
        }
        return(lineWidth);
    }
示例#7
0
        public void Prepare(bool inLoad)
        {
            if (inLoad == false)
            {
                //DestroyObject(m_Font); /// ???
                m_Font = null;
            }
            else if (m_Font == null && string.IsNullOrEmpty(m_FontAssetPath) == false)
            {
                Debug.Log("Load asset from path: " + m_FontAssetPath);
                GameObject go = Resources.Load(m_FontAssetPath) as GameObject;

                if (go == null)
                {
                    Debug.LogWarning("Filed to load font! path=" + m_FontAssetPath);
                    return;
                }

                Debug.Log("GameObject go: " + go);
                m_Font = go.GetComponent <GUIBase_FontBase>();
            }
        }