test
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 10d1425d9e87841d9a9deafe9e93a6f2
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eecc124dc0b994047aac97ccf8c8ed0a
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e3795795b029fde4395e6953ce72b5a6
|
||||
timeCreated: 1469844810
|
||||
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,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 645409e9544820042937871953f20509
|
||||
timeCreated: 1469844810
|
||||
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,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 85016528879d5d644981050d1d0a4368
|
||||
timeCreated: 1469844718
|
||||
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,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bad96c2cfa78a124cb8ec890d2386dfe
|
||||
timeCreated: 1469844718
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ea7c31b5b377c314db28ad3fabbbd38d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,63 @@
|
||||
using UnityEditorInternal;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEditor;
|
||||
|
||||
namespace TMPro.EditorUtilities
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(TMP_Dropdown.OptionDataList), true)]
|
||||
class DropdownOptionListDrawer : PropertyDrawer
|
||||
{
|
||||
private ReorderableList m_ReorderableList;
|
||||
|
||||
private void Init(SerializedProperty property)
|
||||
{
|
||||
if (m_ReorderableList != null)
|
||||
return;
|
||||
|
||||
SerializedProperty array = property.FindPropertyRelative("m_Options");
|
||||
|
||||
m_ReorderableList = new ReorderableList(property.serializedObject, array);
|
||||
m_ReorderableList.drawElementCallback = DrawOptionData;
|
||||
m_ReorderableList.drawHeaderCallback = DrawHeader;
|
||||
m_ReorderableList.elementHeight += 40;
|
||||
}
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
Init(property);
|
||||
|
||||
m_ReorderableList.DoList(position);
|
||||
}
|
||||
|
||||
private void DrawHeader(Rect rect)
|
||||
{
|
||||
GUI.Label(rect, "Options");
|
||||
}
|
||||
|
||||
private void DrawOptionData(Rect rect, int index, bool isActive, bool isFocused)
|
||||
{
|
||||
SerializedProperty itemData = m_ReorderableList.serializedProperty.GetArrayElementAtIndex(index);
|
||||
SerializedProperty itemText = itemData.FindPropertyRelative("m_Text");
|
||||
SerializedProperty itemImage = itemData.FindPropertyRelative("m_Image");
|
||||
SerializedProperty itemColor = itemData.FindPropertyRelative("m_Color");
|
||||
|
||||
RectOffset offset = new RectOffset(0, 0, -1, -3);
|
||||
rect = offset.Add(rect);
|
||||
rect.height = EditorGUIUtility.singleLineHeight;
|
||||
|
||||
EditorGUI.PropertyField(rect, itemText, GUIContent.none);
|
||||
rect.y += EditorGUIUtility.singleLineHeight + 2;
|
||||
EditorGUI.PropertyField(rect, itemImage, GUIContent.none);
|
||||
rect.y += EditorGUIUtility.singleLineHeight + 2;
|
||||
EditorGUI.PropertyField(rect, itemColor, GUIContent.none);
|
||||
}
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
||||
{
|
||||
Init(property);
|
||||
|
||||
return m_ReorderableList.GetHeight();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9545c9eb3bf94265810463794fec8334
|
||||
timeCreated: 1464818008
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,60 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.TextCore;
|
||||
using UnityEditor;
|
||||
using System.Collections;
|
||||
|
||||
|
||||
namespace TMPro.EditorUtilities
|
||||
{
|
||||
|
||||
[CustomPropertyDrawer(typeof(GlyphMetrics))]
|
||||
internal class GlyphMetricsPropertyDrawer : PropertyDrawer
|
||||
{
|
||||
private static readonly GUIContent k_GlyphMetricLabel = new GUIContent("Glyph Metrics", "The layout metrics of the glyph.");
|
||||
private static readonly GUIContent k_WidthPropertyLabel = new GUIContent("W:", "The width of the glyph.");
|
||||
private static readonly GUIContent k_HeightPropertyLabel = new GUIContent("H:", "The height of the glyph.");
|
||||
private static readonly GUIContent k_BearingXPropertyLabel = new GUIContent("BX:", "The horizontal bearing X of the glyph.");
|
||||
private static readonly GUIContent k_BearingYPropertyLabel = new GUIContent("BY:", "The horizontal bearing Y of the glyph.");
|
||||
private static readonly GUIContent k_HorizontalAdvancePropertyLabel = new GUIContent("AD:", "The horizontal advance of the glyph.");
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
SerializedProperty prop_Width = property.FindPropertyRelative("m_Width");
|
||||
SerializedProperty prop_Height = property.FindPropertyRelative("m_Height");
|
||||
SerializedProperty prop_HoriBearingX = property.FindPropertyRelative("m_HorizontalBearingX");
|
||||
SerializedProperty prop_HoriBearingY = property.FindPropertyRelative("m_HorizontalBearingY");
|
||||
SerializedProperty prop_HoriAdvance = property.FindPropertyRelative("m_HorizontalAdvance");
|
||||
|
||||
// We get Rect since a valid position may not be provided by the caller.
|
||||
Rect rect = new Rect(position.x, position.y, position.width, 49);
|
||||
|
||||
EditorGUI.LabelField(new Rect(rect.x, rect.y - 2.5f, rect.width, 18), k_GlyphMetricLabel);
|
||||
|
||||
EditorGUIUtility.labelWidth = 20f;
|
||||
EditorGUIUtility.fieldWidth = 15f;
|
||||
|
||||
//GUI.enabled = false;
|
||||
float width = (rect.width - 75f) / 2;
|
||||
EditorGUI.PropertyField(new Rect(rect.x + width * 0, rect.y + 20, width - 5f, 18), prop_Width, k_WidthPropertyLabel);
|
||||
EditorGUI.PropertyField(new Rect(rect.x + width * 1, rect.y + 20, width - 5f, 18), prop_Height, k_HeightPropertyLabel);
|
||||
|
||||
//GUI.enabled = true;
|
||||
|
||||
width = (rect.width - 75f) / 3;
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUI.PropertyField(new Rect(rect.x + width * 0, rect.y + 40, width - 5f, 18), prop_HoriBearingX, k_BearingXPropertyLabel);
|
||||
EditorGUI.PropertyField(new Rect(rect.x + width * 1, rect.y + 40, width - 5f, 18), prop_HoriBearingY, k_BearingYPropertyLabel);
|
||||
EditorGUI.PropertyField(new Rect(rect.x + width * 2, rect.y + 40, width - 5f, 18), prop_HoriAdvance, k_HorizontalAdvancePropertyLabel);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
||||
{
|
||||
return 65f;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e3882522a08b6f5459b4dea6f8791278
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,372 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.TextCore;
|
||||
using UnityEngine.TextCore.LowLevel;
|
||||
using UnityEditor;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
||||
namespace TMPro.EditorUtilities
|
||||
{
|
||||
|
||||
[CustomPropertyDrawer(typeof(GlyphPairAdjustmentRecord))]
|
||||
internal class GlyphPairAdjustmentRecordPropertyDrawer : PropertyDrawer
|
||||
{
|
||||
private bool isEditingEnabled;
|
||||
private bool isSelectable;
|
||||
|
||||
private Dictionary<uint, GlyphProxy> m_GlyphLookupDictionary;
|
||||
|
||||
private string m_FirstCharacter = string.Empty;
|
||||
private string m_SecondCharacter = string.Empty;
|
||||
private string m_PreviousInput;
|
||||
|
||||
static GUIContent s_CharacterTextFieldLabel = new GUIContent("Char:", "Enter the character or its UTF16 or UTF32 Unicode character escape sequence. For UTF16 use \"\\uFF00\" and for UTF32 use \"\\UFF00FF00\" representation.");
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
SerializedProperty prop_FirstAdjustmentRecord = property.FindPropertyRelative("m_FirstAdjustmentRecord");
|
||||
SerializedProperty prop_SecondAdjustmentRecord = property.FindPropertyRelative("m_SecondAdjustmentRecord");
|
||||
|
||||
SerializedProperty prop_FirstGlyphIndex = prop_FirstAdjustmentRecord.FindPropertyRelative("m_GlyphIndex");
|
||||
SerializedProperty prop_FirstGlyphValueRecord = prop_FirstAdjustmentRecord.FindPropertyRelative("m_GlyphValueRecord");
|
||||
|
||||
SerializedProperty prop_SecondGlyphIndex = prop_SecondAdjustmentRecord.FindPropertyRelative("m_GlyphIndex");
|
||||
SerializedProperty prop_SecondGlyphValueRecord = prop_SecondAdjustmentRecord.FindPropertyRelative("m_GlyphValueRecord");
|
||||
|
||||
SerializedProperty prop_FontFeatureLookupFlags = property.FindPropertyRelative("m_FeatureLookupFlags");
|
||||
|
||||
// Refresh glyph proxy lookup dictionary if needed
|
||||
if (TMP_PropertyDrawerUtilities.s_RefreshGlyphProxyLookup)
|
||||
TMP_PropertyDrawerUtilities.RefreshGlyphProxyLookup(property.serializedObject);
|
||||
|
||||
position.yMin += 2;
|
||||
|
||||
float width = position.width / 2;
|
||||
float padding = 5.0f;
|
||||
|
||||
Rect rect;
|
||||
|
||||
isEditingEnabled = GUI.enabled;
|
||||
isSelectable = label.text == "Selectable";
|
||||
|
||||
if (isSelectable)
|
||||
GUILayoutUtility.GetRect(position.width, 80);
|
||||
else
|
||||
GUILayoutUtility.GetRect(position.width, 55);
|
||||
|
||||
GUIStyle style = new GUIStyle(EditorStyles.label);
|
||||
style.richText = true;
|
||||
|
||||
// First Glyph
|
||||
GUI.enabled = isEditingEnabled;
|
||||
if (isSelectable)
|
||||
{
|
||||
rect = new Rect(position.x + 70, position.y, position.width, 49);
|
||||
|
||||
float labelWidth = GUI.skin.label.CalcSize(new GUIContent("ID: " + prop_FirstGlyphIndex.intValue)).x;
|
||||
EditorGUI.LabelField(new Rect(position.x + (64 - labelWidth) / 2, position.y + 60, 64f, 18f), new GUIContent("ID: <color=#FFFF80>" + prop_FirstGlyphIndex.intValue + "</color>"), style);
|
||||
|
||||
GUI.enabled = isEditingEnabled;
|
||||
EditorGUIUtility.labelWidth = 25f;
|
||||
|
||||
rect = new Rect(position.x + 70, position.y + 10, (width - 70) - padding, 18);
|
||||
EditorGUI.PropertyField(rect, prop_FirstGlyphValueRecord.FindPropertyRelative("m_XPlacement"), new GUIContent("OX:"));
|
||||
|
||||
rect.y += 20;
|
||||
EditorGUI.PropertyField(rect, prop_FirstGlyphValueRecord.FindPropertyRelative("m_YPlacement"), new GUIContent("OY:"));
|
||||
|
||||
rect.y += 20;
|
||||
EditorGUI.PropertyField(rect, prop_FirstGlyphValueRecord.FindPropertyRelative("m_XAdvance"), new GUIContent("AX:"));
|
||||
|
||||
//rect.y += 20;
|
||||
//EditorGUI.PropertyField(rect, prop_FirstGlyphValueRecord.FindPropertyRelative("m_YAdvance"), new GUIContent("AY:"));
|
||||
|
||||
DrawGlyph((uint)prop_FirstGlyphIndex.intValue, new Rect(position.x, position.y + 2, 64, 60), property);
|
||||
}
|
||||
else
|
||||
{
|
||||
rect = new Rect(position.x, position.y, width / 2 * 0.8f - padding, 18);
|
||||
EditorGUIUtility.labelWidth = 40f;
|
||||
|
||||
// First Character Lookup
|
||||
GUI.SetNextControlName("FirstCharacterField");
|
||||
EditorGUI.BeginChangeCheck();
|
||||
string firstCharacter = EditorGUI.TextField(rect, s_CharacterTextFieldLabel, m_FirstCharacter);
|
||||
|
||||
if (GUI.GetNameOfFocusedControl() == "FirstCharacterField")
|
||||
{
|
||||
if (ValidateInput(firstCharacter))
|
||||
{
|
||||
//Debug.Log("1st Unicode value: [" + firstCharacter + "]");
|
||||
|
||||
uint unicode = GetUnicodeCharacter(firstCharacter);
|
||||
|
||||
// Lookup glyph index
|
||||
TMP_SerializedPropertyHolder propertyHolder = property.serializedObject.targetObject as TMP_SerializedPropertyHolder;
|
||||
TMP_FontAsset fontAsset = propertyHolder.fontAsset;
|
||||
if (fontAsset != null)
|
||||
{
|
||||
prop_FirstGlyphIndex.intValue = (int)fontAsset.GetGlyphIndex(unicode);
|
||||
propertyHolder.firstCharacter = unicode;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
m_FirstCharacter = firstCharacter;
|
||||
|
||||
// First Glyph Index
|
||||
rect.x += width / 2 * 0.8f;
|
||||
|
||||
EditorGUIUtility.labelWidth = 25f;
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUI.PropertyField(rect, prop_FirstGlyphIndex, new GUIContent("ID:"));
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
GUI.enabled = isEditingEnabled;
|
||||
EditorGUIUtility.labelWidth = 25f;
|
||||
|
||||
rect = new Rect(position.x, position.y + 20, width * 0.5f - padding, 18);
|
||||
EditorGUI.PropertyField(rect, prop_FirstGlyphValueRecord.FindPropertyRelative("m_XPlacement"), new GUIContent("OX"));
|
||||
|
||||
rect.x += width * 0.5f;
|
||||
EditorGUI.PropertyField(rect, prop_FirstGlyphValueRecord.FindPropertyRelative("m_YPlacement"), new GUIContent("OY"));
|
||||
|
||||
rect.x = position.x;
|
||||
rect.y += 20;
|
||||
EditorGUI.PropertyField(rect, prop_FirstGlyphValueRecord.FindPropertyRelative("m_XAdvance"), new GUIContent("AX"));
|
||||
|
||||
//rect.x += width * 0.5f;
|
||||
//EditorGUI.PropertyField(rect, prop_FirstGlyphAdjustment.FindPropertyRelative("m_YAdvance"), new GUIContent("AY"));
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Second Glyph
|
||||
GUI.enabled = isEditingEnabled;
|
||||
if (isSelectable)
|
||||
{
|
||||
float labelWidth = GUI.skin.label.CalcSize(new GUIContent("ID: " + prop_SecondGlyphIndex.intValue)).x;
|
||||
EditorGUI.LabelField(new Rect(position.width / 2 + 20 + (64 - labelWidth) / 2, position.y + 60, 64f, 18f), new GUIContent("ID: <color=#FFFF80>" + prop_SecondGlyphIndex.intValue + "</color>"), style);
|
||||
|
||||
GUI.enabled = isEditingEnabled;
|
||||
EditorGUIUtility.labelWidth = 25f;
|
||||
|
||||
rect = new Rect(position.width / 2 + 20 + 70, position.y + 10, (width - 70) - padding, 18);
|
||||
EditorGUI.PropertyField(rect, prop_SecondGlyphValueRecord.FindPropertyRelative("m_XPlacement"), new GUIContent("OX:"));
|
||||
|
||||
rect.y += 20;
|
||||
EditorGUI.PropertyField(rect, prop_SecondGlyphValueRecord.FindPropertyRelative("m_YPlacement"), new GUIContent("OY:"));
|
||||
|
||||
rect.y += 20;
|
||||
EditorGUI.PropertyField(rect, prop_SecondGlyphValueRecord.FindPropertyRelative("m_XAdvance"), new GUIContent("AX:"));
|
||||
|
||||
//rect.y += 20;
|
||||
//EditorGUI.PropertyField(rect, prop_SecondGlyphAdjustment.FindPropertyRelative("m_YAdvance"), new GUIContent("AY"));
|
||||
|
||||
DrawGlyph((uint)prop_SecondGlyphIndex.intValue, new Rect(position.width / 2 + 20, position.y + 2, 64, 60), property);
|
||||
}
|
||||
else
|
||||
{
|
||||
rect = new Rect(position.width / 2 + 20, position.y, width / 2 * 0.8f - padding, 18);
|
||||
EditorGUIUtility.labelWidth = 40f;
|
||||
|
||||
// Second Character Lookup
|
||||
GUI.SetNextControlName("SecondCharacterField");
|
||||
EditorGUI.BeginChangeCheck();
|
||||
string secondCharacter = EditorGUI.TextField(rect, s_CharacterTextFieldLabel, m_SecondCharacter);
|
||||
|
||||
if (GUI.GetNameOfFocusedControl() == "SecondCharacterField")
|
||||
{
|
||||
if (ValidateInput(secondCharacter))
|
||||
{
|
||||
//Debug.Log("2nd Unicode value: [" + secondCharacter + "]");
|
||||
|
||||
uint unicode = GetUnicodeCharacter(secondCharacter);
|
||||
|
||||
// Lookup glyph index
|
||||
TMP_SerializedPropertyHolder propertyHolder = property.serializedObject.targetObject as TMP_SerializedPropertyHolder;
|
||||
TMP_FontAsset fontAsset = propertyHolder.fontAsset;
|
||||
if (fontAsset != null)
|
||||
{
|
||||
prop_SecondGlyphIndex.intValue = (int)fontAsset.GetGlyphIndex(unicode);
|
||||
propertyHolder.secondCharacter = unicode;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
m_SecondCharacter = secondCharacter;
|
||||
|
||||
// Second Glyph Index
|
||||
rect.x += width / 2 * 0.8f;
|
||||
|
||||
EditorGUIUtility.labelWidth = 25f;
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUI.PropertyField(rect, prop_SecondGlyphIndex, new GUIContent("ID:"));
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
GUI.enabled = isEditingEnabled;
|
||||
EditorGUIUtility.labelWidth = 25f;
|
||||
|
||||
rect = new Rect(position.width / 2 + 20, position.y + 20, width * 0.5f - padding, 18);
|
||||
EditorGUI.PropertyField(rect, prop_SecondGlyphValueRecord.FindPropertyRelative("m_XPlacement"), new GUIContent("OX"));
|
||||
|
||||
rect.x += width * 0.5f;
|
||||
EditorGUI.PropertyField(rect, prop_SecondGlyphValueRecord.FindPropertyRelative("m_YPlacement"), new GUIContent("OY"));
|
||||
|
||||
rect.x = position.width / 2 + 20;
|
||||
rect.y += 20;
|
||||
EditorGUI.PropertyField(rect, prop_SecondGlyphValueRecord.FindPropertyRelative("m_XAdvance"), new GUIContent("AX"));
|
||||
|
||||
//rect.x += width * 0.5f;
|
||||
//EditorGUI.PropertyField(rect, prop_SecondGlyphAdjustment.FindPropertyRelative("m_YAdvance"), new GUIContent("AY"));
|
||||
}
|
||||
|
||||
// Font Feature Lookup Flags
|
||||
if (isSelectable)
|
||||
{
|
||||
EditorGUIUtility.labelWidth = 50f;
|
||||
|
||||
rect.width = position.width * 0.5f;
|
||||
rect.x = rect.width + 16;
|
||||
rect.y += 28;
|
||||
|
||||
FontFeatureLookupFlags flags = (FontFeatureLookupFlags)prop_FontFeatureLookupFlags.intValue;
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
flags = (FontFeatureLookupFlags)EditorGUI.EnumFlagsField(rect, new GUIContent("Options:"), flags);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
prop_FontFeatureLookupFlags.intValue = (int)flags;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool ValidateInput(string source)
|
||||
{
|
||||
int length = string.IsNullOrEmpty(source) ? 0 : source.Length;
|
||||
|
||||
////Filter out unwanted characters.
|
||||
Event evt = Event.current;
|
||||
|
||||
char c = evt.character;
|
||||
|
||||
if (c != '\0')
|
||||
{
|
||||
switch (length)
|
||||
{
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
if (source != m_PreviousInput)
|
||||
return true;
|
||||
|
||||
if ((source[0] == '\\' && (c == 'u' || c == 'U')) == false)
|
||||
evt.character = '\0';
|
||||
|
||||
break;
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
case 5:
|
||||
if ((c < '0' || c > '9') && (c < 'a' || c > 'f') && (c < 'A' || c > 'F'))
|
||||
evt.character = '\0';
|
||||
break;
|
||||
case 6:
|
||||
case 7:
|
||||
case 8:
|
||||
case 9:
|
||||
if (source[1] == 'u' || (c < '0' || c > '9') && (c < 'a' || c > 'f') && (c < 'A' || c > 'F'))
|
||||
evt.character = '\0';
|
||||
|
||||
// Validate input
|
||||
if (length == 6 && source[1] == 'u' && source != m_PreviousInput)
|
||||
return true;
|
||||
break;
|
||||
case 10:
|
||||
if (source != m_PreviousInput)
|
||||
return true;
|
||||
|
||||
evt.character = '\0';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
m_PreviousInput = source;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
uint GetUnicodeCharacter (string source)
|
||||
{
|
||||
uint unicode;
|
||||
|
||||
if (source.Length == 1)
|
||||
unicode = source[0];
|
||||
else if (source.Length == 6)
|
||||
unicode = (uint)TMP_TextUtilities.StringHexToInt(source.Replace("\\u", ""));
|
||||
else
|
||||
unicode = (uint)TMP_TextUtilities.StringHexToInt(source.Replace("\\U", ""));
|
||||
|
||||
return unicode;
|
||||
}
|
||||
|
||||
void DrawGlyph(uint glyphIndex, Rect glyphDrawPosition, SerializedProperty property)
|
||||
{
|
||||
// Get a reference to the serialized object which can either be a TMP_FontAsset or FontAsset.
|
||||
SerializedObject so = property.serializedObject;
|
||||
if (so == null)
|
||||
return;
|
||||
|
||||
if (m_GlyphLookupDictionary == null)
|
||||
m_GlyphLookupDictionary = TMP_PropertyDrawerUtilities.GetGlyphProxyLookupDictionary(so);
|
||||
|
||||
// Try getting a reference to the glyph for the given glyph index.
|
||||
if (!m_GlyphLookupDictionary.TryGetValue(glyphIndex, out GlyphProxy glyph))
|
||||
return;
|
||||
|
||||
Texture2D atlasTexture;
|
||||
if (TMP_PropertyDrawerUtilities.TryGetAtlasTextureFromSerializedObject(so, glyph.atlasIndex, out atlasTexture) == false)
|
||||
return;
|
||||
|
||||
Material mat;
|
||||
if (TMP_PropertyDrawerUtilities.TryGetMaterial(so, atlasTexture, out mat) == false)
|
||||
return;
|
||||
|
||||
int padding = so.FindProperty("m_AtlasPadding").intValue;
|
||||
GlyphRect glyphRect = glyph.glyphRect;
|
||||
int glyphOriginX = glyphRect.x - padding;
|
||||
int glyphOriginY = glyphRect.y - padding;
|
||||
int glyphWidth = glyphRect.width + padding * 2;
|
||||
int glyphHeight = glyphRect.height + padding * 2;
|
||||
|
||||
SerializedProperty faceInfoProperty = so.FindProperty("m_FaceInfo");
|
||||
float ascentLine = faceInfoProperty.FindPropertyRelative("m_AscentLine").floatValue;
|
||||
float descentLine = faceInfoProperty.FindPropertyRelative("m_DescentLine").floatValue;
|
||||
|
||||
float normalizedHeight = ascentLine - descentLine;
|
||||
float scale = glyphDrawPosition.width / normalizedHeight;
|
||||
|
||||
// Compute the normalized texture coordinates
|
||||
Rect texCoords = new Rect((float)glyphOriginX / atlasTexture.width, (float)glyphOriginY / atlasTexture.height, (float)glyphWidth / atlasTexture.width, (float)glyphHeight / atlasTexture.height);
|
||||
|
||||
if (Event.current.type == EventType.Repaint)
|
||||
{
|
||||
glyphDrawPosition.x += (glyphDrawPosition.width - glyphWidth * scale) / 2;
|
||||
glyphDrawPosition.y += (glyphDrawPosition.height - glyphHeight * scale) / 2;
|
||||
glyphDrawPosition.width = glyphWidth * scale;
|
||||
glyphDrawPosition.height = glyphHeight * scale;
|
||||
|
||||
// Could switch to using the default material of the font asset which would require passing scale to the shader.
|
||||
Graphics.DrawTexture(glyphDrawPosition, atlasTexture, texCoords, 0, 0, 0, 0, new Color(1f, 1f, 1f), mat);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d256fa541faf5d4409992c631adb98a1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,50 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.TextCore;
|
||||
using UnityEditor;
|
||||
using System.Collections;
|
||||
|
||||
|
||||
namespace TMPro.EditorUtilities
|
||||
{
|
||||
|
||||
[CustomPropertyDrawer(typeof(GlyphRect))]
|
||||
public class GlyphRectPropertyDrawer : PropertyDrawer
|
||||
{
|
||||
private static readonly GUIContent k_GlyphRectLabel = new GUIContent("Glyph Rect", "A rectangle (rect) that represents the position of the glyph in the atlas texture.");
|
||||
private static readonly GUIContent k_XPropertyLabel = new GUIContent("X:", "The X coordinate of the glyph in the atlas texture.");
|
||||
private static readonly GUIContent k_YPropertyLabel = new GUIContent("Y:", "The Y coordinate of the glyph in the atlas texture.");
|
||||
private static readonly GUIContent k_WidthPropertyLabel = new GUIContent("W:", "The width of the glyph in the atlas texture.");
|
||||
private static readonly GUIContent k_HeightPropertyLabel = new GUIContent("H:", "The height of the glyph in the atlas texture.");
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
//EditorGUI.BeginProperty(position, label, property);
|
||||
|
||||
SerializedProperty prop_X = property.FindPropertyRelative("m_X");
|
||||
SerializedProperty prop_Y = property.FindPropertyRelative("m_Y");
|
||||
SerializedProperty prop_Width = property.FindPropertyRelative("m_Width");
|
||||
SerializedProperty prop_Height = property.FindPropertyRelative("m_Height");
|
||||
|
||||
// We get Rect since a valid position may not be provided by the caller.
|
||||
Rect rect = new Rect(position.x, position.y, position.width, 49);
|
||||
EditorGUI.LabelField(new Rect(rect.x, rect.y - 2.5f, rect.width, 18), k_GlyphRectLabel);
|
||||
|
||||
EditorGUIUtility.labelWidth = 20f;
|
||||
EditorGUIUtility.fieldWidth = 20f;
|
||||
|
||||
//GUI.enabled = false;
|
||||
float width = (rect.width - 75f) / 4;
|
||||
EditorGUI.PropertyField(new Rect(rect.x + width * 0, rect.y + 20, width - 5f, 18), prop_X, k_XPropertyLabel);
|
||||
EditorGUI.PropertyField(new Rect(rect.x + width * 1, rect.y + 20, width - 5f, 18), prop_Y, k_YPropertyLabel);
|
||||
EditorGUI.PropertyField(new Rect(rect.x + width * 2, rect.y + 20, width - 5f, 18), prop_Width, k_WidthPropertyLabel);
|
||||
EditorGUI.PropertyField(new Rect(rect.x + width * 3, rect.y + 20, width - 5f, 18), prop_Height, k_HeightPropertyLabel);
|
||||
|
||||
//EditorGUI.EndProperty();
|
||||
}
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
||||
{
|
||||
return 45f;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8bc2b083b068f3546a9509c805e0541c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,123 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TextCore;
|
||||
using UnityEngine.TextCore.LowLevel;
|
||||
|
||||
namespace TMPro.EditorUtilities
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(LigatureSubstitutionRecord))]
|
||||
class LigatureSubstitutionRecordPropertyDrawer : PropertyDrawer
|
||||
{
|
||||
private Dictionary<uint, GlyphProxy> m_GlyphLookupDictionary;
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
SerializedProperty prop_ComponentGlyphIDs = property.FindPropertyRelative("m_ComponentGlyphIDs");
|
||||
int ComponentGlyphIDCount = prop_ComponentGlyphIDs.arraySize;
|
||||
SerializedProperty prop_LigatureGlyphID = property.FindPropertyRelative("m_LigatureGlyphID");
|
||||
|
||||
// Refresh glyph proxy lookup dictionary if needed
|
||||
if (TMP_PropertyDrawerUtilities.s_RefreshGlyphProxyLookup)
|
||||
TMP_PropertyDrawerUtilities.RefreshGlyphProxyLookup(property.serializedObject);
|
||||
|
||||
Rect rect = position;
|
||||
GUILayoutUtility.GetRect(position.width, 100);
|
||||
|
||||
EditorGUIUtility.labelWidth = 115;
|
||||
EditorGUI.BeginChangeCheck();
|
||||
int size = EditorGUI.DelayedIntField(new Rect(rect.x, position.y + 3, 130, rect.height), new GUIContent("Component Glyphs"), prop_ComponentGlyphIDs.arraySize);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
size = Mathf.Clamp(size, 0, 20);
|
||||
prop_ComponentGlyphIDs.arraySize = size;
|
||||
return;
|
||||
}
|
||||
|
||||
// Spacing between glyphs
|
||||
int glyphSpacing = 60;
|
||||
|
||||
// Draw Component Glyphs
|
||||
for (int i = 0; i < ComponentGlyphIDCount; i++)
|
||||
{
|
||||
Rect componentGlyphPosition = new Rect(50 + (glyphSpacing * i), position.y + 24, 48, 48);
|
||||
|
||||
// Draw glyph
|
||||
uint glyphIndex = (uint)prop_ComponentGlyphIDs.GetArrayElementAtIndex(i).intValue;
|
||||
DrawGlyph(glyphIndex, componentGlyphPosition, property);
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUI.DelayedIntField(new Rect(componentGlyphPosition.x - 13, componentGlyphPosition.y + 73, 40, EditorGUIUtility.singleLineHeight), prop_ComponentGlyphIDs.GetArrayElementAtIndex(i), GUIContent.none);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Draw Ligature glyph
|
||||
Rect ligatureGlyphPosition = new Rect(50 + (glyphSpacing * ComponentGlyphIDCount + 1), position.y + 3, 95, EditorGUIUtility.singleLineHeight);
|
||||
ligatureGlyphPosition.x = Mathf.Max(200, ligatureGlyphPosition.x);
|
||||
EditorGUI.LabelField(ligatureGlyphPosition, new GUIContent("Ligature Glyph"));
|
||||
|
||||
DrawGlyph((uint)prop_LigatureGlyphID.intValue, new Rect(ligatureGlyphPosition.x + 37, ligatureGlyphPosition.y + 21, 48, 48), property);
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUI.DelayedIntField(new Rect(ligatureGlyphPosition.x + 24, ligatureGlyphPosition.y + 94, 40, EditorGUIUtility.singleLineHeight), prop_LigatureGlyphID, GUIContent.none);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void DrawGlyph(uint glyphIndex, Rect glyphDrawPosition, SerializedProperty property)
|
||||
{
|
||||
// Get a reference to the serialized object which can either be a TMP_FontAsset or FontAsset.
|
||||
SerializedObject so = property.serializedObject;
|
||||
if (so == null)
|
||||
return;
|
||||
|
||||
if (m_GlyphLookupDictionary == null)
|
||||
m_GlyphLookupDictionary = TMP_PropertyDrawerUtilities.GetGlyphProxyLookupDictionary(so);
|
||||
|
||||
// Try getting a reference to the glyph for the given glyph index.
|
||||
if (!m_GlyphLookupDictionary.TryGetValue(glyphIndex, out GlyphProxy glyph))
|
||||
return;
|
||||
|
||||
Texture2D atlasTexture;
|
||||
if (TMP_PropertyDrawerUtilities.TryGetAtlasTextureFromSerializedObject(so, glyph.atlasIndex, out atlasTexture) == false)
|
||||
return;
|
||||
|
||||
Material mat;
|
||||
if (TMP_PropertyDrawerUtilities.TryGetMaterial(so, atlasTexture, out mat) == false)
|
||||
return;
|
||||
|
||||
int padding = so.FindProperty("m_AtlasPadding").intValue;
|
||||
GlyphRect glyphRect = glyph.glyphRect;
|
||||
int glyphOriginX = glyphRect.x - padding;
|
||||
int glyphOriginY = glyphRect.y - padding;
|
||||
int glyphWidth = glyphRect.width + padding * 2;
|
||||
int glyphHeight = glyphRect.height + padding * 2;
|
||||
|
||||
SerializedProperty faceInfoProperty = so.FindProperty("m_FaceInfo");
|
||||
float ascentLine = faceInfoProperty.FindPropertyRelative("m_AscentLine").floatValue;
|
||||
float descentLine = faceInfoProperty.FindPropertyRelative("m_DescentLine").floatValue;
|
||||
|
||||
float normalizedHeight = ascentLine - descentLine;
|
||||
float scale = glyphDrawPosition.width / normalizedHeight;
|
||||
|
||||
// Compute the normalized texture coordinates
|
||||
Rect texCoords = new Rect((float)glyphOriginX / atlasTexture.width, (float)glyphOriginY / atlasTexture.height, (float)glyphWidth / atlasTexture.width, (float)glyphHeight / atlasTexture.height);
|
||||
|
||||
if (Event.current.type == EventType.Repaint)
|
||||
{
|
||||
glyphDrawPosition.x += -(glyphWidth * scale / 2 - padding * scale);
|
||||
glyphDrawPosition.y += glyphDrawPosition.height - glyph.metrics.horizontalBearingY * scale;
|
||||
glyphDrawPosition.width = glyphWidth * scale;
|
||||
glyphDrawPosition.height = glyphHeight * scale;
|
||||
|
||||
// Could switch to using the default material of the font asset which would require passing scale to the shader.
|
||||
Graphics.DrawTexture(glyphDrawPosition, atlasTexture, texCoords, 0, 0, 0, 0, new Color(1f, 1f, 1f), mat);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7b6c2e51603686247afd5ab620c490e6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,209 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.TextCore;
|
||||
using UnityEngine.TextCore.LowLevel;
|
||||
using UnityEditor;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
||||
namespace TMPro.EditorUtilities
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(TMP_Character))]
|
||||
public class TMP_CharacterPropertyDrawer : PropertyDrawer
|
||||
{
|
||||
private Dictionary<uint, GlyphProxy> m_GlyphLookupDictionary;
|
||||
int m_GlyphSelectedForEditing = -1;
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
SerializedProperty prop_Unicode = property.FindPropertyRelative("m_Unicode");
|
||||
SerializedProperty prop_GlyphIndex = property.FindPropertyRelative("m_GlyphIndex");
|
||||
SerializedProperty prop_Scale = property.FindPropertyRelative("m_Scale");
|
||||
|
||||
// Refresh glyph proxy lookup dictionary if needed
|
||||
if (TMP_PropertyDrawerUtilities.s_RefreshGlyphProxyLookup)
|
||||
TMP_PropertyDrawerUtilities.RefreshGlyphProxyLookup(property.serializedObject);
|
||||
|
||||
GUIStyle style = new GUIStyle(EditorStyles.label);
|
||||
style.richText = true;
|
||||
|
||||
EditorGUIUtility.labelWidth = 40f;
|
||||
EditorGUIUtility.fieldWidth = 50;
|
||||
|
||||
Rect rect = new Rect(position.x + 50, position.y, position.width, 49);
|
||||
|
||||
// Display non-editable fields
|
||||
if (GUI.enabled == false)
|
||||
{
|
||||
int unicode = prop_Unicode.intValue;
|
||||
EditorGUI.LabelField(new Rect(rect.x, rect.y, 120f, 18), new GUIContent("Unicode: <color=#FFFF80>0x" + unicode.ToString("X") + "</color>"), style);
|
||||
EditorGUI.LabelField(new Rect(rect.x + 115, rect.y, 120f, 18), unicode <= 0xFFFF ? new GUIContent("UTF16: <color=#FFFF80>\\u" + unicode.ToString("X4") + "</color>") : new GUIContent("UTF32: <color=#FFFF80>\\U" + unicode.ToString("X8") + "</color>"), style);
|
||||
EditorGUI.LabelField(new Rect(rect.x, rect.y + 18, 120, 18), new GUIContent("Glyph ID: <color=#FFFF80>" + prop_GlyphIndex.intValue + "</color>"), style);
|
||||
EditorGUI.LabelField(new Rect(rect.x, rect.y + 36, 80, 18), new GUIContent("Scale: <color=#FFFF80>" + prop_Scale.floatValue + "</color>"), style);
|
||||
|
||||
// Draw Glyph (if exists)
|
||||
DrawGlyph((uint)prop_GlyphIndex.intValue, new Rect(position.x, position.y, 48, 58), property);
|
||||
}
|
||||
else // Display editable fields
|
||||
{
|
||||
EditorGUIUtility.labelWidth = 55f;
|
||||
GUI.SetNextControlName("Unicode Input");
|
||||
EditorGUI.BeginChangeCheck();
|
||||
string unicode = EditorGUI.TextField(new Rect(rect.x, rect.y, 120, 18), "Unicode:", prop_Unicode.intValue.ToString("X"));
|
||||
|
||||
if (GUI.GetNameOfFocusedControl() == "Unicode Input")
|
||||
{
|
||||
//Filter out unwanted characters.
|
||||
char chr = Event.current.character;
|
||||
if ((chr < '0' || chr > '9') && (chr < 'a' || chr > 'f') && (chr < 'A' || chr > 'F'))
|
||||
{
|
||||
Event.current.character = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
// Update Unicode value
|
||||
prop_Unicode.intValue = TMP_TextUtilities.StringHexToInt(unicode);
|
||||
}
|
||||
|
||||
// Cache current glyph index in case it needs to be restored if the new glyph index is invalid.
|
||||
int currentGlyphIndex = prop_GlyphIndex.intValue;
|
||||
|
||||
EditorGUIUtility.labelWidth = 59f;
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUI.DelayedIntField(new Rect(rect.x, rect.y + 18, 100, 18), prop_GlyphIndex, new GUIContent("Glyph ID:"));
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
// Get a reference to the font asset
|
||||
TMP_FontAsset fontAsset = property.serializedObject.targetObject as TMP_FontAsset;
|
||||
|
||||
// Make sure new glyph index is valid.
|
||||
int elementIndex = fontAsset.glyphTable.FindIndex(item => item.index == prop_GlyphIndex.intValue);
|
||||
|
||||
if (elementIndex == -1)
|
||||
prop_GlyphIndex.intValue = currentGlyphIndex;
|
||||
else
|
||||
fontAsset.IsFontAssetLookupTablesDirty = true;
|
||||
}
|
||||
|
||||
int glyphIndex = prop_GlyphIndex.intValue;
|
||||
|
||||
// Reset glyph selection if new character has been selected.
|
||||
if (GUI.enabled && m_GlyphSelectedForEditing != glyphIndex)
|
||||
m_GlyphSelectedForEditing = -1;
|
||||
|
||||
// Display button to edit the glyph data.
|
||||
if (GUI.Button(new Rect(rect.x + 120, rect.y + 18, 75, 18), new GUIContent("Edit Glyph")))
|
||||
{
|
||||
if (m_GlyphSelectedForEditing == -1)
|
||||
m_GlyphSelectedForEditing = glyphIndex;
|
||||
else
|
||||
m_GlyphSelectedForEditing = -1;
|
||||
|
||||
// Button clicks should not result in potential change.
|
||||
GUI.changed = false;
|
||||
}
|
||||
|
||||
// Show the glyph property drawer if selected
|
||||
if (glyphIndex == m_GlyphSelectedForEditing && GUI.enabled)
|
||||
{
|
||||
// Get a reference to the font asset
|
||||
TMP_FontAsset fontAsset = property.serializedObject.targetObject as TMP_FontAsset;
|
||||
|
||||
if (fontAsset != null)
|
||||
{
|
||||
// Get the index of the glyph in the font asset glyph table.
|
||||
int elementIndex = fontAsset.glyphTable.FindIndex(item => item.index == glyphIndex);
|
||||
|
||||
if (elementIndex != -1)
|
||||
{
|
||||
SerializedProperty prop_GlyphTable = property.serializedObject.FindProperty("m_GlyphTable");
|
||||
SerializedProperty prop_Glyph = prop_GlyphTable.GetArrayElementAtIndex(elementIndex);
|
||||
|
||||
SerializedProperty prop_GlyphMetrics = prop_Glyph.FindPropertyRelative("m_Metrics");
|
||||
SerializedProperty prop_GlyphRect = prop_Glyph.FindPropertyRelative("m_GlyphRect");
|
||||
|
||||
Rect newRect = EditorGUILayout.GetControlRect(false, 115);
|
||||
EditorGUI.DrawRect(new Rect(newRect.x + 52, newRect.y - 20, newRect.width - 52, newRect.height - 5), new Color(0.1f, 0.1f, 0.1f, 0.45f));
|
||||
EditorGUI.DrawRect(new Rect(newRect.x + 53, newRect.y - 19, newRect.width - 54, newRect.height - 7), new Color(0.3f, 0.3f, 0.3f, 0.8f));
|
||||
|
||||
// Display GlyphRect
|
||||
newRect.x += 55;
|
||||
newRect.y -= 18;
|
||||
newRect.width += 5;
|
||||
EditorGUI.PropertyField(newRect, prop_GlyphRect);
|
||||
|
||||
// Display GlyphMetrics
|
||||
newRect.y += 45;
|
||||
EditorGUI.PropertyField(newRect, prop_GlyphMetrics);
|
||||
|
||||
rect.y += 120;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EditorGUIUtility.labelWidth = 39f;
|
||||
EditorGUI.PropertyField(new Rect(rect.x, rect.y + 36, 80, 18), prop_Scale, new GUIContent("Scale:"));
|
||||
|
||||
// Draw Glyph (if exists)
|
||||
DrawGlyph((uint)prop_GlyphIndex.intValue, new Rect(position.x, position.y, 48, 58), property);
|
||||
}
|
||||
}
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
||||
{
|
||||
return 58;
|
||||
}
|
||||
|
||||
void DrawGlyph(uint glyphIndex, Rect glyphDrawPosition, SerializedProperty property)
|
||||
{
|
||||
// Get a reference to the serialized object which can either be a TMP_FontAsset or FontAsset.
|
||||
SerializedObject so = property.serializedObject;
|
||||
if (so == null)
|
||||
return;
|
||||
|
||||
if (m_GlyphLookupDictionary == null)
|
||||
m_GlyphLookupDictionary = TMP_PropertyDrawerUtilities.GetGlyphProxyLookupDictionary(so);
|
||||
|
||||
// Try getting a reference to the glyph for the given glyph index.
|
||||
if (!m_GlyphLookupDictionary.TryGetValue(glyphIndex, out GlyphProxy glyph))
|
||||
return;
|
||||
|
||||
Texture2D atlasTexture;
|
||||
if (TMP_PropertyDrawerUtilities.TryGetAtlasTextureFromSerializedObject(so, glyph.atlasIndex, out atlasTexture) == false)
|
||||
return;
|
||||
|
||||
Material mat;
|
||||
if (TMP_PropertyDrawerUtilities.TryGetMaterial(so, atlasTexture, out mat) == false)
|
||||
return;
|
||||
|
||||
int padding = so.FindProperty("m_AtlasPadding").intValue;
|
||||
GlyphRect glyphRect = glyph.glyphRect;
|
||||
int glyphOriginX = glyphRect.x - padding;
|
||||
int glyphOriginY = glyphRect.y - padding;
|
||||
int glyphWidth = glyphRect.width + padding * 2;
|
||||
int glyphHeight = glyphRect.height + padding * 2;
|
||||
|
||||
SerializedProperty faceInfoProperty = so.FindProperty("m_FaceInfo");
|
||||
float ascentLine = faceInfoProperty.FindPropertyRelative("m_AscentLine").floatValue;
|
||||
float descentLine = faceInfoProperty.FindPropertyRelative("m_DescentLine").floatValue;
|
||||
|
||||
float normalizedHeight = ascentLine - descentLine;
|
||||
float scale = glyphDrawPosition.width / normalizedHeight;
|
||||
|
||||
// Compute the normalized texture coordinates
|
||||
Rect texCoords = new Rect((float)glyphOriginX / atlasTexture.width, (float)glyphOriginY / atlasTexture.height, (float)glyphWidth / atlasTexture.width, (float)glyphHeight / atlasTexture.height);
|
||||
|
||||
if (Event.current.type == EventType.Repaint)
|
||||
{
|
||||
glyphDrawPosition.x += (glyphDrawPosition.width - glyphWidth * scale) / 2;
|
||||
glyphDrawPosition.y += (glyphDrawPosition.height - glyphHeight * scale) / 2;
|
||||
glyphDrawPosition.width = glyphWidth * scale;
|
||||
glyphDrawPosition.height = glyphHeight * scale;
|
||||
|
||||
// Could switch to using the default material of the font asset which would require passing scale to the shader.
|
||||
Graphics.DrawTexture(glyphDrawPosition, atlasTexture, texCoords, 0, 0, 0, 0, new Color(1f, 1f, 1f), mat);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 01ada73c4792aba4c937ff5d92cce866
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,106 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.TextCore;
|
||||
using UnityEditor;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
||||
namespace TMPro.EditorUtilities
|
||||
{
|
||||
|
||||
[CustomPropertyDrawer(typeof(Glyph))]
|
||||
public class TMP_GlyphPropertyDrawer : PropertyDrawer
|
||||
{
|
||||
private static readonly GUIContent k_ScaleLabel = new GUIContent("Scale:", "The scale of this glyph.");
|
||||
private static readonly GUIContent k_AtlasIndexLabel = new GUIContent("Atlas Index:", "The index of the atlas texture that contains this glyph.");
|
||||
private static readonly GUIContent k_ClassTypeLabel = new GUIContent("Class Type:", "The class definition type of this glyph.");
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
SerializedProperty prop_GlyphIndex = property.FindPropertyRelative("m_Index");
|
||||
SerializedProperty prop_GlyphMetrics = property.FindPropertyRelative("m_Metrics");
|
||||
SerializedProperty prop_GlyphRect = property.FindPropertyRelative("m_GlyphRect");
|
||||
SerializedProperty prop_Scale = property.FindPropertyRelative("m_Scale");
|
||||
SerializedProperty prop_AtlasIndex = property.FindPropertyRelative("m_AtlasIndex");
|
||||
SerializedProperty prop_ClassDefinitionType = property.FindPropertyRelative("m_ClassDefinitionType");
|
||||
|
||||
GUIStyle style = new GUIStyle(EditorStyles.label);
|
||||
style.richText = true;
|
||||
|
||||
Rect rect = new Rect(position.x + 70, position.y, position.width, 49);
|
||||
|
||||
float labelWidth = GUI.skin.label.CalcSize(new GUIContent("ID: " + prop_GlyphIndex.intValue)).x;
|
||||
EditorGUI.LabelField(new Rect(position.x + (64 - labelWidth) / 2, position.y + 85, 64f, 18f), new GUIContent("ID: <color=#FFFF80>" + prop_GlyphIndex.intValue + "</color>"), style);
|
||||
|
||||
// We get Rect since a valid position may not be provided by the caller.
|
||||
EditorGUI.PropertyField(new Rect(rect.x, rect.y, position.width, 49), prop_GlyphRect);
|
||||
|
||||
rect.y += 45;
|
||||
EditorGUI.PropertyField(rect, prop_GlyphMetrics);
|
||||
|
||||
EditorGUIUtility.labelWidth = 40f;
|
||||
EditorGUI.PropertyField(new Rect(rect.x, rect.y + 65, 75, 18), prop_Scale, k_ScaleLabel);
|
||||
|
||||
EditorGUIUtility.labelWidth = 70f;
|
||||
EditorGUI.PropertyField(new Rect(rect.x + 85, rect.y + 65, 95, 18), prop_AtlasIndex, k_AtlasIndexLabel);
|
||||
|
||||
if (prop_ClassDefinitionType != null)
|
||||
{
|
||||
EditorGUIUtility.labelWidth = 70f;
|
||||
float minWidth = Mathf.Max(90, rect.width - 270);
|
||||
EditorGUI.PropertyField(new Rect(rect.x + 190, rect.y + 65, minWidth, 18), prop_ClassDefinitionType, k_ClassTypeLabel);
|
||||
}
|
||||
|
||||
DrawGlyph(new Rect(position.x, position.y + 2, 64, 80), property);
|
||||
}
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
||||
{
|
||||
return 130f;
|
||||
}
|
||||
|
||||
void DrawGlyph(Rect glyphDrawPosition, SerializedProperty property)
|
||||
{
|
||||
// Get a reference to the serialized object which can either be a TMP_FontAsset or FontAsset.
|
||||
SerializedObject so = property.serializedObject;
|
||||
if (so == null)
|
||||
return;
|
||||
|
||||
Texture2D atlasTexture;
|
||||
int atlasIndex = property.FindPropertyRelative("m_AtlasIndex").intValue;
|
||||
int padding = so.FindProperty("m_AtlasPadding").intValue;
|
||||
if (TMP_PropertyDrawerUtilities.TryGetAtlasTextureFromSerializedObject(so, atlasIndex, out atlasTexture) == false)
|
||||
return;
|
||||
|
||||
Material mat;
|
||||
if (TMP_PropertyDrawerUtilities.TryGetMaterial(so, atlasTexture, out mat) == false)
|
||||
return;
|
||||
|
||||
GlyphRect glyphRect = TMP_PropertyDrawerUtilities.GetGlyphRectFromGlyphSerializedProperty(property);
|
||||
int glyphOriginX = glyphRect.x - padding;
|
||||
int glyphOriginY = glyphRect.y - padding;
|
||||
int glyphWidth = glyphRect.width + padding * 2;
|
||||
int glyphHeight = glyphRect.height + padding * 2;
|
||||
|
||||
SerializedProperty faceInfoProperty = so.FindProperty("m_FaceInfo");
|
||||
float ascentLine = faceInfoProperty.FindPropertyRelative("m_AscentLine").floatValue;
|
||||
float descentLine = faceInfoProperty.FindPropertyRelative("m_DescentLine").floatValue;
|
||||
|
||||
float normalizedHeight = ascentLine - descentLine;
|
||||
float scale = glyphDrawPosition.width / normalizedHeight;
|
||||
|
||||
// Compute the normalized texture coordinates
|
||||
Rect texCoords = new Rect((float)glyphOriginX / atlasTexture.width, (float)glyphOriginY / atlasTexture.height, (float)glyphWidth / atlasTexture.width, (float)glyphHeight / atlasTexture.height);
|
||||
|
||||
if (Event.current.type == EventType.Repaint)
|
||||
{
|
||||
glyphDrawPosition.x += (glyphDrawPosition.width - glyphWidth * scale) / 2;
|
||||
glyphDrawPosition.y += (glyphDrawPosition.height - glyphHeight * scale) / 2;
|
||||
glyphDrawPosition.width = glyphWidth * scale;
|
||||
glyphDrawPosition.height = glyphHeight * scale;
|
||||
|
||||
// Could switch to using the default material of the font asset which would require passing scale to the shader.
|
||||
Graphics.DrawTexture(glyphDrawPosition, atlasTexture, texCoords, 0, 0, 0, 0, new Color(1f, 1f, 1f), mat);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c4777500b5da6094e956c3d4f04de4db
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,236 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.TextCore;
|
||||
using UnityEditor;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
||||
namespace TMPro.EditorUtilities
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(MarkToBaseAdjustmentRecord))]
|
||||
internal class TMP_MarkToBaseAdjustmentRecordPropertyDrawer : PropertyDrawer
|
||||
{
|
||||
private bool isEditingEnabled;
|
||||
private bool isSelectable;
|
||||
private Dictionary<uint, GlyphProxy> m_GlyphLookupDictionary;
|
||||
|
||||
private string m_PreviousInput;
|
||||
|
||||
//static GUIContent s_CharacterTextFieldLabel = new GUIContent("Char:", "Enter the character or its UTF16 or UTF32 Unicode character escape sequence. For UTF16 use \"\\uFF00\" and for UTF32 use \"\\UFF00FF00\" representation.");
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
SerializedProperty prop_BaseGlyphID = property.FindPropertyRelative("m_BaseGlyphID");
|
||||
SerializedProperty prop_BaseGlyphAnchorPoint = property.FindPropertyRelative("m_BaseGlyphAnchorPoint");
|
||||
|
||||
SerializedProperty prop_MarkGlyphID = property.FindPropertyRelative("m_MarkGlyphID");
|
||||
SerializedProperty prop_MarkAdjustmentRecord = property.FindPropertyRelative("m_MarkPositionAdjustment");
|
||||
|
||||
// Refresh glyph proxy lookup dictionary if needed
|
||||
if (TMP_PropertyDrawerUtilities.s_RefreshGlyphProxyLookup)
|
||||
TMP_PropertyDrawerUtilities.RefreshGlyphProxyLookup(property.serializedObject);
|
||||
|
||||
position.yMin += 2;
|
||||
|
||||
float width = position.width / 2;
|
||||
float padding = 5.0f;
|
||||
|
||||
Rect rect;
|
||||
|
||||
isEditingEnabled = GUI.enabled;
|
||||
isSelectable = label.text == "Selectable";
|
||||
|
||||
if (isSelectable)
|
||||
GUILayoutUtility.GetRect(position.width, 75);
|
||||
else
|
||||
GUILayoutUtility.GetRect(position.width, 55);
|
||||
|
||||
GUIStyle style = new GUIStyle(EditorStyles.label) {richText = true};
|
||||
|
||||
// Base Glyph
|
||||
GUI.enabled = isEditingEnabled;
|
||||
if (isSelectable)
|
||||
{
|
||||
float labelWidth = GUI.skin.label.CalcSize(new GUIContent("ID: " + prop_BaseGlyphID.intValue)).x;
|
||||
|
||||
if (!isEditingEnabled)
|
||||
{
|
||||
EditorGUI.LabelField(new Rect(position.x + (64 - labelWidth) / 2, position.y + 60, 64f, 18f), new GUIContent("ID: <color=#FFFF80>" + prop_BaseGlyphID.intValue + "</color>"), style);
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUIUtility.labelWidth = 25f;
|
||||
EditorGUI.DelayedIntField(new Rect(position.x + (64 - labelWidth) / 2, position.y + 60, 64, 18), prop_BaseGlyphID, new GUIContent("ID:"));
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
GUI.enabled = isEditingEnabled;
|
||||
EditorGUIUtility.labelWidth = 30f;
|
||||
|
||||
rect = new Rect(position.x + 70, position.y + 10, (width - 70) - padding, 18);
|
||||
EditorGUI.PropertyField(rect, prop_BaseGlyphAnchorPoint.FindPropertyRelative("m_XCoordinate"), new GUIContent("X:"));
|
||||
|
||||
rect.y += 20;
|
||||
EditorGUI.PropertyField(rect, prop_BaseGlyphAnchorPoint.FindPropertyRelative("m_YCoordinate"), new GUIContent("Y:"));
|
||||
|
||||
DrawGlyph((uint)prop_BaseGlyphID.intValue, new Rect(position.x, position.y + 2, 64, 60), property);
|
||||
}
|
||||
|
||||
// Mark Glyph
|
||||
GUI.enabled = isEditingEnabled;
|
||||
if (isSelectable)
|
||||
{
|
||||
float labelWidth = GUI.skin.label.CalcSize(new GUIContent("ID: " + prop_MarkGlyphID.intValue)).x;
|
||||
|
||||
if (!isEditingEnabled)
|
||||
{
|
||||
EditorGUI.LabelField(new Rect(position.width / 2 + 20 + (64 - labelWidth) / 2, position.y + 60, 64f, 18f), new GUIContent("ID: <color=#FFFF80>" + prop_MarkGlyphID.intValue + "</color>"), style);
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUIUtility.labelWidth = 25f;
|
||||
EditorGUI.DelayedIntField(new Rect(position.width / 2 + 20 + (64 - labelWidth) / 2, position.y + 60, 64, 18), prop_MarkGlyphID, new GUIContent("ID:"));
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
GUI.enabled = isEditingEnabled;
|
||||
EditorGUIUtility.labelWidth = 30f;
|
||||
|
||||
rect = new Rect(position.width / 2 + 20 + 70, position.y + 10, (width - 70) - padding, 18);
|
||||
EditorGUI.PropertyField(rect, prop_MarkAdjustmentRecord.FindPropertyRelative("m_XPositionAdjustment"), new GUIContent("X:"));
|
||||
|
||||
rect.y += 20;
|
||||
EditorGUI.PropertyField(rect, prop_MarkAdjustmentRecord.FindPropertyRelative("m_YPositionAdjustment"), new GUIContent("Y:"));
|
||||
|
||||
DrawGlyph((uint)prop_MarkGlyphID.intValue, new Rect(position.width / 2 + 20, position.y + 2, 64, 60), property);
|
||||
}
|
||||
}
|
||||
|
||||
bool ValidateInput(string source)
|
||||
{
|
||||
int length = string.IsNullOrEmpty(source) ? 0 : source.Length;
|
||||
|
||||
////Filter out unwanted characters.
|
||||
Event evt = Event.current;
|
||||
|
||||
char c = evt.character;
|
||||
|
||||
if (c != '\0')
|
||||
{
|
||||
switch (length)
|
||||
{
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
if (source != m_PreviousInput)
|
||||
return true;
|
||||
|
||||
if ((source[0] == '\\' && (c == 'u' || c == 'U')) == false)
|
||||
evt.character = '\0';
|
||||
|
||||
break;
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
case 5:
|
||||
if ((c < '0' || c > '9') && (c < 'a' || c > 'f') && (c < 'A' || c > 'F'))
|
||||
evt.character = '\0';
|
||||
break;
|
||||
case 6:
|
||||
case 7:
|
||||
case 8:
|
||||
case 9:
|
||||
if (source[1] == 'u' || (c < '0' || c > '9') && (c < 'a' || c > 'f') && (c < 'A' || c > 'F'))
|
||||
evt.character = '\0';
|
||||
|
||||
// Validate input
|
||||
if (length == 6 && source[1] == 'u' && source != m_PreviousInput)
|
||||
return true;
|
||||
break;
|
||||
case 10:
|
||||
if (source != m_PreviousInput)
|
||||
return true;
|
||||
|
||||
evt.character = '\0';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
m_PreviousInput = source;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
uint GetUnicodeCharacter (string source)
|
||||
{
|
||||
uint unicode;
|
||||
|
||||
if (source.Length == 1)
|
||||
unicode = source[0];
|
||||
else if (source.Length == 6)
|
||||
unicode = (uint)TMP_TextUtilities.StringHexToInt(source.Replace("\\u", ""));
|
||||
else
|
||||
unicode = (uint)TMP_TextUtilities.StringHexToInt(source.Replace("\\U", ""));
|
||||
|
||||
return unicode;
|
||||
}
|
||||
|
||||
void DrawGlyph(uint glyphIndex, Rect glyphDrawPosition, SerializedProperty property)
|
||||
{
|
||||
// Get a reference to the serialized object which can either be a TMP_FontAsset or FontAsset.
|
||||
SerializedObject so = property.serializedObject;
|
||||
if (so == null)
|
||||
return;
|
||||
|
||||
if (m_GlyphLookupDictionary == null)
|
||||
m_GlyphLookupDictionary = TMP_PropertyDrawerUtilities.GetGlyphProxyLookupDictionary(so);
|
||||
|
||||
// Try getting a reference to the glyph for the given glyph index.
|
||||
if (!m_GlyphLookupDictionary.TryGetValue(glyphIndex, out GlyphProxy glyph))
|
||||
return;
|
||||
|
||||
Texture2D atlasTexture;
|
||||
if (TMP_PropertyDrawerUtilities.TryGetAtlasTextureFromSerializedObject(so, glyph.atlasIndex, out atlasTexture) == false)
|
||||
return;
|
||||
|
||||
Material mat;
|
||||
if (TMP_PropertyDrawerUtilities.TryGetMaterial(so, atlasTexture, out mat) == false)
|
||||
return;
|
||||
|
||||
int padding = so.FindProperty("m_AtlasPadding").intValue;
|
||||
GlyphRect glyphRect = glyph.glyphRect;
|
||||
int glyphOriginX = glyphRect.x - padding;
|
||||
int glyphOriginY = glyphRect.y - padding;
|
||||
int glyphWidth = glyphRect.width + padding * 2;
|
||||
int glyphHeight = glyphRect.height + padding * 2;
|
||||
|
||||
SerializedProperty faceInfoProperty = so.FindProperty("m_FaceInfo");
|
||||
float ascentLine = faceInfoProperty.FindPropertyRelative("m_AscentLine").floatValue;
|
||||
float descentLine = faceInfoProperty.FindPropertyRelative("m_DescentLine").floatValue;
|
||||
|
||||
float normalizedHeight = ascentLine - descentLine;
|
||||
float scale = glyphDrawPosition.width / normalizedHeight;
|
||||
|
||||
// Compute the normalized texture coordinates
|
||||
Rect texCoords = new Rect((float)glyphOriginX / atlasTexture.width, (float)glyphOriginY / atlasTexture.height, (float)glyphWidth / atlasTexture.width, (float)glyphHeight / atlasTexture.height);
|
||||
|
||||
if (Event.current.type == EventType.Repaint)
|
||||
{
|
||||
glyphDrawPosition.x += (glyphDrawPosition.width - glyphWidth * scale) / 2;
|
||||
glyphDrawPosition.y += (glyphDrawPosition.height - glyphHeight * scale) / 2;
|
||||
glyphDrawPosition.width = glyphWidth * scale;
|
||||
glyphDrawPosition.height = glyphHeight * scale;
|
||||
|
||||
// Could switch to using the default material of the font asset which would require passing scale to the shader.
|
||||
Graphics.DrawTexture(glyphDrawPosition, atlasTexture, texCoords, 0, 0, 0, 0, new Color(1f, 1f, 1f), mat);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 065a7fcf0d7286d418f3114ec18d1a2d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,237 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.TextCore;
|
||||
using UnityEditor;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
||||
namespace TMPro.EditorUtilities
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(MarkToMarkAdjustmentRecord))]
|
||||
public class TMP_MarkToMarkAdjustmentRecordPropertyDrawer : PropertyDrawer
|
||||
{
|
||||
private bool isEditingEnabled;
|
||||
private bool isSelectable;
|
||||
|
||||
private Dictionary<uint, GlyphProxy> m_GlyphLookupDictionary;
|
||||
|
||||
private string m_PreviousInput;
|
||||
|
||||
static GUIContent s_CharacterTextFieldLabel = new GUIContent("Char:", "Enter the character or its UTF16 or UTF32 Unicode character escape sequence. For UTF16 use \"\\uFF00\" and for UTF32 use \"\\UFF00FF00\" representation.");
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
SerializedProperty prop_BaseGlyphID = property.FindPropertyRelative("m_BaseMarkGlyphID");
|
||||
SerializedProperty prop_BaseGlyphAnchorPoint = property.FindPropertyRelative("m_BaseMarkGlyphAnchorPoint");
|
||||
|
||||
SerializedProperty prop_MarkGlyphID = property.FindPropertyRelative("m_CombiningMarkGlyphID");
|
||||
SerializedProperty prop_MarkAdjustmentRecord = property.FindPropertyRelative("m_CombiningMarkPositionAdjustment");
|
||||
|
||||
// Refresh glyph proxy lookup dictionary if needed
|
||||
if (TMP_PropertyDrawerUtilities.s_RefreshGlyphProxyLookup)
|
||||
TMP_PropertyDrawerUtilities.RefreshGlyphProxyLookup(property.serializedObject);
|
||||
|
||||
position.yMin += 2;
|
||||
|
||||
float width = position.width / 2;
|
||||
float padding = 5.0f;
|
||||
|
||||
Rect rect;
|
||||
|
||||
isEditingEnabled = GUI.enabled;
|
||||
isSelectable = label.text == "Selectable";
|
||||
|
||||
if (isSelectable)
|
||||
GUILayoutUtility.GetRect(position.width, 75);
|
||||
else
|
||||
GUILayoutUtility.GetRect(position.width, 55);
|
||||
|
||||
GUIStyle style = new GUIStyle(EditorStyles.label) {richText = true};
|
||||
|
||||
// Base Glyph
|
||||
GUI.enabled = isEditingEnabled;
|
||||
if (isSelectable)
|
||||
{
|
||||
float labelWidth = GUI.skin.label.CalcSize(new GUIContent("ID: " + prop_BaseGlyphID.intValue)).x;
|
||||
|
||||
if (!isEditingEnabled)
|
||||
{
|
||||
EditorGUI.LabelField(new Rect(position.x + (64 - labelWidth) / 2, position.y + 60, 64f, 18f), new GUIContent("ID: <color=#FFFF80>" + prop_BaseGlyphID.intValue + "</color>"), style);
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUIUtility.labelWidth = 25f;
|
||||
EditorGUI.DelayedIntField(new Rect(position.x + (64 - labelWidth) / 2, position.y + 60, 64, 18), prop_BaseGlyphID, new GUIContent("ID:"));
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
GUI.enabled = isEditingEnabled;
|
||||
EditorGUIUtility.labelWidth = 30f;
|
||||
|
||||
rect = new Rect(position.x + 70, position.y + 10, (width - 70) - padding, 18);
|
||||
EditorGUI.PropertyField(rect, prop_BaseGlyphAnchorPoint.FindPropertyRelative("m_XCoordinate"), new GUIContent("X:"));
|
||||
|
||||
rect.y += 20;
|
||||
EditorGUI.PropertyField(rect, prop_BaseGlyphAnchorPoint.FindPropertyRelative("m_YCoordinate"), new GUIContent("Y:"));
|
||||
|
||||
DrawGlyph((uint)prop_BaseGlyphID.intValue, new Rect(position.x, position.y + 2, 64, 60), property);
|
||||
}
|
||||
|
||||
// Mark Glyph
|
||||
GUI.enabled = isEditingEnabled;
|
||||
if (isSelectable)
|
||||
{
|
||||
float labelWidth = GUI.skin.label.CalcSize(new GUIContent("ID: " + prop_MarkGlyphID.intValue)).x;
|
||||
|
||||
if (!isEditingEnabled)
|
||||
{
|
||||
EditorGUI.LabelField(new Rect(position.width / 2 + 20 + (64 - labelWidth) / 2, position.y + 60, 64f, 18f), new GUIContent("ID: <color=#FFFF80>" + prop_MarkGlyphID.intValue + "</color>"), style);
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUIUtility.labelWidth = 25f;
|
||||
EditorGUI.DelayedIntField(new Rect(position.width / 2 + 20 + (64 - labelWidth) / 2, position.y + 60, 64, 18), prop_MarkGlyphID, new GUIContent("ID:"));
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
GUI.enabled = isEditingEnabled;
|
||||
EditorGUIUtility.labelWidth = 30f;
|
||||
|
||||
rect = new Rect(position.width / 2 + 20 + 70, position.y + 10, (width - 70) - padding, 18);
|
||||
EditorGUI.PropertyField(rect, prop_MarkAdjustmentRecord.FindPropertyRelative("m_XPositionAdjustment"), new GUIContent("X:"));
|
||||
|
||||
rect.y += 20;
|
||||
EditorGUI.PropertyField(rect, prop_MarkAdjustmentRecord.FindPropertyRelative("m_YPositionAdjustment"), new GUIContent("Y:"));
|
||||
|
||||
DrawGlyph((uint)prop_MarkGlyphID.intValue, new Rect(position.width / 2 + 20, position.y + 2, 64, 60), property);
|
||||
}
|
||||
}
|
||||
|
||||
bool ValidateInput(string source)
|
||||
{
|
||||
int length = string.IsNullOrEmpty(source) ? 0 : source.Length;
|
||||
|
||||
////Filter out unwanted characters.
|
||||
Event evt = Event.current;
|
||||
|
||||
char c = evt.character;
|
||||
|
||||
if (c != '\0')
|
||||
{
|
||||
switch (length)
|
||||
{
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
if (source != m_PreviousInput)
|
||||
return true;
|
||||
|
||||
if ((source[0] == '\\' && (c == 'u' || c == 'U')) == false)
|
||||
evt.character = '\0';
|
||||
|
||||
break;
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
case 5:
|
||||
if ((c < '0' || c > '9') && (c < 'a' || c > 'f') && (c < 'A' || c > 'F'))
|
||||
evt.character = '\0';
|
||||
break;
|
||||
case 6:
|
||||
case 7:
|
||||
case 8:
|
||||
case 9:
|
||||
if (source[1] == 'u' || (c < '0' || c > '9') && (c < 'a' || c > 'f') && (c < 'A' || c > 'F'))
|
||||
evt.character = '\0';
|
||||
|
||||
// Validate input
|
||||
if (length == 6 && source[1] == 'u' && source != m_PreviousInput)
|
||||
return true;
|
||||
break;
|
||||
case 10:
|
||||
if (source != m_PreviousInput)
|
||||
return true;
|
||||
|
||||
evt.character = '\0';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
m_PreviousInput = source;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
uint GetUnicodeCharacter (string source)
|
||||
{
|
||||
uint unicode;
|
||||
|
||||
if (source.Length == 1)
|
||||
unicode = source[0];
|
||||
else if (source.Length == 6)
|
||||
unicode = (uint)TMP_TextUtilities.StringHexToInt(source.Replace("\\u", ""));
|
||||
else
|
||||
unicode = (uint)TMP_TextUtilities.StringHexToInt(source.Replace("\\U", ""));
|
||||
|
||||
return unicode;
|
||||
}
|
||||
|
||||
void DrawGlyph(uint glyphIndex, Rect glyphDrawPosition, SerializedProperty property)
|
||||
{
|
||||
// Get a reference to the serialized object which can either be a TMP_FontAsset or FontAsset.
|
||||
SerializedObject so = property.serializedObject;
|
||||
if (so == null)
|
||||
return;
|
||||
|
||||
if (m_GlyphLookupDictionary == null)
|
||||
m_GlyphLookupDictionary = TMP_PropertyDrawerUtilities.GetGlyphProxyLookupDictionary(so);
|
||||
|
||||
// Try getting a reference to the glyph for the given glyph index.
|
||||
if (!m_GlyphLookupDictionary.TryGetValue(glyphIndex, out GlyphProxy glyph))
|
||||
return;
|
||||
|
||||
Texture2D atlasTexture;
|
||||
if (TMP_PropertyDrawerUtilities.TryGetAtlasTextureFromSerializedObject(so, glyph.atlasIndex, out atlasTexture) == false)
|
||||
return;
|
||||
|
||||
Material mat;
|
||||
if (TMP_PropertyDrawerUtilities.TryGetMaterial(so, atlasTexture, out mat) == false)
|
||||
return;
|
||||
|
||||
int padding = so.FindProperty("m_AtlasPadding").intValue;
|
||||
GlyphRect glyphRect = glyph.glyphRect;
|
||||
int glyphOriginX = glyphRect.x - padding;
|
||||
int glyphOriginY = glyphRect.y - padding;
|
||||
int glyphWidth = glyphRect.width + padding * 2;
|
||||
int glyphHeight = glyphRect.height + padding * 2;
|
||||
|
||||
SerializedProperty faceInfoProperty = so.FindProperty("m_FaceInfo");
|
||||
float ascentLine = faceInfoProperty.FindPropertyRelative("m_AscentLine").floatValue;
|
||||
float descentLine = faceInfoProperty.FindPropertyRelative("m_DescentLine").floatValue;
|
||||
|
||||
float normalizedHeight = ascentLine - descentLine;
|
||||
float scale = glyphDrawPosition.width / normalizedHeight;
|
||||
|
||||
// Compute the normalized texture coordinates
|
||||
Rect texCoords = new Rect((float)glyphOriginX / atlasTexture.width, (float)glyphOriginY / atlasTexture.height, (float)glyphWidth / atlasTexture.width, (float)glyphHeight / atlasTexture.height);
|
||||
|
||||
if (Event.current.type == EventType.Repaint)
|
||||
{
|
||||
glyphDrawPosition.x += (glyphDrawPosition.width - glyphWidth * scale) / 2;
|
||||
glyphDrawPosition.y += (glyphDrawPosition.height - glyphHeight * scale) / 2;
|
||||
glyphDrawPosition.width = glyphWidth * scale;
|
||||
glyphDrawPosition.height = glyphHeight * scale;
|
||||
|
||||
// Could switch to using the default material of the font asset which would require passing scale to the shader.
|
||||
Graphics.DrawTexture(glyphDrawPosition, atlasTexture, texCoords, 0, 0, 0, 0, new Color(1f, 1f, 1f), mat);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 149e85704eb73624ba2d705408274f3e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,180 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TextCore;
|
||||
using UnityEngine.TextCore.LowLevel;
|
||||
|
||||
|
||||
namespace TMPro.EditorUtilities
|
||||
{
|
||||
internal struct GlyphProxy
|
||||
{
|
||||
public uint index;
|
||||
public GlyphRect glyphRect;
|
||||
public GlyphMetrics metrics;
|
||||
public int atlasIndex;
|
||||
}
|
||||
|
||||
internal static class TMP_PropertyDrawerUtilities
|
||||
{
|
||||
internal static bool s_RefreshGlyphProxyLookup;
|
||||
private static Dictionary<SerializedObject, Dictionary<uint, GlyphProxy>> s_GlyphProxyLookups = new Dictionary<SerializedObject, Dictionary<uint, GlyphProxy>>();
|
||||
|
||||
internal static void ClearGlyphProxyLookups()
|
||||
{
|
||||
s_GlyphProxyLookups.Clear();
|
||||
}
|
||||
|
||||
internal static void RefreshGlyphProxyLookup(SerializedObject so)
|
||||
{
|
||||
if (!s_GlyphProxyLookups.ContainsKey(so))
|
||||
return;
|
||||
|
||||
Dictionary<uint, GlyphProxy> glyphProxyLookup = s_GlyphProxyLookups[so];
|
||||
|
||||
glyphProxyLookup.Clear();
|
||||
PopulateGlyphProxyLookupDictionary(so, glyphProxyLookup);
|
||||
|
||||
s_RefreshGlyphProxyLookup = false;
|
||||
}
|
||||
|
||||
internal static Dictionary<uint, GlyphProxy> GetGlyphProxyLookupDictionary(SerializedObject so)
|
||||
{
|
||||
if (s_GlyphProxyLookups.ContainsKey(so))
|
||||
return s_GlyphProxyLookups[so];
|
||||
|
||||
Dictionary<uint, GlyphProxy> glyphProxyLookup = new Dictionary<uint, GlyphProxy>();
|
||||
PopulateGlyphProxyLookupDictionary(so, glyphProxyLookup);
|
||||
s_GlyphProxyLookups.Add(so, glyphProxyLookup);
|
||||
|
||||
return glyphProxyLookup;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="so"></param>
|
||||
/// <param name="lookupDictionary"></param>
|
||||
static void PopulateGlyphProxyLookupDictionary(SerializedObject so, Dictionary<uint, GlyphProxy> lookupDictionary)
|
||||
{
|
||||
if (lookupDictionary == null)
|
||||
return;
|
||||
|
||||
// Get reference to serialized property for the glyph table
|
||||
SerializedProperty glyphTable = so.FindProperty("m_GlyphTable");
|
||||
|
||||
for (int i = 0; i < glyphTable.arraySize; i++)
|
||||
{
|
||||
SerializedProperty glyphProperty = glyphTable.GetArrayElementAtIndex(i);
|
||||
GlyphProxy proxy = GetGlyphProxyFromSerializedProperty(glyphProperty);
|
||||
|
||||
lookupDictionary.Add(proxy.index, proxy);
|
||||
}
|
||||
}
|
||||
|
||||
internal static GlyphRect GetGlyphRectFromGlyphSerializedProperty(SerializedProperty property)
|
||||
{
|
||||
SerializedProperty glyphRectProp = property.FindPropertyRelative("m_GlyphRect");
|
||||
|
||||
GlyphRect glyphRect = new GlyphRect();
|
||||
glyphRect.x = glyphRectProp.FindPropertyRelative("m_X").intValue;
|
||||
glyphRect.y = glyphRectProp.FindPropertyRelative("m_Y").intValue;
|
||||
glyphRect.width = glyphRectProp.FindPropertyRelative("m_Width").intValue;
|
||||
glyphRect.height = glyphRectProp.FindPropertyRelative("m_Height").intValue;
|
||||
|
||||
return glyphRect;
|
||||
}
|
||||
|
||||
internal static GlyphMetrics GetGlyphMetricsFromGlyphSerializedProperty(SerializedProperty property)
|
||||
{
|
||||
SerializedProperty glyphMetricsProperty = property.FindPropertyRelative("m_Metrics");
|
||||
|
||||
GlyphMetrics glyphMetrics = new GlyphMetrics();
|
||||
glyphMetrics.horizontalBearingX = glyphMetricsProperty.FindPropertyRelative("m_HorizontalBearingX").floatValue;
|
||||
glyphMetrics.horizontalBearingY = glyphMetricsProperty.FindPropertyRelative("m_HorizontalBearingY").floatValue;
|
||||
glyphMetrics.horizontalAdvance = glyphMetricsProperty.FindPropertyRelative("m_HorizontalAdvance").floatValue;
|
||||
glyphMetrics.width = glyphMetricsProperty.FindPropertyRelative("m_Width").floatValue;
|
||||
glyphMetrics.height = glyphMetricsProperty.FindPropertyRelative("m_Height").floatValue;
|
||||
|
||||
return glyphMetrics;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="property"></param>
|
||||
/// <returns></returns>
|
||||
internal static GlyphProxy GetGlyphProxyFromSerializedProperty(SerializedProperty property)
|
||||
{
|
||||
GlyphProxy proxy = new GlyphProxy();
|
||||
proxy.index = (uint)property.FindPropertyRelative("m_Index").intValue;
|
||||
proxy.glyphRect = GetGlyphRectFromGlyphSerializedProperty(property);
|
||||
proxy.metrics = GetGlyphMetricsFromGlyphSerializedProperty(property);
|
||||
proxy.atlasIndex = property.FindPropertyRelative("m_AtlasIndex").intValue;
|
||||
|
||||
return proxy;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="serializedObject"></param>
|
||||
/// <param name="glyphIndex"></param>
|
||||
/// <param name="texture"></param>
|
||||
/// <returns></returns>
|
||||
internal static bool TryGetAtlasTextureFromSerializedObject(SerializedObject serializedObject, int glyphIndex, out Texture2D texture)
|
||||
{
|
||||
SerializedProperty atlasTextureProperty = serializedObject.FindProperty("m_AtlasTextures");
|
||||
|
||||
texture = atlasTextureProperty.GetArrayElementAtIndex(glyphIndex).objectReferenceValue as Texture2D;
|
||||
|
||||
if (texture == null)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="serializedObject"></param>
|
||||
/// <param name="texture"></param>
|
||||
/// <param name="mat"></param>
|
||||
/// <returns></returns>
|
||||
internal static bool TryGetMaterial(SerializedObject serializedObject, Texture2D texture, out Material mat)
|
||||
{
|
||||
GlyphRenderMode atlasRenderMode = (GlyphRenderMode)serializedObject.FindProperty("m_AtlasRenderMode").intValue;
|
||||
|
||||
if (((GlyphRasterModes)atlasRenderMode & GlyphRasterModes.RASTER_MODE_BITMAP) == GlyphRasterModes.RASTER_MODE_BITMAP)
|
||||
{
|
||||
#if TEXTCORE_FONT_ENGINE_1_5_OR_NEWER
|
||||
if (atlasRenderMode == GlyphRenderMode.COLOR || atlasRenderMode == GlyphRenderMode.COLOR_HINTED)
|
||||
mat = TMP_FontAssetEditor.internalRGBABitmapMaterial;
|
||||
else
|
||||
mat = TMP_FontAssetEditor.internalBitmapMaterial;
|
||||
#else
|
||||
mat = TMP_FontAssetEditor.internalBitmapMaterial;
|
||||
#endif
|
||||
|
||||
if (mat == null)
|
||||
return false;
|
||||
|
||||
mat.mainTexture = texture;
|
||||
mat.color = Color.white;
|
||||
}
|
||||
else
|
||||
{
|
||||
mat = TMP_FontAssetEditor.internalSDFMaterial;
|
||||
|
||||
if (mat == null)
|
||||
return false;
|
||||
|
||||
int padding = serializedObject.FindProperty("m_AtlasPadding").intValue;
|
||||
mat.mainTexture = texture;
|
||||
mat.SetFloat(ShaderUtilities.ID_GradientScale, padding + 1);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 371a2245f9a9ff344997fec3609bf73e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,212 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.TextCore;
|
||||
using UnityEditor;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
||||
namespace TMPro.EditorUtilities
|
||||
{
|
||||
|
||||
[CustomPropertyDrawer(typeof(TMP_SpriteCharacter))]
|
||||
public class TMP_SpriteCharacterPropertyDrawer : PropertyDrawer
|
||||
{
|
||||
int m_GlyphSelectedForEditing = -1;
|
||||
private Dictionary<uint, GlyphProxy> m_GlyphLookupDictionary;
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
SerializedProperty prop_SpriteName = property.FindPropertyRelative("m_Name");
|
||||
SerializedProperty prop_SpriteUnicode = property.FindPropertyRelative("m_Unicode");
|
||||
SerializedProperty prop_SpriteGlyphIndex = property.FindPropertyRelative("m_GlyphIndex");
|
||||
SerializedProperty prop_SpriteScale = property.FindPropertyRelative("m_Scale");
|
||||
|
||||
GUIStyle style = new GUIStyle(EditorStyles.label);
|
||||
style.richText = true;
|
||||
|
||||
EditorGUIUtility.labelWidth = 40f;
|
||||
EditorGUIUtility.fieldWidth = 50;
|
||||
|
||||
Rect rect = new Rect(position.x + 60, position.y, position.width, 49);
|
||||
|
||||
// Display non-editable fields
|
||||
if (GUI.enabled == false)
|
||||
{
|
||||
// Sprite Character Index
|
||||
int spriteCharacterIndex;
|
||||
int.TryParse(property.displayName.Split(' ')[1], out spriteCharacterIndex);
|
||||
EditorGUI.LabelField(new Rect(rect.x, rect.y, 75f, 18), new GUIContent("Index: <color=#FFFF80>" + spriteCharacterIndex + "</color>"), style);
|
||||
|
||||
EditorGUI.LabelField(new Rect(rect.x + 75f, rect.y, 120f, 18), new GUIContent("Unicode: <color=#FFFF80>0x" + prop_SpriteUnicode.intValue.ToString("X") + "</color>"), style);
|
||||
EditorGUI.LabelField(new Rect(rect.x + 195f, rect.y, rect.width - 255, 18), new GUIContent("Name: <color=#FFFF80>" + prop_SpriteName.stringValue + "</color>"), style);
|
||||
|
||||
EditorGUI.LabelField(new Rect(rect.x, rect.y + 18, 120, 18), new GUIContent("Glyph ID: <color=#FFFF80>" + prop_SpriteGlyphIndex.intValue + "</color>"), style);
|
||||
|
||||
// Draw Sprite Glyph (if exists)
|
||||
DrawSpriteGlyph((uint)prop_SpriteGlyphIndex.intValue, position, property);
|
||||
|
||||
EditorGUI.LabelField(new Rect(rect.x, rect.y + 36, 80, 18), new GUIContent("Scale: <color=#FFFF80>" + prop_SpriteScale.floatValue + "</color>"), style);
|
||||
}
|
||||
else // Display editable fields
|
||||
{
|
||||
// Get a reference to the underlying Sprite Asset
|
||||
TMP_SpriteAsset spriteAsset = property.serializedObject.targetObject as TMP_SpriteAsset;
|
||||
|
||||
// Sprite Character Index
|
||||
int spriteCharacterIndex;
|
||||
int.TryParse(property.displayName.Split(' ')[1], out spriteCharacterIndex);
|
||||
|
||||
EditorGUI.LabelField(new Rect(rect.x, rect.y, 75f, 18), new GUIContent("Index: <color=#FFFF80>" + spriteCharacterIndex + "</color>"), style);
|
||||
|
||||
EditorGUIUtility.labelWidth = 55f;
|
||||
GUI.SetNextControlName("Unicode Input");
|
||||
EditorGUI.BeginChangeCheck();
|
||||
string unicode = EditorGUI.DelayedTextField(new Rect(rect.x + 75f, rect.y, 120, 18), "Unicode:", prop_SpriteUnicode.intValue.ToString("X"));
|
||||
|
||||
if (GUI.GetNameOfFocusedControl() == "Unicode Input")
|
||||
{
|
||||
//Filter out unwanted characters.
|
||||
char chr = Event.current.character;
|
||||
if ((chr < '0' || chr > '9') && (chr < 'a' || chr > 'f') && (chr < 'A' || chr > 'F'))
|
||||
{
|
||||
Event.current.character = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
// Update Unicode value
|
||||
prop_SpriteUnicode.intValue = TMP_TextUtilities.StringHexToInt(unicode);
|
||||
spriteAsset.m_IsSpriteAssetLookupTablesDirty = true;
|
||||
}
|
||||
|
||||
EditorGUIUtility.labelWidth = 41f;
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUI.DelayedTextField(new Rect(rect.x + 195f, rect.y, rect.width - 255, 18), prop_SpriteName, new GUIContent("Name:"));
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
spriteAsset.m_IsSpriteAssetLookupTablesDirty = true;
|
||||
}
|
||||
|
||||
EditorGUIUtility.labelWidth = 59f;
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUI.DelayedIntField(new Rect(rect.x, rect.y + 18, 100, 18), prop_SpriteGlyphIndex, new GUIContent("Glyph ID:"));
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
spriteAsset.m_IsSpriteAssetLookupTablesDirty = true;
|
||||
}
|
||||
|
||||
// Draw Sprite Glyph (if exists)
|
||||
DrawSpriteGlyph((uint)prop_SpriteGlyphIndex.intValue, position, property);
|
||||
|
||||
int glyphIndex = prop_SpriteGlyphIndex.intValue;
|
||||
|
||||
// Reset glyph selection if new character has been selected.
|
||||
if (GUI.enabled && m_GlyphSelectedForEditing != glyphIndex)
|
||||
m_GlyphSelectedForEditing = -1;
|
||||
|
||||
// Display button to edit the glyph data.
|
||||
if (GUI.Button(new Rect(rect.x + 120, rect.y + 18, 75, 18), new GUIContent("Edit Glyph")))
|
||||
{
|
||||
if (m_GlyphSelectedForEditing == -1)
|
||||
m_GlyphSelectedForEditing = glyphIndex;
|
||||
else
|
||||
m_GlyphSelectedForEditing = -1;
|
||||
|
||||
// Button clicks should not result in potential change.
|
||||
GUI.changed = false;
|
||||
}
|
||||
|
||||
// Show the glyph property drawer if selected
|
||||
if (glyphIndex == m_GlyphSelectedForEditing && GUI.enabled)
|
||||
{
|
||||
if (spriteAsset != null)
|
||||
{
|
||||
// Lookup glyph and draw glyph (if available)
|
||||
int elementIndex = spriteAsset.spriteGlyphTable.FindIndex(item => item.index == glyphIndex);
|
||||
|
||||
if (elementIndex != -1)
|
||||
{
|
||||
// Get a reference to the Sprite Glyph Table
|
||||
SerializedProperty prop_SpriteGlyphTable = property.serializedObject.FindProperty("m_GlyphTable");
|
||||
|
||||
SerializedProperty prop_SpriteGlyph = prop_SpriteGlyphTable.GetArrayElementAtIndex(elementIndex);
|
||||
SerializedProperty prop_GlyphMetrics = prop_SpriteGlyph.FindPropertyRelative("m_Metrics");
|
||||
SerializedProperty prop_GlyphRect = prop_SpriteGlyph.FindPropertyRelative("m_GlyphRect");
|
||||
|
||||
Rect newRect = EditorGUILayout.GetControlRect(false, 115);
|
||||
EditorGUI.DrawRect(new Rect(newRect.x + 62, newRect.y - 20, newRect.width - 62, newRect.height - 5), new Color(0.1f, 0.1f, 0.1f, 0.45f));
|
||||
EditorGUI.DrawRect(new Rect(newRect.x + 63, newRect.y - 19, newRect.width - 64, newRect.height - 7), new Color(0.3f, 0.3f, 0.3f, 0.8f));
|
||||
|
||||
// Display GlyphRect
|
||||
newRect.x += 65;
|
||||
newRect.y -= 18;
|
||||
newRect.width += 5;
|
||||
EditorGUI.PropertyField(newRect, prop_GlyphRect);
|
||||
|
||||
// Display GlyphMetrics
|
||||
newRect.y += 45;
|
||||
EditorGUI.PropertyField(newRect, prop_GlyphMetrics);
|
||||
|
||||
rect.y += 120;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EditorGUIUtility.labelWidth = 39f;
|
||||
EditorGUI.PropertyField(new Rect(rect.x, rect.y + 36, 80, 18), prop_SpriteScale, new GUIContent("Scale:"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
||||
{
|
||||
return 58;
|
||||
}
|
||||
|
||||
|
||||
void DrawSpriteGlyph(uint glyphIndex, Rect position, SerializedProperty property)
|
||||
{
|
||||
if (m_GlyphLookupDictionary == null)
|
||||
m_GlyphLookupDictionary = TMP_PropertyDrawerUtilities.GetGlyphProxyLookupDictionary(property.serializedObject);
|
||||
|
||||
// Try getting a reference to the glyph for the given glyph index.
|
||||
if (!m_GlyphLookupDictionary.TryGetValue(glyphIndex, out GlyphProxy glyph))
|
||||
return;
|
||||
|
||||
GlyphRect glyphRect = glyph.glyphRect;
|
||||
|
||||
// Get a reference to the sprite texture
|
||||
Texture tex = property.serializedObject.FindProperty("spriteSheet").objectReferenceValue as Texture;
|
||||
if (tex == null)
|
||||
{
|
||||
Debug.LogWarning("Please assign a valid Sprite Atlas texture to the [" + property.serializedObject.targetObject.name + "] Sprite Asset.", property.serializedObject.targetObject);
|
||||
return;
|
||||
}
|
||||
|
||||
Vector2 spriteTexPosition = new Vector2(position.x, position.y);
|
||||
Vector2 spriteSize = new Vector2(48, 48);
|
||||
Vector2 alignmentOffset = new Vector2((58 - spriteSize.x) / 2, (58 - spriteSize.y) / 2);
|
||||
|
||||
float x = glyphRect.x;
|
||||
float y = glyphRect.y;
|
||||
float spriteWidth = glyphRect.width;
|
||||
float spriteHeight = glyphRect.height;
|
||||
|
||||
if (spriteWidth >= spriteHeight)
|
||||
{
|
||||
spriteSize.y = spriteHeight * spriteSize.x / spriteWidth;
|
||||
spriteTexPosition.y += (spriteSize.x - spriteSize.y) / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
spriteSize.x = spriteWidth * spriteSize.y / spriteHeight;
|
||||
spriteTexPosition.x += (spriteSize.y - spriteSize.x) / 2;
|
||||
}
|
||||
|
||||
// Compute the normalized texture coordinates
|
||||
Rect texCoords = new Rect(x / tex.width, y / tex.height, spriteWidth / tex.width, spriteHeight / tex.height);
|
||||
GUI.DrawTextureWithTexCoords(new Rect(spriteTexPosition.x + alignmentOffset.x, spriteTexPosition.y + alignmentOffset.y, spriteSize.x, spriteSize.y), tex, texCoords, true);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 37cff9f5a86ae494c8cb04423580480d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,88 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.TextCore;
|
||||
using UnityEditor;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
||||
namespace TMPro.EditorUtilities
|
||||
{
|
||||
|
||||
[CustomPropertyDrawer(typeof(TMP_SpriteGlyph))]
|
||||
public class TMP_SpriteGlyphPropertyDrawer : PropertyDrawer
|
||||
{
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
SerializedProperty prop_GlyphIndex = property.FindPropertyRelative("m_Index");
|
||||
SerializedProperty prop_GlyphMetrics = property.FindPropertyRelative("m_Metrics");
|
||||
SerializedProperty prop_GlyphRect = property.FindPropertyRelative("m_GlyphRect");
|
||||
SerializedProperty prop_Scale = property.FindPropertyRelative("m_Scale");
|
||||
SerializedProperty prop_AtlasIndex = property.FindPropertyRelative("m_AtlasIndex");
|
||||
|
||||
GUIStyle style = new GUIStyle(EditorStyles.label);
|
||||
style.richText = true;
|
||||
|
||||
Rect rect = new Rect(position.x + 70, position.y, position.width, 49);
|
||||
|
||||
// Draw GlyphRect
|
||||
EditorGUI.PropertyField(rect, prop_GlyphRect);
|
||||
|
||||
// Draw GlyphMetrics
|
||||
rect.y += 45;
|
||||
EditorGUI.PropertyField(rect, prop_GlyphMetrics);
|
||||
|
||||
EditorGUIUtility.labelWidth = 40f;
|
||||
EditorGUI.PropertyField(new Rect(rect.x, rect.y + 65, 75, 18), prop_Scale, new GUIContent("Scale:"));
|
||||
|
||||
EditorGUIUtility.labelWidth = 74f;
|
||||
EditorGUI.PropertyField(new Rect(rect.x + 85, rect.y + 65, 95, 18), prop_AtlasIndex, new GUIContent("Atlas Index:"));
|
||||
|
||||
DrawGlyph(position, property);
|
||||
|
||||
int spriteCharacterIndex;
|
||||
int.TryParse(property.displayName.Split(' ')[1], out spriteCharacterIndex);
|
||||
|
||||
EditorGUI.LabelField(new Rect(position.x, position.y + 5, 64f, 18f), new GUIContent("#" + spriteCharacterIndex), style);
|
||||
|
||||
float labelWidthID = GUI.skin.label.CalcSize(new GUIContent("ID: " + prop_GlyphIndex.intValue)).x;
|
||||
EditorGUI.LabelField(new Rect(position.x + (64 - labelWidthID) / 2, position.y + 110, 64f, 18f), new GUIContent("ID: <color=#FFFF80>" + prop_GlyphIndex.intValue + "</color>"), style);
|
||||
}
|
||||
|
||||
void DrawGlyph(Rect position, SerializedProperty property)
|
||||
{
|
||||
// Get a reference to the sprite texture
|
||||
Texture tex = property.serializedObject.FindProperty("spriteSheet").objectReferenceValue as Texture;
|
||||
|
||||
// Return if we don't have a texture assigned to the sprite asset.
|
||||
if (tex == null)
|
||||
{
|
||||
Debug.LogWarning("Please assign a valid Sprite Atlas texture to the [" + property.serializedObject.targetObject.name + "] Sprite Asset.", property.serializedObject.targetObject);
|
||||
return;
|
||||
}
|
||||
|
||||
Vector2 spriteTexPosition = new Vector2(position.x, position.y);
|
||||
Vector2 spriteSize = new Vector2(65, 65);
|
||||
GlyphRect glyphRect = TMP_PropertyDrawerUtilities.GetGlyphRectFromGlyphSerializedProperty(property);
|
||||
|
||||
if (glyphRect.width >= glyphRect.height)
|
||||
{
|
||||
spriteSize.y = glyphRect.height * spriteSize.x / glyphRect.width;
|
||||
spriteTexPosition.y += (spriteSize.x - spriteSize.y) / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
spriteSize.x = glyphRect.width * spriteSize.y / glyphRect.height;
|
||||
spriteTexPosition.x += (spriteSize.y - spriteSize.x) / 2;
|
||||
}
|
||||
|
||||
// Compute the normalized texture coordinates
|
||||
Rect texCoords = new Rect((float)glyphRect.x / tex.width, (float)glyphRect.y / tex.height, (float)glyphRect.width / tex.width, (float)glyphRect.height / tex.height);
|
||||
GUI.DrawTextureWithTexCoords(new Rect(spriteTexPosition.x + 5, spriteTexPosition.y + 32f, spriteSize.x, spriteSize.y), tex, texCoords, true);
|
||||
}
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
||||
{
|
||||
return 130f;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 056819c66570ca54cadb72330a354050
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,273 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace TMPro.EditorUtilities
|
||||
{
|
||||
|
||||
[CustomPropertyDrawer(typeof(TextAlignmentOptions))]
|
||||
public class TMP_TextAlignmentDrawer : PropertyDrawer
|
||||
{
|
||||
const int k_AlignmentButtonWidth = 24;
|
||||
const int k_AlignmentButtonHeight = 20;
|
||||
const int k_WideViewWidth = 504;
|
||||
const int k_ControlsSpacing = 6;
|
||||
const int k_GroupWidth = k_AlignmentButtonWidth * 6;
|
||||
static readonly int k_TextAlignmentHash = "DoTextAligmentControl".GetHashCode();
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
||||
{
|
||||
return EditorGUIUtility.currentViewWidth > k_WideViewWidth ? k_AlignmentButtonHeight : k_AlignmentButtonHeight * 2 + 3;
|
||||
}
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
var id = GUIUtility.GetControlID(k_TextAlignmentHash, FocusType.Keyboard, position);
|
||||
|
||||
EditorGUI.BeginProperty(position, label, property);
|
||||
{
|
||||
var controlArea = EditorGUI.PrefixLabel(position, id, label);
|
||||
|
||||
var horizontalAligment = new Rect(controlArea.x, controlArea.y, k_GroupWidth, k_AlignmentButtonHeight);
|
||||
var verticalAligment = new Rect(!(EditorGUIUtility.currentViewWidth > k_WideViewWidth) ? controlArea.x : horizontalAligment.xMax + k_ControlsSpacing, !(EditorGUIUtility.currentViewWidth > k_WideViewWidth) ? controlArea.y + k_AlignmentButtonHeight + 3 : controlArea.y, k_GroupWidth, k_AlignmentButtonHeight);
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
var selectedHorizontal = DoHorizontalAligmentControl(horizontalAligment, property);
|
||||
var selectedVertical = DoVerticalAligmentControl(verticalAligment, property);
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
var value = (0x1 << selectedHorizontal) | (0x100 << selectedVertical);
|
||||
property.intValue = value;
|
||||
}
|
||||
}
|
||||
EditorGUI.EndProperty();
|
||||
}
|
||||
|
||||
static int DoHorizontalAligmentControl(Rect position, SerializedProperty alignment)
|
||||
{
|
||||
var selected = TMP_EditorUtility.GetHorizontalAlignmentGridValue(alignment.intValue);
|
||||
|
||||
var values = new bool[6];
|
||||
|
||||
values[selected] = true;
|
||||
|
||||
if (alignment.hasMultipleDifferentValues)
|
||||
{
|
||||
foreach (var obj in alignment.serializedObject.targetObjects)
|
||||
{
|
||||
var text = obj as TMP_Text;
|
||||
if (text != null)
|
||||
{
|
||||
values[TMP_EditorUtility.GetHorizontalAlignmentGridValue((int)text.alignment)] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
position.width = k_AlignmentButtonWidth;
|
||||
|
||||
for (var i = 0; i < values.Length; i++)
|
||||
{
|
||||
var oldValue = values[i];
|
||||
var newValue = TMP_EditorUtility.EditorToggle(position, oldValue, TMP_UIStyleManager.alignContentA[i], i == 0 ? TMP_UIStyleManager.alignmentButtonLeft : (i == 5 ? TMP_UIStyleManager.alignmentButtonRight : TMP_UIStyleManager.alignmentButtonMid));
|
||||
if (newValue != oldValue)
|
||||
{
|
||||
selected = i;
|
||||
}
|
||||
position.x += position.width;
|
||||
}
|
||||
|
||||
return selected;
|
||||
}
|
||||
|
||||
static int DoVerticalAligmentControl(Rect position, SerializedProperty alignment)
|
||||
{
|
||||
var selected = TMP_EditorUtility.GetVerticalAlignmentGridValue(alignment.intValue);
|
||||
|
||||
var values = new bool[6];
|
||||
|
||||
values[selected] = true;
|
||||
|
||||
if (alignment.hasMultipleDifferentValues)
|
||||
{
|
||||
foreach (var obj in alignment.serializedObject.targetObjects)
|
||||
{
|
||||
var text = obj as TMP_Text;
|
||||
if (text != null)
|
||||
{
|
||||
values[TMP_EditorUtility.GetVerticalAlignmentGridValue((int)text.alignment)] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
position.width = k_AlignmentButtonWidth;
|
||||
|
||||
for (var i = 0; i < values.Length; i++)
|
||||
{
|
||||
var oldValue = values[i];
|
||||
var newValue = TMP_EditorUtility.EditorToggle(position, oldValue, TMP_UIStyleManager.alignContentB[i], i == 0 ? TMP_UIStyleManager.alignmentButtonLeft : (i == 5 ? TMP_UIStyleManager.alignmentButtonRight : TMP_UIStyleManager.alignmentButtonMid));
|
||||
if (newValue != oldValue)
|
||||
{
|
||||
selected = i;
|
||||
}
|
||||
position.x += position.width;
|
||||
}
|
||||
|
||||
return selected;
|
||||
}
|
||||
}
|
||||
|
||||
[CustomPropertyDrawer(typeof(HorizontalAlignmentOptions))]
|
||||
public class TMP_HorizontalAlignmentDrawer : PropertyDrawer
|
||||
{
|
||||
const int k_AlignmentButtonWidth = 24;
|
||||
const int k_AlignmentButtonHeight = 20;
|
||||
const int k_WideViewWidth = 504;
|
||||
const int k_ControlsSpacing = 6;
|
||||
const int k_GroupWidth = k_AlignmentButtonWidth * 6;
|
||||
static readonly int k_TextAlignmentHash = "DoTextAligmentControl".GetHashCode();
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
||||
{
|
||||
return EditorGUIUtility.currentViewWidth > k_WideViewWidth ? k_AlignmentButtonHeight : k_AlignmentButtonHeight * 2 + 3;
|
||||
}
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
var id = GUIUtility.GetControlID(k_TextAlignmentHash, FocusType.Keyboard, position);
|
||||
|
||||
EditorGUI.BeginProperty(position, label, property);
|
||||
{
|
||||
var controlArea = EditorGUI.PrefixLabel(position, id, label);
|
||||
|
||||
var horizontalAligment = new Rect(controlArea.x, controlArea.y, k_GroupWidth, k_AlignmentButtonHeight);
|
||||
//var verticalAligment = new Rect(!(EditorGUIUtility.currentViewWidth > k_WideViewWidth) ? controlArea.x : horizontalAligment.xMax + k_ControlsSpacing, !(EditorGUIUtility.currentViewWidth > k_WideViewWidth) ? controlArea.y + k_AlignmentButtonHeight + 3 : controlArea.y, k_GroupWidth, k_AlignmentButtonHeight);
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
var selectedHorizontal = DoHorizontalAligmentControl(horizontalAligment, property);
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
var value = 0x1 << selectedHorizontal;
|
||||
property.intValue = value;
|
||||
}
|
||||
}
|
||||
EditorGUI.EndProperty();
|
||||
}
|
||||
|
||||
static int DoHorizontalAligmentControl(Rect position, SerializedProperty alignment)
|
||||
{
|
||||
var selected = TMP_EditorUtility.GetHorizontalAlignmentGridValue(alignment.intValue);
|
||||
|
||||
var values = new bool[6];
|
||||
|
||||
values[selected] = true;
|
||||
|
||||
if (alignment.hasMultipleDifferentValues)
|
||||
{
|
||||
foreach (var obj in alignment.serializedObject.targetObjects)
|
||||
{
|
||||
var text = obj as TMP_Text;
|
||||
if (text != null)
|
||||
{
|
||||
values[TMP_EditorUtility.GetHorizontalAlignmentGridValue((int)text.horizontalAlignment)] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
position.width = k_AlignmentButtonWidth;
|
||||
|
||||
for (var i = 0; i < values.Length; i++)
|
||||
{
|
||||
var oldValue = values[i];
|
||||
var newValue = TMP_EditorUtility.EditorToggle(position, oldValue, TMP_UIStyleManager.alignContentA[i], i == 0 ? TMP_UIStyleManager.alignmentButtonLeft : (i == 5 ? TMP_UIStyleManager.alignmentButtonRight : TMP_UIStyleManager.alignmentButtonMid));
|
||||
if (newValue != oldValue)
|
||||
{
|
||||
selected = i;
|
||||
}
|
||||
position.x += position.width;
|
||||
}
|
||||
|
||||
return selected;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[CustomPropertyDrawer(typeof(VerticalAlignmentOptions))]
|
||||
public class TMP_VerticalAlignmentDrawer : PropertyDrawer
|
||||
{
|
||||
const int k_AlignmentButtonWidth = 24;
|
||||
const int k_AlignmentButtonHeight = 20;
|
||||
const int k_WideViewWidth = 504;
|
||||
const int k_ControlsSpacing = 6;
|
||||
const int k_GroupWidth = k_AlignmentButtonWidth * 6;
|
||||
static readonly int k_TextAlignmentHash = "DoTextAligmentControl".GetHashCode();
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
||||
{
|
||||
return EditorGUIUtility.currentViewWidth > k_WideViewWidth ? k_AlignmentButtonHeight : k_AlignmentButtonHeight * 2 + 3;
|
||||
}
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
var id = GUIUtility.GetControlID(k_TextAlignmentHash, FocusType.Keyboard, position);
|
||||
|
||||
EditorGUI.BeginProperty(position, label, property);
|
||||
{
|
||||
var controlArea = EditorGUI.PrefixLabel(position, id, label);
|
||||
|
||||
var horizontalAligment = new Rect(controlArea.x, controlArea.y, k_GroupWidth, k_AlignmentButtonHeight);
|
||||
var verticalAligment = new Rect(!(EditorGUIUtility.currentViewWidth > k_WideViewWidth) ? controlArea.x : horizontalAligment.xMax + k_ControlsSpacing, !(EditorGUIUtility.currentViewWidth > k_WideViewWidth) ? controlArea.y + k_AlignmentButtonHeight + 3 : controlArea.y, k_GroupWidth, k_AlignmentButtonHeight);
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
//var selectedHorizontal = DoHorizontalAligmentControl(horizontalAligment, property);
|
||||
var selectedVertical = DoVerticalAligmentControl(verticalAligment, property);
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
var value = 0x100 << selectedVertical;
|
||||
property.intValue = value;
|
||||
}
|
||||
}
|
||||
EditorGUI.EndProperty();
|
||||
}
|
||||
|
||||
static int DoVerticalAligmentControl(Rect position, SerializedProperty alignment)
|
||||
{
|
||||
var selected = TMP_EditorUtility.GetVerticalAlignmentGridValue(alignment.intValue);
|
||||
|
||||
var values = new bool[6];
|
||||
|
||||
values[selected] = true;
|
||||
|
||||
if (alignment.hasMultipleDifferentValues)
|
||||
{
|
||||
foreach (var obj in alignment.serializedObject.targetObjects)
|
||||
{
|
||||
var text = obj as TMP_Text;
|
||||
if (text != null)
|
||||
{
|
||||
values[TMP_EditorUtility.GetVerticalAlignmentGridValue((int)text.verticalAlignment)] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
position.width = k_AlignmentButtonWidth;
|
||||
|
||||
for (var i = 0; i < values.Length; i++)
|
||||
{
|
||||
var oldValue = values[i];
|
||||
var newValue = TMP_EditorUtility.EditorToggle(position, oldValue, TMP_UIStyleManager.alignContentB[i], i == 0 ? TMP_UIStyleManager.alignmentButtonLeft : (i == 5 ? TMP_UIStyleManager.alignmentButtonRight : TMP_UIStyleManager.alignmentButtonMid));
|
||||
if (newValue != oldValue)
|
||||
{
|
||||
selected = i;
|
||||
}
|
||||
position.x += position.width;
|
||||
}
|
||||
|
||||
return selected;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c55a64c7570474f47a94abe39ebfef04
|
||||
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: 91950f78729ab144aa36e94690b28fad
|
||||
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: 438efd46088d408d8a53f707fa68d976
|
||||
timeCreated: 1469844810
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,93 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace TMPro.EditorUtilities
|
||||
{
|
||||
public class TMP_BitmapShaderGUI : TMP_BaseShaderGUI
|
||||
{
|
||||
static bool s_Face = true;
|
||||
|
||||
protected override void DoGUI()
|
||||
{
|
||||
s_Face = BeginPanel("Face", s_Face);
|
||||
if (s_Face)
|
||||
{
|
||||
DoFacePanel();
|
||||
}
|
||||
|
||||
EndPanel();
|
||||
|
||||
s_DebugExtended = BeginPanel("Debug Settings", s_DebugExtended);
|
||||
if (s_DebugExtended)
|
||||
{
|
||||
DoDebugPanel();
|
||||
}
|
||||
|
||||
EndPanel();
|
||||
}
|
||||
|
||||
void DoFacePanel()
|
||||
{
|
||||
EditorGUI.indentLevel += 1;
|
||||
if (m_Material.HasProperty(ShaderUtilities.ID_FaceTex))
|
||||
{
|
||||
DoColor("_FaceColor", "Color");
|
||||
DoTexture2D("_FaceTex", "Texture", true);
|
||||
}
|
||||
else
|
||||
{
|
||||
DoColor("_Color", "Color");
|
||||
DoSlider("_DiffusePower", "Diffuse Power");
|
||||
}
|
||||
|
||||
EditorGUI.indentLevel -= 1;
|
||||
|
||||
EditorGUILayout.Space();
|
||||
}
|
||||
|
||||
void DoDebugPanel()
|
||||
{
|
||||
EditorGUI.indentLevel += 1;
|
||||
DoTexture2D("_MainTex", "Font Atlas");
|
||||
if (m_Material.HasProperty(ShaderUtilities.ID_VertexOffsetX))
|
||||
{
|
||||
if (m_Material.HasProperty(ShaderUtilities.ID_Padding))
|
||||
{
|
||||
EditorGUILayout.Space();
|
||||
DoFloat("_Padding", "Padding");
|
||||
}
|
||||
|
||||
EditorGUILayout.Space();
|
||||
DoFloat("_VertexOffsetX", "Offset X");
|
||||
DoFloat("_VertexOffsetY", "Offset Y");
|
||||
}
|
||||
|
||||
if (m_Material.HasProperty(ShaderUtilities.ID_MaskSoftnessX))
|
||||
{
|
||||
EditorGUILayout.Space();
|
||||
DoFloat("_MaskSoftnessX", "Softness X");
|
||||
DoFloat("_MaskSoftnessY", "Softness Y");
|
||||
DoVector("_ClipRect", "Clip Rect", s_LbrtVectorLabels);
|
||||
}
|
||||
|
||||
if (m_Material.HasProperty(ShaderUtilities.ID_StencilID))
|
||||
{
|
||||
EditorGUILayout.Space();
|
||||
DoFloat("_Stencil", "Stencil ID");
|
||||
DoFloat("_StencilComp", "Stencil Comp");
|
||||
}
|
||||
|
||||
if (m_Material.HasProperty(ShaderUtilities.ShaderTag_CullMode))
|
||||
{
|
||||
EditorGUILayout.Space();
|
||||
DoPopup("_CullMode", "Cull Mode", s_CullingTypeLabels);
|
||||
}
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
EditorGUI.indentLevel -= 1;
|
||||
|
||||
EditorGUILayout.Space();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 806de5a9211448c8b65c8435ebb48dd4
|
||||
timeCreated: 1469998850
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,47 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using System.IO;
|
||||
|
||||
|
||||
namespace TMPro.EditorUtilities
|
||||
{
|
||||
public static class TMP_ColorGradientAssetMenu
|
||||
{
|
||||
[MenuItem("Assets/Create/TextMeshPro/Color Gradient", false, 220)]
|
||||
internal static void CreateColorGradient(MenuCommand context)
|
||||
{
|
||||
string filePath;
|
||||
|
||||
if (Selection.assetGUIDs.Length == 0)
|
||||
filePath = "Assets/New TMP Color Gradient.asset";
|
||||
else
|
||||
filePath = AssetDatabase.GUIDToAssetPath(Selection.assetGUIDs[0]);
|
||||
|
||||
if (Directory.Exists(filePath))
|
||||
{
|
||||
filePath += "/New TMP Color Gradient.asset";
|
||||
}
|
||||
else
|
||||
{
|
||||
filePath = Path.GetDirectoryName(filePath) + "/New TMP Color Gradient.asset";
|
||||
}
|
||||
|
||||
filePath = AssetDatabase.GenerateUniqueAssetPath(filePath);
|
||||
|
||||
// Create new Color Gradient Asset.
|
||||
TMP_ColorGradient colorGradient = ScriptableObject.CreateInstance<TMP_ColorGradient>();
|
||||
|
||||
// Create Asset
|
||||
AssetDatabase.CreateAsset(colorGradient, filePath);
|
||||
|
||||
//EditorUtility.SetDirty(colorGradient);
|
||||
|
||||
AssetDatabase.SaveAssets();
|
||||
|
||||
AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(colorGradient));
|
||||
|
||||
EditorUtility.FocusProjectWindow();
|
||||
EditorGUIUtility.PingObject(colorGradient);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d9647b571c5e44729b71d756b3d55317
|
||||
timeCreated: 1468187791
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,146 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.Collections;
|
||||
|
||||
|
||||
namespace TMPro.EditorUtilities
|
||||
{
|
||||
[CustomEditor(typeof(TMP_ColorGradient))]
|
||||
public class TMP_ColorGradientEditor : Editor
|
||||
{
|
||||
SerializedProperty m_ColorMode;
|
||||
SerializedProperty m_TopLeftColor;
|
||||
SerializedProperty m_TopRightColor;
|
||||
SerializedProperty m_BottomLeftColor;
|
||||
SerializedProperty m_BottomRightColor;
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
m_ColorMode = serializedObject.FindProperty("colorMode");
|
||||
m_TopLeftColor = serializedObject.FindProperty("topLeft");
|
||||
m_TopRightColor = serializedObject.FindProperty("topRight");
|
||||
m_BottomLeftColor = serializedObject.FindProperty("bottomLeft");
|
||||
m_BottomRightColor = serializedObject.FindProperty("bottomRight");
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
serializedObject.Update();
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUILayout.PropertyField(m_ColorMode, new GUIContent("Color Mode"));
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
switch ((ColorMode)m_ColorMode.enumValueIndex)
|
||||
{
|
||||
case ColorMode.Single:
|
||||
m_TopRightColor.colorValue = m_TopLeftColor.colorValue;
|
||||
m_BottomLeftColor.colorValue = m_TopLeftColor.colorValue;
|
||||
m_BottomRightColor.colorValue = m_TopLeftColor.colorValue;
|
||||
break;
|
||||
case ColorMode.HorizontalGradient:
|
||||
m_BottomLeftColor.colorValue = m_TopLeftColor.colorValue;
|
||||
m_BottomRightColor.colorValue = m_TopRightColor.colorValue;
|
||||
break;
|
||||
case ColorMode.VerticalGradient:
|
||||
m_TopRightColor.colorValue = m_TopLeftColor.colorValue;
|
||||
m_BottomRightColor.colorValue = m_BottomLeftColor.colorValue;
|
||||
break;
|
||||
}
|
||||
}
|
||||
Rect rect;
|
||||
switch ((ColorMode)m_ColorMode.enumValueIndex)
|
||||
{
|
||||
case ColorMode.Single:
|
||||
EditorGUI.BeginChangeCheck();
|
||||
rect = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight * (EditorGUIUtility.wideMode ? 1 : 2));
|
||||
EditorGUI.PrefixLabel(rect, new GUIContent("Colors"));
|
||||
rect.x += EditorGUIUtility.labelWidth;
|
||||
rect.width = (rect.width - EditorGUIUtility.labelWidth) / (EditorGUIUtility.wideMode ? 1f : 2f);
|
||||
TMP_EditorUtility.DrawColorProperty(rect, m_TopLeftColor);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
m_TopRightColor.colorValue = m_TopLeftColor.colorValue;
|
||||
m_BottomLeftColor.colorValue = m_TopLeftColor.colorValue;
|
||||
m_BottomRightColor.colorValue = m_TopLeftColor.colorValue;
|
||||
}
|
||||
break;
|
||||
|
||||
case ColorMode.HorizontalGradient:
|
||||
rect = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight * (EditorGUIUtility.wideMode ? 1 : 2));
|
||||
EditorGUI.PrefixLabel(rect, new GUIContent("Colors"));
|
||||
rect.x += EditorGUIUtility.labelWidth;
|
||||
rect.width = (rect.width - EditorGUIUtility.labelWidth) / 2f;
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
TMP_EditorUtility.DrawColorProperty(rect, m_TopLeftColor);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
m_BottomLeftColor.colorValue = m_TopLeftColor.colorValue;
|
||||
}
|
||||
|
||||
rect.x += rect.width;
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
TMP_EditorUtility.DrawColorProperty(rect, m_TopRightColor);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
m_BottomRightColor.colorValue = m_TopRightColor.colorValue;
|
||||
}
|
||||
break;
|
||||
|
||||
case ColorMode.VerticalGradient:
|
||||
rect = EditorGUILayout.GetControlRect(false, EditorGUIUtility.singleLineHeight * (EditorGUIUtility.wideMode ? 1 : 2));
|
||||
EditorGUI.PrefixLabel(rect, new GUIContent("Colors"));
|
||||
rect.x += EditorGUIUtility.labelWidth;
|
||||
rect.width = (rect.width - EditorGUIUtility.labelWidth) / (EditorGUIUtility.wideMode ? 1f : 2f);
|
||||
rect.height = EditorGUIUtility.singleLineHeight * (EditorGUIUtility.wideMode ? 1 : 2);
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
TMP_EditorUtility.DrawColorProperty(rect, m_TopLeftColor);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
m_TopRightColor.colorValue = m_TopLeftColor.colorValue;
|
||||
}
|
||||
|
||||
rect = EditorGUILayout.GetControlRect(false, EditorGUIUtility.singleLineHeight * (EditorGUIUtility.wideMode ? 1 : 2));
|
||||
rect.x += EditorGUIUtility.labelWidth;
|
||||
rect.width = (rect.width - EditorGUIUtility.labelWidth) / (EditorGUIUtility.wideMode ? 1f : 2f);
|
||||
rect.height = EditorGUIUtility.singleLineHeight * (EditorGUIUtility.wideMode ? 1 : 2);
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
TMP_EditorUtility.DrawColorProperty(rect, m_BottomLeftColor);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
m_BottomRightColor.colorValue = m_BottomLeftColor.colorValue;
|
||||
}
|
||||
break;
|
||||
|
||||
case ColorMode.FourCornersGradient:
|
||||
rect = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight * (EditorGUIUtility.wideMode ? 1 : 2));
|
||||
EditorGUI.PrefixLabel(rect, new GUIContent("Colors"));
|
||||
rect.x += EditorGUIUtility.labelWidth;
|
||||
rect.width = (rect.width - EditorGUIUtility.labelWidth) / 2f;
|
||||
rect.height = EditorGUIUtility.singleLineHeight * (EditorGUIUtility.wideMode ? 1 : 2);
|
||||
|
||||
TMP_EditorUtility.DrawColorProperty(rect, m_TopLeftColor);
|
||||
rect.x += rect.width;
|
||||
TMP_EditorUtility.DrawColorProperty(rect, m_TopRightColor);
|
||||
|
||||
rect = EditorGUILayout.GetControlRect(false, EditorGUIUtility.singleLineHeight * (EditorGUIUtility.wideMode ? 1 : 2));
|
||||
rect.x += EditorGUIUtility.labelWidth;
|
||||
rect.width = (rect.width - EditorGUIUtility.labelWidth) / 2f;
|
||||
rect.height = EditorGUIUtility.singleLineHeight * (EditorGUIUtility.wideMode ? 1 : 2);
|
||||
|
||||
TMP_EditorUtility.DrawColorProperty(rect, m_BottomLeftColor);
|
||||
rect.x += rect.width;
|
||||
TMP_EditorUtility.DrawColorProperty(rect, m_BottomRightColor);
|
||||
break;
|
||||
}
|
||||
|
||||
if (serializedObject.ApplyModifiedProperties())
|
||||
TMPro_EventManager.ON_COLOR_GRADIENT_PROPERTY_CHANGED(target as TMP_ColorGradient);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fcc60c1d6bb544d9b712b652f418ff3a
|
||||
timeCreated: 1468400050
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,60 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using UnityEditor.UI;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace TMPro.EditorUtilities
|
||||
{
|
||||
[CustomEditor(typeof(TMP_Dropdown), true)]
|
||||
[CanEditMultipleObjects]
|
||||
public class DropdownEditor : SelectableEditor
|
||||
{
|
||||
SerializedProperty m_Template;
|
||||
SerializedProperty m_CaptionText;
|
||||
SerializedProperty m_CaptionImage;
|
||||
SerializedProperty m_Placeholder;
|
||||
SerializedProperty m_ItemText;
|
||||
SerializedProperty m_ItemImage;
|
||||
SerializedProperty m_OnSelectionChanged;
|
||||
SerializedProperty m_Value;
|
||||
SerializedProperty m_MultiSelect;
|
||||
SerializedProperty m_AlphaFadeSpeed;
|
||||
SerializedProperty m_Options;
|
||||
|
||||
protected override void OnEnable()
|
||||
{
|
||||
base.OnEnable();
|
||||
m_Template = serializedObject.FindProperty("m_Template");
|
||||
m_CaptionText = serializedObject.FindProperty("m_CaptionText");
|
||||
m_CaptionImage = serializedObject.FindProperty("m_CaptionImage");
|
||||
m_Placeholder = serializedObject.FindProperty("m_Placeholder");
|
||||
m_ItemText = serializedObject.FindProperty("m_ItemText");
|
||||
m_ItemImage = serializedObject.FindProperty("m_ItemImage");
|
||||
m_OnSelectionChanged = serializedObject.FindProperty("m_OnValueChanged");
|
||||
m_Value = serializedObject.FindProperty("m_Value");
|
||||
m_MultiSelect = serializedObject.FindProperty("m_MultiSelect");
|
||||
m_AlphaFadeSpeed = serializedObject.FindProperty("m_AlphaFadeSpeed");
|
||||
m_Options = serializedObject.FindProperty("m_Options");
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
base.OnInspectorGUI();
|
||||
EditorGUILayout.Space();
|
||||
|
||||
serializedObject.Update();
|
||||
EditorGUILayout.PropertyField(m_Template);
|
||||
EditorGUILayout.PropertyField(m_CaptionText);
|
||||
EditorGUILayout.PropertyField(m_CaptionImage);
|
||||
EditorGUILayout.PropertyField(m_Placeholder);
|
||||
EditorGUILayout.PropertyField(m_ItemText);
|
||||
EditorGUILayout.PropertyField(m_ItemImage);
|
||||
EditorGUILayout.PropertyField(m_Value);
|
||||
EditorGUILayout.PropertyField(m_MultiSelect);
|
||||
EditorGUILayout.PropertyField(m_AlphaFadeSpeed);
|
||||
EditorGUILayout.PropertyField(m_Options);
|
||||
EditorGUILayout.PropertyField(m_OnSelectionChanged);
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6dbcf248c987476181a37f01a1814975
|
||||
timeCreated: 1446377461
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,96 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
namespace TMPro.EditorUtilities
|
||||
{
|
||||
/// <summary>
|
||||
/// Simple implementation of coroutine working in the Unity Editor.
|
||||
/// </summary>
|
||||
public class TMP_EditorCoroutine
|
||||
{
|
||||
//private static Dictionary<int, EditorCoroutine> s_ActiveCoroutines;
|
||||
|
||||
readonly IEnumerator coroutine;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <param name="routine"></param>
|
||||
TMP_EditorCoroutine(IEnumerator routine)
|
||||
{
|
||||
this.coroutine = routine;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Starts a new EditorCoroutine.
|
||||
/// </summary>
|
||||
/// <param name="newCoroutine">Coroutine</param>
|
||||
/// <returns>new EditorCoroutine</returns>
|
||||
public static TMP_EditorCoroutine StartCoroutine(IEnumerator routine)
|
||||
{
|
||||
TMP_EditorCoroutine coroutine = new TMP_EditorCoroutine(routine);
|
||||
coroutine.Start();
|
||||
|
||||
// Add coroutine to tracking list
|
||||
//if (s_ActiveCoroutines == null)
|
||||
// s_ActiveCoroutines = new Dictionary<int, EditorCoroutine>();
|
||||
|
||||
// Add new instance of editor coroutine to dictionary.
|
||||
//s_ActiveCoroutines.Add(coroutine.GetHashCode(), coroutine);
|
||||
|
||||
return coroutine;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Clear delegate list
|
||||
/// </summary>
|
||||
//public static void StopAllEditorCoroutines()
|
||||
//{
|
||||
// EditorApplication.update = null;
|
||||
//}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Register callback for editor updates
|
||||
/// </summary>
|
||||
void Start()
|
||||
{
|
||||
EditorApplication.update += EditorUpdate;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Unregister callback for editor updates.
|
||||
/// </summary>
|
||||
public void Stop()
|
||||
{
|
||||
if (EditorApplication.update != null)
|
||||
EditorApplication.update -= EditorUpdate;
|
||||
|
||||
//s_ActiveCoroutines.Remove(this.GetHashCode());
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Delegate function called on editor updates.
|
||||
/// </summary>
|
||||
void EditorUpdate()
|
||||
{
|
||||
// Stop editor coroutine if it does not continue.
|
||||
if (coroutine.MoveNext() == false)
|
||||
Stop();
|
||||
|
||||
// Process the different types of EditorCoroutines.
|
||||
if (coroutine.Current != null)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user