From 9e786f6aa623aa7d9bf69ccfe6037d83bb181637 Mon Sep 17 00:00:00 2001 From: herbst Date: Wed, 22 Mar 2017 12:56:21 +0100 Subject: [PATCH 1/2] added monospacing script and added TextEffects example scene --- Examples/TextEffects.meta | 9 + Examples/TextEffects/TextEffects.unity | Bin 0 -> 36328 bytes Examples/TextEffects/TextEffects.unity.meta | 8 + Scripts/Effects/MonoSpacing.cs | 180 ++++++++++++++++++++ Scripts/Effects/MonoSpacing.cs.meta | 12 ++ 5 files changed, 209 insertions(+) create mode 100644 Examples/TextEffects.meta create mode 100644 Examples/TextEffects/TextEffects.unity create mode 100644 Examples/TextEffects/TextEffects.unity.meta create mode 100644 Scripts/Effects/MonoSpacing.cs create mode 100644 Scripts/Effects/MonoSpacing.cs.meta diff --git a/Examples/TextEffects.meta b/Examples/TextEffects.meta new file mode 100644 index 0000000..af0e258 --- /dev/null +++ b/Examples/TextEffects.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: afd482c1b3a787a47be2acc874c4fc44 +folderAsset: yes +timeCreated: 1490183285 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Examples/TextEffects/TextEffects.unity b/Examples/TextEffects/TextEffects.unity new file mode 100644 index 0000000000000000000000000000000000000000..678592152b4d7c92a865f8e342cbdbebbb23d320 GIT binary patch literal 36328 zcmeHw37A|}weGG?2uVN#QIRoLLXZ$b$Q%+#Qq@xiGBn*um`P5mPj?rouIf}(C+Wbu zlmY@5;pzt>gLo4_uTN0;nB-lqh=N{t0-}$>0U-h^laGkX)$9An`~SW6sxzcI>1e!u z@6j7}YVZH7v-Y(1T5Iop&S_%`Q;oUmHDk=d#uQrcYi3TKIeBWwRP)}>ojVhU0XT~2 z&YkU@FU=@*Z@v4;JiH(?Uy%R@}%?u4lf1(K-7 zgdy7#5f4O^`zyF!XSRXILSUpHf{1JtKLa`9jA7h&*nU+!VV(xTCgcx79A*IUXK@(sPYTsGg?=9kO(DVgepdT+g7MZ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BJnCchobUB#o+1I_7NSKom5>H3suUB6PU7+bK_%7qdA!@qX^>KYoXLLuHB<|R_^ zGU%F>X4cb1H_c~DP+N<`BT3%(r zoO>UeulN1E{SmHTZ<;7I);jT5^`T<5+Z3SM9|5v!N_a-cRrfMTt$Q6z>s|=u((0^2 zzM!9f+!ykxdoo~O2_nZR9D*@ZROeESeo?t`zoQ<3hYVfv=?2U+L@QG<{>nA@)p{v^ z&f&P9P3jA-y~^pS;NDuPI6uni`^j&vpuNleO-ZiMM)Dh?$!Q~3cEMZ5|6abpKk;XM z#e&R8z5ev=sBG4f7|7NMCPY z^GNHZ^N4*HpGR+<_5k_qHpKb7-{uc>tfnM%^nW58X?q z93P0-(8pD)U*vq=7j{7Rw86R(#DUANwgvZUh{`YaTTJDgz20xpda3-f{c-ud^v&Px z(FVl%yx-*a@4auL{jb7N>sMtc?6c}w2I;G39Z2h02<3r3vwP-ZpZM%xXY~9<<&N^A zX9T>?px0`xi-aQhw-!G=X9%d6;@&yu-J(XE<{(O-|AW&*Tw{#SOQ8w>8!s<>&6c5+ zk6!3Er~IM>{nta;tDhLYkA3;K2r56}HIkl5u{=GqVp`9%C_g-FqO0S)g5(6gaFfj7 zjhoVO`$D&}JUweevJ%92|1qx-R0!ICHTo>7Uk&~2p6~3fpRM)M@uHl?^(*%PHq5&k za<}IY=f`@#pZx6O(B7yw9CL^F(jnIV++EMB+=tiwdQQsw^c verts = new List(); + vh.GetUIVertexStream(verts); + + Text text = GetComponent(); + if (text == null) + { + Debug.LogWarning("LetterSpacing: Missing Text component"); + return; + } + + string[] lines = text.text.Split('\n'); + // Vector3 pos; + float letterOffset = spacing * (float)text.fontSize / 100f; + float alignmentFactor = 0; + int glyphIdx = 0; + + switch (text.alignment) + { + case TextAnchor.LowerLeft: + case TextAnchor.MiddleLeft: + case TextAnchor.UpperLeft: + alignmentFactor = 0f; + break; + + case TextAnchor.LowerCenter: + case TextAnchor.MiddleCenter: + case TextAnchor.UpperCenter: + alignmentFactor = 0.5f; + break; + + case TextAnchor.LowerRight: + case TextAnchor.MiddleRight: + case TextAnchor.UpperRight: + alignmentFactor = 1f; + break; + } + + for (int lineIdx=0; lineIdx < lines.Length; lineIdx++) + { + string line = lines[lineIdx]; + float lineOffset = (line.Length -1) * letterOffset * alignmentFactor; + + var offsetX = - lineOffset + letterOffset / 2; + for (int charIdx = 0; charIdx < line.Length; charIdx++) + { + int idx1 = glyphIdx * 6 + 0; + int idx2 = glyphIdx * 6 + 1; + int idx3 = glyphIdx * 6 + 2; + int idx4 = glyphIdx * 6 + 3; + int idx5 = glyphIdx * 6 + 4; + int idx6 = glyphIdx * 6 + 5; + + // Check for truncated text (doesn't generate verts for all characters) + if (idx6 > verts.Count - 1) return; + + UIVertex vert1 = verts[idx1]; + UIVertex vert2 = verts[idx2]; + UIVertex vert3 = verts[idx3]; + UIVertex vert4 = verts[idx4]; + UIVertex vert5 = verts[idx5]; + UIVertex vert6 = verts[idx6]; + + // pos = Vector3.right * (letterOffset * (charIdx) - lineOffset); + float charWidth = (vert2.position - vert1.position).x; + var smallChar = charWidth < halfCharWidth; + + var smallCharOffset = smallChar ? -letterOffset/4 : 0; + + vert1.position += new Vector3(-vert1.position.x + offsetX + -.5f * charWidth + smallCharOffset, 0, 0); + vert2.position += new Vector3(-vert2.position.x + offsetX + .5f * charWidth + smallCharOffset, 0, 0); + vert3.position += new Vector3(-vert3.position.x + offsetX + .5f * charWidth + smallCharOffset, 0, 0); + vert4.position += new Vector3(-vert4.position.x + offsetX + .5f * charWidth + smallCharOffset, 0, 0); + vert5.position += new Vector3(-vert5.position.x + offsetX + -.5f * charWidth + smallCharOffset, 0, 0); + vert6.position += new Vector3(-vert6.position.x + offsetX + -.5f * charWidth + smallCharOffset, 0, 0); + + if (smallChar) + offsetX += letterOffset / 2; + else + offsetX += letterOffset; + + verts[idx1] = vert1; + verts[idx2] = vert2; + verts[idx3] = vert3; + verts[idx4] = vert4; + verts[idx5] = vert5; + verts[idx6] = vert6; + + glyphIdx++; + } + + // Offset for carriage return character that still generates verts + glyphIdx++; + } + vh.Clear(); + vh.AddUIVertexTriangleStream(verts); + } + } +} diff --git a/Scripts/Effects/MonoSpacing.cs.meta b/Scripts/Effects/MonoSpacing.cs.meta new file mode 100644 index 0000000..775d928 --- /dev/null +++ b/Scripts/Effects/MonoSpacing.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 97a58789aa01843488ef44dc747ee8e8 +timeCreated: 1490183235 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From 1ef67d5fbaf794ea8163c45556e1b37dc9893b98 Mon Sep 17 00:00:00 2001 From: herbst Date: Wed, 22 Mar 2017 14:16:03 +0100 Subject: [PATCH 2/2] mono spacing text works with right alignment now, example scene --- Examples/TextEffects/TextEffects.unity | Bin 36328 -> 40736 bytes Scripts/Effects/MonoSpacing.cs | 21 +++++++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Examples/TextEffects/TextEffects.unity b/Examples/TextEffects/TextEffects.unity index 678592152b4d7c92a865f8e342cbdbebbb23d320..e49b674f48433261581e942327e5ca420080fd66 100644 GIT binary patch delta 3183 zcmb7`ZA?>F7{^ab!Kx@lPzwrHp^AzM;u4p|@lqE^bQ=mH$==#YD_syuTTmR>3gRG; zOn0*Qx(LopHs`YCx`~b`@e^(?A!b>~KH(SRG>iSPWbD)Se{P?{og*Z!dN}9)?s?wM zbIx<_qjTngTjmrYnqL&+fM59D3oh<>~R#i&|!T<1)P5rKRpJ zH_Ol7v^xidh(bnK&@#~IXTm??848Q z_lKO9Fe?%5@gIc==){B>;^>pmo-nJGruWh!6Hu53YDKGVb}vPzi?*R7TYH#Aq3#%- z=c3gxvqD`hp68+MW#$G8;CVjU*xUBy=)^c!3wqLbms!OeAx;Ys(cS!k;Ur+SNeFb} zM`l}LQ8~E#$zENd8%!yzVm1K=g}T0KW&wD%h4t-WHU!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MJ0jQ-I2^B@t__jh+L(!=50^SS4D&iDNOBpxZL zAtj&ah>z%eiiqan`%eDXnuV8N?s3{DO5blNyEPX6eR$te{4Ce!?b@n{;BKcV2)aaS zovOdCd*D<`NDLfmiN=tU4g2)Vmjy>t3Xuk%1N+RZ8h@;1dfWBX$Z_q z=w?QXW}2LRGgvE|s9>kzOI}yw4+{J7X!3bh` zc7MMWABLkQSLQCrCX~)FS~4?;g;@;DJQ9Uj3M|08l@(=JQZO^g*qKi!W!)f{ImumS zDKK-l?lIGrWiBB!(Kxd-n7Lc`nS}~xddOD>4Wz$2a>61eI&6AF^9kib#3nwptj^Kq zJ~{BwE^hSuM54u}2f{&%Xc}_qQ>|e|-*jq9amcmLo>r9&#p7i^fBYyDFCtD|)y6GW zd9Whg>(r-DU$lrn9S>#E=bgoQ`A_f$Dv5gicmsanJ);V5muhXhc)n899PqM;k8d7Yc{9IBNS>IEfw;e@lQNRsLR~SW-Jq|J2z6lD1b)swexs#*{)G7}0ND&doA}4`zgi s9{(>q?m^{5d2?x>Azs(wUSs!8_8T?hgKfs{X~Q<%dnJ&m8@t;550W@CVE_OC diff --git a/Scripts/Effects/MonoSpacing.cs b/Scripts/Effects/MonoSpacing.cs index b012da0..55086bc 100644 --- a/Scripts/Effects/MonoSpacing.cs +++ b/Scripts/Effects/MonoSpacing.cs @@ -1,10 +1,10 @@ -/// Credit Deeperbeige +/// Credit herbst / derived from LetterSpacing by Deeperbeige /// Sourced from - http://forum.unity3d.com/threads/adjustable-character-spacing-free-script.288277/ /* -Produces an simple tracking/letter-spacing effect on UI Text components. +Produces an simple mono-spacing effect on UI Text components. -Set the spacing parameter to adjust letter spacing. +Set the spacing parameter to adjust mono spacing. Negative values cuddle the text up tighter than normal. Go too far and it'll look odd. Positive values spread the text out more than normal. This will NOT respect the text area you've defined. Zero spacing will present the font with no changes. @@ -50,17 +50,21 @@ namespace UnityEngine.UI.Extensions /// Note, Vertex Count has changed in 5.2.1+, is now 6 (two tris) instead of 4 (tri strip). public class MonoSpacing : BaseMeshEffect { + public bool useHalfCharWidth = false; public float halfCharWidth = 1; [SerializeField] private float m_spacing = 0f; + RectTransform rectTransform; + protected MonoSpacing() { } #if UNITY_EDITOR protected override void OnValidate() { spacing = m_spacing; + rectTransform = GetComponent().GetComponent(); base.OnValidate(); } #endif @@ -86,7 +90,7 @@ namespace UnityEngine.UI.Extensions Text text = GetComponent(); if (text == null) { - Debug.LogWarning("LetterSpacing: Missing Text component"); + Debug.LogWarning("MonoSpacing: Missing Text component"); return; } @@ -120,9 +124,10 @@ namespace UnityEngine.UI.Extensions for (int lineIdx=0; lineIdx < lines.Length; lineIdx++) { string line = lines[lineIdx]; - float lineOffset = (line.Length -1) * letterOffset * alignmentFactor; + float lineOffset = (line.Length - 1) * letterOffset * (alignmentFactor) - (alignmentFactor - 0.5f) * rectTransform.rect.width; + + var offsetX = -lineOffset + letterOffset / 2 * (1 - alignmentFactor * 2); - var offsetX = - lineOffset + letterOffset / 2; for (int charIdx = 0; charIdx < line.Length; charIdx++) { int idx1 = glyphIdx * 6 + 0; @@ -144,10 +149,10 @@ namespace UnityEngine.UI.Extensions // pos = Vector3.right * (letterOffset * (charIdx) - lineOffset); float charWidth = (vert2.position - vert1.position).x; - var smallChar = charWidth < halfCharWidth; + var smallChar = useHalfCharWidth && (charWidth < halfCharWidth); var smallCharOffset = smallChar ? -letterOffset/4 : 0; - + vert1.position += new Vector3(-vert1.position.x + offsetX + -.5f * charWidth + smallCharOffset, 0, 0); vert2.position += new Vector3(-vert2.position.x + offsetX + .5f * charWidth + smallCharOffset, 0, 0); vert3.position += new Vector3(-vert3.position.x + offsetX + .5f * charWidth + smallCharOffset, 0, 0);