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