当前位置: 首页>>代码示例>>C#>>正文


C# UIFont.Refresh方法代码示例

本文整理汇总了C#中UIFont.Refresh方法的典型用法代码示例。如果您正苦于以下问题:C# UIFont.Refresh方法的具体用法?C# UIFont.Refresh怎么用?C# UIFont.Refresh使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UIFont的用法示例。


在下文中一共展示了UIFont.Refresh方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnInspectorGUI

    public override void OnInspectorGUI()
    {
        EditorGUIUtility.LookLikeControls(80f);
        NGUIEditorTools.DrawSeparator();

        mFont = target as UIFont;

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

        if (mFont.atlas != null)
        {
            if (mFont.bmFont.isValid)
            {
                string spriteName = UISlicedSpriteInspector.SpriteField((UIAtlas)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.Refresh();
                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)
                    {
//.........这里部分代码省略.........
开发者ID:light17,项目名称:Thunder,代码行数:101,代码来源:UIFontInspector.cs


注:本文中的UIFont.Refresh方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。