private static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
        {
            bool textureImported = false;
            foreach (var asset in importedAssets)
            {
                // Return if imported asset path is outside of the project.
                if (asset.StartsWith("Assets/", StringComparison.OrdinalIgnoreCase) == false)
                    continue;

                Type assetType = AssetDatabase.GetMainAssetTypeAtPath(asset);
                if (assetType == typeof(FontAsset))
                {
                    FontAsset fontAsset = AssetDatabase.LoadAssetAtPath(asset, typeof(FontAsset)) as FontAsset;
                    // Only refresh font asset definition if font asset was previously initialized.
                    if (fontAsset != null && fontAsset.m_CharacterLookupDictionary != null)
                        TextEditorResourceManager.RegisterFontAssetForDefinitionRefresh(fontAsset);
                    continue;
                }

                if (assetType == typeof(Texture2D))
                    textureImported = true;
            }

            // If textures were imported, issue callback to any potential text objects that might require updating.
            if (textureImported)
                TextEventManager.ON_SPRITE_ASSET_PROPERTY_CHANGED(true, null);
        }
示例#2
0
        void PrepareGUI()
        {
            m_IsNewGUI = false;
            TextShaderUtilities.GetShaderPropertyIDs();

            // New GUI just got constructed. This happens in response to a selection,
            // but also after undo/redo events.
            if (s_LastSeenUndoRedoCount != s_UndoRedoCount)
            {
                // There's been at least one undo/redo since the last time this GUI got constructed.
                // Maybe the undo/redo was for this material? Assume that is was.
                TextEventManager.ON_MATERIAL_PROPERTY_CHANGED(true, m_Material as Material);
            }

            s_LastSeenUndoRedoCount = s_UndoRedoCount;
        }
示例#3
0
        static void ClearFontAssetData(MenuCommand command)
        {
            FontAsset fontAsset = command.context as FontAsset;

            if (fontAsset == null)
            {
                return;
            }

            if (Selection.activeObject != fontAsset)
            {
                Selection.activeObject = fontAsset;
            }

            fontAsset.ClearFontAssetData(true);
            TextResourceManager.RebuildFontAssetCache();

            TextEventManager.ON_FONT_PROPERTY_CHANGED(true, fontAsset);
        }
        void DoPreRenderUpdates()
        {
            // Handle Font Asset Definition Refresh
            for (int i = 0; i < m_FontAssetDefinitionRefreshQueue.Count; i++)
            {
                FontAsset fontAsset = m_FontAssetDefinitionRefreshQueue[i];

                if (fontAsset != null)
                {
                    fontAsset.ReadFontAssetDefinition();
                    TextEventManager.ON_FONT_PROPERTY_CHANGED(true, fontAsset);
                }
            }

            if (m_FontAssetDefinitionRefreshQueue.Count > 0)
            {
                m_FontAssetDefinitionRefreshQueue.Clear();
                m_FontAssetDefinitionRefreshQueueLookup.Clear();
            }
        }
示例#5
0
        static void PasteMaterialProperties(MenuCommand command)
        {
            if (m_copiedProperties == null)
            {
                Debug.LogWarning("No Material Properties to Paste. Use Copy Material Properties first.");
                return;
            }

            Material mat = null;

            if (command.context.GetType() == typeof(Material))
            {
                mat = (Material)command.context;
            }
            else
            {
                mat = Selection.activeGameObject.GetComponent <CanvasRenderer>().GetMaterial();
            }

            Undo.RecordObject(mat, "Paste Material");

            TextShaderUtilities.GetShaderPropertyIDs(); // Make sure we have valid Property IDs
            if (mat.HasProperty(TextShaderUtilities.ID_GradientScale))
            {
                // Preserve unique SDF properties from destination material.
                m_copiedProperties.SetTexture(TextShaderUtilities.ID_MainTex, mat.GetTexture(TextShaderUtilities.ID_MainTex));
                m_copiedProperties.SetFloat(TextShaderUtilities.ID_GradientScale, mat.GetFloat(TextShaderUtilities.ID_GradientScale));
                m_copiedProperties.SetFloat(TextShaderUtilities.ID_TextureWidth, mat.GetFloat(TextShaderUtilities.ID_TextureWidth));
                m_copiedProperties.SetFloat(TextShaderUtilities.ID_TextureHeight, mat.GetFloat(TextShaderUtilities.ID_TextureHeight));
            }

            EditorShaderUtilities.CopyMaterialProperties(m_copiedProperties, mat);

            // Copy ShaderKeywords from one material to the other.
            mat.shaderKeywords = m_copiedProperties.shaderKeywords;

            // Let TextMeshPro Objects that this mat has changed.
            TextEventManager.ON_MATERIAL_PROPERTY_CHANGED(true, mat);
        }
示例#6
0
        public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties)
        {
            m_Editor          = materialEditor;
            m_Material        = materialEditor.target as Material;
            this.m_Properties = properties;

            if (m_IsNewGUI)
            {
                PrepareGUI();
            }

            //DoDragAndDropBegin();

            EditorGUI.BeginChangeCheck();
            DoGUI();
            if (EditorGUI.EndChangeCheck())
            {
                TextEventManager.ON_MATERIAL_PROPERTY_CHANGED(true, m_Material);
            }

            //DoDragAndDropEnd();
        }
示例#7
0
        static void ResetSettings(MenuCommand command)
        {
            Material mat = null;

            if (command.context.GetType() == typeof(Material))
            {
                mat = (Material)command.context;
            }
            else
            {
                mat = Selection.activeGameObject.GetComponent <CanvasRenderer>().GetMaterial();
            }

            Undo.RecordObject(mat, "Reset Material");

            TextShaderUtilities.GetShaderPropertyIDs(); // Make sure we have valid Property IDs
            if (mat.HasProperty(TextShaderUtilities.ID_GradientScale))
            {
                // Copy unique properties of the SDF Material
                var texture       = mat.GetTexture(TextShaderUtilities.ID_MainTex);
                var gradientScale = mat.GetFloat(TextShaderUtilities.ID_GradientScale);
                var texWidth      = mat.GetFloat(TextShaderUtilities.ID_TextureWidth);
                var texHeight     = mat.GetFloat(TextShaderUtilities.ID_TextureHeight);

                var stencilId   = 0.0f;
                var stencilComp = 0.0f;

                if (mat.HasProperty(TextShaderUtilities.ID_StencilID))
                {
                    stencilId   = mat.GetFloat(TextShaderUtilities.ID_StencilID);
                    stencilComp = mat.GetFloat(TextShaderUtilities.ID_StencilComp);
                }

                var normalWeight = mat.GetFloat(TextShaderUtilities.ID_WeightNormal);
                var boldWeight   = mat.GetFloat(TextShaderUtilities.ID_WeightBold);

                // Reset the material
                Unsupported.SmartReset(mat);

                // Reset ShaderKeywords
                mat.shaderKeywords = new string[0]; // { "BEVEL_OFF", "GLOW_OFF", "UNDERLAY_OFF" };

                // Copy unique material properties back to the material.
                mat.SetTexture(TextShaderUtilities.ID_MainTex, texture);
                mat.SetFloat(TextShaderUtilities.ID_GradientScale, gradientScale);
                mat.SetFloat(TextShaderUtilities.ID_TextureWidth, texWidth);
                mat.SetFloat(TextShaderUtilities.ID_TextureHeight, texHeight);

                if (mat.HasProperty(TextShaderUtilities.ID_StencilID))
                {
                    mat.SetFloat(TextShaderUtilities.ID_StencilID, stencilId);
                    mat.SetFloat(TextShaderUtilities.ID_StencilComp, stencilComp);
                }

                mat.SetFloat(TextShaderUtilities.ID_WeightNormal, normalWeight);
                mat.SetFloat(TextShaderUtilities.ID_WeightBold, boldWeight);
            }
            else
            {
                Unsupported.SmartReset(mat);
            }

            TextEventManager.ON_MATERIAL_PROPERTY_CHANGED(true, mat);
        }
        public override void OnInspectorGUI()
        {
            serializedObject.Update();
            string evt_cmd = Event.current.commandName;

            float labelWidth = EditorGUIUtility.labelWidth;
            float fieldWidth = EditorGUIUtility.fieldWidth;

            // TextMeshPro Font Info Panel
            EditorGUI.indentLevel = 0;

            // FONT ASSET
            EditorGUILayout.BeginVertical(EditorStyles.helpBox);
            GUILayout.Label(Styles.defaultFontAssetLabel, EditorStyles.boldLabel);
            EditorGUI.indentLevel = 1;
            EditorGUILayout.PropertyField(m_PropFontAsset, Styles.defaultFontAssetLabel);
            EditorGUILayout.PropertyField(m_PropDefaultFontAssetPath, Styles.defaultFontAssetPathLabel);
            EditorGUI.indentLevel = 0;

            EditorGUILayout.Space();
            EditorGUILayout.EndVertical();

            EditorGUILayout.Space();

            // FONT ASSET FALLBACK(s)
            EditorGUILayout.BeginVertical(EditorStyles.helpBox);
            GUILayout.Label(Styles.fallbackFontAssetsLabel, EditorStyles.boldLabel);
            EditorGUI.BeginChangeCheck();
            m_FontAssetFallbackList.DoLayoutList();
            if (EditorGUI.EndChangeCheck())
            {
                TextResourceManager.RebuildFontAssetCache();
            }

            GUILayout.Label(Styles.fallbackMaterialSettingsLabel, EditorStyles.boldLabel);
            EditorGUI.indentLevel = 1;
            EditorGUILayout.PropertyField(m_PropMatchMaterialPreset, Styles.matchMaterialPresetLabel);
            EditorGUI.indentLevel = 0;

            EditorGUILayout.Space();
            EditorGUILayout.EndVertical();

            EditorGUILayout.Space();

            // MISSING GLYPHS
            EditorGUILayout.BeginVertical(EditorStyles.helpBox);
            GUILayout.Label(Styles.dynamicFontSystemSettingsLabel, EditorStyles.boldLabel);
            EditorGUI.indentLevel = 1;
            //EditorGUILayout.PropertyField(m_GetFontFeaturesAtRuntime, Styles.getFontFeaturesAtRuntime);
            EditorGUILayout.PropertyField(m_PropMissingGlyphCharacter, Styles.missingGlyphLabel);
            EditorGUILayout.PropertyField(m_PropClearDynamicDataOnBuild, Styles.clearDynamicDataOnBuildLabel);
            EditorGUILayout.PropertyField(m_PropDisplayWarnings, Styles.disableWarningsLabel);
            //EditorGUILayout.PropertyField(m_DynamicAtlasTextureManager, Styles.dynamicAtlasTextureManager);
            EditorGUI.indentLevel = 0;

            EditorGUILayout.Space();
            EditorGUILayout.EndVertical();

            EditorGUILayout.Space();

            // TEXT OBJECT DEFAULT PROPERTIES

            /*
             * EditorGUILayout.BeginVertical(EditorStyles.helpBox);
             * GUILayout.Label(Styles.containerDefaultSettingsLabel, EditorStyles.boldLabel);
             * EditorGUI.indentLevel = 1;
             *
             * EditorGUILayout.PropertyField(m_PropDefaultTextMeshProTextContainerSize, Styles.textMeshProLabel);
             * EditorGUILayout.PropertyField(m_PropDefaultTextMeshProUITextContainerSize, Styles.textMeshProUiLabel);
             * EditorGUILayout.PropertyField(m_PropEnableRaycastTarget, Styles.enableRaycastTarget);
             * EditorGUILayout.PropertyField(m_PropAutoSizeTextContainer, Styles.autoSizeContainerLabel);
             * EditorGUI.indentLevel = 0;
             *
             * EditorGUILayout.Space();
             *
             * GUILayout.Label(Styles.textComponentDefaultSettingsLabel, EditorStyles.boldLabel);
             * EditorGUI.indentLevel = 1;
             * EditorGUILayout.PropertyField(m_PropDefaultFontSize, Styles.defaultFontSize);
             *
             * EditorGUILayout.BeginHorizontal();
             * {
             *  EditorGUILayout.PrefixLabel(Styles.autoSizeRatioLabel);
             *  EditorGUIUtility.labelWidth = 32;
             *  EditorGUIUtility.fieldWidth = 10;
             *
             *  EditorGUI.indentLevel = 0;
             *  EditorGUILayout.PropertyField(m_PropDefaultAutoSizeMinRatio, Styles.minLabel);
             *  EditorGUILayout.PropertyField(m_PropDefaultAutoSizeMaxRatio, Styles.maxLabel);
             *  EditorGUI.indentLevel = 1;
             * }
             * EditorGUILayout.EndHorizontal();
             *
             * EditorGUIUtility.labelWidth = labelWidth;
             * EditorGUIUtility.fieldWidth = fieldWidth;
             *
             * EditorGUILayout.PropertyField(m_PropWordWrapping, Styles.wordWrappingLabel);
             * EditorGUILayout.PropertyField(m_PropKerning, Styles.kerningLabel);
             *
             * EditorGUILayout.PropertyField(m_PropExtraPadding, Styles.extraPaddingLabel);
             * EditorGUILayout.PropertyField(m_PropTintAllSprites, Styles.tintAllSpritesLabel);
             *
             * EditorGUILayout.PropertyField(m_PropParseEscapeCharacters, Styles.parseEscapeCharactersLabel);
             *
             * EditorGUI.indentLevel = 0;
             *
             * EditorGUILayout.Space();
             * EditorGUILayout.EndVertical();
             */

            // SPRITE ASSET
            EditorGUILayout.BeginVertical(EditorStyles.helpBox);
            GUILayout.Label(Styles.defaultSpriteAssetLabel, EditorStyles.boldLabel);
            EditorGUI.indentLevel = 1;
            EditorGUILayout.PropertyField(m_PropSpriteAsset, Styles.defaultSpriteAssetLabel);
            EditorGUILayout.PropertyField(m_PropMissingSpriteCharacterUnicode, Styles.missingSpriteCharacterUnicodeLabel);
            //EditorGUILayout.PropertyField(m_PropEnableEmojiSupport, Styles.enableEmojiSupportLabel);
            //EditorGUILayout.PropertyField(m_PropSpriteRelativeScaling, Styles.spriteRelativeScale);
            EditorGUILayout.PropertyField(m_PropSpriteAssetPath, Styles.spriteAssetsPathLabel);
            EditorGUI.indentLevel = 0;

            EditorGUILayout.Space();
            EditorGUILayout.EndVertical();

            EditorGUILayout.Space();

            // SPRITE ASSET FALLBACK(s)
            EditorGUILayout.BeginVertical(EditorStyles.helpBox);
            GUILayout.Label(Styles.fallbackSpriteAssetsLabel, EditorStyles.boldLabel);
            m_SpriteAssetFallbackList.DoLayoutList();

            EditorGUILayout.Space();
            EditorGUILayout.EndVertical();

            EditorGUILayout.Space();

            // STYLE SHEET
            EditorGUILayout.BeginVertical(EditorStyles.helpBox);
            GUILayout.Label(Styles.defaultStyleSheetLabel, EditorStyles.boldLabel);
            EditorGUI.indentLevel = 1;
            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(m_PropStyleSheet, Styles.defaultStyleSheetLabel);
            if (EditorGUI.EndChangeCheck())
            {
                serializedObject.ApplyModifiedProperties();

                TextStyleSheet styleSheet = m_PropStyleSheet.objectReferenceValue as TextStyleSheet;
                if (styleSheet != null)
                {
                    styleSheet.RefreshStyles();
                }
            }
            EditorGUILayout.PropertyField(m_PropStyleSheetsResourcePath, Styles.styleSheetResourcePathLabel);
            EditorGUI.indentLevel = 0;

            EditorGUILayout.Space();
            EditorGUILayout.EndVertical();

            EditorGUILayout.Space();

            // COLOR GRADIENT PRESETS
            EditorGUILayout.BeginVertical(EditorStyles.helpBox);
            GUILayout.Label(Styles.colorGradientPresetsLabel, EditorStyles.boldLabel);
            EditorGUI.indentLevel = 1;
            EditorGUILayout.PropertyField(m_PropColorGradientPresetsPath, Styles.colorGradientsPathLabel);
            EditorGUI.indentLevel = 0;

            EditorGUILayout.Space();
            EditorGUILayout.EndVertical();

            EditorGUILayout.Space();

            // LINE BREAKING RULE
            EditorGUILayout.BeginVertical(EditorStyles.helpBox);
            GUILayout.Label(Styles.lineBreakingLabel, EditorStyles.boldLabel);
            EditorGUI.indentLevel = 1;
            EditorGUILayout.PropertyField(m_PropUnicodeLineBreakingRules);
            //EditorGUILayout.Space();
            //GUILayout.Label(Styles.koreanSpecificRules, EditorStyles.boldLabel);
            //EditorGUILayout.PropertyField(m_PropUseModernHangulLineBreakingRules, new GUIContent("Use Modern Line Breaking", "Determines if traditional or modern line breaking rules will be used to control line breaking. Traditional line breaking rules use the Leading and Following Character rules whereas Modern uses spaces for line breaking."));

            EditorGUI.indentLevel = 0;

            EditorGUILayout.Space();
            EditorGUILayout.EndVertical();

            if (serializedObject.ApplyModifiedProperties() || evt_cmd == k_UndoRedo)
            {
                EditorUtility.SetDirty(target);
                TextEventManager.ON_TMP_SETTINGS_CHANGED();
            }
        }
        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");

            position.yMin += 2;

            float width   = position.width / 2;
            float padding = 5.0f;

            Rect rect;

            isEditingEnabled = GUI.enabled;
            isSelectable     = label.text == "Selectable" ? true : false;

            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())
                    {
                        FontAsset fontAsset = property.serializedObject.targetObject as FontAsset;
                        if (fontAsset != null)
                        {
                            property.serializedObject.ApplyModifiedProperties();
                            fontAsset.ReadFontAssetDefinition();
                            TextEventManager.ON_FONT_PROPERTY_CHANGED(true, fontAsset);
                        }
                    }
                }

                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, position.width, position.height), 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())
                    {
                        FontAsset fontAsset = property.serializedObject.targetObject as FontAsset;
                        if (fontAsset != null)
                        {
                            property.serializedObject.ApplyModifiedProperties();
                            fontAsset.ReadFontAssetDefinition();
                            TextEventManager.ON_FONT_PROPERTY_CHANGED(true, fontAsset);
                        }
                    }
                }

                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, position.width, position.height), property);
            }
        }
        public override void OnInspectorGUI()
        {
            Event currentEvent = Event.current;

            serializedObject.Update();

            m_IsStyleSheetDirty = false;
            int arraySize    = m_StyleListProp.arraySize;
            int itemsPerPage = (Screen.height - 100) / 110;

            if (arraySize > 0)
            {
                // Display each Style entry using the StyleDrawer PropertyDrawer.
                for (int i = itemsPerPage * m_Page; i < arraySize && i < itemsPerPage * (m_Page + 1); i++)
                {
                    // Define the start of the selection region of the element.
                    Rect elementStartRegion = GUILayoutUtility.GetRect(0f, 0f, GUILayout.ExpandWidth(true));

                    EditorGUILayout.BeginVertical(EditorStyles.helpBox);

                    SerializedProperty styleProperty = m_StyleListProp.GetArrayElementAtIndex(i);
                    EditorGUI.BeginChangeCheck();
                    EditorGUILayout.PropertyField(styleProperty);
                    EditorGUILayout.EndVertical();
                    if (EditorGUI.EndChangeCheck())
                    {
                        //
                    }

                    // Define the end of the selection region of the element.
                    Rect elementEndRegion = GUILayoutUtility.GetRect(0f, 0f, GUILayout.ExpandWidth(true));

                    // Check for Item selection
                    Rect selectionArea = new Rect(elementStartRegion.x, elementStartRegion.y, elementEndRegion.width, elementEndRegion.y - elementStartRegion.y);
                    if (DoSelectionCheck(selectionArea))
                    {
                        if (m_SelectedElement == i)
                        {
                            m_SelectedElement = -1;
                        }
                        else
                        {
                            m_SelectedElement          = i;
                            GUIUtility.keyboardControl = 0;
                        }
                    }

                    // Handle Selection Highlighting
                    if (m_SelectedElement == i)
                    {
                        TextCoreEditorUtilities.DrawBox(selectionArea, 2f, new Color32(40, 192, 255, 255));
                    }
                }
            }

            // STYLE LIST MANAGEMENT
            Rect  rect       = EditorGUILayout.GetControlRect(false, 20);
            float totalWidth = rect.width;

            rect.width = totalWidth * 0.175f;

            // Move Style up.
            bool guiEnabled = GUI.enabled;

            if (m_SelectedElement == -1 || m_SelectedElement == 0)
            {
                GUI.enabled = false;
            }
            if (GUI.Button(rect, "Up"))
            {
                SwapStyleElements(m_SelectedElement, m_SelectedElement - 1);
            }
            GUI.enabled = guiEnabled;

            // Move Style down.
            rect.x += rect.width;
            if (m_SelectedElement == arraySize - 1)
            {
                GUI.enabled = false;
            }
            if (GUI.Button(rect, "Down"))
            {
                SwapStyleElements(m_SelectedElement, m_SelectedElement + 1);
            }
            GUI.enabled = guiEnabled;

            // Add Style
            rect.x += rect.width + totalWidth * 0.3f;
            if (GUI.Button(rect, "+"))
            {
                int index = m_SelectedElement == -1 ? 0 : m_SelectedElement;

                if (index > arraySize)
                {
                    index = arraySize;
                }

                // Copy selected element
                m_StyleListProp.InsertArrayElementAtIndex(index);

                // Select newly inserted element
                m_SelectedElement = index + 1;

                serializedObject.ApplyModifiedProperties();
                m_StyleSheet.RefreshStyles();
            }

            // Delete style
            rect.x += rect.width;
            if (m_SelectedElement == -1 || m_SelectedElement >= arraySize)
            {
                GUI.enabled = false;
            }
            if (GUI.Button(rect, "-"))
            {
                int index = m_SelectedElement == -1 ? 0 : m_SelectedElement;

                m_StyleListProp.DeleteArrayElementAtIndex(index);

                m_SelectedElement = -1;
                serializedObject.ApplyModifiedProperties();
                m_StyleSheet.RefreshStyles();
                return;
            }

            // Return if we can't display any items.
            if (itemsPerPage == 0)
            {
                return;
            }

            // DISPLAY PAGE CONTROLS
            int shiftMultiplier = currentEvent.shift ? 10 : 1; // Page + Shift goes 10 page forward

            Rect pagePos = EditorGUILayout.GetControlRect(false, 20);

            pagePos.width = totalWidth * 0.35f;

            // Previous Page
            if (m_Page > 0)
            {
                GUI.enabled = true;
            }
            else
            {
                GUI.enabled = false;
            }

            if (GUI.Button(pagePos, "Previous"))
            {
                m_Page -= 1 * shiftMultiplier;
            }

            // PAGE COUNTER
            GUI.enabled   = true;
            pagePos.x    += pagePos.width;
            pagePos.width = totalWidth * 0.30f;
            int totalPages = (int)(arraySize / (float)itemsPerPage + 0.999f);

            GUI.Label(pagePos, "Page " + (m_Page + 1) + " / " + totalPages, TM_EditorStyles.centeredLabel);

            // Next Page
            pagePos.x    += pagePos.width;
            pagePos.width = totalWidth * 0.35f;
            if (itemsPerPage * (m_Page + 1) < arraySize)
            {
                GUI.enabled = true;
            }
            else
            {
                GUI.enabled = false;
            }

            if (GUI.Button(pagePos, "Next"))
            {
                m_Page += 1 * shiftMultiplier;
            }

            // Clamp page range
            m_Page = Mathf.Clamp(m_Page, 0, arraySize / itemsPerPage);


            if (serializedObject.ApplyModifiedProperties())
            {
                TextEventManager.ON_TEXT_STYLE_PROPERTY_CHANGED(true);

                if (m_IsStyleSheetDirty)
                {
                    m_IsStyleSheetDirty = false;
                    m_StyleSheet.RefreshStyles();
                }
            }

            // Clear selection if mouse event was not consumed.
            GUI.enabled = true;
            if (currentEvent.type == EventType.MouseDown && currentEvent.button == 0)
            {
                m_SelectedElement = -1;
            }
        }
        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);
                TextCoreEditorUtilities.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();
                TextCoreEditorUtilities.DrawColorProperty(rect, m_TopLeftColor);
                if (EditorGUI.EndChangeCheck())
                {
                    m_BottomLeftColor.colorValue = m_TopLeftColor.colorValue;
                }

                rect.x += rect.width;

                EditorGUI.BeginChangeCheck();
                TextCoreEditorUtilities.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();
                TextCoreEditorUtilities.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();
                TextCoreEditorUtilities.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);

                TextCoreEditorUtilities.DrawColorProperty(rect, m_TopLeftColor);
                rect.x += rect.width;
                TextCoreEditorUtilities.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);

                TextCoreEditorUtilities.DrawColorProperty(rect, m_BottomLeftColor);
                rect.x += rect.width;
                TextCoreEditorUtilities.DrawColorProperty(rect, m_BottomRightColor);
                break;
            }

            if (serializedObject.ApplyModifiedProperties())
            {
                TextEventManager.ON_COLOR_GRADIENT_PROPERTY_CHANGED(target as TextColorGradient);
            }
        }
        internal static void UpdateSpriteAsset(SpriteAsset spriteAsset)
        {
            // Get a list of all the sprites contained in the texture referenced by the sprite asset.
            // This only works if the texture is set to sprite mode.
            string filePath = AssetDatabase.GetAssetPath(spriteAsset.spriteSheet);

            if (string.IsNullOrEmpty(filePath))
            {
                return;
            }

            // Get all the sprites defined in the sprite sheet texture referenced by this sprite asset.
            Sprite[] sprites = AssetDatabase.LoadAllAssetsAtPath(filePath).Select(x => x as Sprite).Where(x => x != null).ToArray();

            // Return if sprite sheet texture does not have any sprites defined in it.
            if (sprites.Length == 0)
            {
                Debug.Log("Sprite Asset <color=#FFFF80>[" + spriteAsset.name + "]</color>'s atlas texture does not appear to have any sprites defined in it. Use the Unity Sprite Editor to define sprites for this texture.", spriteAsset.spriteSheet);
                return;
            }

            List <SpriteGlyph> spriteGlyphTable = spriteAsset.spriteGlyphTable;

            // Find available glpyh indexes
            uint[]      existingGlyphIndexes  = spriteGlyphTable.Select(x => x.index).ToArray();
            List <uint> availableGlyphIndexes = new List <uint>();

            uint lastGlyphIndex = existingGlyphIndexes.Length > 0 ? existingGlyphIndexes.Last() : 0;
            int  elementIndex   = 0;

            for (uint i = 0; i < lastGlyphIndex; i++)
            {
                uint existingGlyphIndex = existingGlyphIndexes[elementIndex];

                if (i == existingGlyphIndex)
                {
                    elementIndex += 1;
                }
                else
                {
                    availableGlyphIndexes.Add(i);
                }
            }

            // Iterate over sprites contained in the updated sprite sheet to identify new and / or modified sprites.
            for (int i = 0; i < sprites.Length; i++)
            {
                Sprite sprite = sprites[i];

                // Check if current sprites is already contained in the sprite glyph table of the sprite asset.
                SpriteGlyph spriteGlyph = spriteGlyphTable.FirstOrDefault(x => x.sprite == sprite);

                if (spriteGlyph != null)
                {
                    // update existing sprite glyph
                    if (spriteGlyph.glyphRect.x != sprite.rect.x || spriteGlyph.glyphRect.y != sprite.rect.y || spriteGlyph.glyphRect.width != sprite.rect.width || spriteGlyph.glyphRect.height != sprite.rect.height)
                    {
                        spriteGlyph.glyphRect = new GlyphRect(sprite.rect);
                    }
                }
                else
                {
                    SpriteCharacter spriteCharacter;

                    // Check if this sprite potentially exists under the same name in the sprite character table.
                    if (spriteAsset.spriteCharacterTable != null && spriteAsset.spriteCharacterTable.Count > 0)
                    {
                        spriteCharacter = spriteAsset.spriteCharacterTable.FirstOrDefault(x => x.name == sprite.name);
                        spriteGlyph     = spriteCharacter != null ? spriteGlyphTable[(int)spriteCharacter.glyphIndex] : null;

                        if (spriteGlyph != null)
                        {
                            // Update sprite reference and data
                            spriteGlyph.sprite = sprite;

                            if (spriteGlyph.glyphRect.x != sprite.rect.x || spriteGlyph.glyphRect.y != sprite.rect.y || spriteGlyph.glyphRect.width != sprite.rect.width || spriteGlyph.glyphRect.height != sprite.rect.height)
                            {
                                spriteGlyph.glyphRect = new GlyphRect(sprite.rect);
                            }
                        }
                    }

                    spriteGlyph = new SpriteGlyph();

                    // Get available glyph index
                    if (availableGlyphIndexes.Count > 0)
                    {
                        spriteGlyph.index = availableGlyphIndexes[0];
                        availableGlyphIndexes.RemoveAt(0);
                    }
                    else
                    {
                        spriteGlyph.index = (uint)spriteGlyphTable.Count;
                    }

                    spriteGlyph.metrics   = new GlyphMetrics(sprite.rect.width, sprite.rect.height, -sprite.pivot.x, sprite.rect.height - sprite.pivot.y, sprite.rect.width);
                    spriteGlyph.glyphRect = new GlyphRect(sprite.rect);
                    spriteGlyph.scale     = 1.0f;
                    spriteGlyph.sprite    = sprite;

                    spriteGlyphTable.Add(spriteGlyph);

                    spriteCharacter = new SpriteCharacter(0xFFFE, spriteGlyph);

                    // Special handling for .notdef sprite name.
                    string fileNameToLowerInvariant = sprite.name.ToLowerInvariant();
                    if (fileNameToLowerInvariant == ".notdef" || fileNameToLowerInvariant == "notdef")
                    {
                        spriteCharacter.unicode = 0;
                        spriteCharacter.name    = fileNameToLowerInvariant;
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(sprite.name) && sprite.name.Length > 2 && sprite.name[0] == '0' && (sprite.name[1] == 'x' || sprite.name[1] == 'X'))
                        {
                            spriteCharacter.unicode = TextUtilities.StringHexToInt(sprite.name.Remove(0, 2));
                        }
                        spriteCharacter.name = sprite.name;
                    }

                    spriteCharacter.scale = 1.0f;

                    spriteAsset.spriteCharacterTable.Add(spriteCharacter);
                }
            }

            // Update Sprite Character Table to replace unicode 0x0 by 0xFFFE
            for (int i = 0; i < spriteAsset.spriteCharacterTable.Count; i++)
            {
                SpriteCharacter spriteCharacter = spriteAsset.spriteCharacterTable[i];
                if (spriteCharacter.unicode == 0)
                {
                    spriteCharacter.unicode = 0xFFFE;
                }
            }

            // Sort glyph table by glyph index
            spriteAsset.SortGlyphTable();
            spriteAsset.UpdateLookupTables();
            TextEventManager.ON_SPRITE_ASSET_PROPERTY_CHANGED(true, spriteAsset);
        }
示例#13
0
        public override void OnInspectorGUI()
        {
            //Debug.Log("OnInspectorGUI Called.");
            Event  currentEvent = Event.current;
            string evt_cmd      = currentEvent.commandName; // Get Current Event CommandName to check for Undo Events

            serializedObject.Update();


            // TEXTMESHPRO SPRITE INFO PANEL
            #region Display Sprite Asset Face Info
            Rect rect = EditorGUILayout.GetControlRect(false, 24);

            GUI.Label(rect, new GUIContent("<b>Face Info</b> - v" + m_SpriteAsset.version), TM_EditorStyles.sectionHeader);

            rect.x     += rect.width - 132f;
            rect.y     += 2;
            rect.width  = 130f;
            rect.height = 18f;
            if (GUI.Button(rect, new GUIContent("Update Sprite Asset")))
            {
                SpriteAssetCreationMenu.UpdateSpriteAsset(m_SpriteAsset);
            }
            EditorGUI.indentLevel = 1;

            EditorGUILayout.PropertyField(m_PointSizeProperty);
            EditorGUILayout.PropertyField(m_ScaleProperty);
            //EditorGUILayout.PropertyField(m_LineHeightProperty);
            EditorGUILayout.PropertyField(m_AscentLineProperty);
            EditorGUILayout.PropertyField(m_BaselineProperty);
            EditorGUILayout.PropertyField(m_DescentLineProperty);
            EditorGUILayout.Space();
            #endregion


            // ATLAS TEXTURE & MATERIAL
            #region Display Atlas Texture and Material
            rect = EditorGUILayout.GetControlRect(false, 24);

            if (GUI.Button(rect, new GUIContent("<b>Atlas & Material</b>"), TM_EditorStyles.sectionHeader))
            {
                UI_PanelState.spriteAtlasInfoPanel = !UI_PanelState.spriteAtlasInfoPanel;
            }

            GUI.Label(rect, (UI_PanelState.spriteAtlasInfoPanel ? "" : s_UiStateLabel[1]), TM_EditorStyles.rightLabel);

            if (UI_PanelState.spriteAtlasInfoPanel)
            {
                EditorGUI.BeginChangeCheck();
                EditorGUILayout.PropertyField(m_spriteAtlas_prop, new GUIContent("Sprite Atlas"));
                if (EditorGUI.EndChangeCheck())
                {
                    // Assign the new sprite atlas texture to the current material
                    Texture2D tex = m_spriteAtlas_prop.objectReferenceValue as Texture2D;
                    if (tex != null)
                    {
                        Material mat = m_material_prop.objectReferenceValue as Material;
                        if (mat != null)
                        {
                            mat.mainTexture = tex;
                        }
                    }
                }

                EditorGUILayout.PropertyField(m_material_prop, new GUIContent("Default Material"));
                EditorGUILayout.Space();
            }
            #endregion


            // FALLBACK SPRITE ASSETS
            #region Display Sprite Fallbacks
            rect = EditorGUILayout.GetControlRect(false, 24);
            EditorGUI.indentLevel = 0;
            if (GUI.Button(rect, new GUIContent("<b>Fallback Sprite Assets</b>", "Select the Sprite Assets that will be searched and used as fallback when a given sprite is missing from this sprite asset."), TM_EditorStyles.sectionHeader))
            {
                UI_PanelState.fallbackSpriteAssetPanel = !UI_PanelState.fallbackSpriteAssetPanel;
            }

            GUI.Label(rect, (UI_PanelState.fallbackSpriteAssetPanel ? "" : s_UiStateLabel[1]), TM_EditorStyles.rightLabel);

            if (UI_PanelState.fallbackSpriteAssetPanel)
            {
                m_fallbackSpriteAssetList.DoLayoutList();
                EditorGUILayout.Space();
            }
            #endregion


            // SPRITE CHARACTER TABLE
            #region Display Sprite Character Table
            EditorGUI.indentLevel = 0;
            rect = EditorGUILayout.GetControlRect(false, 24);

            if (GUI.Button(rect, new GUIContent("<b>Sprite Character Table</b>", "List of sprite characters contained in this sprite asset."), TM_EditorStyles.sectionHeader))
            {
                UI_PanelState.spriteCharacterTablePanel = !UI_PanelState.spriteCharacterTablePanel;
            }

            GUI.Label(rect, (UI_PanelState.spriteCharacterTablePanel ? "" : s_UiStateLabel[1]), TM_EditorStyles.rightLabel);

            if (UI_PanelState.spriteCharacterTablePanel)
            {
                int arraySize    = m_SpriteCharacterTableProperty.arraySize;
                int itemsPerPage = 10;

                // Display Glyph Management Tools
                EditorGUILayout.BeginVertical(EditorStyles.helpBox, GUILayout.ExpandWidth(true));
                {
                    // Search Bar implementation
                    #region DISPLAY SEARCH BAR
                    EditorGUILayout.BeginHorizontal();
                    {
                        EditorGUIUtility.labelWidth = 110f;
                        EditorGUI.BeginChangeCheck();
                        string searchPattern = EditorGUILayout.TextField("Sprite Search", m_CharacterSearchPattern, "SearchTextField");
                        if (EditorGUI.EndChangeCheck() || m_IsCharacterSearchDirty)
                        {
                            if (string.IsNullOrEmpty(searchPattern) == false)
                            {
                                //GUIUtility.keyboardControl = 0;
                                m_CharacterSearchPattern = searchPattern.ToLower(System.Globalization.CultureInfo.InvariantCulture).Trim();

                                // Search Glyph Table for potential matches
                                SearchCharacterTable(m_CharacterSearchPattern, ref m_CharacterSearchList);
                            }
                            else
                            {
                                m_CharacterSearchPattern = null;
                            }

                            m_IsCharacterSearchDirty = false;
                        }

                        string styleName = string.IsNullOrEmpty(m_CharacterSearchPattern) ? "SearchCancelButtonEmpty" : "SearchCancelButton";
                        if (GUILayout.Button(GUIContent.none, styleName))
                        {
                            GUIUtility.keyboardControl = 0;
                            m_CharacterSearchPattern   = string.Empty;
                        }
                    }
                    EditorGUILayout.EndHorizontal();
                    #endregion

                    // Display Page Navigation
                    if (!string.IsNullOrEmpty(m_CharacterSearchPattern))
                    {
                        arraySize = m_CharacterSearchList.Count;
                    }

                    // Display Page Navigation
                    DisplayPageNavigation(ref m_CurrentCharacterPage, arraySize, itemsPerPage);
                }
                EditorGUILayout.EndVertical();

                if (arraySize > 0)
                {
                    // Display each SpriteInfo entry using the SpriteInfo property drawer.
                    for (int i = itemsPerPage * m_CurrentCharacterPage; i < arraySize && i < itemsPerPage * (m_CurrentCharacterPage + 1); i++)
                    {
                        // Define the start of the selection region of the element.
                        Rect elementStartRegion = GUILayoutUtility.GetRect(0f, 0f, GUILayout.ExpandWidth(true));

                        int elementIndex = i;
                        if (!string.IsNullOrEmpty(m_CharacterSearchPattern))
                        {
                            elementIndex = m_CharacterSearchList[i];
                        }

                        SerializedProperty spriteCharacterProperty = m_SpriteCharacterTableProperty.GetArrayElementAtIndex(elementIndex);

                        EditorGUILayout.BeginVertical(EditorStyles.helpBox);
                        {
                            EditorGUI.BeginDisabledGroup(i != m_selectedElement);
                            {
                                EditorGUILayout.PropertyField(spriteCharacterProperty);
                            }
                            EditorGUI.EndDisabledGroup();
                        }
                        EditorGUILayout.EndVertical();

                        // Define the end of the selection region of the element.
                        Rect elementEndRegion = GUILayoutUtility.GetRect(0f, 0f, GUILayout.ExpandWidth(true));

                        // Check for Item selection
                        Rect selectionArea = new Rect(elementStartRegion.x, elementStartRegion.y, elementEndRegion.width, elementEndRegion.y - elementStartRegion.y);
                        if (DoSelectionCheck(selectionArea))
                        {
                            if (m_selectedElement == i)
                            {
                                m_selectedElement = -1;
                            }
                            else
                            {
                                m_selectedElement          = i;
                                GUIUtility.keyboardControl = 0;
                            }
                        }

                        // Draw & Handle Section Area
                        if (m_selectedElement == i)
                        {
                            // Draw selection highlight
                            TextCoreEditorUtilities.DrawBox(selectionArea, 2f, new Color32(40, 192, 255, 255));

                            // Draw options to MoveUp, MoveDown, Add or Remove Sprites
                            Rect controlRect = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight * 1f);
                            controlRect.width /= 8;

                            // Move sprite up.
                            bool guiEnabled = GUI.enabled;
                            if (i == 0)
                            {
                                GUI.enabled = false;
                            }
                            if (GUI.Button(controlRect, "Up"))
                            {
                                SwapCharacterElements(i, i - 1);
                            }
                            GUI.enabled = guiEnabled;

                            // Move sprite down.
                            controlRect.x += controlRect.width;
                            if (i == arraySize - 1)
                            {
                                GUI.enabled = false;
                            }
                            if (GUI.Button(controlRect, "Down"))
                            {
                                SwapCharacterElements(i, i + 1);
                            }
                            GUI.enabled = guiEnabled;

                            // Move sprite to new index
                            controlRect.x += controlRect.width * 2;
                            //if (i == arraySize - 1) { GUI.enabled = false; }
                            m_moveToIndex  = EditorGUI.IntField(controlRect, m_moveToIndex);
                            controlRect.x -= controlRect.width;
                            if (GUI.Button(controlRect, "Goto"))
                            {
                                MoveCharacterToIndex(i, m_moveToIndex);
                            }
                            //controlRect.x += controlRect.width;
                            GUI.enabled = guiEnabled;

                            // Add new Sprite
                            controlRect.x += controlRect.width * 4;
                            if (GUI.Button(controlRect, "+"))
                            {
                                m_SpriteCharacterTableProperty.arraySize += 1;

                                int index = m_SpriteCharacterTableProperty.arraySize - 1;

                                SerializedProperty spriteInfo_prop = m_SpriteCharacterTableProperty.GetArrayElementAtIndex(index);

                                // Copy properties of the selected element
                                CopyCharacterSerializedProperty(m_SpriteCharacterTableProperty.GetArrayElementAtIndex(elementIndex), ref spriteInfo_prop);

                                //spriteInfo_prop.FindPropertyRelative("m_Index").intValue = index;
                                serializedObject.ApplyModifiedProperties();

                                m_IsCharacterSearchDirty = true;
                            }

                            // Delete selected Sprite
                            controlRect.x += controlRect.width;
                            if (m_selectedElement == -1)
                            {
                                GUI.enabled = false;
                            }
                            if (GUI.Button(controlRect, "-"))
                            {
                                m_SpriteCharacterTableProperty.DeleteArrayElementAtIndex(elementIndex);

                                m_selectedElement = -1;
                                serializedObject.ApplyModifiedProperties();

                                m_IsCharacterSearchDirty = true;

                                return;
                            }
                        }
                    }
                }

                DisplayPageNavigation(ref m_CurrentCharacterPage, arraySize, itemsPerPage);

                EditorGUIUtility.labelWidth = 40f;
                EditorGUIUtility.fieldWidth = 20f;

                GUILayout.Space(5f);

                // GLOBAL TOOLS
                #region Global Tools

                /*
                 * GUI.enabled = true;
                 * EditorGUILayout.BeginVertical(EditorStyles.helpBox);
                 * rect = EditorGUILayout.GetControlRect(false, 40);
                 *
                 * float width = (rect.width - 75f) / 4;
                 * EditorGUI.LabelField(rect, "Global Offsets & Scale", EditorStyles.boldLabel);
                 *
                 *
                 * rect.x += 70;
                 * bool old_ChangedState = GUI.changed;
                 *
                 * GUI.changed = false;
                 * m_xOffset = EditorGUI.FloatField(new Rect(rect.x + 5f + width * 0, rect.y + 20, width - 5f, 18), new GUIContent("OX:"), m_xOffset);
                 * if (GUI.changed) UpdateGlobalProperty("m_HorizontalBearingX", m_xOffset);
                 *
                 * m_yOffset = EditorGUI.FloatField(new Rect(rect.x + 5f + width * 1, rect.y + 20, width - 5f, 18), new GUIContent("OY:"), m_yOffset);
                 * if (GUI.changed) UpdateGlobalProperty("m_HorizontalBearingY", m_yOffset);
                 *
                 * m_xAdvance = EditorGUI.FloatField(new Rect(rect.x + 5f + width * 2, rect.y + 20, width - 5f, 18), new GUIContent("ADV."), m_xAdvance);
                 * if (GUI.changed) UpdateGlobalProperty("m_HorizontalAdvance", m_xAdvance);
                 *
                 * m_scale = EditorGUI.FloatField(new Rect(rect.x + 5f + width * 3, rect.y + 20, width - 5f, 18), new GUIContent("SF."), m_scale);
                 * if (GUI.changed) UpdateGlobalProperty("m_Scale", m_scale);
                 *
                 * EditorGUILayout.EndVertical();
                 *
                 * GUI.changed = old_ChangedState;
                 */
                #endregion
            }
            #endregion


            // SPRITE GLYPH TABLE
            #region Display Sprite Glyph Table
            EditorGUI.indentLevel = 0;
            rect = EditorGUILayout.GetControlRect(false, 24);

            if (GUI.Button(rect, new GUIContent("<b>Sprite Glyph Table</b>", "A list of the SpriteGlyphs contained in this sprite asset."), TM_EditorStyles.sectionHeader))
            {
                UI_PanelState.spriteGlyphTablePanel = !UI_PanelState.spriteGlyphTablePanel;
            }

            GUI.Label(rect, (UI_PanelState.spriteGlyphTablePanel ? "" : s_UiStateLabel[1]), TM_EditorStyles.rightLabel);

            if (UI_PanelState.spriteGlyphTablePanel)
            {
                int arraySize    = m_SpriteGlyphTableProperty.arraySize;
                int itemsPerPage = 10;

                // Display Glyph Management Tools
                EditorGUILayout.BeginVertical(EditorStyles.helpBox, GUILayout.ExpandWidth(true));
                {
                    // Search Bar implementation
                    #region DISPLAY SEARCH BAR
                    EditorGUILayout.BeginHorizontal();
                    {
                        EditorGUIUtility.labelWidth = 110f;
                        EditorGUI.BeginChangeCheck();
                        string searchPattern = EditorGUILayout.TextField("Sprite Search", m_GlyphSearchPattern, "SearchTextField");
                        if (EditorGUI.EndChangeCheck() || m_IsGlyphSearchDirty)
                        {
                            if (string.IsNullOrEmpty(searchPattern) == false)
                            {
                                //GUIUtility.keyboardControl = 0;
                                m_GlyphSearchPattern = searchPattern.ToLower(System.Globalization.CultureInfo.InvariantCulture).Trim();

                                // Search Glyph Table for potential matches
                                SearchCharacterTable(m_GlyphSearchPattern, ref m_GlyphSearchList);
                            }
                            else
                            {
                                m_GlyphSearchPattern = null;
                            }

                            m_IsGlyphSearchDirty = false;
                        }

                        string styleName = string.IsNullOrEmpty(m_GlyphSearchPattern) ? "SearchCancelButtonEmpty" : "SearchCancelButton";
                        if (GUILayout.Button(GUIContent.none, styleName))
                        {
                            GUIUtility.keyboardControl = 0;
                            m_GlyphSearchPattern       = string.Empty;
                        }
                    }
                    EditorGUILayout.EndHorizontal();
                    #endregion

                    // Display Page Navigation
                    if (!string.IsNullOrEmpty(m_GlyphSearchPattern))
                    {
                        arraySize = m_GlyphSearchList.Count;
                    }

                    // Display Page Navigation
                    DisplayPageNavigation(ref m_CurrentGlyphPage, arraySize, itemsPerPage);
                }
                EditorGUILayout.EndVertical();

                if (arraySize > 0)
                {
                    // Display each SpriteInfo entry using the SpriteInfo property drawer.
                    for (int i = itemsPerPage * m_CurrentGlyphPage; i < arraySize && i < itemsPerPage * (m_CurrentGlyphPage + 1); i++)
                    {
                        // Define the start of the selection region of the element.
                        Rect elementStartRegion = GUILayoutUtility.GetRect(0f, 0f, GUILayout.ExpandWidth(true));

                        int elementIndex = i;
                        if (!string.IsNullOrEmpty(m_GlyphSearchPattern))
                        {
                            elementIndex = m_GlyphSearchList[i];
                        }

                        SerializedProperty spriteGlyphProperty = m_SpriteGlyphTableProperty.GetArrayElementAtIndex(elementIndex);

                        EditorGUILayout.BeginVertical(EditorStyles.helpBox);
                        {
                            EditorGUI.BeginDisabledGroup(i != m_selectedElement);
                            {
                                EditorGUILayout.PropertyField(spriteGlyphProperty);
                            }
                            EditorGUI.EndDisabledGroup();
                        }
                        EditorGUILayout.EndVertical();

                        // Define the end of the selection region of the element.
                        Rect elementEndRegion = GUILayoutUtility.GetRect(0f, 0f, GUILayout.ExpandWidth(true));

                        // Check for Item selection
                        Rect selectionArea = new Rect(elementStartRegion.x, elementStartRegion.y, elementEndRegion.width, elementEndRegion.y - elementStartRegion.y);
                        if (DoSelectionCheck(selectionArea))
                        {
                            if (m_selectedElement == i)
                            {
                                m_selectedElement = -1;
                            }
                            else
                            {
                                m_selectedElement          = i;
                                GUIUtility.keyboardControl = 0;
                            }
                        }

                        // Draw & Handle Section Area
                        if (m_selectedElement == i)
                        {
                            // Draw selection highlight
                            TextCoreEditorUtilities.DrawBox(selectionArea, 2f, new Color32(40, 192, 255, 255));

                            // Draw options to MoveUp, MoveDown, Add or Remove Sprites
                            Rect controlRect = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight * 1f);
                            controlRect.width /= 8;

                            // Move sprite up.
                            bool guiEnabled = GUI.enabled;
                            if (i == 0)
                            {
                                GUI.enabled = false;
                            }
                            if (GUI.Button(controlRect, "Up"))
                            {
                                SwapGlyphElements(i, i - 1);
                            }
                            GUI.enabled = guiEnabled;

                            // Move sprite down.
                            controlRect.x += controlRect.width;
                            if (i == arraySize - 1)
                            {
                                GUI.enabled = false;
                            }
                            if (GUI.Button(controlRect, "Down"))
                            {
                                SwapGlyphElements(i, i + 1);
                            }
                            GUI.enabled = guiEnabled;

                            // Move sprite to new index
                            controlRect.x += controlRect.width * 2;
                            //if (i == arraySize - 1) { GUI.enabled = false; }
                            m_moveToIndex  = EditorGUI.IntField(controlRect, m_moveToIndex);
                            controlRect.x -= controlRect.width;
                            if (GUI.Button(controlRect, "Goto"))
                            {
                                MoveGlyphToIndex(i, m_moveToIndex);
                            }
                            //controlRect.x += controlRect.width;
                            GUI.enabled = guiEnabled;

                            // Add new Sprite
                            controlRect.x += controlRect.width * 4;
                            if (GUI.Button(controlRect, "+"))
                            {
                                m_SpriteGlyphTableProperty.arraySize += 1;

                                int index = m_SpriteGlyphTableProperty.arraySize - 1;

                                SerializedProperty newSpriteGlyphProperty = m_SpriteGlyphTableProperty.GetArrayElementAtIndex(index);

                                // Copy properties of the selected element
                                CopyGlyphSerializedProperty(m_SpriteGlyphTableProperty.GetArrayElementAtIndex(elementIndex), ref newSpriteGlyphProperty);

                                newSpriteGlyphProperty.FindPropertyRelative("m_Index").intValue = index;

                                serializedObject.ApplyModifiedProperties();

                                m_IsGlyphSearchDirty = true;

                                //m_SpriteAsset.UpdateLookupTables();
                            }

                            // Delete selected Sprite
                            controlRect.x += controlRect.width;
                            if (m_selectedElement == -1)
                            {
                                GUI.enabled = false;
                            }
                            if (GUI.Button(controlRect, "-"))
                            {
                                SerializedProperty selectedSpriteGlyphProperty = m_SpriteGlyphTableProperty.GetArrayElementAtIndex(elementIndex);

                                int selectedGlyphIndex = selectedSpriteGlyphProperty.FindPropertyRelative("m_Index").intValue;

                                m_SpriteGlyphTableProperty.DeleteArrayElementAtIndex(elementIndex);

                                // Remove all Sprite Characters referencing this glyph.
                                for (int j = 0; j < m_SpriteCharacterTableProperty.arraySize; j++)
                                {
                                    int glyphIndex = m_SpriteCharacterTableProperty.GetArrayElementAtIndex(j).FindPropertyRelative("m_GlyphIndex").intValue;

                                    if (glyphIndex == selectedGlyphIndex)
                                    {
                                        // Remove character
                                        m_SpriteCharacterTableProperty.DeleteArrayElementAtIndex(j);
                                    }
                                }

                                m_selectedElement = -1;
                                serializedObject.ApplyModifiedProperties();

                                m_IsGlyphSearchDirty = true;

                                //m_SpriteAsset.UpdateLookupTables();

                                return;
                            }
                        }
                    }
                }

                DisplayPageNavigation(ref m_CurrentGlyphPage, arraySize, itemsPerPage);

                EditorGUIUtility.labelWidth = 40f;
                EditorGUIUtility.fieldWidth = 20f;

                GUILayout.Space(5f);

                // GLOBAL TOOLS
                #region Global Tools
                GUI.enabled = true;
                EditorGUILayout.BeginVertical(EditorStyles.helpBox);
                rect = EditorGUILayout.GetControlRect(false, 40);

                float width = (rect.width - 75f) / 4;
                EditorGUI.LabelField(rect, "Global Offsets & Scale", EditorStyles.boldLabel);


                rect.x += 70;
                bool old_ChangedState = GUI.changed;

                GUI.changed = false;
                m_xOffset   = EditorGUI.FloatField(new Rect(rect.x + 5f + width * 0, rect.y + 20, width - 5f, 18), new GUIContent("OX:"), m_xOffset);
                if (GUI.changed)
                {
                    UpdateGlobalProperty("m_HorizontalBearingX", m_xOffset);
                }

                m_yOffset = EditorGUI.FloatField(new Rect(rect.x + 5f + width * 1, rect.y + 20, width - 5f, 18), new GUIContent("OY:"), m_yOffset);
                if (GUI.changed)
                {
                    UpdateGlobalProperty("m_HorizontalBearingY", m_yOffset);
                }

                m_xAdvance = EditorGUI.FloatField(new Rect(rect.x + 5f + width * 2, rect.y + 20, width - 5f, 18), new GUIContent("ADV."), m_xAdvance);
                if (GUI.changed)
                {
                    UpdateGlobalProperty("m_HorizontalAdvance", m_xAdvance);
                }

                m_scale = EditorGUI.FloatField(new Rect(rect.x + 5f + width * 3, rect.y + 20, width - 5f, 18), new GUIContent("SF."), m_scale);
                if (GUI.changed)
                {
                    UpdateGlobalProperty("m_Scale", m_scale);
                }

                EditorGUILayout.EndVertical();
                #endregion

                GUI.changed = old_ChangedState;
            }
            #endregion


            if (serializedObject.ApplyModifiedProperties() || evt_cmd == k_UndoRedo || isAssetDirty)
            {
                if (m_SpriteAsset.m_IsSpriteAssetLookupTablesDirty || evt_cmd == k_UndoRedo)
                {
                    m_SpriteAsset.UpdateLookupTables();
                }

                TextEventManager.ON_SPRITE_ASSET_PROPERTY_CHANGED(true, m_SpriteAsset);

                isAssetDirty = false;
                EditorUtility.SetDirty(target);
            }

            // Clear selection if mouse event was not consumed.
            GUI.enabled = true;
            if (currentEvent.type == EventType.MouseDown && currentEvent.button == 0)
            {
                m_selectedElement = -1;
            }
        }