コード例 #1
0
    /// <summary>
    /// Draw the font preview window.
    /// </summary>

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

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

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

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

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

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

                HUDEditorTools.DrawSprite(tex, rect, outer, inner, uv, Color.white, m);
            }
        }
    }
コード例 #2
0
 void OnSelectAtlas(MonoBehaviour obj)
 {
     if (mFont != null)
     {
         HUDEditorTools.RegisterUndo("Font Atlas", mFont);
         MarkAsChanged();
     }
 }
コード例 #3
0
    /// <summary>
    /// Sprites's custom properties based on the type.
    /// </summary>

    protected virtual void DrawExtraProperties()
    {
        if (mSprite == null)
        {
            return;
        }

        HUDEditorTools.DrawSeparator();

        DrawEditData();

        GUILayout.Space(4f);
    }
コード例 #4
0
    /// <summary>
    /// Draw the custom wizard.
    /// </summary>

    void OnGUI()
    {
        EditorGUIUtility.LookLikeControls(80f);
        GUILayout.Label("Recently used components", "LODLevelNotifyText");
        HUDEditorTools.DrawSeparator();

        if (mObjects.Length == 0)
        {
            EditorGUILayout.HelpBox("No recently used " + mType.ToString() + " components found.\nTry drag & dropping one instead, or creating a new one.", MessageType.Info);

            bool isDone = false;

            EditorGUILayout.Space();
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();

            if (mType == typeof(UIFont))
            {
                if (GUILayout.Button("Open the Font Maker", GUILayout.Width(150f)))
                {
                    EditorWindow.GetWindow <UIFontMaker>(false, "Font Maker", true);
                    isDone = true;
                }
            }
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
            if (isDone)
            {
                Close();
            }
        }
        else
        {
            MonoBehaviour sel = null;

            foreach (MonoBehaviour o in mObjects)
            {
                if (DrawObject(o))
                {
                    sel = o;
                }
            }

            if (sel != null)
            {
                mCallback(sel);
                Close();
            }
        }
    }
コード例 #5
0
    /// <summary>
    /// Draw the sprite preview.
    /// </summary>

    public override void OnPreviewGUI(Rect rect, GUIStyle background)
    {
        // 绘制预览面板
        if (mSprite == null || !mSprite.isValid)
        {
            return;
        }

        if (m_sprite == null)
        {
            return;
        }

        UISpriteInfo sp = AtlasMng_Editor.instance.GetSprite(mSprite.name);

        if (sp == null)
        {
            return;
        }

        UITexAtlas atlas = AtlasMng_Editor.instance.GetAltasBySpriteName(mSprite.name);

        if (atlas == null || atlas.m_material == null)
        {
            return;
        }
        Texture2D tex = atlas.m_material.mainTexture as Texture2D;

        if (tex == null)
        {
            return;
        }

        Rect outer = new Rect(sp.outer);
        Rect inner = new Rect(sp.inner);
        Rect uv    = outer;

        if (atlas.coordinates == UITexAtlas.Coordinates.Pixels)
        {
            uv = HUDMath.ConvertToTexCoords(outer, tex.width, tex.height);
        }
        else
        {
            outer = HUDMath.ConvertToPixels(outer, tex.width, tex.height, true);
            inner = HUDMath.ConvertToPixels(inner, tex.width, tex.height, true);
        }
        HUDEditorTools.DrawSprite(tex, rect, outer, inner, uv, new Color(1.0f, 1.0f, 1.0f, 1.0f));
    }
コード例 #6
0
 Texture2D ImportPackTextureFunc(string szPathName)
 {
     return(HUDEditorTools.ImportTexture(szPathName, true, false));
 }
コード例 #7
0
    void  DrawEditData()
    {
        Color blue  = new Color(0f, 0.7f, 1f, 1f);
        Color green = new Color(0.4f, 1f, 0f, 1f);

        // 绘制预览面板
        if (mSprite == null || !mSprite.isValid)
        {
            return;
        }
        if (m_sprite == null)
        {
            return;
        }
        UISpriteInfo sprite = AtlasMng_Editor.instance.GetSprite(mSprite.name);

        if (sprite == null)
        {
            return;
        }
        UITexAtlas atlas = AtlasMng_Editor.instance.GetAltasBySpriteName(mSprite.name);

        if (atlas == null)
        {
            return;
        }

        Rect inner = sprite.inner;
        Rect outer = sprite.outer;

        if (atlas.coordinates == UITexAtlas.Coordinates.Pixels)
        {
            GUI.backgroundColor = green;

            // 渲染编辑对象
            outer = HUDEditorTools.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 = HUDEditorTools.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)
        {
            sprite.inner = inner;
            sprite.outer = outer;
            MarkSpriteAsDirty();              // 应用修改
            changed  = true;
            m_bDirty = true;
        }

        EditorGUILayout.Separator();

        if (atlas.coordinates == UITexAtlas.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);

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

            if (changed || a.x != left || a.y != top || b.x != right || b.y != bottom)
            {
                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();                  // 应用修改
                m_bDirty = true;
                changed  = true;
            }
        }
        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 (atlas.coordinates == UITexAtlas.Coordinates.Pixels)
                {
                    corrected0 = HUDMath.MakePixelPerfect(corrected0);
                    corrected1 = HUDMath.MakePixelPerfect(corrected1);
                }
                else
                {
                    corrected0 = HUDMath.MakePixelPerfect(corrected0, atlas.texWidth, atlas.texHeight);
                    corrected1 = HUDMath.MakePixelPerfect(corrected1, atlas.texWidth, atlas.texHeight);
                }

                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;
                    m_bDirty    = true;
                    changed     = true;
                }
            }
            GUILayout.EndHorizontal();
        }

        if (changed)
        {
            m_bDirty = IsChangeSprite(m_sprite, sprite);
        }

        HUDEditorTools.DrawSeparator();
        GUILayout.BeginHorizontal();
        GUI.backgroundColor = m_bDirty ? Color.green : Color.white;
        if (GUILayout.Button("修改"))
        {
            if (m_bDirty && m_sprite != null)
            {
                m_sprite.Copy(sprite);
                MarkSpriteAsDirty();                  // 应用修改
                AtlasMng_Editor.instance.SaveAltasCfg();
                m_bDirty = false;
            }
        }
        if (GUILayout.Button("撤消"))
        {
            sprite.Copy(m_sprite);
            MarkSpriteAsDirty();              // 应用修改
            m_bDirty = false;
        }
        GUI.backgroundColor = Color.white;
        GUILayout.EndHorizontal();


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

            //GUI.backgroundColor = Color.green;

            //if (GUILayout.Button("<< Return to " + NGUIEditorTools.previousSelection.name))
            //{
            //    NGUIEditorTools.SelectPrevious();
            //}
            //GUI.backgroundColor = Color.white;
        }
    }
コード例 #8
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();
        }
    }
コード例 #9
0
    /// <summary>
    /// Sprite selection callback.
    /// </summary>

    void SelectSprite(string spriteName)
    {
        HUDEditorTools.RegisterUndo("Font Sprite", mFont);
        mFont.spriteName = spriteName;
        Repaint();
    }