Dossier complet
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
// Allow internal visibility for testing purposes.
|
||||
[assembly: InternalsVisibleTo("Unity.TextCore")]
|
||||
|
||||
[assembly: InternalsVisibleTo("Unity.FontEngine.Tests")]
|
||||
|
||||
#if UNITY_EDITOR
|
||||
[assembly: InternalsVisibleTo("Unity.TextCore.Editor")]
|
||||
[assembly: InternalsVisibleTo("Unity.TextMeshPro.Editor")]
|
||||
#endif
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1c147d10db452eb4b854a35f84472017
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,150 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
||||
namespace TMPro
|
||||
{
|
||||
public class FastAction
|
||||
{
|
||||
|
||||
LinkedList<System.Action> delegates = new LinkedList<System.Action>();
|
||||
|
||||
Dictionary<System.Action, LinkedListNode<System.Action>> lookup = new Dictionary<System.Action, LinkedListNode<System.Action>>();
|
||||
|
||||
public void Add(System.Action rhs)
|
||||
{
|
||||
if (lookup.ContainsKey(rhs)) return;
|
||||
|
||||
lookup[rhs] = delegates.AddLast(rhs);
|
||||
}
|
||||
|
||||
public void Remove(System.Action rhs)
|
||||
{
|
||||
LinkedListNode<System.Action> node;
|
||||
if (lookup.TryGetValue(rhs, out node))
|
||||
{
|
||||
lookup.Remove(rhs);
|
||||
delegates.Remove(node);
|
||||
}
|
||||
}
|
||||
|
||||
public void Call()
|
||||
{
|
||||
var node = delegates.First;
|
||||
while (node != null)
|
||||
{
|
||||
node.Value();
|
||||
node = node.Next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class FastAction<A>
|
||||
{
|
||||
|
||||
LinkedList<System.Action<A>> delegates = new LinkedList<System.Action<A>>();
|
||||
|
||||
Dictionary<System.Action<A>, LinkedListNode<System.Action<A>>> lookup = new Dictionary<System.Action<A>, LinkedListNode<System.Action<A>>>();
|
||||
|
||||
public void Add(System.Action<A> rhs)
|
||||
{
|
||||
if (lookup.ContainsKey(rhs)) return;
|
||||
|
||||
lookup[rhs] = delegates.AddLast(rhs);
|
||||
}
|
||||
|
||||
public void Remove(System.Action<A> rhs)
|
||||
{
|
||||
LinkedListNode<System.Action<A>> node;
|
||||
if (lookup.TryGetValue(rhs, out node))
|
||||
{
|
||||
lookup.Remove(rhs);
|
||||
delegates.Remove(node);
|
||||
}
|
||||
}
|
||||
|
||||
public void Call(A a)
|
||||
{
|
||||
var node = delegates.First;
|
||||
while (node != null)
|
||||
{
|
||||
node.Value(a);
|
||||
node = node.Next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class FastAction<A, B>
|
||||
{
|
||||
|
||||
LinkedList<System.Action<A, B>> delegates = new LinkedList<System.Action<A, B>>();
|
||||
|
||||
Dictionary<System.Action<A, B>, LinkedListNode<System.Action<A, B>>> lookup = new Dictionary<System.Action<A, B>, LinkedListNode<System.Action<A, B>>>();
|
||||
|
||||
public void Add(System.Action<A, B> rhs)
|
||||
{
|
||||
if (lookup.ContainsKey(rhs)) return;
|
||||
|
||||
lookup[rhs] = delegates.AddLast(rhs);
|
||||
}
|
||||
|
||||
public void Remove(System.Action<A, B> rhs)
|
||||
{
|
||||
LinkedListNode<System.Action<A, B>> node;
|
||||
if (lookup.TryGetValue(rhs, out node))
|
||||
{
|
||||
lookup.Remove(rhs);
|
||||
delegates.Remove(node);
|
||||
}
|
||||
}
|
||||
|
||||
public void Call(A a, B b)
|
||||
{
|
||||
var node = delegates.First;
|
||||
while (node != null)
|
||||
{
|
||||
node.Value(a, b);
|
||||
node = node.Next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class FastAction<A, B, C>
|
||||
{
|
||||
|
||||
LinkedList<System.Action<A, B, C>> delegates = new LinkedList<System.Action<A, B, C>>();
|
||||
|
||||
Dictionary<System.Action<A, B, C>, LinkedListNode<System.Action<A, B, C>>> lookup = new Dictionary<System.Action<A, B, C>, LinkedListNode<System.Action<A, B, C>>>();
|
||||
|
||||
public void Add(System.Action<A, B, C> rhs)
|
||||
{
|
||||
if (lookup.ContainsKey(rhs)) return;
|
||||
|
||||
lookup[rhs] = delegates.AddLast(rhs);
|
||||
}
|
||||
|
||||
public void Remove(System.Action<A, B, C> rhs)
|
||||
{
|
||||
LinkedListNode<System.Action<A, B, C>> node;
|
||||
if (lookup.TryGetValue(rhs, out node))
|
||||
{
|
||||
lookup.Remove(rhs);
|
||||
delegates.Remove(node);
|
||||
}
|
||||
}
|
||||
|
||||
public void Call(A a, B b, C c)
|
||||
{
|
||||
var node = delegates.First;
|
||||
while (node != null)
|
||||
{
|
||||
node.Value(a, b, c);
|
||||
node = node.Next;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 871f8edd56e84b8fb295b10cc3c78f36
|
||||
timeCreated: 1435956061
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,17 @@
|
||||
|
||||
|
||||
namespace TMPro
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface used for preprocessing and shaping of text.
|
||||
/// </summary>
|
||||
public interface ITextPreprocessor
|
||||
{
|
||||
/// <summary>
|
||||
/// Function used for preprocessing of text
|
||||
/// </summary>
|
||||
/// <param name="text">Source text to be processed</param>
|
||||
/// <returns>Processed text</returns>
|
||||
string PreprocessText(string text);
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: afc31ad767318c9488de260c166cd21d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 11a6a034ab84493cbed6af5ae7aae78b
|
||||
timeCreated: 1449743129
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TMPro
|
||||
{
|
||||
|
||||
// Base class inherited by the various TextMeshPro Assets.
|
||||
[Serializable]
|
||||
public abstract class TMP_Asset : ScriptableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Instance ID of the TMP Asset
|
||||
/// </summary>
|
||||
public int instanceID
|
||||
{
|
||||
get
|
||||
{
|
||||
if (m_InstanceID == 0)
|
||||
m_InstanceID = GetInstanceID();
|
||||
|
||||
return m_InstanceID;
|
||||
}
|
||||
}
|
||||
private int m_InstanceID;
|
||||
|
||||
/// <summary>
|
||||
/// HashCode based on the name of the asset.
|
||||
/// </summary>
|
||||
public int hashCode;
|
||||
|
||||
/// <summary>
|
||||
/// The material used by this asset.
|
||||
/// </summary>
|
||||
public Material material;
|
||||
|
||||
/// <summary>
|
||||
/// HashCode based on the name of the material assigned to this asset.
|
||||
/// </summary>
|
||||
public int materialHashCode;
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3bda1886f58f4e0ab1139400b160c3ee
|
||||
timeCreated: 1459318952
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,70 @@
|
||||
using System;
|
||||
using UnityEngine.TextCore;
|
||||
|
||||
namespace TMPro
|
||||
{
|
||||
/// <summary>
|
||||
/// A basic element of text.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class TMP_Character : TMP_TextElement
|
||||
{
|
||||
/// <summary>
|
||||
/// Default constructor.
|
||||
/// </summary>
|
||||
public TMP_Character()
|
||||
{
|
||||
m_ElementType = TextElementType.Character;
|
||||
this.scale = 1.0f;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for new character
|
||||
/// </summary>
|
||||
/// <param name="unicode">Unicode value.</param>
|
||||
/// <param name="glyph">Glyph</param>
|
||||
public TMP_Character(uint unicode, Glyph glyph)
|
||||
{
|
||||
m_ElementType = TextElementType.Character;
|
||||
|
||||
this.unicode = unicode;
|
||||
this.textAsset = null;
|
||||
this.glyph = glyph;
|
||||
this.glyphIndex = glyph.index;
|
||||
this.scale = 1.0f;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for new character
|
||||
/// </summary>
|
||||
/// <param name="unicode">Unicode value.</param>
|
||||
/// <param name="fontAsset">The font asset to which this character belongs.</param>
|
||||
/// <param name="glyph">Glyph</param>
|
||||
public TMP_Character(uint unicode, TMP_FontAsset fontAsset, Glyph glyph)
|
||||
{
|
||||
m_ElementType = TextElementType.Character;
|
||||
|
||||
this.unicode = unicode;
|
||||
this.textAsset = fontAsset;
|
||||
this.glyph = glyph;
|
||||
this.glyphIndex = glyph.index;
|
||||
this.scale = 1.0f;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for new character
|
||||
/// </summary>
|
||||
/// <param name="unicode">Unicode value.</param>
|
||||
/// <param name="glyphIndex">Glyph index.</param>
|
||||
internal TMP_Character(uint unicode, uint glyphIndex)
|
||||
{
|
||||
m_ElementType = TextElementType.Character;
|
||||
|
||||
this.unicode = unicode;
|
||||
this.textAsset = null;
|
||||
this.glyph = null;
|
||||
this.glyphIndex = glyphIndex;
|
||||
this.scale = 1.0f;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4ac5b6a65aaeb59478e3b78660e9f134
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,220 @@
|
||||
using System.Diagnostics;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
namespace TMPro
|
||||
{
|
||||
public struct TMP_Vertex
|
||||
{
|
||||
public Vector3 position;
|
||||
public Vector2 uv;
|
||||
public Vector2 uv2;
|
||||
public Vector2 uv4;
|
||||
public Color32 color;
|
||||
|
||||
public static TMP_Vertex zero { get { return k_Zero; } }
|
||||
|
||||
//public Vector3 normal;
|
||||
//public Vector4 tangent;
|
||||
|
||||
static readonly TMP_Vertex k_Zero = new TMP_Vertex();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public struct TMP_Offset
|
||||
{
|
||||
public float left { get { return m_Left; } set { m_Left = value; } }
|
||||
|
||||
public float right { get { return m_Right; } set { m_Right = value; } }
|
||||
|
||||
public float top { get { return m_Top; } set { m_Top = value; } }
|
||||
|
||||
public float bottom { get { return m_Bottom; } set { m_Bottom = value; } }
|
||||
|
||||
public float horizontal { get { return m_Left; } set { m_Left = value; m_Right = value; } }
|
||||
|
||||
public float vertical { get { return m_Top; } set { m_Top = value; m_Bottom = value; } }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public static TMP_Offset zero { get { return k_ZeroOffset; } }
|
||||
|
||||
// =============================================
|
||||
// Private backing fields for public properties.
|
||||
// =============================================
|
||||
|
||||
float m_Left;
|
||||
float m_Right;
|
||||
float m_Top;
|
||||
float m_Bottom;
|
||||
|
||||
static readonly TMP_Offset k_ZeroOffset = new TMP_Offset(0F, 0F, 0F, 0F);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="left"></param>
|
||||
/// <param name="right"></param>
|
||||
/// <param name="top"></param>
|
||||
/// <param name="bottom"></param>
|
||||
public TMP_Offset(float left, float right, float top, float bottom)
|
||||
{
|
||||
m_Left = left;
|
||||
m_Right = right;
|
||||
m_Top = top;
|
||||
m_Bottom = bottom;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="horizontal"></param>
|
||||
/// <param name="vertical"></param>
|
||||
public TMP_Offset(float horizontal, float vertical)
|
||||
{
|
||||
m_Left = horizontal;
|
||||
m_Right = horizontal;
|
||||
m_Top = vertical;
|
||||
m_Bottom = vertical;
|
||||
}
|
||||
|
||||
public static bool operator ==(TMP_Offset lhs, TMP_Offset rhs)
|
||||
{
|
||||
return lhs.m_Left == rhs.m_Left &&
|
||||
lhs.m_Right == rhs.m_Right &&
|
||||
lhs.m_Top == rhs.m_Top &&
|
||||
lhs.m_Bottom == rhs.m_Bottom;
|
||||
}
|
||||
|
||||
public static bool operator !=(TMP_Offset lhs, TMP_Offset rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
public static TMP_Offset operator *(TMP_Offset a, float b)
|
||||
{
|
||||
return new TMP_Offset(a.m_Left * b, a.m_Right * b, a.m_Top * b, a.m_Bottom * b);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return base.Equals(obj);
|
||||
}
|
||||
|
||||
public bool Equals(TMP_Offset other)
|
||||
{
|
||||
return base.Equals(other);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public struct HighlightState
|
||||
{
|
||||
public Color32 color;
|
||||
public TMP_Offset padding;
|
||||
|
||||
public HighlightState(Color32 color, TMP_Offset padding)
|
||||
{
|
||||
this.color = color;
|
||||
this.padding = padding;
|
||||
}
|
||||
|
||||
public static bool operator ==(HighlightState lhs, HighlightState rhs)
|
||||
{
|
||||
return lhs.color.Compare(rhs.color) && lhs.padding == rhs.padding;
|
||||
}
|
||||
|
||||
public static bool operator !=(HighlightState lhs, HighlightState rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return base.Equals(obj);
|
||||
}
|
||||
|
||||
public bool Equals(HighlightState other)
|
||||
{
|
||||
return base.Equals(other);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Structure containing information about individual text elements (character or sprites).
|
||||
/// </summary>
|
||||
[DebuggerDisplay("Unicode '{character}' ({((uint)character).ToString(\"X\")})")]
|
||||
public struct TMP_CharacterInfo
|
||||
{
|
||||
public char character; // Should be changed to an uint to handle UTF32
|
||||
/// <summary>
|
||||
/// Index of the character in the raw string.
|
||||
/// </summary>
|
||||
public int index; // Index of the character in the input string.
|
||||
public int stringLength;
|
||||
public TMP_TextElementType elementType;
|
||||
|
||||
public TMP_TextElement textElement;
|
||||
public TMP_FontAsset fontAsset;
|
||||
public TMP_SpriteAsset spriteAsset;
|
||||
public int spriteIndex;
|
||||
public Material material;
|
||||
public int materialReferenceIndex;
|
||||
public bool isUsingAlternateTypeface;
|
||||
|
||||
public float pointSize;
|
||||
|
||||
//public short wordNumber;
|
||||
public int lineNumber;
|
||||
//public short charNumber;
|
||||
public int pageNumber;
|
||||
|
||||
|
||||
public int vertexIndex;
|
||||
public TMP_Vertex vertex_BL;
|
||||
public TMP_Vertex vertex_TL;
|
||||
public TMP_Vertex vertex_TR;
|
||||
public TMP_Vertex vertex_BR;
|
||||
|
||||
public Vector3 topLeft;
|
||||
public Vector3 bottomLeft;
|
||||
public Vector3 topRight;
|
||||
public Vector3 bottomRight;
|
||||
|
||||
public float origin;
|
||||
public float xAdvance;
|
||||
public float ascender;
|
||||
public float baseLine;
|
||||
public float descender;
|
||||
internal float adjustedAscender;
|
||||
internal float adjustedDescender;
|
||||
|
||||
public float aspectRatio;
|
||||
public float scale;
|
||||
public Color32 color;
|
||||
public Color32 underlineColor;
|
||||
public int underlineVertexIndex;
|
||||
public Color32 strikethroughColor;
|
||||
public int strikethroughVertexIndex;
|
||||
public Color32 highlightColor;
|
||||
public HighlightState highlightState;
|
||||
public FontStyles style;
|
||||
public bool isVisible;
|
||||
//public bool isIgnoringAlignment;
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 90fe1c65e6bb3bc4e90862df7297719e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,68 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
namespace TMPro
|
||||
{
|
||||
public enum ColorMode
|
||||
{
|
||||
Single,
|
||||
HorizontalGradient,
|
||||
VerticalGradient,
|
||||
FourCornersGradient
|
||||
}
|
||||
|
||||
[System.Serializable][ExcludeFromPresetAttribute]
|
||||
public class TMP_ColorGradient : ScriptableObject
|
||||
{
|
||||
public ColorMode colorMode = ColorMode.FourCornersGradient;
|
||||
|
||||
public Color topLeft;
|
||||
public Color topRight;
|
||||
public Color bottomLeft;
|
||||
public Color bottomRight;
|
||||
|
||||
const ColorMode k_DefaultColorMode = ColorMode.FourCornersGradient;
|
||||
static readonly Color k_DefaultColor = Color.white;
|
||||
|
||||
/// <summary>
|
||||
/// Default Constructor which sets each of the colors as white.
|
||||
/// </summary>
|
||||
public TMP_ColorGradient()
|
||||
{
|
||||
colorMode = k_DefaultColorMode;
|
||||
topLeft = k_DefaultColor;
|
||||
topRight = k_DefaultColor;
|
||||
bottomLeft = k_DefaultColor;
|
||||
bottomRight = k_DefaultColor;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor allowing to set the default color of the Color Gradient.
|
||||
/// </summary>
|
||||
/// <param name="color"></param>
|
||||
public TMP_ColorGradient(Color color)
|
||||
{
|
||||
colorMode = k_DefaultColorMode;
|
||||
topLeft = color;
|
||||
topRight = color;
|
||||
bottomLeft = color;
|
||||
bottomRight = color;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The vertex colors at the corners of the characters.
|
||||
/// </summary>
|
||||
/// <param name="color0">Top left color.</param>
|
||||
/// <param name="color1">Top right color.</param>
|
||||
/// <param name="color2">Bottom left color.</param>
|
||||
/// <param name="color3">Bottom right color.</param>
|
||||
public TMP_ColorGradient(Color color0, Color color1, Color color2, Color color3)
|
||||
{
|
||||
colorMode = k_DefaultColorMode;
|
||||
this.topLeft = color0;
|
||||
this.topRight = color1;
|
||||
this.bottomLeft = color2;
|
||||
this.bottomRight = color3;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 54d21f6ece3b46479f0c328f8c6007e0
|
||||
timeCreated: 1468187202
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,74 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
|
||||
namespace TMPro
|
||||
{
|
||||
// Class used to convert scenes and objects saved in version 0.1.44 to the new Text Container
|
||||
public static class TMP_Compatibility
|
||||
{
|
||||
public enum AnchorPositions { TopLeft, Top, TopRight, Left, Center, Right, BottomLeft, Bottom, BottomRight, BaseLine, None };
|
||||
|
||||
/// <summary>
|
||||
/// Function used to convert text alignment option enumeration format.
|
||||
/// </summary>
|
||||
/// <param name="oldValue"></param>
|
||||
/// <returns></returns>
|
||||
public static TextAlignmentOptions ConvertTextAlignmentEnumValues(TextAlignmentOptions oldValue)
|
||||
{
|
||||
switch ((int)oldValue)
|
||||
{
|
||||
case 0:
|
||||
return TextAlignmentOptions.TopLeft;
|
||||
case 1:
|
||||
return TextAlignmentOptions.Top;
|
||||
case 2:
|
||||
return TextAlignmentOptions.TopRight;
|
||||
case 3:
|
||||
return TextAlignmentOptions.TopJustified;
|
||||
case 4:
|
||||
return TextAlignmentOptions.Left;
|
||||
case 5:
|
||||
return TextAlignmentOptions.Center;
|
||||
case 6:
|
||||
return TextAlignmentOptions.Right;
|
||||
case 7:
|
||||
return TextAlignmentOptions.Justified;
|
||||
case 8:
|
||||
return TextAlignmentOptions.BottomLeft;
|
||||
case 9:
|
||||
return TextAlignmentOptions.Bottom;
|
||||
case 10:
|
||||
return TextAlignmentOptions.BottomRight;
|
||||
case 11:
|
||||
return TextAlignmentOptions.BottomJustified;
|
||||
case 12:
|
||||
return TextAlignmentOptions.BaselineLeft;
|
||||
case 13:
|
||||
return TextAlignmentOptions.Baseline;
|
||||
case 14:
|
||||
return TextAlignmentOptions.BaselineRight;
|
||||
case 15:
|
||||
return TextAlignmentOptions.BaselineJustified;
|
||||
case 16:
|
||||
return TextAlignmentOptions.MidlineLeft;
|
||||
case 17:
|
||||
return TextAlignmentOptions.Midline;
|
||||
case 18:
|
||||
return TextAlignmentOptions.MidlineRight;
|
||||
case 19:
|
||||
return TextAlignmentOptions.MidlineJustified;
|
||||
case 20:
|
||||
return TextAlignmentOptions.CaplineLeft;
|
||||
case 21:
|
||||
return TextAlignmentOptions.Capline;
|
||||
case 22:
|
||||
return TextAlignmentOptions.CaplineRight;
|
||||
case 23:
|
||||
return TextAlignmentOptions.CaplineJustified;
|
||||
}
|
||||
|
||||
return TextAlignmentOptions.TopLeft;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 21364f754cf9b9b47a60742332d4af56
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,246 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using System.Collections;
|
||||
|
||||
|
||||
namespace TMPro
|
||||
{
|
||||
// Base interface for tweeners,
|
||||
// using an interface instead of
|
||||
// an abstract class as we want the
|
||||
// tweens to be structs.
|
||||
internal interface ITweenValue
|
||||
{
|
||||
void TweenValue(float floatPercentage);
|
||||
bool ignoreTimeScale { get; }
|
||||
float duration { get; }
|
||||
bool ValidTarget();
|
||||
}
|
||||
|
||||
// Color tween class, receives the
|
||||
// TweenValue callback and then sets
|
||||
// the value on the target.
|
||||
internal struct ColorTween : ITweenValue
|
||||
{
|
||||
public enum ColorTweenMode
|
||||
{
|
||||
All,
|
||||
RGB,
|
||||
Alpha
|
||||
}
|
||||
|
||||
public class ColorTweenCallback : UnityEvent<Color> { }
|
||||
|
||||
private ColorTweenCallback m_Target;
|
||||
private Color m_StartColor;
|
||||
private Color m_TargetColor;
|
||||
private ColorTweenMode m_TweenMode;
|
||||
|
||||
private float m_Duration;
|
||||
private bool m_IgnoreTimeScale;
|
||||
|
||||
public Color startColor
|
||||
{
|
||||
get { return m_StartColor; }
|
||||
set { m_StartColor = value; }
|
||||
}
|
||||
|
||||
public Color targetColor
|
||||
{
|
||||
get { return m_TargetColor; }
|
||||
set { m_TargetColor = value; }
|
||||
}
|
||||
|
||||
public ColorTweenMode tweenMode
|
||||
{
|
||||
get { return m_TweenMode; }
|
||||
set { m_TweenMode = value; }
|
||||
}
|
||||
|
||||
public float duration
|
||||
{
|
||||
get { return m_Duration; }
|
||||
set { m_Duration = value; }
|
||||
}
|
||||
|
||||
public bool ignoreTimeScale
|
||||
{
|
||||
get { return m_IgnoreTimeScale; }
|
||||
set { m_IgnoreTimeScale = value; }
|
||||
}
|
||||
|
||||
public void TweenValue(float floatPercentage)
|
||||
{
|
||||
if (!ValidTarget())
|
||||
return;
|
||||
|
||||
var newColor = Color.Lerp(m_StartColor, m_TargetColor, floatPercentage);
|
||||
|
||||
if (m_TweenMode == ColorTweenMode.Alpha)
|
||||
{
|
||||
newColor.r = m_StartColor.r;
|
||||
newColor.g = m_StartColor.g;
|
||||
newColor.b = m_StartColor.b;
|
||||
}
|
||||
else if (m_TweenMode == ColorTweenMode.RGB)
|
||||
{
|
||||
newColor.a = m_StartColor.a;
|
||||
}
|
||||
m_Target.Invoke(newColor);
|
||||
}
|
||||
|
||||
public void AddOnChangedCallback(UnityAction<Color> callback)
|
||||
{
|
||||
if (m_Target == null)
|
||||
m_Target = new ColorTweenCallback();
|
||||
|
||||
m_Target.AddListener(callback);
|
||||
}
|
||||
|
||||
public bool GetIgnoreTimescale()
|
||||
{
|
||||
return m_IgnoreTimeScale;
|
||||
}
|
||||
|
||||
public float GetDuration()
|
||||
{
|
||||
return m_Duration;
|
||||
}
|
||||
|
||||
public bool ValidTarget()
|
||||
{
|
||||
return m_Target != null;
|
||||
}
|
||||
}
|
||||
|
||||
// Float tween class, receives the
|
||||
// TweenValue callback and then sets
|
||||
// the value on the target.
|
||||
internal struct FloatTween : ITweenValue
|
||||
{
|
||||
public class FloatTweenCallback : UnityEvent<float> { }
|
||||
|
||||
private FloatTweenCallback m_Target;
|
||||
private float m_StartValue;
|
||||
private float m_TargetValue;
|
||||
|
||||
private float m_Duration;
|
||||
private bool m_IgnoreTimeScale;
|
||||
|
||||
public float startValue
|
||||
{
|
||||
get { return m_StartValue; }
|
||||
set { m_StartValue = value; }
|
||||
}
|
||||
|
||||
public float targetValue
|
||||
{
|
||||
get { return m_TargetValue; }
|
||||
set { m_TargetValue = value; }
|
||||
}
|
||||
|
||||
public float duration
|
||||
{
|
||||
get { return m_Duration; }
|
||||
set { m_Duration = value; }
|
||||
}
|
||||
|
||||
public bool ignoreTimeScale
|
||||
{
|
||||
get { return m_IgnoreTimeScale; }
|
||||
set { m_IgnoreTimeScale = value; }
|
||||
}
|
||||
|
||||
public void TweenValue(float floatPercentage)
|
||||
{
|
||||
if (!ValidTarget())
|
||||
return;
|
||||
|
||||
var newValue = Mathf.Lerp(m_StartValue, m_TargetValue, floatPercentage);
|
||||
m_Target.Invoke(newValue);
|
||||
}
|
||||
|
||||
public void AddOnChangedCallback(UnityAction<float> callback)
|
||||
{
|
||||
if (m_Target == null)
|
||||
m_Target = new FloatTweenCallback();
|
||||
|
||||
m_Target.AddListener(callback);
|
||||
}
|
||||
|
||||
public bool GetIgnoreTimescale()
|
||||
{
|
||||
return m_IgnoreTimeScale;
|
||||
}
|
||||
|
||||
public float GetDuration()
|
||||
{
|
||||
return m_Duration;
|
||||
}
|
||||
|
||||
public bool ValidTarget()
|
||||
{
|
||||
return m_Target != null;
|
||||
}
|
||||
}
|
||||
|
||||
// Tween runner, executes the given tween.
|
||||
// The coroutine will live within the given
|
||||
// behaviour container.
|
||||
internal class TweenRunner<T> where T : struct, ITweenValue
|
||||
{
|
||||
protected MonoBehaviour m_CoroutineContainer;
|
||||
protected IEnumerator m_Tween;
|
||||
|
||||
// utility function for starting the tween
|
||||
private static IEnumerator Start(T tweenInfo)
|
||||
{
|
||||
if (!tweenInfo.ValidTarget())
|
||||
yield break;
|
||||
|
||||
var elapsedTime = 0.0f;
|
||||
while (elapsedTime < tweenInfo.duration)
|
||||
{
|
||||
elapsedTime += tweenInfo.ignoreTimeScale ? Time.unscaledDeltaTime : Time.deltaTime;
|
||||
var percentage = Mathf.Clamp01(elapsedTime / tweenInfo.duration);
|
||||
tweenInfo.TweenValue(percentage);
|
||||
yield return null;
|
||||
}
|
||||
tweenInfo.TweenValue(1.0f);
|
||||
}
|
||||
|
||||
public void Init(MonoBehaviour coroutineContainer)
|
||||
{
|
||||
m_CoroutineContainer = coroutineContainer;
|
||||
}
|
||||
|
||||
public void StartTween(T info)
|
||||
{
|
||||
if (m_CoroutineContainer == null)
|
||||
{
|
||||
Debug.LogWarning("Coroutine container not configured... did you forget to call Init?");
|
||||
return;
|
||||
}
|
||||
|
||||
StopTween();
|
||||
|
||||
if (!m_CoroutineContainer.gameObject.activeInHierarchy)
|
||||
{
|
||||
info.TweenValue(1.0f);
|
||||
return;
|
||||
}
|
||||
|
||||
m_Tween = Start(info);
|
||||
m_CoroutineContainer.StartCoroutine(m_Tween);
|
||||
}
|
||||
|
||||
public void StopTween()
|
||||
{
|
||||
if (m_Tween != null)
|
||||
{
|
||||
m_CoroutineContainer.StopCoroutine(m_Tween);
|
||||
m_Tween = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 658c1fb149e7498aa072b0c0f3bf13f0
|
||||
timeCreated: 1464850953
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,400 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using UnityEngine.UI;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
|
||||
namespace TMPro
|
||||
{
|
||||
|
||||
public static class TMP_DefaultControls
|
||||
{
|
||||
public struct Resources
|
||||
{
|
||||
public Sprite standard;
|
||||
public Sprite background;
|
||||
public Sprite inputField;
|
||||
public Sprite knob;
|
||||
public Sprite checkmark;
|
||||
public Sprite dropdown;
|
||||
public Sprite mask;
|
||||
}
|
||||
|
||||
private const float kWidth = 160f;
|
||||
private const float kThickHeight = 30f;
|
||||
private const float kThinHeight = 20f;
|
||||
private static Vector2 s_TextElementSize = new Vector2(100f, 100f);
|
||||
private static Vector2 s_ThickElementSize = new Vector2(kWidth, kThickHeight);
|
||||
private static Vector2 s_ThinElementSize = new Vector2(kWidth, kThinHeight);
|
||||
//private static Vector2 s_ImageElementSize = new Vector2(100f, 100f);
|
||||
private static Color s_DefaultSelectableColor = new Color(1f, 1f, 1f, 1f);
|
||||
//private static Color s_PanelColor = new Color(1f, 1f, 1f, 0.392f);
|
||||
private static Color s_TextColor = new Color(50f / 255f, 50f / 255f, 50f / 255f, 1f);
|
||||
|
||||
|
||||
private static GameObject CreateUIElementRoot(string name, Vector2 size)
|
||||
{
|
||||
GameObject child = new GameObject(name);
|
||||
RectTransform rectTransform = child.AddComponent<RectTransform>();
|
||||
rectTransform.sizeDelta = size;
|
||||
return child;
|
||||
}
|
||||
|
||||
static GameObject CreateUIObject(string name, GameObject parent)
|
||||
{
|
||||
GameObject go = new GameObject(name);
|
||||
go.AddComponent<RectTransform>();
|
||||
SetParentAndAlign(go, parent);
|
||||
return go;
|
||||
}
|
||||
|
||||
private static void SetDefaultTextValues(TMP_Text lbl)
|
||||
{
|
||||
// Set text values we want across UI elements in default controls.
|
||||
// Don't set values which are the same as the default values for the Text component,
|
||||
// since there's no point in that, and it's good to keep them as consistent as possible.
|
||||
lbl.color = s_TextColor;
|
||||
lbl.fontSize = 14;
|
||||
}
|
||||
|
||||
private static void SetDefaultColorTransitionValues(Selectable slider)
|
||||
{
|
||||
ColorBlock colors = slider.colors;
|
||||
colors.highlightedColor = new Color(0.882f, 0.882f, 0.882f);
|
||||
colors.pressedColor = new Color(0.698f, 0.698f, 0.698f);
|
||||
colors.disabledColor = new Color(0.521f, 0.521f, 0.521f);
|
||||
}
|
||||
|
||||
private static void SetParentAndAlign(GameObject child, GameObject parent)
|
||||
{
|
||||
if (parent == null)
|
||||
return;
|
||||
|
||||
child.transform.SetParent(parent.transform, false);
|
||||
SetLayerRecursively(child, parent.layer);
|
||||
}
|
||||
|
||||
private static void SetLayerRecursively(GameObject go, int layer)
|
||||
{
|
||||
go.layer = layer;
|
||||
Transform t = go.transform;
|
||||
for (int i = 0; i < t.childCount; i++)
|
||||
SetLayerRecursively(t.GetChild(i).gameObject, layer);
|
||||
}
|
||||
|
||||
// Actual controls
|
||||
|
||||
public static GameObject CreateScrollbar(Resources resources)
|
||||
{
|
||||
// Create GOs Hierarchy
|
||||
GameObject scrollbarRoot = CreateUIElementRoot("Scrollbar", s_ThinElementSize);
|
||||
|
||||
GameObject sliderArea = CreateUIObject("Sliding Area", scrollbarRoot);
|
||||
GameObject handle = CreateUIObject("Handle", sliderArea);
|
||||
|
||||
Image bgImage = scrollbarRoot.AddComponent<Image>();
|
||||
bgImage.sprite = resources.background;
|
||||
bgImage.type = Image.Type.Sliced;
|
||||
bgImage.color = s_DefaultSelectableColor;
|
||||
|
||||
Image handleImage = handle.AddComponent<Image>();
|
||||
handleImage.sprite = resources.standard;
|
||||
handleImage.type = Image.Type.Sliced;
|
||||
handleImage.color = s_DefaultSelectableColor;
|
||||
|
||||
RectTransform sliderAreaRect = sliderArea.GetComponent<RectTransform>();
|
||||
sliderAreaRect.sizeDelta = new Vector2(-20, -20);
|
||||
sliderAreaRect.anchorMin = Vector2.zero;
|
||||
sliderAreaRect.anchorMax = Vector2.one;
|
||||
|
||||
RectTransform handleRect = handle.GetComponent<RectTransform>();
|
||||
handleRect.sizeDelta = new Vector2(20, 20);
|
||||
|
||||
Scrollbar scrollbar = scrollbarRoot.AddComponent<Scrollbar>();
|
||||
scrollbar.handleRect = handleRect;
|
||||
scrollbar.targetGraphic = handleImage;
|
||||
SetDefaultColorTransitionValues(scrollbar);
|
||||
|
||||
return scrollbarRoot;
|
||||
}
|
||||
|
||||
public static GameObject CreateButton(Resources resources)
|
||||
{
|
||||
GameObject buttonRoot = CreateUIElementRoot("Button", s_ThickElementSize);
|
||||
|
||||
GameObject childText = new GameObject("Text (TMP)");
|
||||
childText.AddComponent<RectTransform>();
|
||||
SetParentAndAlign(childText, buttonRoot);
|
||||
|
||||
Image image = buttonRoot.AddComponent<Image>();
|
||||
image.sprite = resources.standard;
|
||||
image.type = Image.Type.Sliced;
|
||||
image.color = s_DefaultSelectableColor;
|
||||
|
||||
Button bt = buttonRoot.AddComponent<Button>();
|
||||
SetDefaultColorTransitionValues(bt);
|
||||
|
||||
TextMeshProUGUI text = childText.AddComponent<TextMeshProUGUI>();
|
||||
text.text = "Button";
|
||||
text.alignment = TextAlignmentOptions.Center;
|
||||
SetDefaultTextValues(text);
|
||||
|
||||
RectTransform textRectTransform = childText.GetComponent<RectTransform>();
|
||||
textRectTransform.anchorMin = Vector2.zero;
|
||||
textRectTransform.anchorMax = Vector2.one;
|
||||
textRectTransform.sizeDelta = Vector2.zero;
|
||||
|
||||
return buttonRoot;
|
||||
}
|
||||
|
||||
public static GameObject CreateText(Resources resources)
|
||||
{
|
||||
GameObject go = null;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
go = ObjectFactory.CreateGameObject("Text (TMP)");
|
||||
ObjectFactory.AddComponent<TextMeshProUGUI>(go);
|
||||
#else
|
||||
go = CreateUIElementRoot("Text (TMP)", s_TextElementSize);
|
||||
go.AddComponent<TextMeshProUGUI>();
|
||||
#endif
|
||||
|
||||
return go;
|
||||
}
|
||||
|
||||
|
||||
public static GameObject CreateInputField(Resources resources)
|
||||
{
|
||||
GameObject root = CreateUIElementRoot("InputField (TMP)", s_ThickElementSize);
|
||||
|
||||
GameObject textArea = CreateUIObject("Text Area", root);
|
||||
GameObject childPlaceholder = CreateUIObject("Placeholder", textArea);
|
||||
GameObject childText = CreateUIObject("Text", textArea);
|
||||
|
||||
Image image = root.AddComponent<Image>();
|
||||
image.sprite = resources.inputField;
|
||||
image.type = Image.Type.Sliced;
|
||||
image.color = s_DefaultSelectableColor;
|
||||
|
||||
TMP_InputField inputField = root.AddComponent<TMP_InputField>();
|
||||
SetDefaultColorTransitionValues(inputField);
|
||||
|
||||
// Use UI.Mask for Unity 5.0 - 5.1 and 2D RectMask for Unity 5.2 and up
|
||||
RectMask2D rectMask = textArea.AddComponent<RectMask2D>();
|
||||
#if UNITY_2019_4_OR_NEWER && !UNITY_2019_4_1 && !UNITY_2019_4_2 && !UNITY_2019_4_3 && !UNITY_2019_4_4 && !UNITY_2019_4_5 && !UNITY_2019_4_6 && !UNITY_2019_4_7 && !UNITY_2019_4_8 && !UNITY_2019_4_9 && !UNITY_2019_4_10 && !UNITY_2019_4_11
|
||||
rectMask.padding = new Vector4(-8, -5, -8, -5);
|
||||
#endif
|
||||
|
||||
RectTransform textAreaRectTransform = textArea.GetComponent<RectTransform>();
|
||||
textAreaRectTransform.anchorMin = Vector2.zero;
|
||||
textAreaRectTransform.anchorMax = Vector2.one;
|
||||
textAreaRectTransform.sizeDelta = Vector2.zero;
|
||||
textAreaRectTransform.offsetMin = new Vector2(10, 6);
|
||||
textAreaRectTransform.offsetMax = new Vector2(-10, -7);
|
||||
|
||||
|
||||
TextMeshProUGUI text = childText.AddComponent<TextMeshProUGUI>();
|
||||
text.text = "";
|
||||
text.enableWordWrapping = false;
|
||||
text.extraPadding = true;
|
||||
text.richText = true;
|
||||
SetDefaultTextValues(text);
|
||||
|
||||
TextMeshProUGUI placeholder = childPlaceholder.AddComponent<TextMeshProUGUI>();
|
||||
placeholder.text = "Enter text...";
|
||||
placeholder.fontSize = 14;
|
||||
placeholder.fontStyle = FontStyles.Italic;
|
||||
placeholder.enableWordWrapping = false;
|
||||
placeholder.extraPadding = true;
|
||||
|
||||
// Make placeholder color half as opaque as normal text color.
|
||||
Color placeholderColor = text.color;
|
||||
placeholderColor.a *= 0.5f;
|
||||
placeholder.color = placeholderColor;
|
||||
|
||||
// Add Layout component to placeholder.
|
||||
placeholder.gameObject.AddComponent<LayoutElement>().ignoreLayout = true;
|
||||
|
||||
RectTransform textRectTransform = childText.GetComponent<RectTransform>();
|
||||
textRectTransform.anchorMin = Vector2.zero;
|
||||
textRectTransform.anchorMax = Vector2.one;
|
||||
textRectTransform.sizeDelta = Vector2.zero;
|
||||
textRectTransform.offsetMin = new Vector2(0, 0);
|
||||
textRectTransform.offsetMax = new Vector2(0, 0);
|
||||
|
||||
RectTransform placeholderRectTransform = childPlaceholder.GetComponent<RectTransform>();
|
||||
placeholderRectTransform.anchorMin = Vector2.zero;
|
||||
placeholderRectTransform.anchorMax = Vector2.one;
|
||||
placeholderRectTransform.sizeDelta = Vector2.zero;
|
||||
placeholderRectTransform.offsetMin = new Vector2(0, 0);
|
||||
placeholderRectTransform.offsetMax = new Vector2(0, 0);
|
||||
|
||||
inputField.textViewport = textAreaRectTransform;
|
||||
inputField.textComponent = text;
|
||||
inputField.placeholder = placeholder;
|
||||
inputField.fontAsset = text.font;
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
public static GameObject CreateDropdown(Resources resources)
|
||||
{
|
||||
GameObject root = CreateUIElementRoot("Dropdown", s_ThickElementSize);
|
||||
|
||||
GameObject label = CreateUIObject("Label", root);
|
||||
GameObject arrow = CreateUIObject("Arrow", root);
|
||||
GameObject template = CreateUIObject("Template", root);
|
||||
GameObject viewport = CreateUIObject("Viewport", template);
|
||||
GameObject content = CreateUIObject("Content", viewport);
|
||||
GameObject item = CreateUIObject("Item", content);
|
||||
GameObject itemBackground = CreateUIObject("Item Background", item);
|
||||
GameObject itemCheckmark = CreateUIObject("Item Checkmark", item);
|
||||
GameObject itemLabel = CreateUIObject("Item Label", item);
|
||||
|
||||
// Sub controls.
|
||||
|
||||
GameObject scrollbar = CreateScrollbar(resources);
|
||||
scrollbar.name = "Scrollbar";
|
||||
SetParentAndAlign(scrollbar, template);
|
||||
|
||||
Scrollbar scrollbarScrollbar = scrollbar.GetComponent<Scrollbar>();
|
||||
scrollbarScrollbar.SetDirection(Scrollbar.Direction.BottomToTop, true);
|
||||
|
||||
RectTransform vScrollbarRT = scrollbar.GetComponent<RectTransform>();
|
||||
vScrollbarRT.anchorMin = Vector2.right;
|
||||
vScrollbarRT.anchorMax = Vector2.one;
|
||||
vScrollbarRT.pivot = Vector2.one;
|
||||
vScrollbarRT.sizeDelta = new Vector2(vScrollbarRT.sizeDelta.x, 0);
|
||||
|
||||
// Setup item UI components.
|
||||
|
||||
TextMeshProUGUI itemLabelText = itemLabel.AddComponent<TextMeshProUGUI>();
|
||||
SetDefaultTextValues(itemLabelText);
|
||||
itemLabelText.alignment = TextAlignmentOptions.Left;
|
||||
|
||||
Image itemBackgroundImage = itemBackground.AddComponent<Image>();
|
||||
itemBackgroundImage.color = new Color32(245, 245, 245, 255);
|
||||
|
||||
Image itemCheckmarkImage = itemCheckmark.AddComponent<Image>();
|
||||
itemCheckmarkImage.sprite = resources.checkmark;
|
||||
|
||||
Toggle itemToggle = item.AddComponent<Toggle>();
|
||||
itemToggle.targetGraphic = itemBackgroundImage;
|
||||
itemToggle.graphic = itemCheckmarkImage;
|
||||
itemToggle.isOn = true;
|
||||
|
||||
// Setup template UI components.
|
||||
|
||||
Image templateImage = template.AddComponent<Image>();
|
||||
templateImage.sprite = resources.standard;
|
||||
templateImage.type = Image.Type.Sliced;
|
||||
|
||||
ScrollRect templateScrollRect = template.AddComponent<ScrollRect>();
|
||||
templateScrollRect.content = (RectTransform)content.transform;
|
||||
templateScrollRect.viewport = (RectTransform)viewport.transform;
|
||||
templateScrollRect.horizontal = false;
|
||||
templateScrollRect.movementType = ScrollRect.MovementType.Clamped;
|
||||
templateScrollRect.verticalScrollbar = scrollbarScrollbar;
|
||||
templateScrollRect.verticalScrollbarVisibility = ScrollRect.ScrollbarVisibility.AutoHideAndExpandViewport;
|
||||
templateScrollRect.verticalScrollbarSpacing = -3;
|
||||
|
||||
Mask scrollRectMask = viewport.AddComponent<Mask>();
|
||||
scrollRectMask.showMaskGraphic = false;
|
||||
|
||||
Image viewportImage = viewport.AddComponent<Image>();
|
||||
viewportImage.sprite = resources.mask;
|
||||
viewportImage.type = Image.Type.Sliced;
|
||||
|
||||
// Setup dropdown UI components.
|
||||
|
||||
TextMeshProUGUI labelText = label.AddComponent<TextMeshProUGUI>();
|
||||
SetDefaultTextValues(labelText);
|
||||
labelText.alignment = TextAlignmentOptions.Left;
|
||||
|
||||
Image arrowImage = arrow.AddComponent<Image>();
|
||||
arrowImage.sprite = resources.dropdown;
|
||||
|
||||
Image backgroundImage = root.AddComponent<Image>();
|
||||
backgroundImage.sprite = resources.standard;
|
||||
backgroundImage.color = s_DefaultSelectableColor;
|
||||
backgroundImage.type = Image.Type.Sliced;
|
||||
|
||||
TMP_Dropdown dropdown = root.AddComponent<TMP_Dropdown>();
|
||||
dropdown.targetGraphic = backgroundImage;
|
||||
SetDefaultColorTransitionValues(dropdown);
|
||||
dropdown.template = template.GetComponent<RectTransform>();
|
||||
dropdown.captionText = labelText;
|
||||
dropdown.itemText = itemLabelText;
|
||||
|
||||
// Setting default Item list.
|
||||
itemLabelText.text = "Option A";
|
||||
dropdown.options.Add(new TMP_Dropdown.OptionData {text = "Option A" });
|
||||
dropdown.options.Add(new TMP_Dropdown.OptionData {text = "Option B" });
|
||||
dropdown.options.Add(new TMP_Dropdown.OptionData {text = "Option C" });
|
||||
dropdown.RefreshShownValue();
|
||||
|
||||
// Set up RectTransforms.
|
||||
|
||||
RectTransform labelRT = label.GetComponent<RectTransform>();
|
||||
labelRT.anchorMin = Vector2.zero;
|
||||
labelRT.anchorMax = Vector2.one;
|
||||
labelRT.offsetMin = new Vector2(10, 6);
|
||||
labelRT.offsetMax = new Vector2(-25, -7);
|
||||
|
||||
RectTransform arrowRT = arrow.GetComponent<RectTransform>();
|
||||
arrowRT.anchorMin = new Vector2(1, 0.5f);
|
||||
arrowRT.anchorMax = new Vector2(1, 0.5f);
|
||||
arrowRT.sizeDelta = new Vector2(20, 20);
|
||||
arrowRT.anchoredPosition = new Vector2(-15, 0);
|
||||
|
||||
RectTransform templateRT = template.GetComponent<RectTransform>();
|
||||
templateRT.anchorMin = new Vector2(0, 0);
|
||||
templateRT.anchorMax = new Vector2(1, 0);
|
||||
templateRT.pivot = new Vector2(0.5f, 1);
|
||||
templateRT.anchoredPosition = new Vector2(0, 2);
|
||||
templateRT.sizeDelta = new Vector2(0, 150);
|
||||
|
||||
RectTransform viewportRT = viewport.GetComponent<RectTransform>();
|
||||
viewportRT.anchorMin = new Vector2(0, 0);
|
||||
viewportRT.anchorMax = new Vector2(1, 1);
|
||||
viewportRT.sizeDelta = new Vector2(-18, 0);
|
||||
viewportRT.pivot = new Vector2(0, 1);
|
||||
|
||||
RectTransform contentRT = content.GetComponent<RectTransform>();
|
||||
contentRT.anchorMin = new Vector2(0f, 1);
|
||||
contentRT.anchorMax = new Vector2(1f, 1);
|
||||
contentRT.pivot = new Vector2(0.5f, 1);
|
||||
contentRT.anchoredPosition = new Vector2(0, 0);
|
||||
contentRT.sizeDelta = new Vector2(0, 28);
|
||||
|
||||
RectTransform itemRT = item.GetComponent<RectTransform>();
|
||||
itemRT.anchorMin = new Vector2(0, 0.5f);
|
||||
itemRT.anchorMax = new Vector2(1, 0.5f);
|
||||
itemRT.sizeDelta = new Vector2(0, 20);
|
||||
|
||||
RectTransform itemBackgroundRT = itemBackground.GetComponent<RectTransform>();
|
||||
itemBackgroundRT.anchorMin = Vector2.zero;
|
||||
itemBackgroundRT.anchorMax = Vector2.one;
|
||||
itemBackgroundRT.sizeDelta = Vector2.zero;
|
||||
|
||||
RectTransform itemCheckmarkRT = itemCheckmark.GetComponent<RectTransform>();
|
||||
itemCheckmarkRT.anchorMin = new Vector2(0, 0.5f);
|
||||
itemCheckmarkRT.anchorMax = new Vector2(0, 0.5f);
|
||||
itemCheckmarkRT.sizeDelta = new Vector2(20, 20);
|
||||
itemCheckmarkRT.anchoredPosition = new Vector2(10, 0);
|
||||
|
||||
RectTransform itemLabelRT = itemLabel.GetComponent<RectTransform>();
|
||||
itemLabelRT.anchorMin = Vector2.zero;
|
||||
itemLabelRT.anchorMax = Vector2.one;
|
||||
itemLabelRT.offsetMin = new Vector2(20, 1);
|
||||
itemLabelRT.offsetMax = new Vector2(-10, -2);
|
||||
|
||||
template.SetActive(false);
|
||||
|
||||
return root;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 322392995be44d23a3c86cfd972f838f
|
||||
timeCreated: 1446378357
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7b743370ac3e4ec2a1668f5455a8ef8a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: a7ec9e7ad8b847b7ae4510af83c5d868, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,184 @@
|
||||
#if UNITY_EDITOR
|
||||
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
|
||||
namespace TMPro
|
||||
{
|
||||
public class TMP_EditorResourceManager
|
||||
{
|
||||
private static TMP_EditorResourceManager s_Instance;
|
||||
|
||||
private readonly List<Object> m_ObjectUpdateQueue = new List<Object>();
|
||||
private HashSet<int> m_ObjectUpdateQueueLookup = new HashSet<int>();
|
||||
|
||||
private readonly List<Object> m_ObjectReImportQueue = new List<Object>();
|
||||
private HashSet<int> m_ObjectReImportQueueLookup = new HashSet<int>();
|
||||
|
||||
private readonly List<TMP_FontAsset> m_FontAssetDefinitionRefreshQueue = new List<TMP_FontAsset>();
|
||||
private HashSet<int> m_FontAssetDefinitionRefreshQueueLookup = new HashSet<int>();
|
||||
|
||||
/// <summary>
|
||||
/// Get a singleton instance of the manager.
|
||||
/// </summary>
|
||||
public static TMP_EditorResourceManager instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (s_Instance == null)
|
||||
s_Instance = new TMP_EditorResourceManager();
|
||||
|
||||
return s_Instance;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Register to receive rendering callbacks.
|
||||
/// </summary>
|
||||
private TMP_EditorResourceManager()
|
||||
{
|
||||
Camera.onPostRender += OnCameraPostRender;
|
||||
Canvas.willRenderCanvases += OnPreRenderCanvases;
|
||||
}
|
||||
|
||||
void OnCameraPostRender(Camera cam)
|
||||
{
|
||||
// Exclude the PreRenderCamera
|
||||
if (cam.cameraType != CameraType.SceneView)
|
||||
return;
|
||||
|
||||
DoPostRenderUpdates();
|
||||
}
|
||||
|
||||
void OnPreRenderCanvases()
|
||||
{
|
||||
DoPreRenderUpdates();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Register resource for re-import.
|
||||
/// </summary>
|
||||
/// <param name="obj"></param>
|
||||
internal static void RegisterResourceForReimport(Object obj)
|
||||
{
|
||||
instance.InternalRegisterResourceForReimport(obj);
|
||||
}
|
||||
|
||||
private void InternalRegisterResourceForReimport(Object obj)
|
||||
{
|
||||
int id = obj.GetInstanceID();
|
||||
|
||||
if (m_ObjectReImportQueueLookup.Contains(id))
|
||||
return;
|
||||
|
||||
m_ObjectReImportQueueLookup.Add(id);
|
||||
m_ObjectReImportQueue.Add(obj);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Register resource to be updated.
|
||||
/// </summary>
|
||||
/// <param name="textObject"></param>
|
||||
internal static void RegisterResourceForUpdate(Object obj)
|
||||
{
|
||||
instance.InternalRegisterResourceForUpdate(obj);
|
||||
}
|
||||
|
||||
private void InternalRegisterResourceForUpdate(Object obj)
|
||||
{
|
||||
int id = obj.GetInstanceID();
|
||||
|
||||
if (m_ObjectUpdateQueueLookup.Contains(id))
|
||||
return;
|
||||
|
||||
m_ObjectUpdateQueueLookup.Add(id);
|
||||
m_ObjectUpdateQueue.Add(obj);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="fontAsset"></param>
|
||||
internal static void RegisterFontAssetForDefinitionRefresh(TMP_FontAsset fontAsset)
|
||||
{
|
||||
instance.InternalRegisterFontAssetForDefinitionRefresh(fontAsset);
|
||||
}
|
||||
|
||||
private void InternalRegisterFontAssetForDefinitionRefresh(TMP_FontAsset fontAsset)
|
||||
{
|
||||
int id = fontAsset.GetInstanceID();
|
||||
|
||||
if (m_FontAssetDefinitionRefreshQueueLookup.Contains(id))
|
||||
return;
|
||||
|
||||
m_FontAssetDefinitionRefreshQueueLookup.Add(id);
|
||||
m_FontAssetDefinitionRefreshQueue.Add(fontAsset);
|
||||
}
|
||||
|
||||
void DoPostRenderUpdates()
|
||||
{
|
||||
// Handle objects that need updating
|
||||
int objUpdateCount = m_ObjectUpdateQueue.Count;
|
||||
|
||||
for (int i = 0; i < objUpdateCount; i++)
|
||||
{
|
||||
Object obj = m_ObjectUpdateQueue[i];
|
||||
if (obj != null)
|
||||
{
|
||||
EditorUtility.SetDirty(obj);
|
||||
}
|
||||
}
|
||||
|
||||
if (objUpdateCount > 0)
|
||||
{
|
||||
//Debug.Log("Saving assets");
|
||||
//AssetDatabase.SaveAssets();
|
||||
|
||||
m_ObjectUpdateQueue.Clear();
|
||||
m_ObjectUpdateQueueLookup.Clear();
|
||||
}
|
||||
|
||||
// Handle objects that need re-importing
|
||||
int objReImportCount = m_ObjectReImportQueue.Count;
|
||||
|
||||
for (int i = 0; i < objReImportCount; i++)
|
||||
{
|
||||
Object obj = m_ObjectReImportQueue[i];
|
||||
if (obj != null)
|
||||
{
|
||||
AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(obj));
|
||||
}
|
||||
}
|
||||
|
||||
if (objReImportCount > 0)
|
||||
{
|
||||
m_ObjectReImportQueue.Clear();
|
||||
m_ObjectReImportQueueLookup.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
void DoPreRenderUpdates()
|
||||
{
|
||||
// Handle Font Asset Definition Refresh
|
||||
for (int i = 0; i < m_FontAssetDefinitionRefreshQueue.Count; i++)
|
||||
{
|
||||
TMP_FontAsset fontAsset = m_FontAssetDefinitionRefreshQueue[i];
|
||||
|
||||
if (fontAsset != null)
|
||||
{
|
||||
fontAsset.ReadFontAssetDefinition();
|
||||
TMPro_EventManager.ON_FONT_PROPERTY_CHANGED(true, fontAsset);
|
||||
}
|
||||
}
|
||||
|
||||
if (m_FontAssetDefinitionRefreshQueue.Count > 0)
|
||||
{
|
||||
m_FontAssetDefinitionRefreshQueue.Clear();
|
||||
m_FontAssetDefinitionRefreshQueueLookup.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6b259c4003a802847b9ada90744e34c5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 71c1514a6bd24e1e882cebbe1904ce04
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: ee148e281f3c41c5b4ff5f8a5afe5a6c, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,456 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
using UnityEngine.TextCore;
|
||||
using UnityEngine.TextCore.LowLevel;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
|
||||
namespace TMPro
|
||||
{
|
||||
/// <summary>
|
||||
/// Class that contains the basic information about the font.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class FaceInfo_Legacy
|
||||
{
|
||||
public string Name;
|
||||
public float PointSize;
|
||||
public float Scale;
|
||||
|
||||
public int CharacterCount;
|
||||
|
||||
public float LineHeight;
|
||||
public float Baseline;
|
||||
public float Ascender;
|
||||
public float CapHeight;
|
||||
public float Descender;
|
||||
public float CenterLine;
|
||||
|
||||
public float SuperscriptOffset;
|
||||
public float SubscriptOffset;
|
||||
public float SubSize;
|
||||
|
||||
public float Underline;
|
||||
public float UnderlineThickness;
|
||||
|
||||
public float strikethrough;
|
||||
public float strikethroughThickness;
|
||||
|
||||
public float TabWidth;
|
||||
|
||||
public float Padding;
|
||||
public float AtlasWidth;
|
||||
public float AtlasHeight;
|
||||
}
|
||||
|
||||
|
||||
// Class which contains the Glyph Info / Character definition for each character contained in the font asset.
|
||||
[Serializable]
|
||||
public class TMP_Glyph : TMP_TextElement_Legacy
|
||||
{
|
||||
/// <summary>
|
||||
/// Function to create a deep copy of a GlyphInfo.
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <returns></returns>
|
||||
public static TMP_Glyph Clone(TMP_Glyph source)
|
||||
{
|
||||
TMP_Glyph copy = new TMP_Glyph();
|
||||
|
||||
copy.id = source.id;
|
||||
copy.x = source.x;
|
||||
copy.y = source.y;
|
||||
copy.width = source.width;
|
||||
copy.height = source.height;
|
||||
copy.xOffset = source.xOffset;
|
||||
copy.yOffset = source.yOffset;
|
||||
copy.xAdvance = source.xAdvance;
|
||||
copy.scale = source.scale;
|
||||
|
||||
return copy;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Structure which holds the font creation settings
|
||||
[Serializable]
|
||||
public struct FontAssetCreationSettings
|
||||
{
|
||||
public string sourceFontFileName;
|
||||
public string sourceFontFileGUID;
|
||||
public int pointSizeSamplingMode;
|
||||
public int pointSize;
|
||||
public int padding;
|
||||
public int packingMode;
|
||||
public int atlasWidth;
|
||||
public int atlasHeight;
|
||||
public int characterSetSelectionMode;
|
||||
public string characterSequence;
|
||||
public string referencedFontAssetGUID;
|
||||
public string referencedTextAssetGUID;
|
||||
public int fontStyle;
|
||||
public float fontStyleModifier;
|
||||
public int renderMode;
|
||||
public bool includeFontFeatures;
|
||||
|
||||
internal FontAssetCreationSettings(string sourceFontFileGUID, int pointSize, int pointSizeSamplingMode, int padding, int packingMode, int atlasWidth, int atlasHeight, int characterSelectionMode, string characterSet, int renderMode)
|
||||
{
|
||||
this.sourceFontFileName = string.Empty;
|
||||
this.sourceFontFileGUID = sourceFontFileGUID;
|
||||
this.pointSize = pointSize;
|
||||
this.pointSizeSamplingMode = pointSizeSamplingMode;
|
||||
this.padding = padding;
|
||||
this.packingMode = packingMode;
|
||||
this.atlasWidth = atlasWidth;
|
||||
this.atlasHeight = atlasHeight;
|
||||
this.characterSequence = characterSet;
|
||||
this.characterSetSelectionMode = characterSelectionMode;
|
||||
this.renderMode = renderMode;
|
||||
|
||||
this.referencedFontAssetGUID = string.Empty;
|
||||
this.referencedTextAssetGUID = string.Empty;
|
||||
this.fontStyle = 0;
|
||||
this.fontStyleModifier = 0;
|
||||
this.includeFontFeatures = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Contains the font assets for the regular and italic styles associated with a given font weight.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public struct TMP_FontWeightPair
|
||||
{
|
||||
public TMP_FontAsset regularTypeface;
|
||||
public TMP_FontAsset italicTypeface;
|
||||
}
|
||||
|
||||
|
||||
public struct KerningPairKey
|
||||
{
|
||||
public uint ascii_Left;
|
||||
public uint ascii_Right;
|
||||
public uint key;
|
||||
|
||||
public KerningPairKey(uint ascii_left, uint ascii_right)
|
||||
{
|
||||
ascii_Left = ascii_left;
|
||||
ascii_Right = ascii_right;
|
||||
key = (ascii_right << 16) + ascii_left;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Positional adjustments of a glyph
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public struct GlyphValueRecord_Legacy
|
||||
{
|
||||
public float xPlacement;
|
||||
public float yPlacement;
|
||||
public float xAdvance;
|
||||
public float yAdvance;
|
||||
|
||||
internal GlyphValueRecord_Legacy(UnityEngine.TextCore.LowLevel.GlyphValueRecord valueRecord)
|
||||
{
|
||||
this.xPlacement = valueRecord.xPlacement;
|
||||
this.yPlacement = valueRecord.yPlacement;
|
||||
this.xAdvance = valueRecord.xAdvance;
|
||||
this.yAdvance = valueRecord.yAdvance;
|
||||
}
|
||||
|
||||
public static GlyphValueRecord_Legacy operator +(GlyphValueRecord_Legacy a, GlyphValueRecord_Legacy b)
|
||||
{
|
||||
GlyphValueRecord_Legacy c;
|
||||
c.xPlacement = a.xPlacement + b.xPlacement;
|
||||
c.yPlacement = a.yPlacement + b.yPlacement;
|
||||
c.xAdvance = a.xAdvance + b.xAdvance;
|
||||
c.yAdvance = a.yAdvance + b.yAdvance;
|
||||
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class KerningPair
|
||||
{
|
||||
/// <summary>
|
||||
/// The first glyph part of a kerning pair.
|
||||
/// </summary>
|
||||
public uint firstGlyph
|
||||
{
|
||||
get { return m_FirstGlyph; }
|
||||
set { m_FirstGlyph = value; }
|
||||
}
|
||||
[FormerlySerializedAs("AscII_Left")]
|
||||
[SerializeField]
|
||||
private uint m_FirstGlyph;
|
||||
|
||||
/// <summary>
|
||||
/// The positional adjustment of the first glyph.
|
||||
/// </summary>
|
||||
public GlyphValueRecord_Legacy firstGlyphAdjustments
|
||||
{
|
||||
get { return m_FirstGlyphAdjustments; }
|
||||
}
|
||||
[SerializeField]
|
||||
private GlyphValueRecord_Legacy m_FirstGlyphAdjustments;
|
||||
|
||||
/// <summary>
|
||||
/// The second glyph part of a kerning pair.
|
||||
/// </summary>
|
||||
public uint secondGlyph
|
||||
{
|
||||
get { return m_SecondGlyph; }
|
||||
set { m_SecondGlyph = value; }
|
||||
}
|
||||
[FormerlySerializedAs("AscII_Right")]
|
||||
[SerializeField]
|
||||
private uint m_SecondGlyph;
|
||||
|
||||
/// <summary>
|
||||
/// The positional adjustment of the second glyph.
|
||||
/// </summary>
|
||||
public GlyphValueRecord_Legacy secondGlyphAdjustments
|
||||
{
|
||||
get { return m_SecondGlyphAdjustments; }
|
||||
}
|
||||
[SerializeField]
|
||||
private GlyphValueRecord_Legacy m_SecondGlyphAdjustments;
|
||||
|
||||
[FormerlySerializedAs("XadvanceOffset")]
|
||||
public float xOffset;
|
||||
|
||||
internal static KerningPair empty = new KerningPair(0, new GlyphValueRecord_Legacy(), 0, new GlyphValueRecord_Legacy());
|
||||
|
||||
/// <summary>
|
||||
/// Determines if the Character Spacing property of the text object will affect the kerning pair.
|
||||
/// This is mostly relevant when using Diacritical marks to prevent Character Spacing from altering the
|
||||
/// </summary>
|
||||
public bool ignoreSpacingAdjustments
|
||||
{
|
||||
get { return m_IgnoreSpacingAdjustments; }
|
||||
}
|
||||
[SerializeField]
|
||||
private bool m_IgnoreSpacingAdjustments = false;
|
||||
|
||||
public KerningPair()
|
||||
{
|
||||
m_FirstGlyph = 0;
|
||||
m_FirstGlyphAdjustments = new GlyphValueRecord_Legacy();
|
||||
|
||||
m_SecondGlyph = 0;
|
||||
m_SecondGlyphAdjustments = new GlyphValueRecord_Legacy();
|
||||
}
|
||||
|
||||
public KerningPair(uint left, uint right, float offset)
|
||||
{
|
||||
firstGlyph = left;
|
||||
m_SecondGlyph = right;
|
||||
xOffset = offset;
|
||||
}
|
||||
|
||||
public KerningPair(uint firstGlyph, GlyphValueRecord_Legacy firstGlyphAdjustments, uint secondGlyph, GlyphValueRecord_Legacy secondGlyphAdjustments)
|
||||
{
|
||||
m_FirstGlyph = firstGlyph;
|
||||
m_FirstGlyphAdjustments = firstGlyphAdjustments;
|
||||
m_SecondGlyph = secondGlyph;
|
||||
m_SecondGlyphAdjustments = secondGlyphAdjustments;
|
||||
}
|
||||
|
||||
internal void ConvertLegacyKerningData()
|
||||
{
|
||||
m_FirstGlyphAdjustments.xAdvance = xOffset;
|
||||
//xOffset = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class KerningTable
|
||||
{
|
||||
public List<KerningPair> kerningPairs;
|
||||
|
||||
public KerningTable()
|
||||
{
|
||||
kerningPairs = new List<KerningPair>();
|
||||
}
|
||||
|
||||
|
||||
public void AddKerningPair()
|
||||
{
|
||||
if (kerningPairs.Count == 0)
|
||||
{
|
||||
kerningPairs.Add(new KerningPair(0, 0, 0));
|
||||
}
|
||||
else
|
||||
{
|
||||
uint left = kerningPairs.Last().firstGlyph;
|
||||
uint right = kerningPairs.Last().secondGlyph;
|
||||
float xoffset = kerningPairs.Last().xOffset;
|
||||
|
||||
kerningPairs.Add(new KerningPair(left, right, xoffset));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Add Kerning Pair
|
||||
/// </summary>
|
||||
/// <param name="first">First glyph</param>
|
||||
/// <param name="second">Second glyph</param>
|
||||
/// <param name="offset">xAdvance value</param>
|
||||
/// <returns></returns>
|
||||
public int AddKerningPair(uint first, uint second, float offset)
|
||||
{
|
||||
int index = kerningPairs.FindIndex(item => item.firstGlyph == first && item.secondGlyph == second);
|
||||
|
||||
if (index == -1)
|
||||
{
|
||||
kerningPairs.Add(new KerningPair(first, second, offset));
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Return -1 if Kerning Pair already exists.
|
||||
return -1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add Glyph pair adjustment record
|
||||
/// </summary>
|
||||
/// <param name="firstGlyph">The first glyph</param>
|
||||
/// <param name="firstGlyphAdjustments">Adjustment record for the first glyph</param>
|
||||
/// <param name="secondGlyph">The second glyph</param>
|
||||
/// <param name="secondGlyphAdjustments">Adjustment record for the second glyph</param>
|
||||
/// <returns></returns>
|
||||
public int AddGlyphPairAdjustmentRecord(uint first, GlyphValueRecord_Legacy firstAdjustments, uint second, GlyphValueRecord_Legacy secondAdjustments)
|
||||
{
|
||||
int index = kerningPairs.FindIndex(item => item.firstGlyph == first && item.secondGlyph == second);
|
||||
|
||||
if (index == -1)
|
||||
{
|
||||
kerningPairs.Add(new KerningPair(first, firstAdjustments, second, secondAdjustments));
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Return -1 if Kerning Pair already exists.
|
||||
return -1;
|
||||
}
|
||||
|
||||
public void RemoveKerningPair(int left, int right)
|
||||
{
|
||||
int index = kerningPairs.FindIndex(item => item.firstGlyph == left && item.secondGlyph == right);
|
||||
|
||||
if (index != -1)
|
||||
kerningPairs.RemoveAt(index);
|
||||
}
|
||||
|
||||
|
||||
public void RemoveKerningPair(int index)
|
||||
{
|
||||
kerningPairs.RemoveAt(index);
|
||||
}
|
||||
|
||||
|
||||
public void SortKerningPairs()
|
||||
{
|
||||
// Sort List of Kerning Info
|
||||
if (kerningPairs.Count > 0)
|
||||
kerningPairs = kerningPairs.OrderBy(s => s.firstGlyph).ThenBy(s => s.secondGlyph).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class TMP_FontUtilities
|
||||
{
|
||||
private static List<int> k_searchedFontAssets;
|
||||
|
||||
/// <summary>
|
||||
/// Search through the given font and its fallbacks for the specified character.
|
||||
/// </summary>
|
||||
/// <param name="font">The font asset to search for the given character.</param>
|
||||
/// <param name="unicode">The character to find.</param>
|
||||
/// <param name="character">out parameter containing the glyph for the specified character (if found).</param>
|
||||
/// <returns></returns>
|
||||
public static TMP_FontAsset SearchForCharacter(TMP_FontAsset font, uint unicode, out TMP_Character character)
|
||||
{
|
||||
if (k_searchedFontAssets == null)
|
||||
k_searchedFontAssets = new List<int>();
|
||||
|
||||
k_searchedFontAssets.Clear();
|
||||
|
||||
return SearchForCharacterInternal(font, unicode, out character);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Search through the given list of fonts and their possible fallbacks for the specified character.
|
||||
/// </summary>
|
||||
/// <param name="fonts"></param>
|
||||
/// <param name="unicode"></param>
|
||||
/// <param name="character"></param>
|
||||
/// <returns></returns>
|
||||
public static TMP_FontAsset SearchForCharacter(List<TMP_FontAsset> fonts, uint unicode, out TMP_Character character)
|
||||
{
|
||||
return SearchForCharacterInternal(fonts, unicode, out character);
|
||||
}
|
||||
|
||||
|
||||
private static TMP_FontAsset SearchForCharacterInternal(TMP_FontAsset font, uint unicode, out TMP_Character character)
|
||||
{
|
||||
character = null;
|
||||
|
||||
if (font == null) return null;
|
||||
|
||||
if (font.characterLookupTable.TryGetValue(unicode, out character))
|
||||
{
|
||||
return font;
|
||||
}
|
||||
else if (font.fallbackFontAssetTable != null && font.fallbackFontAssetTable.Count > 0)
|
||||
{
|
||||
for (int i = 0; i < font.fallbackFontAssetTable.Count && character == null; i++)
|
||||
{
|
||||
TMP_FontAsset temp = font.fallbackFontAssetTable[i];
|
||||
if (temp == null) continue;
|
||||
|
||||
int id = temp.GetInstanceID();
|
||||
|
||||
// Skip over the fallback font asset in the event it is null or if already searched.
|
||||
if (k_searchedFontAssets.Contains(id)) continue;
|
||||
|
||||
// Add to list of font assets already searched.
|
||||
k_searchedFontAssets.Add(id);
|
||||
|
||||
temp = SearchForCharacterInternal(temp, unicode, out character);
|
||||
|
||||
if (temp != null)
|
||||
return temp;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private static TMP_FontAsset SearchForCharacterInternal(List<TMP_FontAsset> fonts, uint unicode, out TMP_Character character)
|
||||
{
|
||||
character = null;
|
||||
|
||||
if (fonts != null && fonts.Count > 0)
|
||||
{
|
||||
for (int i = 0; i < fonts.Count; i++)
|
||||
{
|
||||
TMP_FontAsset fontAsset = SearchForCharacterInternal(fonts[i], unicode, out character);
|
||||
|
||||
if (fontAsset != null)
|
||||
return fontAsset;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f695b5f9415c40b39ae877eaff41c96e
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,442 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine.TextCore;
|
||||
using UnityEngine.TextCore.LowLevel;
|
||||
|
||||
|
||||
namespace TMPro
|
||||
{
|
||||
public class TMP_FontAssetUtilities
|
||||
{
|
||||
private static readonly TMP_FontAssetUtilities s_Instance = new TMP_FontAssetUtilities();
|
||||
|
||||
/// <summary>
|
||||
/// Default constructor
|
||||
/// </summary>
|
||||
static TMP_FontAssetUtilities() { }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get a singleton instance of the Font Asset Utilities class.
|
||||
/// </summary>
|
||||
public static TMP_FontAssetUtilities instance
|
||||
{
|
||||
get { return s_Instance; }
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// HashSet containing instance ID of font assets already searched.
|
||||
/// </summary>
|
||||
private static HashSet<int> k_SearchedAssets;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Returns the text element (character) for the given unicode value taking into consideration the requested font style and weight.
|
||||
/// Function searches the source font asset, its list of font assets assigned as alternative typefaces and potentially its fallbacks.
|
||||
/// The font asset out parameter contains a reference to the font asset containing the character.
|
||||
/// The typeface type indicates whether the returned font asset is the source font asset, an alternative typeface or fallback font asset.
|
||||
/// </summary>
|
||||
/// <param name="unicode">The unicode value of the requested character</param>
|
||||
/// <param name="sourceFontAsset">The font asset to be searched</param>
|
||||
/// <param name="includeFallbacks">Include the fallback font assets in the search</param>
|
||||
/// <param name="fontStyle">The font style</param>
|
||||
/// <param name="fontWeight">The font weight</param>
|
||||
/// <param name="isAlternativeTypeface">Indicates if the OUT font asset is an alternative typeface or fallback font asset</param>
|
||||
/// <param name="fontAsset">The font asset that contains the requested character</param>
|
||||
/// <returns></returns>
|
||||
public static TMP_Character GetCharacterFromFontAsset(uint unicode, TMP_FontAsset sourceFontAsset, bool includeFallbacks, FontStyles fontStyle, FontWeight fontWeight, out bool isAlternativeTypeface)
|
||||
{
|
||||
if (includeFallbacks)
|
||||
{
|
||||
if (k_SearchedAssets == null)
|
||||
k_SearchedAssets = new HashSet<int>();
|
||||
else
|
||||
k_SearchedAssets.Clear();
|
||||
}
|
||||
|
||||
return GetCharacterFromFontAsset_Internal(unicode, sourceFontAsset, includeFallbacks, fontStyle, fontWeight, out isAlternativeTypeface);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Internal function returning the text element character for the given unicode value taking into consideration the font style and weight.
|
||||
/// Function searches the source font asset, list of font assets assigned as alternative typefaces and list of fallback font assets.
|
||||
/// </summary>
|
||||
private static TMP_Character GetCharacterFromFontAsset_Internal(uint unicode, TMP_FontAsset sourceFontAsset, bool includeFallbacks, FontStyles fontStyle, FontWeight fontWeight, out bool isAlternativeTypeface)
|
||||
{
|
||||
isAlternativeTypeface = false;
|
||||
TMP_Character character = null;
|
||||
|
||||
#region FONT WEIGHT AND FONT STYLE HANDLING
|
||||
// Determine if a font weight or style is used. If so check if an alternative typeface is assigned for the given weight and / or style.
|
||||
bool isItalic = (fontStyle & FontStyles.Italic) == FontStyles.Italic;
|
||||
|
||||
if (isItalic || fontWeight != FontWeight.Regular)
|
||||
{
|
||||
// Get reference to the font weight pairs of the given font asset.
|
||||
TMP_FontWeightPair[] fontWeights = sourceFontAsset.fontWeightTable;
|
||||
|
||||
int fontWeightIndex = 4;
|
||||
switch (fontWeight)
|
||||
{
|
||||
case FontWeight.Thin:
|
||||
fontWeightIndex = 1;
|
||||
break;
|
||||
case FontWeight.ExtraLight:
|
||||
fontWeightIndex = 2;
|
||||
break;
|
||||
case FontWeight.Light:
|
||||
fontWeightIndex = 3;
|
||||
break;
|
||||
case FontWeight.Regular:
|
||||
fontWeightIndex = 4;
|
||||
break;
|
||||
case FontWeight.Medium:
|
||||
fontWeightIndex = 5;
|
||||
break;
|
||||
case FontWeight.SemiBold:
|
||||
fontWeightIndex = 6;
|
||||
break;
|
||||
case FontWeight.Bold:
|
||||
fontWeightIndex = 7;
|
||||
break;
|
||||
case FontWeight.Heavy:
|
||||
fontWeightIndex = 8;
|
||||
break;
|
||||
case FontWeight.Black:
|
||||
fontWeightIndex = 9;
|
||||
break;
|
||||
}
|
||||
|
||||
TMP_FontAsset temp = isItalic ? fontWeights[fontWeightIndex].italicTypeface : fontWeights[fontWeightIndex].regularTypeface;
|
||||
|
||||
if (temp != null)
|
||||
{
|
||||
if (temp.characterLookupTable.TryGetValue(unicode, out character))
|
||||
{
|
||||
isAlternativeTypeface = true;
|
||||
|
||||
return character;
|
||||
}
|
||||
|
||||
if (temp.atlasPopulationMode == AtlasPopulationMode.Dynamic)
|
||||
{
|
||||
if (temp.TryAddCharacterInternal(unicode, out character))
|
||||
{
|
||||
isAlternativeTypeface = true;
|
||||
|
||||
return character;
|
||||
}
|
||||
|
||||
// Check if the source font file contains the requested character.
|
||||
//if (TryGetCharacterFromFontFile(unicode, fontAsset, out characterData))
|
||||
//{
|
||||
// isAlternativeTypeface = true;
|
||||
|
||||
// return characterData;
|
||||
//}
|
||||
|
||||
// If we find the requested character, we add it to the font asset character table
|
||||
// and return its character data.
|
||||
// We also add this character to the list of characters we will need to add to the font atlas.
|
||||
// We assume the font atlas has room otherwise this font asset should not be marked as dynamic.
|
||||
// Alternatively, we could also add multiple pages of font atlas textures (feature consideration).
|
||||
}
|
||||
|
||||
// At this point, we were not able to find the requested character in the alternative typeface
|
||||
// so we check the source font asset and its potential fallbacks.
|
||||
}
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
// Search the source font asset for the requested character.
|
||||
if (sourceFontAsset.characterLookupTable.TryGetValue(unicode, out character))
|
||||
return character;
|
||||
|
||||
if (sourceFontAsset.atlasPopulationMode == AtlasPopulationMode.Dynamic)
|
||||
{
|
||||
if (sourceFontAsset.TryAddCharacterInternal(unicode, out character))
|
||||
return character;
|
||||
}
|
||||
|
||||
// Search fallback font assets if we still don't have a valid character and include fallback is set to true.
|
||||
if (character == null && includeFallbacks && sourceFontAsset.fallbackFontAssetTable != null)
|
||||
{
|
||||
// Get reference to the list of fallback font assets.
|
||||
List<TMP_FontAsset> fallbackFontAssets = sourceFontAsset.fallbackFontAssetTable;
|
||||
int fallbackCount = fallbackFontAssets.Count;
|
||||
|
||||
if (fallbackCount == 0)
|
||||
return null;
|
||||
|
||||
for (int i = 0; i < fallbackCount; i++)
|
||||
{
|
||||
TMP_FontAsset temp = fallbackFontAssets[i];
|
||||
|
||||
if (temp == null)
|
||||
continue;
|
||||
|
||||
int id = temp.instanceID;
|
||||
|
||||
// Try adding font asset to search list. If already present skip to the next one otherwise check if it contains the requested character.
|
||||
if (k_SearchedAssets.Add(id) == false)
|
||||
continue;
|
||||
|
||||
// Add reference to this search query
|
||||
sourceFontAsset.FallbackSearchQueryLookup.Add(id);
|
||||
|
||||
character = GetCharacterFromFontAsset_Internal(unicode, temp, true, fontStyle, fontWeight, out isAlternativeTypeface);
|
||||
|
||||
if (character != null)
|
||||
return character;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Returns the text element (character) for the given unicode value taking into consideration the requested font style and weight.
|
||||
/// Function searches the provided list of font assets, the list of font assets assigned as alternative typefaces to them as well as their fallbacks.
|
||||
/// The font asset out parameter contains a reference to the font asset containing the character.
|
||||
/// The typeface type indicates whether the returned font asset is the source font asset, an alternative typeface or fallback font asset.
|
||||
/// </summary>
|
||||
/// <param name="unicode">The unicode value of the requested character</param>
|
||||
/// <param name="sourceFontAsset">The font asset originating the search query</param>
|
||||
/// <param name="fontAssets">The list of font assets to search</param>
|
||||
/// <param name="includeFallbacks">Determines if the fallback of each font assets on the list will be searched</param>
|
||||
/// <param name="fontStyle">The font style</param>
|
||||
/// <param name="fontWeight">The font weight</param>
|
||||
/// <param name="isAlternativeTypeface">Determines if the OUT font asset is an alternative typeface or fallback font asset</param>
|
||||
/// <returns></returns>
|
||||
public static TMP_Character GetCharacterFromFontAssets(uint unicode, TMP_FontAsset sourceFontAsset, List<TMP_FontAsset> fontAssets, bool includeFallbacks, FontStyles fontStyle, FontWeight fontWeight, out bool isAlternativeTypeface)
|
||||
{
|
||||
isAlternativeTypeface = false;
|
||||
|
||||
// Make sure font asset list is valid
|
||||
if (fontAssets == null || fontAssets.Count == 0)
|
||||
return null;
|
||||
|
||||
if (includeFallbacks)
|
||||
{
|
||||
if (k_SearchedAssets == null)
|
||||
k_SearchedAssets = new HashSet<int>();
|
||||
else
|
||||
k_SearchedAssets.Clear();
|
||||
}
|
||||
|
||||
int fontAssetCount = fontAssets.Count;
|
||||
|
||||
for (int i = 0; i < fontAssetCount; i++)
|
||||
{
|
||||
TMP_FontAsset fontAsset = fontAssets[i];
|
||||
|
||||
if (fontAsset == null) continue;
|
||||
|
||||
// Add reference to this search query
|
||||
sourceFontAsset.FallbackSearchQueryLookup.Add(fontAsset.instanceID);
|
||||
|
||||
TMP_Character character = GetCharacterFromFontAsset_Internal(unicode, fontAsset, includeFallbacks, fontStyle, fontWeight, out isAlternativeTypeface);
|
||||
|
||||
if (character != null)
|
||||
return character;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// =====================================================================
|
||||
// SPRITE ASSET - Functions
|
||||
// =====================================================================
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="unicode"></param>
|
||||
/// <param name="spriteAsset"></param>
|
||||
/// <param name="includeFallbacks"></param>
|
||||
/// <returns></returns>
|
||||
public static TMP_SpriteCharacter GetSpriteCharacterFromSpriteAsset(uint unicode, TMP_SpriteAsset spriteAsset, bool includeFallbacks)
|
||||
{
|
||||
// Make sure we have a valid sprite asset to search
|
||||
if (spriteAsset == null)
|
||||
return null;
|
||||
|
||||
TMP_SpriteCharacter spriteCharacter;
|
||||
|
||||
// Search sprite asset for potential sprite character for the given unicode value
|
||||
if (spriteAsset.spriteCharacterLookupTable.TryGetValue(unicode, out spriteCharacter))
|
||||
return spriteCharacter;
|
||||
|
||||
if (includeFallbacks)
|
||||
{
|
||||
// Clear searched assets
|
||||
if (k_SearchedAssets == null)
|
||||
k_SearchedAssets = new HashSet<int>();
|
||||
else
|
||||
k_SearchedAssets.Clear();
|
||||
|
||||
// Add current sprite asset to already searched assets.
|
||||
k_SearchedAssets.Add(spriteAsset.instanceID);
|
||||
|
||||
List<TMP_SpriteAsset> fallbackSpriteAsset = spriteAsset.fallbackSpriteAssets;
|
||||
|
||||
if (fallbackSpriteAsset != null && fallbackSpriteAsset.Count > 0)
|
||||
{
|
||||
int fallbackCount = fallbackSpriteAsset.Count;
|
||||
|
||||
for (int i = 0; i < fallbackCount; i++)
|
||||
{
|
||||
TMP_SpriteAsset temp = fallbackSpriteAsset[i];
|
||||
|
||||
if (temp == null)
|
||||
continue;
|
||||
|
||||
int id = temp.instanceID;
|
||||
|
||||
// Try adding asset to search list. If already present skip to the next one otherwise check if it contains the requested character.
|
||||
if (k_SearchedAssets.Add(id) == false)
|
||||
continue;
|
||||
|
||||
spriteCharacter = GetSpriteCharacterFromSpriteAsset_Internal(unicode, temp, true);
|
||||
|
||||
if (spriteCharacter != null)
|
||||
return spriteCharacter;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="unicode"></param>
|
||||
/// <param name="spriteAsset"></param>
|
||||
/// <param name="includeFallbacks"></param>
|
||||
/// <returns></returns>
|
||||
static TMP_SpriteCharacter GetSpriteCharacterFromSpriteAsset_Internal(uint unicode, TMP_SpriteAsset spriteAsset, bool includeFallbacks)
|
||||
{
|
||||
TMP_SpriteCharacter spriteCharacter;
|
||||
|
||||
// Search sprite asset for potential sprite character for the given unicode value
|
||||
if (spriteAsset.spriteCharacterLookupTable.TryGetValue(unicode, out spriteCharacter))
|
||||
return spriteCharacter;
|
||||
|
||||
if (includeFallbacks)
|
||||
{
|
||||
List<TMP_SpriteAsset> fallbackSpriteAsset = spriteAsset.fallbackSpriteAssets;
|
||||
|
||||
if (fallbackSpriteAsset != null && fallbackSpriteAsset.Count > 0)
|
||||
{
|
||||
int fallbackCount = fallbackSpriteAsset.Count;
|
||||
|
||||
for (int i = 0; i < fallbackCount; i++)
|
||||
{
|
||||
TMP_SpriteAsset temp = fallbackSpriteAsset[i];
|
||||
|
||||
if (temp == null)
|
||||
continue;
|
||||
|
||||
int id = temp.instanceID;
|
||||
|
||||
// Try adding asset to search list. If already present skip to the next one otherwise check if it contains the requested character.
|
||||
if (k_SearchedAssets.Add(id) == false)
|
||||
continue;
|
||||
|
||||
spriteCharacter = GetSpriteCharacterFromSpriteAsset_Internal(unicode, temp, true);
|
||||
|
||||
if (spriteCharacter != null)
|
||||
return spriteCharacter;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
// =====================================================================
|
||||
// FONT ENGINE & FONT FILE MANAGEMENT - Fields, Properties and Functions
|
||||
// =====================================================================
|
||||
|
||||
private static bool k_IsFontEngineInitialized;
|
||||
|
||||
/*
|
||||
private static bool TryGetCharacterFromFontFile(uint unicode, TMP_FontAsset fontAsset, out TMP_Character character)
|
||||
{
|
||||
character = null;
|
||||
|
||||
// Initialize Font Engine library if not already initialized
|
||||
if (k_IsFontEngineInitialized == false)
|
||||
{
|
||||
FontEngineError error = FontEngine.InitializeFontEngine();
|
||||
|
||||
if (error == 0)
|
||||
k_IsFontEngineInitialized = true;
|
||||
}
|
||||
|
||||
// Load the font face for the given font asset.
|
||||
// TODO: Add manager to keep track of which font faces are currently loaded.
|
||||
FontEngine.LoadFontFace(fontAsset.sourceFontFile, fontAsset.faceInfo.pointSize);
|
||||
|
||||
Glyph glyph = null;
|
||||
uint glyphIndex = FontEngine.GetGlyphIndex(unicode);
|
||||
|
||||
// Check if glyph is already contained in the font asset as the same glyph might be referenced by multiple character.
|
||||
if (fontAsset.glyphLookupTable.TryGetValue(glyphIndex, out glyph))
|
||||
{
|
||||
character = fontAsset.AddCharacter_Internal(unicode, glyph);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
GlyphLoadFlags glyphLoadFlags = ((GlyphRasterModes)fontAsset.atlasRenderMode & GlyphRasterModes.RASTER_MODE_HINTED) == GlyphRasterModes.RASTER_MODE_HINTED ? GlyphLoadFlags.LOAD_RENDER : GlyphLoadFlags.LOAD_RENDER | GlyphLoadFlags.LOAD_NO_HINTING;
|
||||
|
||||
if (FontEngine.TryGetGlyphWithUnicodeValue(unicode, glyphLoadFlags, out glyph))
|
||||
{
|
||||
// Add new character to font asset (if needed)
|
||||
character = fontAsset.AddCharacter_Internal(unicode, glyph);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public static bool TryGetGlyphFromFontFile(uint glyphIndex, TMP_FontAsset fontAsset, out Glyph glyph)
|
||||
{
|
||||
glyph = null;
|
||||
|
||||
// Initialize Font Engine library if not already initialized
|
||||
if (k_IsFontEngineInitialized == false)
|
||||
{
|
||||
FontEngineError error = FontEngine.InitializeFontEngine();
|
||||
|
||||
if (error == 0)
|
||||
k_IsFontEngineInitialized = true;
|
||||
}
|
||||
|
||||
// Load the font face for the given font asset.
|
||||
// TODO: Add manager to keep track of which font faces are currently loaded.
|
||||
FontEngine.LoadFontFace(fontAsset.sourceFontFile, fontAsset.faceInfo.pointSize);
|
||||
|
||||
GlyphLoadFlags glyphLoadFlags = ((GlyphRasterModes)fontAsset.atlasRenderMode & GlyphRasterModes.RASTER_MODE_HINTED) == GlyphRasterModes.RASTER_MODE_HINTED ? GlyphLoadFlags.LOAD_RENDER : GlyphLoadFlags.LOAD_RENDER | GlyphLoadFlags.LOAD_NO_HINTING;
|
||||
|
||||
if (FontEngine.TryGetGlyphWithIndexValue(glyphIndex, glyphLoadFlags, out glyph))
|
||||
{
|
||||
// Add new glyph to font asset (if needed)
|
||||
//fontAsset.AddGlyph_Internal(glyph);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0a017569bfe174e4890797b4d64cbabc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
namespace TMPro
|
||||
{
|
||||
/// <summary>
|
||||
/// Table that contains the various font features available for the given font asset.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class TMP_FontFeatureTable
|
||||
{
|
||||
/// <summary>
|
||||
/// List that contains the glyph pair adjustment records.
|
||||
/// </summary>
|
||||
public List<TMP_GlyphPairAdjustmentRecord> glyphPairAdjustmentRecords
|
||||
{
|
||||
get { return m_GlyphPairAdjustmentRecords; }
|
||||
set { m_GlyphPairAdjustmentRecords = value; }
|
||||
}
|
||||
[SerializeField]
|
||||
internal List<TMP_GlyphPairAdjustmentRecord> m_GlyphPairAdjustmentRecords;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
internal Dictionary<uint, TMP_GlyphPairAdjustmentRecord> m_GlyphPairAdjustmentRecordLookupDictionary;
|
||||
|
||||
// =============================================
|
||||
// Constructor(s)
|
||||
// =============================================
|
||||
|
||||
public TMP_FontFeatureTable()
|
||||
{
|
||||
m_GlyphPairAdjustmentRecords = new List<TMP_GlyphPairAdjustmentRecord>();
|
||||
m_GlyphPairAdjustmentRecordLookupDictionary = new Dictionary<uint, TMP_GlyphPairAdjustmentRecord>();
|
||||
}
|
||||
|
||||
// =============================================
|
||||
// Utility Functions
|
||||
// =============================================
|
||||
|
||||
/// <summary>
|
||||
/// Sort the glyph pair adjustment records by glyph index.
|
||||
/// </summary>
|
||||
public void SortGlyphPairAdjustmentRecords()
|
||||
{
|
||||
// Sort List of Kerning Info
|
||||
if (m_GlyphPairAdjustmentRecords.Count > 0)
|
||||
m_GlyphPairAdjustmentRecords = m_GlyphPairAdjustmentRecords.OrderBy(s => s.firstAdjustmentRecord.glyphIndex).ThenBy(s => s.secondAdjustmentRecord.glyphIndex).ToList();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5ea9f573d4b800a49b9d83a1f61c0a88
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,227 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TextCore.LowLevel;
|
||||
|
||||
|
||||
namespace TMPro
|
||||
{
|
||||
[Flags]
|
||||
public enum FontFeatureLookupFlags
|
||||
{
|
||||
None = 0x0,
|
||||
IgnoreLigatures = 0x004,
|
||||
IgnoreSpacingAdjustments = 0x100,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The values used to adjust the position of a glyph or set of glyphs.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public struct TMP_GlyphValueRecord
|
||||
{
|
||||
/// <summary>
|
||||
/// The positional adjustment affecting the horizontal bearing X of the glyph.
|
||||
/// </summary>
|
||||
public float xPlacement { get { return m_XPlacement; } set { m_XPlacement = value; } }
|
||||
|
||||
/// <summary>
|
||||
/// The positional adjustment affecting the horizontal bearing Y of the glyph.
|
||||
/// </summary>
|
||||
public float yPlacement { get { return m_YPlacement; } set { m_YPlacement = value; } }
|
||||
|
||||
/// <summary>
|
||||
/// The positional adjustment affecting the horizontal advance of the glyph.
|
||||
/// </summary>
|
||||
public float xAdvance { get { return m_XAdvance; } set { m_XAdvance = value; } }
|
||||
|
||||
/// <summary>
|
||||
/// The positional adjustment affecting the vertical advance of the glyph.
|
||||
/// </summary>
|
||||
public float yAdvance { get { return m_YAdvance; } set { m_YAdvance = value; } }
|
||||
|
||||
// =============================================
|
||||
// Private backing fields for public properties.
|
||||
// =============================================
|
||||
|
||||
[SerializeField]
|
||||
internal float m_XPlacement;
|
||||
|
||||
[SerializeField]
|
||||
internal float m_YPlacement;
|
||||
|
||||
[SerializeField]
|
||||
internal float m_XAdvance;
|
||||
|
||||
[SerializeField]
|
||||
internal float m_YAdvance;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <param name="xPlacement">The positional adjustment affecting the horizontal bearing X of the glyph.</param>
|
||||
/// <param name="yPlacement">The positional adjustment affecting the horizontal bearing Y of the glyph.</param>
|
||||
/// <param name="xAdvance">The positional adjustment affecting the horizontal advance of the glyph.</param>
|
||||
/// <param name="yAdvance">The positional adjustment affecting the vertical advance of the glyph.</param>
|
||||
public TMP_GlyphValueRecord(float xPlacement, float yPlacement, float xAdvance, float yAdvance)
|
||||
{
|
||||
m_XPlacement = xPlacement;
|
||||
m_YPlacement = yPlacement;
|
||||
m_XAdvance = xAdvance;
|
||||
m_YAdvance = yAdvance;
|
||||
}
|
||||
|
||||
internal TMP_GlyphValueRecord(GlyphValueRecord_Legacy valueRecord)
|
||||
{
|
||||
m_XPlacement = valueRecord.xPlacement;
|
||||
m_YPlacement = valueRecord.yPlacement;
|
||||
m_XAdvance = valueRecord.xAdvance;
|
||||
m_YAdvance = valueRecord.yAdvance;
|
||||
}
|
||||
|
||||
internal TMP_GlyphValueRecord(GlyphValueRecord valueRecord)
|
||||
{
|
||||
m_XPlacement = valueRecord.xPlacement;
|
||||
m_YPlacement = valueRecord.yPlacement;
|
||||
m_XAdvance = valueRecord.xAdvance;
|
||||
m_YAdvance = valueRecord.yAdvance;
|
||||
}
|
||||
|
||||
public static TMP_GlyphValueRecord operator +(TMP_GlyphValueRecord a, TMP_GlyphValueRecord b)
|
||||
{
|
||||
TMP_GlyphValueRecord c;
|
||||
c.m_XPlacement = a.xPlacement + b.xPlacement;
|
||||
c.m_YPlacement = a.yPlacement + b.yPlacement;
|
||||
c.m_XAdvance = a.xAdvance + b.xAdvance;
|
||||
c.m_YAdvance = a.yAdvance + b.yAdvance;
|
||||
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The positional adjustment values of a glyph.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public struct TMP_GlyphAdjustmentRecord
|
||||
{
|
||||
/// <summary>
|
||||
/// The index of the glyph in the source font file.
|
||||
/// </summary>
|
||||
public uint glyphIndex { get { return m_GlyphIndex; } set { m_GlyphIndex = value; } }
|
||||
|
||||
/// <summary>
|
||||
/// The GlyphValueRecord contains the positional adjustments of the glyph.
|
||||
/// </summary>
|
||||
public TMP_GlyphValueRecord glyphValueRecord { get { return m_GlyphValueRecord; } set { m_GlyphValueRecord = value; } }
|
||||
|
||||
// =============================================
|
||||
// Private backing fields for public properties.
|
||||
// =============================================
|
||||
|
||||
[SerializeField]
|
||||
internal uint m_GlyphIndex;
|
||||
|
||||
[SerializeField]
|
||||
internal TMP_GlyphValueRecord m_GlyphValueRecord;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <param name="glyphIndex">The index of the glyph in the source font file.</param>
|
||||
/// <param name="glyphValueRecord">The GlyphValueRecord contains the positional adjustments of the glyph.</param>
|
||||
public TMP_GlyphAdjustmentRecord(uint glyphIndex, TMP_GlyphValueRecord glyphValueRecord)
|
||||
{
|
||||
m_GlyphIndex = glyphIndex;
|
||||
m_GlyphValueRecord = glyphValueRecord;
|
||||
}
|
||||
|
||||
internal TMP_GlyphAdjustmentRecord(GlyphAdjustmentRecord adjustmentRecord)
|
||||
{
|
||||
m_GlyphIndex = adjustmentRecord.glyphIndex;
|
||||
m_GlyphValueRecord = new TMP_GlyphValueRecord(adjustmentRecord.glyphValueRecord);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The positional adjustment values for a pair of glyphs.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class TMP_GlyphPairAdjustmentRecord
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains the positional adjustment values for the first glyph.
|
||||
/// </summary>
|
||||
public TMP_GlyphAdjustmentRecord firstAdjustmentRecord { get { return m_FirstAdjustmentRecord; } set { m_FirstAdjustmentRecord = value; } }
|
||||
|
||||
/// <summary>
|
||||
/// Contains the positional adjustment values for the second glyph.
|
||||
/// </summary>
|
||||
public TMP_GlyphAdjustmentRecord secondAdjustmentRecord { get { return m_SecondAdjustmentRecord; } set { m_SecondAdjustmentRecord = value; } }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public FontFeatureLookupFlags featureLookupFlags { get { return m_FeatureLookupFlags; } set { m_FeatureLookupFlags = value; } }
|
||||
|
||||
// =============================================
|
||||
// Private backing fields for public properties.
|
||||
// =============================================
|
||||
|
||||
[SerializeField]
|
||||
internal TMP_GlyphAdjustmentRecord m_FirstAdjustmentRecord;
|
||||
|
||||
[SerializeField]
|
||||
internal TMP_GlyphAdjustmentRecord m_SecondAdjustmentRecord;
|
||||
|
||||
[SerializeField]
|
||||
internal FontFeatureLookupFlags m_FeatureLookupFlags;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <param name="firstAdjustmentRecord">First glyph adjustment record.</param>
|
||||
/// <param name="secondAdjustmentRecord">Second glyph adjustment record.</param>
|
||||
public TMP_GlyphPairAdjustmentRecord(TMP_GlyphAdjustmentRecord firstAdjustmentRecord, TMP_GlyphAdjustmentRecord secondAdjustmentRecord)
|
||||
{
|
||||
m_FirstAdjustmentRecord = firstAdjustmentRecord;
|
||||
m_SecondAdjustmentRecord = secondAdjustmentRecord;
|
||||
m_FeatureLookupFlags = FontFeatureLookupFlags.None;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Internal constructor
|
||||
/// </summary>
|
||||
/// <param name="firstAdjustmentRecord"></param>
|
||||
/// <param name="secondAdjustmentRecord"></param>
|
||||
internal TMP_GlyphPairAdjustmentRecord(GlyphPairAdjustmentRecord glyphPairAdjustmentRecord)
|
||||
{
|
||||
m_FirstAdjustmentRecord = new TMP_GlyphAdjustmentRecord(glyphPairAdjustmentRecord.firstAdjustmentRecord);
|
||||
m_SecondAdjustmentRecord = new TMP_GlyphAdjustmentRecord(glyphPairAdjustmentRecord.secondAdjustmentRecord);
|
||||
m_FeatureLookupFlags = FontFeatureLookupFlags.None;
|
||||
}
|
||||
}
|
||||
|
||||
public struct GlyphPairKey
|
||||
{
|
||||
public uint firstGlyphIndex;
|
||||
public uint secondGlyphIndex;
|
||||
public uint key;
|
||||
|
||||
public GlyphPairKey(uint firstGlyphIndex, uint secondGlyphIndex)
|
||||
{
|
||||
this.firstGlyphIndex = firstGlyphIndex;
|
||||
this.secondGlyphIndex = secondGlyphIndex;
|
||||
key = secondGlyphIndex << 16 | firstGlyphIndex;
|
||||
}
|
||||
|
||||
internal GlyphPairKey(TMP_GlyphPairAdjustmentRecord record)
|
||||
{
|
||||
firstGlyphIndex = record.firstAdjustmentRecord.glyphIndex;
|
||||
secondGlyphIndex = record.secondAdjustmentRecord.glyphIndex;
|
||||
key = secondGlyphIndex << 16 | firstGlyphIndex;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 27df3b12f30d0b74a9b10a3968c402ff
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2da0c512f12947e489f739169773d7ca
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: 3ee40aa79cd242a5b53b0b0ca4f13f0f, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,15 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
|
||||
namespace TMPro
|
||||
{
|
||||
/// <summary>
|
||||
/// Custom text input validator where user can implement their own custom character validation.
|
||||
/// </summary>
|
||||
[System.Serializable]
|
||||
public abstract class TMP_InputValidator : ScriptableObject
|
||||
{
|
||||
public abstract char Validate(ref string text, ref int pos, char ch);
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 79ff392d1bde4ad78a3836a4a480392d
|
||||
timeCreated: 1473021069
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,51 @@
|
||||
namespace TMPro
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Structure which contains information about the individual lines of text.
|
||||
/// </summary>
|
||||
public struct TMP_LineInfo
|
||||
{
|
||||
internal int controlCharacterCount;
|
||||
|
||||
public int characterCount;
|
||||
public int visibleCharacterCount;
|
||||
public int spaceCount;
|
||||
public int wordCount;
|
||||
public int firstCharacterIndex;
|
||||
public int firstVisibleCharacterIndex;
|
||||
public int lastCharacterIndex;
|
||||
public int lastVisibleCharacterIndex;
|
||||
|
||||
public float length;
|
||||
public float lineHeight;
|
||||
public float ascender;
|
||||
public float baseline;
|
||||
public float descender;
|
||||
public float maxAdvance;
|
||||
|
||||
public float width;
|
||||
public float marginLeft;
|
||||
public float marginRight;
|
||||
|
||||
public HorizontalAlignmentOptions alignment;
|
||||
public Extents lineExtents;
|
||||
|
||||
/// <summary>
|
||||
/// Function returning the current line of text.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
//public string GetLineText()
|
||||
//{
|
||||
// string word = string.Empty;
|
||||
// TMP_CharacterInfo[] charInfo = textComponent.textInfo.characterInfo;
|
||||
|
||||
// for (int i = firstCharacterIndex; i < lastCharacterIndex + 1; i++)
|
||||
// {
|
||||
// word += charInfo[i].character;
|
||||
// }
|
||||
|
||||
// return word;
|
||||
//}
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b6e75d7f429a4e7e9e1ffb4f85cff49f
|
||||
timeCreated: 1464310403
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,21 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
||||
namespace TMPro
|
||||
{
|
||||
internal static class TMP_ListPool<T>
|
||||
{
|
||||
// Object pool to avoid allocations.
|
||||
private static readonly TMP_ObjectPool<List<T>> s_ListPool = new TMP_ObjectPool<List<T>>(null, l => l.Clear());
|
||||
|
||||
public static List<T> Get()
|
||||
{
|
||||
return s_ListPool.Get();
|
||||
}
|
||||
|
||||
public static void Release(List<T> toRelease)
|
||||
{
|
||||
s_ListPool.Release(toRelease);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 28375447bcea455c9b51a6650b10c9d7
|
||||
timeCreated: 1458521386
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6d9df2bc198c417db00037803568139c
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e21bec35f48a44298911b25ead550ce3
|
||||
timeCreated: 1462398762
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,51 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
|
||||
namespace TMPro
|
||||
{
|
||||
|
||||
internal class TMP_ObjectPool<T> where T : new()
|
||||
{
|
||||
private readonly Stack<T> m_Stack = new Stack<T>();
|
||||
private readonly UnityAction<T> m_ActionOnGet;
|
||||
private readonly UnityAction<T> m_ActionOnRelease;
|
||||
|
||||
public int countAll { get; private set; }
|
||||
public int countActive { get { return countAll - countInactive; } }
|
||||
public int countInactive { get { return m_Stack.Count; } }
|
||||
|
||||
public TMP_ObjectPool(UnityAction<T> actionOnGet, UnityAction<T> actionOnRelease)
|
||||
{
|
||||
m_ActionOnGet = actionOnGet;
|
||||
m_ActionOnRelease = actionOnRelease;
|
||||
}
|
||||
|
||||
public T Get()
|
||||
{
|
||||
T element;
|
||||
if (m_Stack.Count == 0)
|
||||
{
|
||||
element = new T();
|
||||
countAll++;
|
||||
}
|
||||
else
|
||||
{
|
||||
element = m_Stack.Pop();
|
||||
}
|
||||
if (m_ActionOnGet != null)
|
||||
m_ActionOnGet(element);
|
||||
return element;
|
||||
}
|
||||
|
||||
public void Release(T element)
|
||||
{
|
||||
if (m_Stack.Count > 0 && ReferenceEquals(m_Stack.Peek(), element))
|
||||
Debug.LogError("Internal error. Trying to destroy object that is already released to pool.");
|
||||
if (m_ActionOnRelease != null)
|
||||
m_ActionOnRelease(element);
|
||||
m_Stack.Push(element);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e69259f6ff914146ad610be5491eb44a
|
||||
timeCreated: 1458521389
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user