MarkAsDirty() public method

Refresh all labels that use this font.
public MarkAsDirty ( ) : void
return void
Exemplo n.º 1
0
    /// <summary>
    /// Refresh all labels that use this font.
    /// </summary>

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

        mSprite = null;
        UILabel[] labels = NGUITools.FindActive <UILabel>();

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

            if (lbl.enabled && NGUITools.GetActive(lbl.gameObject) && CheckIfRelated(this, lbl.font))
            {
                UIFont fnt = lbl.font;
                lbl.font = null;
                lbl.font = fnt;
            }
        }

        // Clear all symbols
        for (int i = 0, imax = mSymbols.Count; i < imax; ++i)
        {
            symbols[i].MarkAsDirty();
        }
    }
Exemplo n.º 2
0
    public void MarkAsDirty()
    {
        if (mReplacement != null)
        {
            mReplacement.MarkAsDirty();
        }

        RecalculateDynamicOffset();
        mSprite = null;
        var labelArray = NGUITools.FindActive <UILabel>();
        var index      = 0;
        var length     = labelArray.Length;

        while (index < length)
        {
            var label = labelArray[index];
            if (label.enabled && NGUITools.GetActive(label.gameObject) && CheckIfRelated(this, label.font))
            {
                var font = label.font;
                label.font = null;
                label.font = font;
            }

            index++;
        }

        var num3  = 0;
        var count = mSymbols.Count;

        while (num3 < count)
        {
            symbols[num3].MarkAsDirty();
            num3++;
        }
    }
Exemplo n.º 3
0
    public void MarkAsDirty()
    {
        if (mReplacement != null)
        {
            mReplacement.MarkAsDirty();
        }
        RecalculateDynamicOffset();
        mSprite = null;
        UILabel[] array = NGUITools.FindActive <UILabel>();
        int       i     = 0;

        for (int num = array.Length; i < num; i++)
        {
            UILabel uILabel = array[i];
            if (uILabel.enabled && NGUITools.GetActive(uILabel.gameObject) && CheckIfRelated(this, uILabel.font))
            {
                UIFont font = uILabel.font;
                uILabel.font = null;
                uILabel.font = font;
            }
        }
        int j = 0;

        for (int count = mSymbols.Count; j < count; j++)
        {
            symbols[j].MarkAsDirty();
        }
    }
Exemplo n.º 4
0
 public override bool OnUpdate()
 {
     if (mFont.isDynamic && !Application.isPlaying && mFont.RecalculateDynamicOffset())
     {
         mFont.MarkAsDirty();
         return(true);
     }
     return(false);
 }
Exemplo n.º 5
0
    public override void Update()
    {
        base.Update();

        if (mFont != null && mFont.isDynamic && !Application.isPlaying && mFont.RecalculateDynamicOffset())
        {
            mFont.MarkAsDirty();
            mChanged = true;
        }
    }
Exemplo n.º 6
0
    /// <summary>
    /// Existing sprite selection.
    /// </summary>

    void ChangeSymbolSprite(string spriteName)
    {
        if (mSelectedSymbol != null && mFont != null)
        {
            NGUIEditorTools.RegisterUndo("Change symbol", mFont);
            mSelectedSymbol.spriteName = spriteName;
            Repaint();
            mFont.MarkAsDirty();
        }
    }
Exemplo n.º 7
0
    public void MarkAsDirty()
    {
#if UNITY_EDITOR
        UnityEditor.EditorUtility.SetDirty(gameObject);
#endif
        if (mReplacement != null)
        {
            mReplacement.MarkAsDirty();
        }
        RecalculateDynamicOffset();

        ++s_nFontVersion;
    }
Exemplo n.º 8
0
    public override void OnInspectorGUI()
    {
        mFont = target as UIFont;
        NGUIEditorTools.SetLabelWidth(80f);

        GUILayout.Space(6f);

        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<UIFont>(mFont.replacement, OnSelectFont);

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

            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
            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;
            }

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

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

            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;
            }
        #endif
        }
        else
        {
            NGUIEditorTools.DrawSeparator();

            ComponentSelector.Draw<UIAtlas>(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();
            {
                NGUIEditorTools.SetLabelWidth(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);
                NGUIEditorTools.SetLabelWidth(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)
            {
                if (NGUIEditorTools.DrawHeader("Symbols and Emoticons"))
                {
                    NGUIEditorTools.BeginContents();

                    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)
                            {
                                NGUISettings.selectedSprite = 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)
                    {
                        GUILayout.Space(6f);
                    }

                    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);

                    NGUIEditorTools.EndContents();
                }
            }
        }
    }
Exemplo n.º 9
0
    override public void OnInspectorGUI()
    {
        mFont = target as UIFont;
        EditorGUIUtility.LookLikeControls(80f);

        NGUIEditorTools.DrawSeparator();

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

        if (mFont.replacement != null)
        {
            mType        = FontType.Reference;
            mReplacement = mFont.replacement;
        }
        else if (mFont.dynamicFont_1 != 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;
            }

            //Lindean
            if (mType != FontType.Dynamic && mFont.dynamicFont_1 != null)
            {
                mFont.dynamicFont_1 = null;
            }
        }

        //Lindean
        if (mType == FontType.Dynamic)
        {
            //Lindean - Draw settings for dynamic font
            bool changed = false;
            Font f       = EditorGUILayout.ObjectField("Font", mFont.dynamicFont, typeof(Font), false) as Font;
            if (f != mFont.dynamicFont)
            {
                mFont.dynamicFont = f;
                changed           = true;
            }

            Material mat = EditorGUILayout.ObjectField("Material", mFont.dynamicFontMaterial_1, typeof(Material), false) as Material;
            if (mat != mFont.dynamicFontMaterial_1)
            {
                mFont.dynamicFontMaterial_1 = mat;
                changed = true;
            }
            if (mFont.dynamicFontMaterial_1 == null)
            {
                GUILayout.Label("Warning: no coloring or clipping when using default font material");
            }

            int i = EditorGUILayout.IntField("Size", mFont.dynamicFontSize);
            if (i != mFont.dynamicFontSize)
            {
                mFont.dynamicFontSize = i;
                changed = true;
            }

            FontStyle style = (FontStyle)EditorGUILayout.EnumPopup("Style", mFont.dynamicFontStyle);
            if (style != mFont.dynamicFontStyle)
            {
                mFont.dynamicFontStyle = style;
                changed = true;
            }

            if (changed)
            {
                //force access to material property as it refreshes the texture assignment
                Debug.Log("font changed...");
                Material fontMat = mFont.material;
                if (fontMat.mainTexture == null)
                {
                    Debug.Log("font material texture issue...");
                }
                UIFont.OnFontRebuilt(mFont);
            }

            NGUIEditorTools.DrawSeparator();

            // 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);
                EditorGUIUtility.LookLikeControls(80f);

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

        if (mType == FontType.Reference)
        {
            ComponentSelector.Draw <UIFont>(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_1, typeof(Font), false) as Font;

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

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

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

            if (style != mFont.dynamicFontStyle_1)
            {
                NGUIEditorTools.RegisterUndo("Font change", mFont);
                mFont.dynamicFontStyle_1 = 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;
            }
#endif
        }
        else
        {
            NGUIEditorTools.DrawSeparator();

            ComponentSelector.Draw <UIAtlas>(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);
                }
            }
        }
    }
Exemplo n.º 10
0
	override public void OnInspectorGUI ()
	{
		mFont = target as UIFont;
		EditorGUIUtility.LookLikeControls(80f);

		NGUIEditorTools.DrawSeparator();

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

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

		FontType after = (FontType)EditorGUILayout.EnumPopup("Font Type", mType);

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

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

        //UNISIP
        if (mType == FontType.Dynamic)
        {
            //UNISIP - Draw settings for dynamic font
            bool changed = false;
            Font f = EditorGUILayout.ObjectField("Font", mFont.dynamicFont, typeof(Font), false) as Font;
            if (f != mFont.dynamicFont)
            {
                mFont.dynamicFont = f;
                changed = true;
            }

            Material mat = EditorGUILayout.ObjectField("Material", mFont.dynamicFontMaterial, typeof(Material), false) as Material;
            if (mat != mFont.dynamicFontMaterial)
            {
                mFont.dynamicFontMaterial = mat;
                changed = true;
            }
            if (mFont.dynamicFontMaterial == null)
                GUILayout.Label("Warning: no coloring or clipping when using default font material");

            int i = EditorGUILayout.IntField("Size", mFont.dynamicFontSize);
            if (i != mFont.dynamicFontSize)
            {
                mFont.dynamicFontSize = i;
                changed = true;
            }

            FontStyle style = (FontStyle)EditorGUILayout.EnumPopup("Style", mFont.dynamicFontStyle);
            if (style != mFont.dynamicFontStyle)
            {
                mFont.dynamicFontStyle = style;
                changed = true;
            }

            if (changed)
            {
                //force access to material property as it refreshes the texture assignment
                Mogo.Util.LoggerHelper.Debug("font changed...");
                Material fontMat = mFont.material;
                if (fontMat.mainTexture == null)
                    Mogo.Util.LoggerHelper.Debug("font material texture issue...");
                UIFont.OnFontRebuilt(mFont);
            }

            NGUIEditorTools.DrawSeparator();

            // 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);
                EditorGUIUtility.LookLikeControls(80f);

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

		if (mType == FontType.Reference)
		{
			ComponentSelector.Draw<UIFont>(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;
		}

        if (mType != FontType.Dynamic)
        {
            NGUIEditorTools.DrawSeparator();
            ComponentSelector.Draw<UIAtlas>(mFont.atlas, OnSelectAtlas);

            if (mFont.atlas != null)
            {
                //if (mFont.bmFont.LegacyCheck())
                //{
                //    Mogo.Util.LoggerHelper.Debug(mFont.name + " uses a legacy font data structure. Upgrading, please save.");
                //    EditorUtility.SetDirty(mFont);
                //}

                if (mFont.bmFont.isValid)
                {
                    NGUIEditorTools.AdvancedSpriteField(mFont.atlas, mFont.spriteName, SelectSprite, false);
                }
            }
            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;
                }
            }

            bool resetWidthHeight = false;

            if (mFont.atlas != null || mFont.material != null)
            {
                TextAsset data = EditorGUILayout.ObjectField("Import Font", 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;
                    Mogo.Util.LoggerHelper.Debug("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();
                        {
                            GUILayout.Label("Correction", GUILayout.Width(75f));

                            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;
                        }
                    }

                    // 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(62f);
                        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;
                        }
                    }
                    else
                    {
                        GUILayout.Space(4f);
                        GUILayout.BeginHorizontal();
                        {
                            mView = (View)EditorGUILayout.EnumPopup("Preview", mView);
                            GUILayout.Label("Shader", GUILayout.Width(45f));
                            mUseShader = EditorGUILayout.Toggle(mUseShader, GUILayout.Width(20f));
                        }
                        GUILayout.EndHorizontal();
                    }
                }

                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);
                }
            }
        }
	}
Exemplo n.º 11
0
    override public void OnInspectorGUI()
    {
        mFont = target as UIFont;
        EditorGUIUtility.LookLikeControls(80f);

        NGUIEditorTools.DrawSeparator();

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

        FontType after = (FontType)EditorGUILayout.EnumPopup("Font Type", mType);

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

        if (mType == FontType.Reference)
        {
            ComponentSelector.Draw <UIFont>(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;
        }

        NGUIEditorTools.DrawSeparator();
        ComponentSelector.Draw <UIAtlas>(mFont.atlas, OnSelectAtlas);

        if (mFont.atlas != null)
        {
            if (mFont.bmFont.LegacyCheck())
            {
                Debug.Log(mFont.name + " uses a legacy font data structure. Upgrading, please save.");
                EditorUtility.SetDirty(mFont);
            }

            if (mFont.bmFont.isValid)
            {
                NGUIEditorTools.AdvancedSpriteField(mFont.atlas, mFont.spriteName, SelectSprite, false);
            }
        }
        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;
            }
        }

        bool resetWidthHeight = false;

        if (mFont.atlas != null || mFont.material != null)
        {
            TextAsset data = EditorGUILayout.ObjectField("Import Font", 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();
                    {
                        GUILayout.Label("Correction", GUILayout.Width(75f));

                        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;
                    }
                }

                // 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);
                    EditorGUIUtility.LookLikeControls(80f);

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

                GUILayout.BeginHorizontal();
                {
                    mView = (View)EditorGUILayout.EnumPopup("Preview", mView);
                    GUILayout.Label("Shader", GUILayout.Width(45f));
                    mUseShader = EditorGUILayout.Toggle(mUseShader, GUILayout.Width(20f));
                }
                GUILayout.EndHorizontal();
            }
        }
    }
Exemplo n.º 12
0
    public override void OnInspectorGUI()
    {
        mFont = target as UIFont;
        EditorGUIUtility.LookLikeControls(80f);

        NGUIEditorTools.DrawSeparator();

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

        FontType after = (FontType)EditorGUILayout.EnumPopup("Font Type", mType);

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

        if (mType == FontType.Reference)
        {
            ComponentSelector.Draw<UIFont>(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;
        }

        NGUIEditorTools.DrawSeparator();
        ComponentSelector.Draw<UIAtlas>(mFont.atlas, OnSelectAtlas);

        if (mFont.atlas != null)
        {
            if (mFont.bmFont.LegacyCheck())
            {
                Debug.Log(mFont.name + " uses a legacy font data structure. Upgrading, please save.");
                EditorUtility.SetDirty(mFont);
            }

            if (mFont.bmFont.isValid)
            {
                NGUIEditorTools.AdvancedSpriteField(mFont.atlas, mFont.spriteName, SelectSprite, false);
            }
        }
        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;
            }
        }

        bool resetWidthHeight = false;

        if (mFont.atlas != null || mFont.material != null)
        {
            TextAsset data = EditorGUILayout.ObjectField("Import Font", 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();
                    {
                        GUILayout.Label("Correction", GUILayout.Width(75f));

                        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;
                    }
                }

                // 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);
                    EditorGUIUtility.LookLikeControls(80f);

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

                EditorGUILayout.Separator();

                GUILayout.BeginHorizontal();
                {
                    mView = (View)EditorGUILayout.EnumPopup("Show", mView);
                    GUILayout.Label("Shader", GUILayout.Width(45f));

                    if (mUseShader != EditorGUILayout.Toggle(mUseShader, GUILayout.Width(20f)))
                    {
                        mUseShader = !mUseShader;

                        if (mUseShader && mView == View.Font)
                        {
                            // TODO: Remove this when Unity fixes the bug with DrawPreviewTexture not being affected by BeginGroup
                            Debug.LogWarning("There is a bug in Unity that prevents the texture from getting clipped properly.\n" +
                                "Until it's fixed by Unity, your texture may spill onto the rest of the Unity's GUI while using this mode.");
                        }
                    }
                }
                GUILayout.EndHorizontal();

                if (mView != View.Nothing)
                {
                    // Draw the atlas
                    EditorGUILayout.Separator();
                    Material m = mUseShader ? mFont.material : null;
                    Rect rect = (mView == View.Atlas) ? NGUIEditorTools.DrawAtlas(tex, m) : NGUIEditorTools.DrawSprite(tex, mFont.uvRect, m);
                    NGUIEditorTools.DrawOutline(rect, mFont.uvRect, green);

                    rect = GUILayoutUtility.GetRect(Screen.width, 18f);
                    EditorGUI.DropShadowLabel(rect, "Font Size: " + mFont.size);
                }
            }
        }
    }
Exemplo n.º 13
0
    override public void OnInspectorGUI()
    {
        mFont = target as UIFont;
        EditorGUIUtility.LookLikeControls(80f);

        NGUIEditorTools.DrawSeparator();

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

        FontType after = (FontType)EditorGUILayout.EnumPopup("Font Type", mType);

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

        if (mType == FontType.Reference)
        {
            ComponentSelector.Draw <UIFont>(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;
        }

        NGUIEditorTools.DrawSeparator();
        ComponentSelector.Draw <UIAtlas>(mFont.atlas, OnSelectAtlas);

        if (mFont.atlas != null)
        {
            if (mFont.bmFont.isValid)
            {
                string spriteName = UISlicedSpriteInspector.SpriteField(mFont.atlas, mFont.spriteName);

                if (mFont.spriteName != spriteName)
                {
                    NGUIEditorTools.RegisterUndo("Font Sprite", mFont);
                    mFont.spriteName = spriteName;
                }
            }
        }
        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;
            }
        }

        bool resetWidthHeight = false;

        if (mFont.atlas != null || mFont.material != null)
        {
            TextAsset data = EditorGUILayout.ObjectField("Import Font", 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();
                    {
                        GUILayout.Label("Correction", GUILayout.Width(75f));

                        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;
                    }
                }

                // 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);
                    EditorGUIUtility.LookLikeControls(80f);

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

                EditorGUILayout.Separator();

                GUILayout.BeginHorizontal();
                {
                    mView = (View)EditorGUILayout.EnumPopup("Show", mView);
                    GUILayout.Label("Shader", GUILayout.Width(45f));

                    if (mUseShader != EditorGUILayout.Toggle(mUseShader, GUILayout.Width(20f)))
                    {
                        mUseShader = !mUseShader;

                        if (mUseShader && mView == View.Font)
                        {
                            // TODO: Remove this when Unity fixes the bug with DrawPreviewTexture not being affected by BeginGroup
                            Debug.LogWarning("There is a bug in Unity that prevents the texture from getting clipped properly.\n" +
                                             "Until it's fixed by Unity, your texture may spill onto the rest of the Unity's GUI while using this mode.");
                        }
                    }
                }
                GUILayout.EndHorizontal();

                if (mView != View.Nothing)
                {
                    // Draw the atlas
                    EditorGUILayout.Separator();
                    Material m    = mUseShader ? mFont.material : null;
                    Rect     rect = (mView == View.Atlas) ? NGUIEditorTools.DrawAtlas(tex, m) : NGUIEditorTools.DrawSprite(tex, mFont.uvRect, m);
                    NGUIEditorTools.DrawOutline(rect, mFont.uvRect, green);

                    rect = GUILayoutUtility.GetRect(Screen.width, 18f);
                    EditorGUI.DropShadowLabel(rect, "Font Size: " + mFont.size);
                }
            }
        }
    }
Exemplo n.º 14
0
    override public void OnInspectorGUI()
    {
        mFont = target as UIFont;
        EditorGUIUtility.LookLikeControls(80f);

        NGUIEditorTools.DrawSeparator();

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

        FontType after = (FontType)EditorGUILayout.EnumPopup("Font Type", mType);

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

        if (mType == FontType.Reference)
        {
            ComponentSelector.Draw <UIFont>(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;
        }

        NGUIEditorTools.DrawSeparator();
        ComponentSelector.Draw <UIAtlas>(mFont.atlas, OnSelectAtlas);

        if (mFont.atlas != null)
        {
            if (mFont.bmFont.isValid)
            {
                NGUIEditorTools.AdvancedSpriteField(mFont.atlas, mFont.spriteName, SelectSprite, false);
            }
        }
        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;
            }
        }

        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);

                    // 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();
                    {
                        GUILayout.Label("Correction", GUILayout.Width(75f));

                        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;
                    }
                }

                // 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(62f);
                    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;
                    }
                }
                else
                {
                    GUILayout.Space(4f);
                    GUILayout.BeginHorizontal();
                    {
                        mView = (View)EditorGUILayout.EnumPopup("Preview", mView);
                        GUILayout.Label("Shader", GUILayout.Width(45f));
                        mUseShader = EditorGUILayout.Toggle(mUseShader, GUILayout.Width(20f));
                    }
                    GUILayout.EndHorizontal();
                }
            }

            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);
                }
            }
        }
    }
Exemplo n.º 15
0
    public override void OnInspectorGUI()
    {
        mFont = target as UIFont;
        EditorGUIUtility.LookLikeControls(80f);

        HUDEditorTools.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 <UIFont>(mFont.replacement, OnSelectFont);

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

            if (mReplacement != mFont && mFont.replacement != mReplacement)
            {
                HUDEditorTools.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
            HUDEditorTools.DrawSeparator();
            Font fnt = EditorGUILayout.ObjectField("TTF Font", mFont.dynamicFont, typeof(Font), false) as Font;

            if (fnt != mFont.dynamicFont)
            {
                HUDEditorTools.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)
            {
                HUDEditorTools.RegisterUndo("Font change", mFont);
                mFont.dynamicFontSize = size;
            }

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

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

            if (mFont.material != mat)
            {
                HUDEditorTools.RegisterUndo("Font Material", mFont);
                mFont.material = mat;
            }
#endif
        }
        else
        {
            HUDEditorTools.DrawSeparator();

            {
                // 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)
                {
                    HUDEditorTools.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.material != null)
            {
                TextAsset data = EditorGUILayout.ObjectField("Import Data", null, typeof(TextAsset), false) as TextAsset;

                if (data != null)
                {
                    HUDEditorTools.RegisterUndo("Import Font Data", mFont);
                    mFont.MarkAsDirty();
                    resetWidthHeight = true;
                }
            }
        }

        // The font must be valid at this point for the rest of the options to show up
        if (mFont.isDynamic)
        {
            // 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)
                {
                    HUDEditorTools.RegisterUndo("Font Spacing", mFont);
                    mFont.horizontalSpacing = x;
                    mFont.verticalSpacing   = y;
                }
            }
            GUILayout.EndHorizontal();

            EditorGUILayout.Space();
        }

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