Beispiel #1
0
    /// <summary>
    /// Draw the atlas and sprite selection fields.
    /// </summary>

    override protected bool DrawProperties()
    {
        mSprite = mWidget as UISprite;
        ComponentSelector.Draw <UIAtlas>(mSprite.atlas, OnSelectAtlas);
        if (mSprite.atlas == null)
        {
            return(false);
        }
        NGUIEditorTools.AdvancedSpriteField(mSprite.atlas, mSprite.spriteName, SelectSprite, false);
        return(true);
    }
Beispiel #2
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);
                }
            }
        }
    }
Beispiel #3
0
    /// <summary>
    /// Draw the inspector widget.
    /// </summary>

    public override void OnInspectorGUI()
    {
        EditorGUIUtility.LookLikeControls(80f);
        mAtlas = target as UIAtlas;

        UIAtlas.Sprite sprite = (mAtlas != null) ? mAtlas.GetSprite(NGUISettings.selectedSprite) : null;

        NGUIEditorTools.DrawSeparator();

        if (mAtlas.replacement != null)
        {
            mType        = AtlasType.Reference;
            mReplacement = mAtlas.replacement;
        }

        AtlasType after = (AtlasType)EditorGUILayout.EnumPopup("Atlas Type", mType);

        if (mType != after)
        {
            if (after == AtlasType.Normal)
            {
                OnSelectAtlas(null);
            }
            else
            {
                mType = AtlasType.Reference;
            }
        }

        if (mType == AtlasType.Reference)
        {
            ComponentSelector.Draw <UIAtlas>(mAtlas.replacement, OnSelectAtlas);

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

            if (mReplacement != mAtlas && mAtlas.replacement != mReplacement)
            {
                NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas);
                mAtlas.replacement = mReplacement;
                UnityEditor.EditorUtility.SetDirty(mAtlas);
            }
            return;
        }

        if (!mConfirmDelete)
        {
            NGUIEditorTools.DrawSeparator();
            Material mat = EditorGUILayout.ObjectField("Material", mAtlas.spriteMaterial, typeof(Material), false) as Material;

            if (mAtlas.spriteMaterial != mat)
            {
                NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas);
                mAtlas.spriteMaterial = mat;

                // Ensure that this atlas has valid import settings
                if (mAtlas.texture != null)
                {
                    NGUIEditorTools.ImportTexture(mAtlas.texture, false, false);
                }

                mAtlas.MarkAsDirty();
                mConfirmDelete = false;
            }

            if (mat != null)
            {
                TextAsset ta = EditorGUILayout.ObjectField("TP Import", null, typeof(TextAsset), false) as TextAsset;

                if (ta != null)
                {
                    // Ensure that this atlas has valid import settings
                    if (mAtlas.texture != null)
                    {
                        NGUIEditorTools.ImportTexture(mAtlas.texture, false, false);
                    }

                    NGUIEditorTools.RegisterUndo("Import Sprites", mAtlas);
                    NGUIJson.LoadSpriteData(mAtlas, ta);
                    if (sprite != null)
                    {
                        sprite = mAtlas.GetSprite(sprite.name);
                    }
                    mAtlas.MarkAsDirty();
                }

                UIAtlas.Coordinates coords = (UIAtlas.Coordinates)EditorGUILayout.EnumPopup("Coordinates", mAtlas.coordinates);

                if (coords != mAtlas.coordinates)
                {
                    NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas);
                    mAtlas.coordinates = coords;
                    mConfirmDelete     = false;
                }

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

                if (pixelSize != mAtlas.pixelSize)
                {
                    NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas);
                    mAtlas.pixelSize = pixelSize;
                    mConfirmDelete   = false;
                }
            }
        }

        if (mAtlas.spriteMaterial != null)
        {
            Color blue  = new Color(0f, 0.7f, 1f, 1f);
            Color green = new Color(0.4f, 1f, 0f, 1f);

            if (mConfirmDelete)
            {
                if (sprite != null)
                {
                    // Show the confirmation dialog
                    NGUIEditorTools.DrawSeparator();
                    GUILayout.Label("Are you sure you want to delete '" + sprite.name + "'?");
                    NGUIEditorTools.DrawSeparator();

                    GUILayout.BeginHorizontal();
                    {
                        GUI.backgroundColor = Color.green;
                        if (GUILayout.Button("Cancel"))
                        {
                            mConfirmDelete = false;
                        }
                        GUI.backgroundColor = Color.red;

                        if (GUILayout.Button("Delete"))
                        {
                            NGUIEditorTools.RegisterUndo("Delete Sprite", mAtlas);
                            mAtlas.spriteList.Remove(sprite);
                            mConfirmDelete = false;
                        }
                        GUI.backgroundColor = Color.white;
                    }
                    GUILayout.EndHorizontal();
                }
                else
                {
                    mConfirmDelete = false;
                }
            }
            else
            {
                if (sprite == null && mAtlas.spriteList.Count > 0)
                {
                    string spriteName = NGUISettings.selectedSprite;
                    if (!string.IsNullOrEmpty(spriteName))
                    {
                        sprite = mAtlas.GetSprite(spriteName);
                    }
                    if (sprite == null)
                    {
                        sprite = mAtlas.spriteList[0];
                    }
                }

                if (!mConfirmDelete && sprite != null)
                {
                    NGUIEditorTools.DrawSeparator();
                    NGUIEditorTools.AdvancedSpriteField(mAtlas, sprite.name, SelectSprite, true);

                    if (sprite == null)
                    {
                        return;
                    }

                    Texture2D tex = mAtlas.spriteMaterial.mainTexture as Texture2D;

                    if (tex != null)
                    {
                        Rect inner = sprite.inner;
                        Rect outer = sprite.outer;

                        if (mAtlas.coordinates == UIAtlas.Coordinates.Pixels)
                        {
                            GUI.backgroundColor = green;
                            outer = NGUIEditorTools.IntRect("Dimensions", sprite.outer);

                            Vector4 border = new Vector4(
                                sprite.inner.xMin - sprite.outer.xMin,
                                sprite.inner.yMin - sprite.outer.yMin,
                                sprite.outer.xMax - sprite.inner.xMax,
                                sprite.outer.yMax - sprite.inner.yMax);

                            GUI.backgroundColor = blue;
                            border = NGUIEditorTools.IntPadding("Border", border);
                            GUI.backgroundColor = Color.white;

                            inner.xMin = sprite.outer.xMin + border.x;
                            inner.yMin = sprite.outer.yMin + border.y;
                            inner.xMax = sprite.outer.xMax - border.z;
                            inner.yMax = sprite.outer.yMax - border.w;
                        }
                        else
                        {
                            // Draw the inner and outer rectangle dimensions
                            GUI.backgroundColor = green;
                            outer = EditorGUILayout.RectField("Outer Rect", sprite.outer);
                            GUI.backgroundColor = blue;
                            inner = EditorGUILayout.RectField("Inner Rect", sprite.inner);
                            GUI.backgroundColor = Color.white;
                        }

                        if (outer.xMax < outer.xMin)
                        {
                            outer.xMax = outer.xMin;
                        }
                        if (outer.yMax < outer.yMin)
                        {
                            outer.yMax = outer.yMin;
                        }

                        if (outer != sprite.outer)
                        {
                            float x = outer.xMin - sprite.outer.xMin;
                            float y = outer.yMin - sprite.outer.yMin;

                            inner.x += x;
                            inner.y += y;
                        }

                        // Sanity checks to ensure that the inner rect is always inside the outer
                        inner.xMin = Mathf.Clamp(inner.xMin, outer.xMin, outer.xMax);
                        inner.xMax = Mathf.Clamp(inner.xMax, outer.xMin, outer.xMax);
                        inner.yMin = Mathf.Clamp(inner.yMin, outer.yMin, outer.yMax);
                        inner.yMax = Mathf.Clamp(inner.yMax, outer.yMin, outer.yMax);

                        bool changed = false;

                        if (sprite.inner != inner || sprite.outer != outer)
                        {
                            NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas);
                            sprite.inner = inner;
                            sprite.outer = outer;
                            MarkSpriteAsDirty();
                            changed = true;
                        }

                        EditorGUILayout.Separator();

                        if (mAtlas.coordinates == UIAtlas.Coordinates.Pixels)
                        {
                            int left   = Mathf.RoundToInt(sprite.paddingLeft * sprite.outer.width);
                            int right  = Mathf.RoundToInt(sprite.paddingRight * sprite.outer.width);
                            int top    = Mathf.RoundToInt(sprite.paddingTop * sprite.outer.height);
                            int bottom = Mathf.RoundToInt(sprite.paddingBottom * sprite.outer.height);

                            NGUIEditorTools.IntVector a = NGUIEditorTools.IntPair("Padding", "Left", "Top", left, top);
                            NGUIEditorTools.IntVector b = NGUIEditorTools.IntPair(null, "Right", "Bottom", right, bottom);

                            if (changed || a.x != left || a.y != top || b.x != right || b.y != bottom)
                            {
                                NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas);
                                sprite.paddingLeft   = a.x / sprite.outer.width;
                                sprite.paddingTop    = a.y / sprite.outer.height;
                                sprite.paddingRight  = b.x / sprite.outer.width;
                                sprite.paddingBottom = b.y / sprite.outer.height;
                                MarkSpriteAsDirty();
                            }
                        }
                        else
                        {
                            // Create a button that can make the coordinates pixel-perfect on click
                            GUILayout.BeginHorizontal();
                            {
                                GUILayout.Label("Correction", GUILayout.Width(75f));

                                Rect corrected0 = outer;
                                Rect corrected1 = inner;

                                if (mAtlas.coordinates == UIAtlas.Coordinates.Pixels)
                                {
                                    corrected0 = NGUIMath.MakePixelPerfect(corrected0);
                                    corrected1 = NGUIMath.MakePixelPerfect(corrected1);
                                }
                                else
                                {
                                    corrected0 = NGUIMath.MakePixelPerfect(corrected0, tex.width, tex.height);
                                    corrected1 = NGUIMath.MakePixelPerfect(corrected1, tex.width, tex.height);
                                }

                                if (corrected0 == sprite.outer && corrected1 == sprite.inner)
                                {
                                    GUI.color = Color.grey;
                                    GUILayout.Button("Make Pixel-Perfect");
                                    GUI.color = Color.white;
                                }
                                else if (GUILayout.Button("Make Pixel-Perfect"))
                                {
                                    outer       = corrected0;
                                    inner       = corrected1;
                                    GUI.changed = true;
                                }
                            }
                            GUILayout.EndHorizontal();
                        }
                    }

                    // This functionality is no longer used. It became obsolete when the Atlas Maker was added.

                    /*NGUIEditorTools.DrawSeparator();
                     *
                     * GUILayout.BeginHorizontal();
                     * {
                     *      EditorGUILayout.PrefixLabel("Add/Delete");
                     *
                     *      if (GUILayout.Button("Clone Sprite"))
                     *      {
                     *              NGUIEditorTools.RegisterUndo("Add Sprite", mAtlas);
                     *              UIAtlas.Sprite newSprite = new UIAtlas.Sprite();
                     *
                     *              if (sprite != null)
                     *              {
                     *                      newSprite.name = "Copy of " + sprite.name;
                     *                      newSprite.outer = sprite.outer;
                     *                      newSprite.inner = sprite.inner;
                     *              }
                     *              else
                     *              {
                     *                      newSprite.name = "New Sprite";
                     *              }
                     *
                     *              mAtlas.spriteList.Add(newSprite);
                     *              sprite = newSprite;
                     *      }
                     *
                     *      // Show the delete button
                     *      GUI.backgroundColor = Color.red;
                     *
                     *      if (sprite != null && GUILayout.Button("Delete", GUILayout.Width(55f)))
                     *      {
                     *              mConfirmDelete = true;
                     *      }
                     *      GUI.backgroundColor = Color.white;
                     * }
                     * GUILayout.EndHorizontal();*/

                    if (NGUIEditorTools.previousSelection != null)
                    {
                        NGUIEditorTools.DrawSeparator();

                        GUI.backgroundColor = Color.green;

                        if (GUILayout.Button("<< Return to " + NGUIEditorTools.previousSelection.name))
                        {
                            NGUIEditorTools.SelectPrevious();
                        }
                        GUI.backgroundColor = Color.white;
                    }
                }
            }
        }
    }
    /// <summary>
    /// Draw the inspector widget.
    /// </summary>

    public override void OnInspectorGUI()
    {
        NGUIEditorTools.SetLabelWidth(80f);
        mAtlas = target as UIAtlas;

        UISpriteData sprite = (mAtlas != null) ? mAtlas.GetSprite(NGUISettings.selectedSprite) : null;

        GUILayout.Space(6f);

        if (mAtlas.replacement != null)
        {
            mType        = AtlasType.Reference;
            mReplacement = mAtlas.replacement;
        }

        GUILayout.BeginHorizontal();
        AtlasType after = (AtlasType)EditorGUILayout.EnumPopup("Atlas Type", mType);

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

        if (mType != after)
        {
            if (after == AtlasType.Normal)
            {
                mType = AtlasType.Normal;
                OnSelectAtlas(null);
            }
            else
            {
                mType = AtlasType.Reference;
            }
        }

        if (mType == AtlasType.Reference)
        {
            ComponentSelector.Draw <UIAtlas>(mAtlas.replacement, OnSelectAtlas);

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

            if (mReplacement != mAtlas && mAtlas.replacement != mReplacement)
            {
                NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas);
                mAtlas.replacement = mReplacement;
                UnityEditor.EditorUtility.SetDirty(mAtlas);
            }
            return;
        }

        //GUILayout.Space(6f);
        Material mat = EditorGUILayout.ObjectField("Material", mAtlas.spriteMaterial, typeof(Material), false) as Material;

        if (mAtlas.spriteMaterial != mat)
        {
            NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas);
            mAtlas.spriteMaterial = mat;

            // Ensure that this atlas has valid import settings
            if (mAtlas.texture != null)
            {
                NGUIEditorTools.ImportTexture(mAtlas.texture, false, false, !mAtlas.premultipliedAlpha);
            }

            mAtlas.MarkAsDirty();
        }

        if (mat != null)
        {
            TextAsset ta = EditorGUILayout.ObjectField("TP Import", null, typeof(TextAsset), false) as TextAsset;

            if (ta != null)
            {
                // Ensure that this atlas has valid import settings
                if (mAtlas.texture != null)
                {
                    NGUIEditorTools.ImportTexture(mAtlas.texture, false, false, !mAtlas.premultipliedAlpha);
                }

                NGUIEditorTools.RegisterUndo("Import Sprites", mAtlas);
                NGUIJson.LoadSpriteData(mAtlas, ta);
                if (sprite != null)
                {
                    sprite = mAtlas.GetSprite(sprite.name);
                }
                mAtlas.MarkAsDirty();
            }

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

            if (pixelSize != mAtlas.pixelSize)
            {
                NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas);
                mAtlas.pixelSize = pixelSize;
            }
        }

        if (mAtlas.spriteMaterial != null)
        {
            Color blue  = new Color(0f, 0.7f, 1f, 1f);
            Color green = new Color(0.4f, 1f, 0f, 1f);

            if (sprite == null && mAtlas.spriteList.Count > 0)
            {
                string spriteName = NGUISettings.selectedSprite;
                if (!string.IsNullOrEmpty(spriteName))
                {
                    sprite = mAtlas.GetSprite(spriteName);
                }
                if (sprite == null)
                {
                    sprite = mAtlas.spriteList[0];
                }
            }

            if (sprite != null)
            {
                if (sprite == null)
                {
                    return;
                }

                Texture2D tex = mAtlas.spriteMaterial.mainTexture as Texture2D;

                if (tex != null)
                {
                    if (!NGUIEditorTools.DrawHeader("Sprite Details"))
                    {
                        return;
                    }

                    NGUIEditorTools.BeginContents();

                    GUILayout.Space(3f);
                    NGUIEditorTools.AdvancedSpriteField(mAtlas, sprite.name, SelectSprite, true);
                    GUILayout.Space(6f);

                    GUI.changed = false;

                    GUI.backgroundColor = green;
                    NGUIEditorTools.IntVector sizeA = NGUIEditorTools.IntPair("Dimensions", "X", "Y", sprite.x, sprite.y);
                    NGUIEditorTools.IntVector sizeB = NGUIEditorTools.IntPair(null, "Width", "Height", sprite.width, sprite.height);

                    EditorGUILayout.Separator();
                    GUI.backgroundColor = blue;
                    NGUIEditorTools.IntVector borderA = NGUIEditorTools.IntPair("Border", "Left", "Right", sprite.borderLeft, sprite.borderRight);
                    NGUIEditorTools.IntVector borderB = NGUIEditorTools.IntPair(null, "Bottom", "Top", sprite.borderBottom, sprite.borderTop);

                    EditorGUILayout.Separator();
                    GUI.backgroundColor = Color.white;
                    NGUIEditorTools.IntVector padA = NGUIEditorTools.IntPair("Padding", "Left", "Right", sprite.paddingLeft, sprite.paddingRight);
                    NGUIEditorTools.IntVector padB = NGUIEditorTools.IntPair(null, "Bottom", "Top", sprite.paddingBottom, sprite.paddingTop);

                    if (GUI.changed)
                    {
                        NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas);

                        sprite.x      = sizeA.x;
                        sprite.y      = sizeA.y;
                        sprite.width  = sizeB.x;
                        sprite.height = sizeB.y;

                        sprite.paddingLeft   = padA.x;
                        sprite.paddingRight  = padA.y;
                        sprite.paddingBottom = padB.x;
                        sprite.paddingTop    = padB.y;

                        sprite.borderLeft   = borderA.x;
                        sprite.borderRight  = borderA.y;
                        sprite.borderBottom = borderB.x;
                        sprite.borderTop    = borderB.y;

                        MarkSpriteAsDirty();
                    }
                    NGUIEditorTools.EndContents();
                }

                if (NGUIEditorTools.previousSelection != null)
                {
                    GUI.backgroundColor = Color.green;

                    if (GUILayout.Button("<< Return to " + NGUIEditorTools.previousSelection.name))
                    {
                        NGUIEditorTools.SelectPrevious();
                    }
                    GUI.backgroundColor = Color.white;
                }
            }
        }
    }
Beispiel #5
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();
            }
        }
    }
Beispiel #6
0
    override public void OnInspectorGUI()
    {
//		if(mWidget==null) return false;

        mTabBar = target as UITabBar;
        ComponentSelector.Draw <UIAtlas>(mTabBar.atlas, OnSelectAtlas);
        ComponentSelector.Draw <UIFont>(mTabBar.font, OnSelectFont);


//		EditorGUILayout.Space();

        if (mTabBar.atlas != null && mTabBar.font != null)
        {
            NGUIEditorTools.AdvancedSpriteField(mTabBar.atlas, mTabBar.spriteName, SelectSprite, false);

            GUILayout.Label("选中的样式");
            NGUIEditorTools.AdvancedSpriteField(mTabBar.atlas, mTabBar.selectSpriteName, SelectedSprite, false);
            GUI.skin.textArea.wordWrap = true;
            string texts = string.IsNullOrEmpty(mTabBar.texts) ? "" : mTabBar.texts;
            texts = EditorGUILayout.TextArea(mTabBar.texts, GUI.skin.textArea, GUILayout.Height(50.0f));
            if (texts != mTabBar.texts)
            {
                mTabBar.texts = texts;
                OnSet();
            }
            GUILayout.Label("Language Keys");
            string languages = string.IsNullOrEmpty(mTabBar.languages) ? "" : mTabBar.languages;
            languages = EditorGUILayout.TextArea(mTabBar.languages, GUI.skin.textArea, GUILayout.Height(50.0f));
            if (languages != mTabBar.languages)
            {
                mTabBar.languages = languages;
                OnSet();
            }

            GUILayout.BeginHorizontal();
            int w = EditorGUILayout.IntField("ItemWidth", mTabBar.w, GUILayout.Width(200f));
            if (w != mTabBar.w)
            {
                mTabBar.w = w;
                OnSet();
            }

            GUILayout.EndHorizontal();


            GUILayout.BeginHorizontal();
            int h = EditorGUILayout.IntField("ItemHeight", mTabBar.h, GUILayout.Width(200f));
            if (h != mTabBar.h)
            {
                mTabBar.h = h;
                OnSet();
            }
            GUILayout.EndHorizontal();



            UITabBar.Direction direction = (UITabBar.Direction)EditorGUILayout.EnumPopup("Direction", mTabBar.direction == null? UITabBar.Direction.Horizontal:mTabBar.direction);
            if (mTabBar.direction != direction)
            {
                mTabBar.direction = direction;
                OnSet();
//				EditorUtility.SetDirty(mTabBar);
            }


            GUILayout.BeginHorizontal();
            int fontSize = EditorGUILayout.IntField("SelectedFontSize", mTabBar.fontSize, GUILayout.Width(200f));
            if (fontSize != mTabBar.fontSize)
            {
                mTabBar.fontSize = fontSize;
                OnSet();
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            int normalSize = EditorGUILayout.IntField("NormalFontSize", mTabBar.normalSize, GUILayout.Width(200f));
            if (normalSize != mTabBar.normalSize)
            {
                mTabBar.normalSize = normalSize;
                OnSet();
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            float gap = EditorGUILayout.FloatField("Gap", mTabBar.gap, GUILayout.Width(200f));
            if (gap != mTabBar.gap)
            {
                mTabBar.gap = gap;
                OnSet();
            }
            GUILayout.EndHorizontal();


            GUILayout.BeginHorizontal();
            GUILayout.Label("SelectedColor");
            Color c = EditorGUILayout.ColorField(mTabBar.SelectedColor);
            if (c != mTabBar.SelectedColor)
            {
                mTabBar.SelectedColor = c;
                OnSet();
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GameColor.GColor SelectedGameColor = (GameColor.GColor)EditorGUILayout.EnumPopup("SelectedColor", mTabBar.SelectedGameColor, GUILayout.Width(200f));
            if (SelectedGameColor != mTabBar.SelectedGameColor)
            {
                mTabBar.SelectedColor = GameColor.GetColor(SelectedGameColor); OnSet(); mTabBar.SelectedGameColor = SelectedGameColor;
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("NormalColor");
            c = EditorGUILayout.ColorField(mTabBar.NormalColor);
            if (c != mTabBar.NormalColor)
            {
                mTabBar.NormalColor = c;
                OnSet();
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GameColor.GColor NormalGameColor = (GameColor.GColor)EditorGUILayout.EnumPopup("NormalColor", mTabBar.NormalGameColor, GUILayout.Width(200f));
            if (NormalGameColor != mTabBar.NormalGameColor)
            {
                mTabBar.NormalColor = GameColor.GetColor(NormalGameColor); OnSet(); mTabBar.NormalGameColor = NormalGameColor;
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            Vector2 SelectedTextPos = EditorGUILayout.Vector2Field("SelectedTextPos", mTabBar.SelectedTextPos);
            if (SelectedTextPos != mTabBar.SelectedTextPos)
            {
                mTabBar.SelectedTextPos = SelectedTextPos;
                OnSet();
            }
            GUILayout.EndHorizontal();


            GUILayout.BeginHorizontal();
            Vector2 NormalTextPos = EditorGUILayout.Vector2Field("NormalTextPos", mTabBar.NormalTextPos);
            if (NormalTextPos != mTabBar.NormalTextPos)
            {
                mTabBar.NormalTextPos = NormalTextPos;
                OnSet();
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            bool IsOutLine = EditorGUILayout.Toggle("IsOutline", mTabBar.IsOutline);
            if (IsOutLine != mTabBar.IsOutline)
            {
                mTabBar.IsOutline = IsOutLine;
                OnSet();
            }
            GUILayout.EndHorizontal();


            GUILayout.BeginHorizontal();
            bool isOnSet = EditorGUILayout.Toggle("OnSet", false);
//			Debug.Log("isOnSet:"+isOnSet);
            if (isOnSet)
            {
                OnSet();
            }
            GUILayout.EndHorizontal();
        }
    }
    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);
                }
            }
        }
    }