using System;
using UnityEngine.Serialization;
namespace UnityEngine.UI
{
[Serializable]
///
/// Struct for storing Text generation settings.
///
public class FontData : ISerializationCallbackReceiver
{
[SerializeField]
[FormerlySerializedAs("font")]
private Font m_Font;
[SerializeField]
[FormerlySerializedAs("fontSize")]
private int m_FontSize;
[SerializeField]
[FormerlySerializedAs("fontStyle")]
private FontStyle m_FontStyle;
[SerializeField]
private bool m_BestFit;
[SerializeField]
private int m_MinSize;
[SerializeField]
private int m_MaxSize;
[SerializeField]
[FormerlySerializedAs("alignment")]
private TextAnchor m_Alignment;
[SerializeField]
private bool m_AlignByGeometry;
[SerializeField]
[FormerlySerializedAs("richText")]
private bool m_RichText;
[SerializeField]
private HorizontalWrapMode m_HorizontalOverflow;
[SerializeField]
private VerticalWrapMode m_VerticalOverflow;
[SerializeField]
private float m_LineSpacing;
///
/// Get a font data with sensible defaults.
///
public static FontData defaultFontData
{
get
{
var fontData = new FontData
{
m_FontSize = 14,
m_LineSpacing = 1f,
m_FontStyle = FontStyle.Normal,
m_BestFit = false,
m_MinSize = 10,
m_MaxSize = 40,
m_Alignment = TextAnchor.UpperLeft,
m_HorizontalOverflow = HorizontalWrapMode.Wrap,
m_VerticalOverflow = VerticalWrapMode.Truncate,
m_RichText = true,
m_AlignByGeometry = false
};
return fontData;
}
}
///
/// The Font to use for this generated Text object.
///
public Font font
{
get { return m_Font; }
set { m_Font = value; }
}
///
/// The Font size to use for this generated Text object.
///
public int fontSize
{
get { return m_FontSize; }
set { m_FontSize = value; }
}
///
/// The font style to use for this generated Text object.
///
public FontStyle fontStyle
{
get { return m_FontStyle; }
set { m_FontStyle = value; }
}
///
/// Is best fit used for this generated Text object.
///
public bool bestFit
{
get { return m_BestFit; }
set { m_BestFit = value; }
}
///
/// The min size for this generated Text object.
///
public int minSize
{
get { return m_MinSize; }
set { m_MinSize = value; }
}
///
/// The max size for this generated Text object.
///
public int maxSize
{
get { return m_MaxSize; }
set { m_MaxSize = value; }
}
///
/// How is the text aligned for this generated Text object.
///
public TextAnchor alignment
{
get { return m_Alignment; }
set { m_Alignment = value; }
}
///
/// Use the extents of glyph geometry to perform horizontal alignment rather than glyph metrics.
///
///
/// This can result in better fitting left and right alignment, but may result in incorrect positioning when attempting to overlay multiple fonts (such as a specialized outline font) on top of each other.
///
public bool alignByGeometry
{
get { return m_AlignByGeometry; }
set { m_AlignByGeometry = value; }
}
///
/// Should rich text be used for this generated Text object.
///
public bool richText
{
get { return m_RichText; }
set { m_RichText = value; }
}
///
/// The horizontal overflow policy for this generated Text object.
///
public HorizontalWrapMode horizontalOverflow
{
get { return m_HorizontalOverflow; }
set { m_HorizontalOverflow = value; }
}
///
/// The vertical overflow policy for this generated Text object.
///
public VerticalWrapMode verticalOverflow
{
get { return m_VerticalOverflow; }
set { m_VerticalOverflow = value; }
}
///
/// The line spaceing for this generated Text object.
///
public float lineSpacing
{
get { return m_LineSpacing; }
set { m_LineSpacing = value; }
}
void ISerializationCallbackReceiver.OnBeforeSerialize()
{}
void ISerializationCallbackReceiver.OnAfterDeserialize()
{
m_FontSize = Mathf.Clamp(m_FontSize, 0, 300);
m_MinSize = Mathf.Clamp(m_MinSize, 0, m_FontSize);
m_MaxSize = Mathf.Clamp(m_MaxSize, m_FontSize, 300);
}
}
}