Ejemplo n.º 1
0
    /// <summary>
    /// Convenience function -- mark all widgets using the sprite as changed.
    /// </summary>

    void MarkSpriteAsDirty()
    {
        if (mSprite == null)
        {
            return;
        }

        NGUISprite[] sprites = NGUITools.FindActive <NGUISprite>();

        foreach (NGUISprite sp in sprites)
        {
            if (sp.spriteName == mSprite.name)
            {
                sp.atlas = null;
                sp.atlas = mAtlas;
                EditorUtility.SetDirty(sp);
            }
        }

        NGUILabel[] labels = NGUITools.FindActive <NGUILabel>();

        foreach (NGUILabel lbl in labels)
        {
            if (lbl.font != null && NGUIAtlas.CheckIfRelated(lbl.font.atlas, mAtlas) && lbl.font.UsesSprite(mSprite.name))
            {
                NGUIFont font = lbl.font;
                lbl.font = null;
                lbl.font = font;
                EditorUtility.SetDirty(lbl);
            }
        }
    }
Ejemplo n.º 2
0
    static void CreateFont(NGUIFont font, int create, Material mat)
    {
        if (create == 1)
        {
            // New dynamic font
            font.atlas            = null;
            font.dynamicFont      = NGUISettings.dynamicFont;
            font.dynamicFontSize  = NGUISettings.dynamicFontSize;
            font.dynamicFontStyle = NGUISettings.dynamicFontStyle;
        }
        else
        {
            // New bitmap font
            font.dynamicFont = null;
            BMFontReader.Load(font.bmFont, NGUITools.GetHierarchy(font.gameObject), NGUISettings.fontData.bytes);

            if (create == 2)
            {
                font.atlas    = null;
                font.material = mat;
            }
            else if (create == 3)
            {
                font.spriteName = NGUISettings.fontTexture.name;
                font.atlas      = NGUISettings.atlas;
            }
        }
    }
Ejemplo n.º 3
0
    /// <summary>
    /// Draw the font preview window.
    /// </summary>

    public override void OnPreviewGUI(Rect rect, GUIStyle background)
    {
        mFont = target as NGUIFont;
        if (mFont == null)
        {
            return;
        }
        Texture2D tex = mFont.texture;

        if (mView != View.Nothing && tex != null)
        {
            Material m = (mUseShader ? mFont.material : null);

            if (mView == View.Font)
            {
                Rect outer = new Rect(mFont.uvRect);
                Rect uv    = outer;

                outer = NGUIMath.ConvertToPixels(outer, tex.width, tex.height, true);

                NGUIEditorTools.DrawSprite(tex, rect, outer, outer, uv, Color.white, m);
            }
            else
            {
                Rect outer = new Rect(0f, 0f, 1f, 1f);
                Rect inner = new Rect(mFont.uvRect);
                Rect uv    = outer;

                outer = NGUIMath.ConvertToPixels(outer, tex.width, tex.height, true);
                inner = NGUIMath.ConvertToPixels(inner, tex.width, tex.height, true);

                NGUIEditorTools.DrawSprite(tex, rect, outer, inner, uv, Color.white, m);
            }
        }
    }
Ejemplo n.º 4
0
    static void CreateFont(NGUIFont font, int create, Material mat)
    {
        if (create == 1)
        {
            // New dynamic font
            font.atlas = null;
            font.dynamicFont = NGUISettings.dynamicFont;
            font.dynamicFontSize = NGUISettings.dynamicFontSize;
            font.dynamicFontStyle = NGUISettings.dynamicFontStyle;
        }
        else
        {
            // New bitmap font
            font.dynamicFont = null;
            BMFontReader.Load(font.bmFont, NGUITools.GetHierarchy(font.gameObject), NGUISettings.fontData.bytes);

            if (create == 2)
            {
                font.atlas = null;
                font.material = mat;
            }
            else if (create == 3)
            {
                font.spriteName = NGUISettings.fontTexture.name;
                font.atlas = NGUISettings.atlas;
            }
        }
    }
Ejemplo n.º 5
0
    static void Load()
    {
        int l = LayerMask.NameToLayer("UI");

        if (l == -1)
        {
            l = LayerMask.NameToLayer("GUI");
        }
        if (l == -1)
        {
            l = 31;
        }

        mLoaded        = true;
        mPartial       = EditorPrefs.GetString("NGUI Partial");
        mFontName      = EditorPrefs.GetString("NGUI Font Name");
        mAtlasName     = EditorPrefs.GetString("NGUI Atlas Name");
        mFontData      = GetObject("NGUI Font Asset") as TextAsset;
        mFontTexture   = GetObject("NGUI Font Texture") as Texture2D;
        mFont          = GetObject("NGUI Font") as NGUIFont;
        mAtlas         = GetObject("NGUI Atlas") as NGUIAtlas;
        mAtlasPadding  = EditorPrefs.GetInt("NGUI Atlas Padding", 1);
        mAtlasTrimming = EditorPrefs.GetBool("NGUI Atlas Trimming", true);
        mUnityPacking  = EditorPrefs.GetBool("NGUI Unity Packing", true);
        mForceSquare   = EditorPrefs.GetBool("NGUI Force Square Atlas", true);
        mPivot         = (NGUIWidget.Pivot)EditorPrefs.GetInt("NGUI Pivot", (int)mPivot);
        mLayer         = EditorPrefs.GetInt("NGUI Layer", l);
        mDynFont       = GetObject("NGUI DynFont") as Font;
        mDynFontSize   = EditorPrefs.GetInt("NGUI DynFontSize", 16);
        mDynFontStyle  = (FontStyle)EditorPrefs.GetInt("NGUI DynFontStyle", (int)FontStyle.Normal);

        LoadColor();
    }
Ejemplo n.º 6
0
    /// <summary>
    /// Text is pixel-perfect when its scale matches the size.
    /// </summary>

    public override void MakePixelPerfect()
    {
        if (mFont != null)
        {
            float pixelSize = font.pixelSize;

            int      scaleHack = fontSize;
            NGUIFont f         = mFont;
            while (f.replacement != null)
            {
                f = f.replacement;
            }
            scaleHack -= scaleHack % 2;

            Vector3 scale = cachedTransform.localScale;
            //scale.x = mFont.size * pixelSize;
            scale.x = scaleHack;// *mFont.scaleFactor;
            scale.y = scale.x;
            scale.z = 1f;

            Vector2 actualSize = relativeSize * scale.x;

            int x = Mathf.RoundToInt(actualSize.x / pixelSize);
            int y = Mathf.RoundToInt(actualSize.y / pixelSize);

            Vector3 pos = cachedTransform.localPosition;
            pos.x = (Mathf.CeilToInt(pos.x / pixelSize * 4f) >> 2);
            pos.y = (Mathf.CeilToInt(pos.y / pixelSize * 4f) >> 2);
            pos.z = Mathf.RoundToInt(pos.z);

            if (cachedTransform.localRotation == Quaternion.identity)
            {
                if ((x % 2 == 1) && (pivot == Pivot.Top || pivot == Pivot.Center || pivot == Pivot.Bottom))
                {
                    pos.x += 0.5f;
                }
                if ((y % 2 == 1) && (pivot == Pivot.Left || pivot == Pivot.Center || pivot == Pivot.Right))
                {
                    pos.y += 0.5f;
                }
            }

            pos.x *= pixelSize;
            pos.y *= pixelSize;

            cachedTransform.localPosition = pos;
            cachedTransform.localScale    = scale;
        }
        else
        {
            base.MakePixelPerfect();
        }
    }
Ejemplo n.º 7
0
    void MarkAsChanged()
    {
        List <NGUILabel> labels = NGUIEditorTools.FindInScene <NGUILabel>();

        foreach (NGUILabel lbl in labels)
        {
            if (NGUIFont.CheckIfRelated(lbl.font, mFont))
            {
                lbl.font = null;
                lbl.font = mFont;
            }
        }
    }
Ejemplo n.º 8
0
    void OnSelectFont(MonoBehaviour obj)
    {
        // Undo doesn't work correctly in this case... so I won't bother.
        //NGUIEditorTools.RegisterUndo("Font Change");
        //NGUIEditorTools.RegisterUndo("Font Change", mFont);

        mFont.replacement = obj as NGUIFont;
        mReplacement      = mFont.replacement;
        UnityEditor.EditorUtility.SetDirty(mFont);
        if (mReplacement == null)
        {
            mType = FontType.Normal;
        }
    }
Ejemplo n.º 9
0
    override public void OnInspectorGUI()
    {
        mFont = target as NGUIFont;
        EditorGUIUtility.LookLikeControls(80f);

        NGUIEditorTools.DrawSeparator();

        if (mFont.replacement != null)
        {
            mType        = FontType.Reference;
            mReplacement = mFont.replacement;
        }
        else if (mFont.dynamicFont != null)
        {
            mType = FontType.Dynamic;
        }

        GUILayout.BeginHorizontal();
        FontType fontType = (FontType)EditorGUILayout.EnumPopup("Font Type", mType);

        GUILayout.Space(18f);
        GUILayout.EndHorizontal();

        if (mType != fontType)
        {
            if (fontType == FontType.Normal)
            {
                OnSelectFont(null);
            }
            else
            {
                mType = fontType;
            }

            if (mType != FontType.Dynamic && mFont.dynamicFont != null)
            {
                mFont.dynamicFont = null;
            }
        }

        if (mType == FontType.Reference)
        {
            ComponentSelector.Draw <NGUIFont>(mFont.replacement, OnSelectFont);

            NGUIEditorTools.DrawSeparator();
            GUILayout.Label("You can have one font simply point to\n" +
                            "another one. This is useful if you want to be\n" +
                            "able to quickly replace the contents of one\n" +
                            "font with another one, for example for\n" +
                            "swapping an SD font with an HD one, or\n" +
                            "replacing an English font with a Chinese\n" +
                            "one. All the labels referencing this font\n" +
                            "will update their references to the new one.");

            if (mReplacement != mFont && mFont.replacement != mReplacement)
            {
                NGUIEditorTools.RegisterUndo("Font Change", mFont);
                mFont.replacement = mReplacement;
                UnityEditor.EditorUtility.SetDirty(mFont);
            }
            return;
        }
        else if (mType == FontType.Dynamic)
        {
#if UNITY_3_5
            EditorGUILayout.HelpBox("Dynamic fonts require Unity 4.0 or higher.", MessageType.Error);
#else
            NGUIEditorTools.DrawSeparator();
            Font fnt = EditorGUILayout.ObjectField("TTF Font", mFont.dynamicFont, typeof(Font), false) as Font;

            if (fnt != mFont.dynamicFont)
            {
                NGUIEditorTools.RegisterUndo("Font change", mFont);
                mFont.dynamicFont = fnt;
            }

            GUILayout.BeginHorizontal();
            int       size  = EditorGUILayout.IntField("Size", mFont.dynamicFontSize, GUILayout.Width(120f));
            FontStyle style = (FontStyle)EditorGUILayout.EnumPopup(mFont.dynamicFontStyle);
            GUILayout.Space(18f);
            GUILayout.EndHorizontal();

            if (size != mFont.dynamicFontSize)
            {
                NGUIEditorTools.RegisterUndo("Font change", mFont);
                mFont.dynamicFontSize = size;
            }

            if (style != mFont.dynamicFontStyle)
            {
                NGUIEditorTools.RegisterUndo("Font change", mFont);
                mFont.dynamicFontStyle = style;
            }

            Material mat = EditorGUILayout.ObjectField("Material", mFont.material, typeof(Material), false) as Material;

            if (mFont.material != mat)
            {
                NGUIEditorTools.RegisterUndo("Font Material", mFont);
                mFont.material = mat;
            }

            //For dynamic font symblos
            NGUIFont fon = EditorGUILayout.ObjectField("DynamicSymblosFont", mFont.dynamicSymbolsFont, typeof(NGUIFont), false) as NGUIFont;

            if (mFont.dynamicSymbolsFont != fon)
            {
                NGUIEditorTools.RegisterUndo("DynamicSymblosFont change", mFont);
                mFont.dynamicSymbolsFont = fon;
            }

            float offset = EditorGUILayout.FloatField("Y Offset", mFont.dynamicFontOffset);
            if (offset != mFont.dynamicFontOffset)
            {
                NGUIEditorTools.RegisterUndo("Dynamic Font change", mFont);
                mFont.dynamicFontOffset = offset;
            }
#endif
        }
        else
        {
            NGUIEditorTools.DrawSeparator();

            ComponentSelector.Draw <NGUIAtlas>(mFont.atlas, OnSelectAtlas);

            if (mFont.atlas != null)
            {
                if (mFont.bmFont.isValid)
                {
                    NGUIEditorTools.AdvancedSpriteField(mFont.atlas, mFont.spriteName, SelectSprite, false);
                }
                EditorGUILayout.Space();
            }
            else
            {
                // No atlas specified -- set the material and texture rectangle directly
                Material mat = EditorGUILayout.ObjectField("Material", mFont.material, typeof(Material), false) as Material;

                if (mFont.material != mat)
                {
                    NGUIEditorTools.RegisterUndo("Font Material", mFont);
                    mFont.material = mat;
                }
            }

            // For updating the font's data when importing from an external source, such as the texture packer
            bool resetWidthHeight = false;

            if (mFont.atlas != null || mFont.material != null)
            {
                TextAsset data = EditorGUILayout.ObjectField("Import Data", null, typeof(TextAsset), false) as TextAsset;

                if (data != null)
                {
                    NGUIEditorTools.RegisterUndo("Import Font Data", mFont);
                    BMFontReader.Load(mFont.bmFont, NGUITools.GetHierarchy(mFont.gameObject), data.bytes);
                    mFont.MarkAsDirty();
                    resetWidthHeight = true;
                    Debug.Log("Imported " + mFont.bmFont.glyphCount + " characters");
                }
            }

            if (mFont.bmFont.isValid)
            {
                Color     green = new Color(0.4f, 1f, 0f, 1f);
                Texture2D tex   = mFont.texture;

                if (tex != null)
                {
                    if (mFont.atlas == null)
                    {
                        // Pixels are easier to work with than UVs
                        Rect pixels = NGUIMath.ConvertToPixels(mFont.uvRect, tex.width, tex.height, false);

                        // Automatically set the width and height of the rectangle to be the original font texture's dimensions
                        if (resetWidthHeight)
                        {
                            pixels.width  = mFont.texWidth;
                            pixels.height = mFont.texHeight;
                        }

                        // Font sprite rectangle
                        GUI.backgroundColor = green;
                        pixels = EditorGUILayout.RectField("Pixel Rect", pixels);
                        GUI.backgroundColor = Color.white;

                        // Create a button that can make the coordinates pixel-perfect on click
                        GUILayout.BeginHorizontal();
                        {
                            Rect corrected = NGUIMath.MakePixelPerfect(pixels);

                            if (corrected == pixels)
                            {
                                GUI.color = Color.grey;
                                GUILayout.Button("Make Pixel-Perfect");
                                GUI.color = Color.white;
                            }
                            else if (GUILayout.Button("Make Pixel-Perfect"))
                            {
                                pixels      = corrected;
                                GUI.changed = true;
                            }
                        }
                        GUILayout.EndHorizontal();

                        // Convert the pixel coordinates back to UV coordinates
                        Rect uvRect = NGUIMath.ConvertToTexCoords(pixels, tex.width, tex.height);

                        if (mFont.uvRect != uvRect)
                        {
                            NGUIEditorTools.RegisterUndo("Font Pixel Rect", mFont);
                            mFont.uvRect = uvRect;
                        }
                        //NGUIEditorTools.DrawSeparator();
                        EditorGUILayout.Space();
                    }
                }
            }
        }

        // The font must be valid at this point for the rest of the options to show up
        if (mFont.isDynamic || mFont.bmFont.isValid)
        {
            // Font spacing
            GUILayout.BeginHorizontal();
            {
                EditorGUIUtility.LookLikeControls(0f);
                GUILayout.Label("Spacing", GUILayout.Width(60f));
                GUILayout.Label("X", GUILayout.Width(12f));
                int x = EditorGUILayout.IntField(mFont.horizontalSpacing);
                GUILayout.Label("Y", GUILayout.Width(12f));
                int y = EditorGUILayout.IntField(mFont.verticalSpacing);
                GUILayout.Space(18f);
                EditorGUIUtility.LookLikeControls(80f);

                if (mFont.horizontalSpacing != x || mFont.verticalSpacing != y)
                {
                    NGUIEditorTools.RegisterUndo("Font Spacing", mFont);
                    mFont.horizontalSpacing = x;
                    mFont.verticalSpacing   = y;
                }
            }
            GUILayout.EndHorizontal();

            if (mFont.atlas == null)
            {
                mView      = View.Font;
                mUseShader = false;

                float pixelSize = EditorGUILayout.FloatField("Pixel Size", mFont.pixelSize, GUILayout.Width(120f));

                if (pixelSize != mFont.pixelSize)
                {
                    NGUIEditorTools.RegisterUndo("Font Change", mFont);
                    mFont.pixelSize = pixelSize;
                }
            }
            EditorGUILayout.Space();
        }

        // Preview option
        if (!mFont.isDynamic && mFont.atlas != null)
        {
            GUILayout.BeginHorizontal();
            {
                mView = (View)EditorGUILayout.EnumPopup("Preview", mView);
                GUILayout.Label("Shader", GUILayout.Width(45f));
                mUseShader = EditorGUILayout.Toggle(mUseShader, GUILayout.Width(20f));
            }
            GUILayout.EndHorizontal();
        }

        // Dynamic fonts don't support emoticons
        if (!mFont.isDynamic && mFont.bmFont.isValid)
        {
            if (mFont.atlas != null)
            {
                NGUIEditorTools.DrawHeader("Symbols and Emoticons");

                List <BMSymbol> symbols = mFont.symbols;

                for (int i = 0; i < symbols.Count;)
                {
                    BMSymbol sym = symbols[i];

                    GUILayout.BeginHorizontal();
                    GUILayout.Label(sym.sequence, GUILayout.Width(40f));
                    if (NGUIEditorTools.SimpleSpriteField(mFont.atlas, sym.spriteName, ChangeSymbolSprite))
                    {
                        mSelectedSymbol = sym;
                    }

                    if (GUILayout.Button("Edit", GUILayout.Width(40f)))
                    {
                        if (mFont.atlas != null)
                        {
                            EditorPrefs.SetString("NGUI Selected Sprite", sym.spriteName);
                            NGUIEditorTools.Select(mFont.atlas.gameObject);
                        }
                    }

                    GUI.backgroundColor = Color.red;

                    if (GUILayout.Button("X", GUILayout.Width(22f)))
                    {
                        NGUIEditorTools.RegisterUndo("Remove symbol", mFont);
                        mSymbolSequence = sym.sequence;
                        mSymbolSprite   = sym.spriteName;
                        symbols.Remove(sym);
                        mFont.MarkAsDirty();
                    }
                    GUI.backgroundColor = Color.white;
                    GUILayout.EndHorizontal();
                    GUILayout.Space(4f);
                    ++i;
                }

                if (symbols.Count > 0)
                {
                    NGUIEditorTools.DrawSeparator();
                }

                GUILayout.BeginHorizontal();
                mSymbolSequence = EditorGUILayout.TextField(mSymbolSequence, GUILayout.Width(40f));
                NGUIEditorTools.SimpleSpriteField(mFont.atlas, mSymbolSprite, SelectSymbolSprite);

                bool isValid = !string.IsNullOrEmpty(mSymbolSequence) && !string.IsNullOrEmpty(mSymbolSprite);
                GUI.backgroundColor = isValid ? Color.green : Color.grey;

                if (GUILayout.Button("Add", GUILayout.Width(40f)) && isValid)
                {
                    NGUIEditorTools.RegisterUndo("Add symbol", mFont);
                    mFont.AddSymbol(mSymbolSequence, mSymbolSprite);
                    mFont.MarkAsDirty();
                    mSymbolSequence = "";
                    mSymbolSprite   = "";
                }
                GUI.backgroundColor = Color.white;
                GUILayout.EndHorizontal();

                if (symbols.Count == 0)
                {
                    EditorGUILayout.HelpBox("Want to add an emoticon to your font? In the field above type ':)', choose a sprite, then hit the Add button.", MessageType.Info);
                }
                else
                {
                    GUILayout.Space(4f);
                }
            }
        }
    }
Ejemplo n.º 10
0
    /// <summary>
    /// Mark all widgets associated with this atlas as having changed.
    /// </summary>

    public void MarkAsDirty()
    {
#if UNITY_EDITOR
        UnityEditor.EditorUtility.SetDirty(gameObject);
#endif
        if (mReplacement != null)
        {
            mReplacement.MarkAsDirty();
        }

        NGUISprite[] list = NGUITools.FindActive <NGUISprite>();

        for (int i = 0, imax = list.Length; i < imax; ++i)
        {
            NGUISprite sp = list[i];

            if (CheckIfRelated(this, sp.atlas))
            {
                NGUIAtlas atl = sp.atlas;
                sp.atlas = null;
                sp.atlas = atl;
#if UNITY_EDITOR
                UnityEditor.EditorUtility.SetDirty(sp);
#endif
            }
        }

        NGUIFont[] fonts = Resources.FindObjectsOfTypeAll(typeof(NGUIFont)) as NGUIFont[];

        for (int i = 0, imax = fonts.Length; i < imax; ++i)
        {
            NGUIFont font = fonts[i];

            if (CheckIfRelated(this, font.atlas))
            {
                NGUIAtlas atl = font.atlas;
                font.atlas = null;
                font.atlas = atl;
#if UNITY_EDITOR
                UnityEditor.EditorUtility.SetDirty(font);
#endif
            }
        }

        NGUILabel[] labels = NGUITools.FindActive <NGUILabel>();

        for (int i = 0, imax = labels.Length; i < imax; ++i)
        {
            NGUILabel lbl = labels[i];

            if (lbl.font != null && CheckIfRelated(this, lbl.font.atlas))
            {
                NGUIFont font = lbl.font;
                lbl.font = null;
                lbl.font = font;
#if UNITY_EDITOR
                UnityEditor.EditorUtility.SetDirty(lbl);
#endif
            }
        }
    }
Ejemplo n.º 11
0
    /// <summary>
    /// Draw the font preview window.
    /// </summary>
    public override void OnPreviewGUI(Rect rect, GUIStyle background)
    {
        mFont = target as NGUIFont;
        if (mFont == null) return;
        Texture2D tex = mFont.texture;

        if (mView != View.Nothing && tex != null)
        {
            Material m = (mUseShader ? mFont.material : null);

            if (mView == View.Font)
            {
                Rect outer = new Rect(mFont.uvRect);
                Rect uv = outer;

                outer = NGUIMath.ConvertToPixels(outer, tex.width, tex.height, true);

                NGUIEditorTools.DrawSprite(tex, rect, outer, outer, uv, Color.white, m);
            }
            else
            {
                Rect outer = new Rect(0f, 0f, 1f, 1f);
                Rect inner = new Rect(mFont.uvRect);
                Rect uv = outer;

                outer = NGUIMath.ConvertToPixels(outer, tex.width, tex.height, true);
                inner = NGUIMath.ConvertToPixels(inner, tex.width, tex.height, true);

                NGUIEditorTools.DrawSprite(tex, rect, outer, inner, uv, Color.white, m);
            }
        }
    }
Ejemplo n.º 12
0
 /// <summary>
 /// Helper function that determines whether the two atlases are related.
 /// </summary>
 public static bool CheckIfRelated(NGUIFont a, NGUIFont b)
 {
     if (a == null || b == null) return false;
     if (a.isDynamic && a.dynamicTexture == b.dynamicTexture) return true;
     return a == b || a.References(b) || b.References(a);
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Helper function that determines whether the font uses the specified one, taking replacements into account.
 /// </summary>
 bool References(NGUIFont font)
 {
     if (font == null) return false;
     if (font == this) return true;
     return (mReplacement != null) ? mReplacement.References(font) : false;
 }
Ejemplo n.º 14
0
        public override void DoLocalize(Localize cmp, string mainTranslation, string secondaryTranslation)
        {
            //--[ Localize Font Object ]----------
            Font newFont = cmp.GetSecondaryTranslatedObj <Font>(ref mainTranslation, ref secondaryTranslation);

            if (newFont != null)
            {
                if (newFont != mTarget.ambigiousFont)
                {
                    mTarget.ambigiousFont = newFont;
                }
            }
            if (newFont == null)
            {
                UIFont newUIFont = cmp.GetSecondaryTranslatedObj <UIFont>(ref mainTranslation, ref secondaryTranslation);
                if (newUIFont != null && mTarget.ambigiousFont != newUIFont)
                {
                    mTarget.ambigiousFont = newUIFont;
                }
            }
            if (newFont == null)
            {
                NGUIFont newUIFont = cmp.GetSecondaryTranslatedObj <NGUIFont>(ref mainTranslation, ref secondaryTranslation);
                if (newUIFont != null && mTarget.ambigiousFont != newUIFont)
                {
                    mTarget.ambigiousFont = newUIFont;
                }
            }


            if (mInitializeAlignment)
            {
                mInitializeAlignment = false;
                mAlignment_LTR       = mAlignment_RTL = mTarget.alignment;

                if (LocalizationManager.IsRight2Left && mAlignment_RTL == NGUIText.Alignment.Right)
                {
                    mAlignment_LTR = NGUIText.Alignment.Left;
                }
                if (!LocalizationManager.IsRight2Left && mAlignment_LTR == NGUIText.Alignment.Left)
                {
                    mAlignment_RTL = NGUIText.Alignment.Right;
                }
            }

            UIInput input = NGUITools.FindInParents <UIInput>(mTarget.gameObject);

            if (input != null && input.label == mTarget)
            {
                if (mainTranslation != null && input.defaultText != mainTranslation)
                {
                    if (cmp.CorrectAlignmentForRTL && (input.label.alignment == NGUIText.Alignment.Left || input.label.alignment == NGUIText.Alignment.Right))
                    {
                        input.label.alignment = (LocalizationManager.IsRight2Left ? mAlignment_RTL : mAlignment_LTR);
                    }

                    input.defaultText = mainTranslation;
                }
            }
            else
            {
                if (mainTranslation != null && mTarget.text != mainTranslation)
                {
                    if (cmp.CorrectAlignmentForRTL && (mTarget.alignment == NGUIText.Alignment.Left || mTarget.alignment == NGUIText.Alignment.Right))
                    {
                        mTarget.alignment = (LocalizationManager.IsRight2Left ? mAlignment_RTL : mAlignment_LTR);
                    }

                    mTarget.text = mainTranslation;
                }
            }
        }
Ejemplo n.º 15
0
    void OnSelectFont(MonoBehaviour obj)
    {
        // Undo doesn't work correctly in this case... so I won't bother.
        //NGUIEditorTools.RegisterUndo("Font Change");
        //NGUIEditorTools.RegisterUndo("Font Change", mFont);

        mFont.replacement = obj as NGUIFont;
        mReplacement = mFont.replacement;
        UnityEditor.EditorUtility.SetDirty(mFont);
        if (mReplacement == null) mType = FontType.Normal;
    }
Ejemplo n.º 16
0
    public override void OnInspectorGUI()
    {
        mFont = target as NGUIFont;
        EditorGUIUtility.LookLikeControls(80f);

        NGUIEditorTools.DrawSeparator();

        if (mFont.replacement != null)
        {
            mType = FontType.Reference;
            mReplacement = mFont.replacement;
        }
        else if (mFont.dynamicFont != null)
        {
            mType = FontType.Dynamic;
        }

        GUILayout.BeginHorizontal();
        FontType fontType = (FontType)EditorGUILayout.EnumPopup("Font Type", mType);
        GUILayout.Space(18f);
        GUILayout.EndHorizontal();

        if (mType != fontType)
        {
            if (fontType == FontType.Normal)
            {
                OnSelectFont(null);
            }
            else
            {
                mType = fontType;
            }

            if (mType != FontType.Dynamic && mFont.dynamicFont != null)
                mFont.dynamicFont = null;
        }

        if (mType == FontType.Reference)
        {
            ComponentSelector.Draw<NGUIFont>(mFont.replacement, OnSelectFont);

            NGUIEditorTools.DrawSeparator();
            GUILayout.Label("You can have one font simply point to\n" +
                "another one. This is useful if you want to be\n" +
                "able to quickly replace the contents of one\n" +
                "font with another one, for example for\n" +
                "swapping an SD font with an HD one, or\n" +
                "replacing an English font with a Chinese\n" +
                "one. All the labels referencing this font\n" +
                "will update their references to the new one.");

            if (mReplacement != mFont && mFont.replacement != mReplacement)
            {
                NGUIEditorTools.RegisterUndo("Font Change", mFont);
                mFont.replacement = mReplacement;
                UnityEditor.EditorUtility.SetDirty(mFont);
            }
            return;
        }
        else if (mType == FontType.Dynamic)
        {
        #if UNITY_3_5
            EditorGUILayout.HelpBox("Dynamic fonts require Unity 4.0 or higher.", MessageType.Error);
        #else
            NGUIEditorTools.DrawSeparator();
            Font fnt = EditorGUILayout.ObjectField("TTF Font", mFont.dynamicFont, typeof(Font), false) as Font;

            if (fnt != mFont.dynamicFont)
            {
                NGUIEditorTools.RegisterUndo("Font change", mFont);
                mFont.dynamicFont = fnt;
            }

            GUILayout.BeginHorizontal();
            int size = EditorGUILayout.IntField("Size", mFont.dynamicFontSize, GUILayout.Width(120f));
            FontStyle style = (FontStyle)EditorGUILayout.EnumPopup(mFont.dynamicFontStyle);
            GUILayout.Space(18f);
            GUILayout.EndHorizontal();

            if (size != mFont.dynamicFontSize)
            {
                NGUIEditorTools.RegisterUndo("Font change", mFont);
                mFont.dynamicFontSize = size;
            }

            if (style != mFont.dynamicFontStyle)
            {
                NGUIEditorTools.RegisterUndo("Font change", mFont);
                mFont.dynamicFontStyle = style;
            }

            Material mat = EditorGUILayout.ObjectField("Material", mFont.material, typeof(Material), false) as Material;

            if (mFont.material != mat)
            {
                NGUIEditorTools.RegisterUndo("Font Material", mFont);
                mFont.material = mat;
            }

            //For dynamic font symblos
            NGUIFont fon = EditorGUILayout.ObjectField("DynamicSymblosFont", mFont.dynamicSymbolsFont, typeof(NGUIFont), false) as NGUIFont;

            if(mFont.dynamicSymbolsFont != fon)
            {
                NGUIEditorTools.RegisterUndo("DynamicSymblosFont change", mFont);
                mFont.dynamicSymbolsFont = fon;
            }

            float offset = EditorGUILayout.FloatField("Y Offset", mFont.dynamicFontOffset);
            if (offset != mFont.dynamicFontOffset)
            {
                NGUIEditorTools.RegisterUndo("Dynamic Font change", mFont);
                mFont.dynamicFontOffset = offset;
            }

        #endif
        }
        else
        {
            NGUIEditorTools.DrawSeparator();

            ComponentSelector.Draw<NGUIAtlas>(mFont.atlas, OnSelectAtlas);

            if (mFont.atlas != null)
            {
                if (mFont.bmFont.isValid)
                {
                    NGUIEditorTools.AdvancedSpriteField(mFont.atlas, mFont.spriteName, SelectSprite, false);
                }
                EditorGUILayout.Space();
            }
            else
            {
                // No atlas specified -- set the material and texture rectangle directly
                Material mat = EditorGUILayout.ObjectField("Material", mFont.material, typeof(Material), false) as Material;

                if (mFont.material != mat)
                {
                    NGUIEditorTools.RegisterUndo("Font Material", mFont);
                    mFont.material = mat;
                }
            }

            // For updating the font's data when importing from an external source, such as the texture packer
            bool resetWidthHeight = false;

            if (mFont.atlas != null || mFont.material != null)
            {
                TextAsset data = EditorGUILayout.ObjectField("Import Data", null, typeof(TextAsset), false) as TextAsset;

                if (data != null)
                {
                    NGUIEditorTools.RegisterUndo("Import Font Data", mFont);
                    BMFontReader.Load(mFont.bmFont, NGUITools.GetHierarchy(mFont.gameObject), data.bytes);
                    mFont.MarkAsDirty();
                    resetWidthHeight = true;
                    Debug.Log("Imported " + mFont.bmFont.glyphCount + " characters");
                }
            }

            if (mFont.bmFont.isValid)
            {
                Color green = new Color(0.4f, 1f, 0f, 1f);
                Texture2D tex = mFont.texture;

                if (tex != null)
                {
                    if (mFont.atlas == null)
                    {
                        // Pixels are easier to work with than UVs
                        Rect pixels = NGUIMath.ConvertToPixels(mFont.uvRect, tex.width, tex.height, false);

                        // Automatically set the width and height of the rectangle to be the original font texture's dimensions
                        if (resetWidthHeight)
                        {
                            pixels.width = mFont.texWidth;
                            pixels.height = mFont.texHeight;
                        }

                        // Font sprite rectangle
                        GUI.backgroundColor = green;
                        pixels = EditorGUILayout.RectField("Pixel Rect", pixels);
                        GUI.backgroundColor = Color.white;

                        // Create a button that can make the coordinates pixel-perfect on click
                        GUILayout.BeginHorizontal();
                        {
                            Rect corrected = NGUIMath.MakePixelPerfect(pixels);

                            if (corrected == pixels)
                            {
                                GUI.color = Color.grey;
                                GUILayout.Button("Make Pixel-Perfect");
                                GUI.color = Color.white;
                            }
                            else if (GUILayout.Button("Make Pixel-Perfect"))
                            {
                                pixels = corrected;
                                GUI.changed = true;
                            }
                        }
                        GUILayout.EndHorizontal();

                        // Convert the pixel coordinates back to UV coordinates
                        Rect uvRect = NGUIMath.ConvertToTexCoords(pixels, tex.width, tex.height);

                        if (mFont.uvRect != uvRect)
                        {
                            NGUIEditorTools.RegisterUndo("Font Pixel Rect", mFont);
                            mFont.uvRect = uvRect;
                        }
                        //NGUIEditorTools.DrawSeparator();
                        EditorGUILayout.Space();
                    }
                }
            }
        }

        // The font must be valid at this point for the rest of the options to show up
        if (mFont.isDynamic || mFont.bmFont.isValid)
        {
            // Font spacing
            GUILayout.BeginHorizontal();
            {
                EditorGUIUtility.LookLikeControls(0f);
                GUILayout.Label("Spacing", GUILayout.Width(60f));
                GUILayout.Label("X", GUILayout.Width(12f));
                int x = EditorGUILayout.IntField(mFont.horizontalSpacing);
                GUILayout.Label("Y", GUILayout.Width(12f));
                int y = EditorGUILayout.IntField(mFont.verticalSpacing);
                GUILayout.Space(18f);
                EditorGUIUtility.LookLikeControls(80f);

                if (mFont.horizontalSpacing != x || mFont.verticalSpacing != y)
                {
                    NGUIEditorTools.RegisterUndo("Font Spacing", mFont);
                    mFont.horizontalSpacing = x;
                    mFont.verticalSpacing = y;
                }
            }
            GUILayout.EndHorizontal();

            if (mFont.atlas == null)
            {
                mView = View.Font;
                mUseShader = false;

                float pixelSize = EditorGUILayout.FloatField("Pixel Size", mFont.pixelSize, GUILayout.Width(120f));

                if (pixelSize != mFont.pixelSize)
                {
                    NGUIEditorTools.RegisterUndo("Font Change", mFont);
                    mFont.pixelSize = pixelSize;
                }
            }
            EditorGUILayout.Space();
        }

        // Preview option
        if (!mFont.isDynamic && mFont.atlas != null)
        {
            GUILayout.BeginHorizontal();
            {
                mView = (View)EditorGUILayout.EnumPopup("Preview", mView);
                GUILayout.Label("Shader", GUILayout.Width(45f));
                mUseShader = EditorGUILayout.Toggle(mUseShader, GUILayout.Width(20f));
            }
            GUILayout.EndHorizontal();
        }

        // Dynamic fonts don't support emoticons
        if (!mFont.isDynamic && mFont.bmFont.isValid)
        {
            if (mFont.atlas != null)
            {
                NGUIEditorTools.DrawHeader("Symbols and Emoticons");

                List<BMSymbol> symbols = mFont.symbols;

                for (int i = 0; i < symbols.Count; )
                {
                    BMSymbol sym = symbols[i];

                    GUILayout.BeginHorizontal();
                    GUILayout.Label(sym.sequence, GUILayout.Width(40f));
                    if (NGUIEditorTools.SimpleSpriteField(mFont.atlas, sym.spriteName, ChangeSymbolSprite))
                        mSelectedSymbol = sym;

                    if (GUILayout.Button("Edit", GUILayout.Width(40f)))
                    {
                        if (mFont.atlas != null)
                        {
                            EditorPrefs.SetString("NGUI Selected Sprite", sym.spriteName);
                            NGUIEditorTools.Select(mFont.atlas.gameObject);
                        }
                    }

                    GUI.backgroundColor = Color.red;

                    if (GUILayout.Button("X", GUILayout.Width(22f)))
                    {
                        NGUIEditorTools.RegisterUndo("Remove symbol", mFont);
                        mSymbolSequence = sym.sequence;
                        mSymbolSprite = sym.spriteName;
                        symbols.Remove(sym);
                        mFont.MarkAsDirty();
                    }
                    GUI.backgroundColor = Color.white;
                    GUILayout.EndHorizontal();
                    GUILayout.Space(4f);
                    ++i;
                }

                if (symbols.Count > 0)
                {
                    NGUIEditorTools.DrawSeparator();
                }

                GUILayout.BeginHorizontal();
                mSymbolSequence = EditorGUILayout.TextField(mSymbolSequence, GUILayout.Width(40f));
                NGUIEditorTools.SimpleSpriteField(mFont.atlas, mSymbolSprite, SelectSymbolSprite);

                bool isValid = !string.IsNullOrEmpty(mSymbolSequence) && !string.IsNullOrEmpty(mSymbolSprite);
                GUI.backgroundColor = isValid ? Color.green : Color.grey;

                if (GUILayout.Button("Add", GUILayout.Width(40f)) && isValid)
                {
                    NGUIEditorTools.RegisterUndo("Add symbol", mFont);
                    mFont.AddSymbol(mSymbolSequence, mSymbolSprite);
                    mFont.MarkAsDirty();
                    mSymbolSequence = "";
                    mSymbolSprite = "";
                }
                GUI.backgroundColor = Color.white;
                GUILayout.EndHorizontal();

                if (symbols.Count == 0)
                {
                    EditorGUILayout.HelpBox("Want to add an emoticon to your font? In the field above type ':)', choose a sprite, then hit the Add button.", MessageType.Info);
                }
                else GUILayout.Space(4f);
            }
        }
    }
Ejemplo n.º 17
0
    static void Load()
    {
        int l = LayerMask.NameToLayer("UI");
        if (l == -1) l = LayerMask.NameToLayer("GUI");
        if (l == -1) l = 31;

        mLoaded			= true;
        mPartial		= EditorPrefs.GetString("NGUI Partial");
        mFontName		= EditorPrefs.GetString("NGUI Font Name");
        mAtlasName		= EditorPrefs.GetString("NGUI Atlas Name");
        mFontData		= GetObject("NGUI Font Asset") as TextAsset;
        mFontTexture	= GetObject("NGUI Font Texture") as Texture2D;
        mFont			= GetObject("NGUI Font") as NGUIFont;
        mAtlas			= GetObject("NGUI Atlas") as NGUIAtlas;
        mAtlasPadding	= EditorPrefs.GetInt("NGUI Atlas Padding", 1);
        mAtlasTrimming	= EditorPrefs.GetBool("NGUI Atlas Trimming", true);
        mUnityPacking	= EditorPrefs.GetBool("NGUI Unity Packing", true);
        mForceSquare	= EditorPrefs.GetBool("NGUI Force Square Atlas", true);
        mPivot			= (NGUIWidget.Pivot)EditorPrefs.GetInt("NGUI Pivot", (int)mPivot);
        mLayer			= EditorPrefs.GetInt("NGUI Layer", l);
        mDynFont		= GetObject("NGUI DynFont") as Font;
        mDynFontSize	= EditorPrefs.GetInt("NGUI DynFontSize", 16);
        mDynFontStyle	= (FontStyle)EditorPrefs.GetInt("NGUI DynFontStyle", (int)FontStyle.Normal);

        LoadColor();
    }
Ejemplo n.º 18
0
    // Token: 0x060006FD RID: 1789 RVA: 0x000394C8 File Offset: 0x000376C8
    public void MarkAsChanged()
    {
        INGUIAtlas replacement = this.replacement;

        if (replacement != null)
        {
            replacement.MarkAsChanged();
        }
        UISprite[] array = NGUITools.FindActive <UISprite>();
        int        i     = 0;
        int        num   = array.Length;

        while (i < num)
        {
            UISprite uisprite = array[i];
            if (NGUITools.CheckIfRelated(this, uisprite.atlas))
            {
                INGUIAtlas atlas = uisprite.atlas;
                uisprite.atlas = null;
                uisprite.atlas = atlas;
            }
            i++;
        }
        NGUIFont[] array2 = Resources.FindObjectsOfTypeAll <NGUIFont>();
        int        j      = 0;
        int        num2   = array2.Length;

        while (j < num2)
        {
            NGUIFont nguifont = array2[j];
            if (nguifont.atlas != null && NGUITools.CheckIfRelated(this, nguifont.atlas))
            {
                INGUIAtlas atlas2 = nguifont.atlas;
                nguifont.atlas = null;
                nguifont.atlas = atlas2;
            }
            j++;
        }
        UIFont[] array3 = Resources.FindObjectsOfTypeAll <UIFont>();
        int      k      = 0;
        int      num3   = array3.Length;

        while (k < num3)
        {
            UIFont uifont = array3[k];
            if (NGUITools.CheckIfRelated(this, uifont.atlas))
            {
                INGUIAtlas atlas3 = uifont.atlas;
                uifont.atlas = null;
                uifont.atlas = atlas3;
            }
            k++;
        }
        UILabel[] array4 = NGUITools.FindActive <UILabel>();
        int       l      = 0;
        int       num4   = array4.Length;

        while (l < num4)
        {
            UILabel uilabel = array4[l];
            if (uilabel.atlas != null && NGUITools.CheckIfRelated(this, uilabel.atlas))
            {
                INGUIAtlas atlas4     = uilabel.atlas;
                INGUIFont  bitmapFont = uilabel.bitmapFont;
                uilabel.bitmapFont = null;
                uilabel.bitmapFont = bitmapFont;
            }
            l++;
        }
    }
Ejemplo n.º 19
0
    /// <summary>
    /// Refill the text label based on what's currently visible.
    /// </summary>

    protected void UpdateVisibleText()
    {
        if (textLabel != null)
        {
            NGUIFont font = textLabel.font;

            if (font != null)
            {
                int lines    = 0;
                int maxLines = maxHeight > 0 ? Mathf.FloorToInt(maxHeight / textLabel.cachedTransform.localScale.y) : 100000;
                int offset   = Mathf.RoundToInt(mScroll);

                // Don't let scrolling to exceed the visible number of lines
                if (maxLines + offset > mTotalLines)
                {
                    offset  = Mathf.Max(0, mTotalLines - maxLines);
                    mScroll = offset;
                }

                if (style == Style.Chat)
                {
                    offset = Mathf.Max(0, mTotalLines - maxLines - offset);
                }

                StringBuilder final = new StringBuilder();

                for (int i = 0, imax = mParagraphs.Count; i < imax; ++i)
                {
                    Paragraph p = mParagraphs[i];

                    for (int b = 0, bmax = p.lines.Length; b < bmax; ++b)
                    {
                        string s = p.lines[b];

                        if (offset > 0)
                        {
                            --offset;
                        }
                        else
                        {
                            if (final.Length > 0)
                            {
                                final.Append("\n");
                            }
                            final.Append(s);
                            ++lines;
                            if (lines >= maxLines)
                            {
                                break;
                            }
                        }
                    }
                    if (lines >= maxLines)
                    {
                        break;
                    }
                }
                textLabel.text = final.ToString();
            }
        }
    }