I've been looking into stylising some fonts, I just want to add a gradient to the titles on the menu pages, I thought I might be able to achieve this with the font material but so far have had no luck. Does anyone know of a way to stylise fonts in the new UI system? Cheers
You can do lots of effects like this. You could modify the color information of the vertices on generation, or you could use UV1 or similar to achieve this. Either way it will require some custom coding. The simplest way is to modify vertex color (note I have not implemented the gradient calculation): Add this to any 'Graphic' and the vert colors will get post processed. Code (csharp): using System.Collections.Generic; namespace UnityEngine.UI { [AddComponentMenu ("UI/Effects/Shadow", 14)] public class Gradient : BaseVertexEffect { [SerializeField] private Color m_EffectColor = new Color (0f, 0f, 0f, 0.5f); protected Gradient() {} public Color effectColor { get { return m_EffectColor; } set { m_EffectColor = value; if (graphic != null) graphic.SetVerticesDirty (); } } protected void ApplyGradient(List<UIVertex> verts, Color32 color) { for (int i = 0; i < verts.Count; ++i) { var vt = verts[i]; vt.color = CalculateGradientThingy(); verts[i] = vt; } } public override void ModifyVertices(List<UIVertex> verts) { if (!IsActive ()) return; ApplyGradient (verts, effectColor); } } }
Cheers Tim! Heres the script for anyone interested. It allows a 2 colour gradient (with alpha if you wish) to be applied to any Unity UI Graphics. I've included a bool to select the direction of the gradient (vertical or horizontal). It would be great to pick the angle of the gradient but my coding capabilities don't extend that far just yet! Code (CSharp): using System.Collections.Generic; using UnityEngine; namespace UnityEngine.UI { [ExecuteInEditMode] [AddComponentMenu ("UI/Effects/gradient", 14)] public class Gradient : BaseVertexEffect { [SerializeField] private Color col_1 = new Color (0f, 0f, 0f, 1f); [SerializeField] private Color col_2 = new Color (255f, 255f, 0f, 1f); [RangeAttribute(-1, 1)] public float _Scale = 1f; public bool Horizontal = false; public Color color1 { get { return col_1; } set { col_1 = value; if (graphic != null) graphic.SetVerticesDirty (); } } public Color color2 { get { return col_2; } set { col_2 = value; if (graphic != null) graphic.SetVerticesDirty (); } } protected void ApplyGradient(List<UIVertex> verts) { for (int i = 0; i < verts.Count; ++i) { var vt = verts[i]; if(!Horizontal){ vt.color = Color32.Lerp(col_2,col_1, vt.position.y * (_Scale/10)); }else{ vt.color = Color32.Lerp(col_2,col_1, vt.position.x * (_Scale/10)); } verts[i] = vt; } } public override void ModifyVertices(List<UIVertex> verts) { if (!IsActive ()) return; ApplyGradient (verts); } } } It works with the other UI effects too (shadow and outline) Hope it helps some of you!