diff --git a/Assets/Editor Default Resources/GTS.GlobalUIFontSettings.meta b/Assets/Editor Default Resources/GTS.GlobalTextSettings.meta similarity index 100% rename from Assets/Editor Default Resources/GTS.GlobalUIFontSettings.meta rename to Assets/Editor Default Resources/GTS.GlobalTextSettings.meta diff --git a/Assets/Editor Default Resources/GTS.GlobalUIFontSettings/README.txt b/Assets/Editor Default Resources/GTS.GlobalTextSettings/README.txt similarity index 53% rename from Assets/Editor Default Resources/GTS.GlobalUIFontSettings/README.txt rename to Assets/Editor Default Resources/GTS.GlobalTextSettings/README.txt index 6919b6c..b48ee49 100644 --- a/Assets/Editor Default Resources/GTS.GlobalUIFontSettings/README.txt +++ b/Assets/Editor Default Resources/GTS.GlobalTextSettings/README.txt @@ -1,3 +1,4 @@ This is where your Global Font preferences are saved. They are saved as ScriptableObjects. -Do not delete them, unless you just want to. \ No newline at end of file +Do not delete them, unless you just want to. +Arial asset is created by default. \ No newline at end of file diff --git a/Assets/Editor Default Resources/GTS.GlobalUIFontSettings/README.txt.meta b/Assets/Editor Default Resources/GTS.GlobalTextSettings/README.txt.meta similarity index 100% rename from Assets/Editor Default Resources/GTS.GlobalUIFontSettings/README.txt.meta rename to Assets/Editor Default Resources/GTS.GlobalTextSettings/README.txt.meta diff --git a/Assets/GTS.GlobalUIFont.meta b/Assets/GTS.GlobalTextSystem.meta similarity index 100% rename from Assets/GTS.GlobalUIFont.meta rename to Assets/GTS.GlobalTextSystem.meta diff --git a/Assets/GTS.GlobalUIFont/Editor.meta b/Assets/GTS.GlobalTextSystem/Editor.meta similarity index 100% rename from Assets/GTS.GlobalUIFont/Editor.meta rename to Assets/GTS.GlobalTextSystem/Editor.meta diff --git a/Assets/GTS.GlobalTextSystem/Editor/Data.meta b/Assets/GTS.GlobalTextSystem/Editor/Data.meta new file mode 100644 index 0000000..228aa2d --- /dev/null +++ b/Assets/GTS.GlobalTextSystem/Editor/Data.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: daca57d4a3b22dd4990a80c30920183f +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/GTS.GlobalTextSystem/Editor/Data/TextData.cs b/Assets/GTS.GlobalTextSystem/Editor/Data/TextData.cs new file mode 100644 index 0000000..6ea047f --- /dev/null +++ b/Assets/GTS.GlobalTextSystem/Editor/Data/TextData.cs @@ -0,0 +1,74 @@ +/* +================================================================================ + Product: Unity-Set-Global_UI-Text_Font + Developer: GlassToeStudio@gmail.com + Source: https://github.com/GlassToeStudio/Unity-Set-Global-UI-Text-Font + Company: GlassToeStudio + Website: http://glasstoestudio.weebly.com/ + Date: June 19, 2018 +================================================================================= + MIT License +================================================================================ +*/ + +using UnityEngine; +using System.Collections.Generic; +using GTS.GlobalTextSystem.Libraries; + +/// +/// Small System that provides useful functionality to Unity's UI Text system. +/// > +namespace GTS.GlobalTextSystem.Data +{ + /// + /// ScriptableObject to hold the global Text Settings. + /// + public class TextData : ScriptableObject + { + public string text = "This holds all of your settings for Text Objects!"; + + [SerializeField] + public Font font { get; set; } + public FontStyle fontStyle { get; set; } + private int _fontSize = 14; + public int fontSize { get { return _fontSize; } set { this._fontSize = value; } } + private float _lineSpacing = 1f; + public float lineSpacing { get { return _lineSpacing; } set { this._lineSpacing = value; } } + public bool supportRichText { get; set; } + + public TextAnchor alignment { get; set; } + public bool alignByGeometry { get; set; } + public HorizontalWrapMode horizontalOverflow { get; set; } + public VerticalWrapMode verticalOverflow { get; set; } + public bool resizeTextForBestFit { get; set; } + + public int resizeTextMinSize { get; set; } + public int resizeTextMaxSize { get; set; } + + private Color _color = Color.black; + public Color color { get { return _color; } set { this._color = value; } } + public Material material { get; set; } + public bool raycastTarget { get; set; } + + public TextOverrides overrides; + + public Dictionary SavedSettings = new Dictionary() + { + { StringLibrary.FONT, true }, + { StringLibrary.FONT_STYLE, false }, + { StringLibrary.FONT_SIZE, false }, + { StringLibrary.LINE_SPACING, false }, + { StringLibrary.RICH_TEXT, false }, + { StringLibrary.ALIGNMENT, false }, + { StringLibrary.ALIGN_BY_GEOMETRY, false }, + { StringLibrary.HORIZONTAL_OVERFLOW, false }, + { StringLibrary.VERTICAL_OVERFLOW, false }, + { StringLibrary.BEST_FIT, false }, + { StringLibrary.TEXT_MIN, false }, + { StringLibrary.TEXT_MAX, false }, + { StringLibrary.COLOR, true }, + { StringLibrary.MATERIAL, false }, + { StringLibrary.RAYCAST, false } + }; + } +} \ No newline at end of file diff --git a/Assets/GTS.GlobalUIFont/Editor/GlobalFontManager.cs.meta b/Assets/GTS.GlobalTextSystem/Editor/Data/TextData.cs.meta similarity index 83% rename from Assets/GTS.GlobalUIFont/Editor/GlobalFontManager.cs.meta rename to Assets/GTS.GlobalTextSystem/Editor/Data/TextData.cs.meta index a5d4e96..a3e6a05 100644 --- a/Assets/GTS.GlobalUIFont/Editor/GlobalFontManager.cs.meta +++ b/Assets/GTS.GlobalTextSystem/Editor/Data/TextData.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: ec6169fe6374ca7458835e8aa90294ae +guid: dda6d5ea9fe9ac14594283763a10b5ee MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/GTS.GlobalTextSystem/Editor/Data/TextDataEditor.cs b/Assets/GTS.GlobalTextSystem/Editor/Data/TextDataEditor.cs new file mode 100644 index 0000000..321706b --- /dev/null +++ b/Assets/GTS.GlobalTextSystem/Editor/Data/TextDataEditor.cs @@ -0,0 +1,256 @@ +/* +================================================================================ + Product: Unity-Set-Global_UI-Text_Font + Developer: GlassToeStudio@gmail.com + Source: https://github.com/GlassToeStudio/Unity-Set-Global-UI-Text-Font + Company: GlassToeStudio + Website: http://glasstoestudio.weebly.com/ + Date: June 19, 2018 +================================================================================= + MIT License +================================================================================ +*/ + +using UnityEditor; +using UnityEngine; +using GTS.GlobalTextSystem.Libraries; + +/// +/// Small System that provides useful functionality to Unity's UI Text system. +/// > +namespace GTS.GlobalTextSystem.Data +{ + [CustomEditor(typeof(TextData))] + public class TextDataEditor : Editor + { + bool foldCharacter = true; + bool foldParagraph = true; + TextData myTarget; + + int startHorizontalWidth = 250; + + int startLabelWidth = 130; + int endLabelWidth = 100; + int startFieldWidth = 120; + int endFieldWidth = 20; + + private void OnEnable() + { + myTarget = (TextData)target; + } + + public override void OnInspectorGUI() + { + //base.OnInspectorGUI(); + + EditorGUILayout.LabelField("Text"); + myTarget.text = EditorGUILayout.TextField(myTarget.text, GUILayout.Height(40)); + + #region Character + + foldCharacter = EditorGUILayout.Foldout(foldCharacter, "Character", + new GUIStyle(EditorStyles.foldout) + { + fontStyle = FontStyle.Bold, + }); + + if(foldCharacter) + { + // Font + StartSection(); + myTarget.font = (Font) EditorGUILayout.ObjectField("Font", myTarget.font, typeof(Font), true, GUILayout.Width(startHorizontalWidth)); + MiddleSection(); + myTarget.overrides.saveFont = EditorGUILayout.Toggle(myTarget.overrides.saveFont); + EditorGUILayout.LabelField("Apply to new."); + EndSction(); + + // FontStyle + StartSection(); + myTarget.fontStyle = (FontStyle)EditorGUILayout.EnumPopup("FontStyle", myTarget.fontStyle, GUILayout.Width(startHorizontalWidth)); + MiddleSection(); + myTarget.overrides.saveFontStyle = EditorGUILayout.Toggle(myTarget.overrides.saveFontStyle); + EditorGUILayout.LabelField("Apply to new."); + EndSction(); + + // FontSize + StartSection(); + myTarget.fontSize = EditorGUILayout.IntField("FontSize", myTarget.fontSize, GUILayout.Width(startHorizontalWidth)); + MiddleSection(); + myTarget.overrides.saveFontSize = EditorGUILayout.Toggle(myTarget.overrides.saveFontSize); + EditorGUILayout.LabelField("Apply to new."); + EndSction(); + + // Line Spacing + StartSection(); + myTarget.lineSpacing = EditorGUILayout.FloatField("Line Spacing", myTarget.lineSpacing, GUILayout.Width(startHorizontalWidth)); + MiddleSection(); + myTarget.overrides.saveLineSpacing = EditorGUILayout.Toggle(myTarget.overrides.saveLineSpacing); + EditorGUILayout.LabelField("Apply to new."); + EndSction(); + + // Rich Text + StartSection(); + myTarget.supportRichText = EditorGUILayout.Toggle("Rich Text", myTarget.supportRichText, GUILayout.Width(startHorizontalWidth)); + MiddleSection(); + myTarget.overrides.saveRichText = EditorGUILayout.Toggle(myTarget.overrides.saveRichText); + EditorGUILayout.LabelField("Apply to new."); + EndSction(); + + EditorGUI.indentLevel = 0; + } + + #endregion + + EditorGUILayout.Space(); + + #region Paragraph + + foldParagraph = EditorGUILayout.Foldout(foldParagraph, "Paragraph", + new GUIStyle(EditorStyles.foldout) + { + fontStyle = FontStyle.Bold, + }); + + + if(foldParagraph) + { + // Alignment + StartSection(); + myTarget.alignment = (TextAnchor)EditorGUILayout.EnumPopup("Alignment", myTarget.alignment, GUILayout.Width(startHorizontalWidth)); + MiddleSection(); + myTarget.overrides.saveAlignment = EditorGUILayout.Toggle(myTarget.overrides.saveAlignment); + EditorGUILayout.LabelField("Apply to new."); + EndSction(); + + // Align By Geometry + StartSection(); + myTarget.alignByGeometry = EditorGUILayout.Toggle("Align By Geometry", myTarget.alignByGeometry, GUILayout.Width(startHorizontalWidth)); + MiddleSection(); + myTarget.overrides.saveAlighnByGeometry = EditorGUILayout.Toggle(myTarget.overrides.saveAlighnByGeometry); + EditorGUILayout.LabelField("Apply to new."); + EndSction(); + + // Horizontal Overflow + StartSection(); + myTarget.horizontalOverflow = (HorizontalWrapMode)EditorGUILayout.EnumPopup("Horizontal Overflow", myTarget.horizontalOverflow, GUILayout.Width(startHorizontalWidth)); + MiddleSection(); + myTarget.overrides.saveHorizontalOverflow = EditorGUILayout.Toggle(myTarget.overrides.saveHorizontalOverflow); + EditorGUILayout.LabelField("Apply to new."); + EndSction(); + + // Vertical Overflow + StartSection(); + myTarget.verticalOverflow = (VerticalWrapMode)EditorGUILayout.EnumPopup("Vertical Overflow", myTarget.verticalOverflow, GUILayout.Width(startHorizontalWidth)); + MiddleSection(); + myTarget.overrides.saveVerticalOVerflow = EditorGUILayout.Toggle(myTarget.overrides.saveVerticalOVerflow); + EditorGUILayout.LabelField("Apply to new."); + EndSction(); + + // Best Fit + StartSection(); + myTarget.resizeTextForBestFit = EditorGUILayout.Toggle("Best Fit", myTarget.resizeTextForBestFit, GUILayout.Width(startHorizontalWidth)); + MiddleSection(); + myTarget.overrides.saveBestFit = EditorGUILayout.Toggle(myTarget.overrides.saveBestFit); + EditorGUILayout.LabelField("Apply to new."); + EndSction(); + + // Best Fit Options + if(myTarget.resizeTextForBestFit) + { + // Min Size + StartSection(2); + myTarget.resizeTextMinSize = EditorGUILayout.IntField("Min Size", myTarget.resizeTextMinSize, GUILayout.Width(startHorizontalWidth)); + MiddleSection(); + myTarget.overrides.saveMinText = EditorGUILayout.Toggle(myTarget.overrides.saveMinText); + EditorGUILayout.LabelField("Apply to new."); + EndSction(); + + // Max Size + StartSection(2); + myTarget.resizeTextMaxSize = EditorGUILayout.IntField("Max Size", myTarget.resizeTextMaxSize, GUILayout.Width(startHorizontalWidth)); + MiddleSection(); + myTarget.overrides.saveMaxText = EditorGUILayout.Toggle(myTarget.overrides.saveMaxText); + EditorGUILayout.LabelField("Apply to new."); + EndSction(); + } + EditorGUI.indentLevel = 0; + } + + #endregion + + EditorGUILayout.Space(); + + #region Other + + // Color + StartSection(0); + myTarget.color = EditorGUILayout.ColorField("Color", myTarget.color, GUILayout.Width(startHorizontalWidth)); + MiddleSection(); + MiddleSection(); + myTarget.overrides.saveColor = EditorGUILayout.Toggle(myTarget.overrides.saveColor); + EditorGUILayout.LabelField("Apply to new."); + EndSction(); + + // Material + StartSection(0); + myTarget.material = (Material)EditorGUILayout.ObjectField("Material", myTarget.material, typeof(Material), true, GUILayout.Width(startHorizontalWidth)); + MiddleSection(); + MiddleSection(); + myTarget.overrides.saveMaterial = EditorGUILayout.Toggle(myTarget.overrides.saveMaterial); + EditorGUILayout.LabelField("Apply to new."); + EndSction(); + + // Raycast + StartSection(0); + myTarget.raycastTarget = EditorGUILayout.Toggle("Raycast Target", myTarget.raycastTarget, GUILayout.Width(startHorizontalWidth)); + MiddleSection(); + MiddleSection(); + myTarget.overrides.saveRaycaset = EditorGUILayout.Toggle(myTarget.overrides.saveRaycaset); + EditorGUILayout.LabelField("Apply to new."); + EndSction(); + + #endregion + + UpdateDictionary(); + + EditorUtility.SetDirty(target); + } + + private void UpdateDictionary() + { + myTarget.SavedSettings[StringLibrary.FONT] = myTarget.overrides.saveFont; + myTarget.SavedSettings[StringLibrary.FONT_STYLE] = myTarget.overrides.saveFontStyle; + myTarget.SavedSettings[StringLibrary.FONT_SIZE] = myTarget.overrides.saveFontSize; + myTarget.SavedSettings[StringLibrary.LINE_SPACING] = myTarget.overrides.saveLineSpacing; + myTarget.SavedSettings[StringLibrary.RICH_TEXT] = myTarget.overrides.saveRichText; + myTarget.SavedSettings[StringLibrary.ALIGNMENT] = myTarget.overrides.saveAlignment; + myTarget.SavedSettings[StringLibrary.ALIGN_BY_GEOMETRY] = myTarget.overrides.saveAlighnByGeometry; + myTarget.SavedSettings[StringLibrary.HORIZONTAL_OVERFLOW] = myTarget.overrides.saveHorizontalOverflow; + myTarget.SavedSettings[StringLibrary.VERTICAL_OVERFLOW] = myTarget.overrides.saveVerticalOVerflow; + myTarget.SavedSettings[StringLibrary.BEST_FIT] = myTarget.overrides.saveBestFit; + myTarget.SavedSettings[StringLibrary.TEXT_MIN] = myTarget.overrides.saveMinText; + myTarget.SavedSettings[StringLibrary.TEXT_MAX] = myTarget.overrides.saveMinText; + myTarget.SavedSettings[StringLibrary.COLOR] = myTarget.overrides.saveColor; + myTarget.SavedSettings[StringLibrary.MATERIAL] = myTarget.overrides.saveMaterial; + myTarget.SavedSettings[StringLibrary.RAYCAST] = myTarget.overrides.saveRaycaset; + } + + private void StartSection(int indent = 1) + { + GUILayout.BeginHorizontal(); + EditorGUI.indentLevel = indent; + EditorGUIUtility.labelWidth = startLabelWidth; + EditorGUIUtility.fieldWidth = startFieldWidth; + } + private void MiddleSection(int indent = 0) + { + EditorGUI.indentLevel = indent; + EditorGUIUtility.labelWidth = endLabelWidth; + EditorGUIUtility.fieldWidth = endFieldWidth; + } + private void EndSction() + { + EditorGUILayout.EndHorizontal(); + } + } +} \ No newline at end of file diff --git a/Assets/GTS.GlobalUIFont/Editor/GlobalFontManagerWindow.cs.meta b/Assets/GTS.GlobalTextSystem/Editor/Data/TextDataEditor.cs.meta similarity index 83% rename from Assets/GTS.GlobalUIFont/Editor/GlobalFontManagerWindow.cs.meta rename to Assets/GTS.GlobalTextSystem/Editor/Data/TextDataEditor.cs.meta index 55fc9d7..586b5df 100644 --- a/Assets/GTS.GlobalUIFont/Editor/GlobalFontManagerWindow.cs.meta +++ b/Assets/GTS.GlobalTextSystem/Editor/Data/TextDataEditor.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 303172e70bb3d484f8dc62aaaa6d84f6 +guid: 6c5d236738bafaf49be6a0710ce1b4fe MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/GTS.GlobalTextSystem/Editor/Data/TextOverrides.cs b/Assets/GTS.GlobalTextSystem/Editor/Data/TextOverrides.cs new file mode 100644 index 0000000..b44d7d0 --- /dev/null +++ b/Assets/GTS.GlobalTextSystem/Editor/Data/TextOverrides.cs @@ -0,0 +1,42 @@ +/* +================================================================================ + Product: Unity-Set-Global_UI-Text_Font + Developer: GlassToeStudio@gmail.com + Source: https://github.com/GlassToeStudio/Unity-Set-Global-UI-Text-Font + Company: GlassToeStudio + Website: http://glasstoestudio.weebly.com/ + Date: June 19, 2018 +================================================================================= + MIT License +================================================================================ +*/ + +/// +/// Small System that provides useful functionality to Unity's UI Text system. +/// > +namespace GTS.GlobalTextSystem.Data +{ + [System.Serializable] + public class TextOverrides + { + private bool _saveFont = true; + public bool saveFont { get { return _saveFont; } set { _saveFont = value; } } + public bool saveFontStyle { get; set; } + public bool saveFontSize { get; set; } + public bool saveLineSpacing { get; set; } + public bool saveRichText { get; set; } + + public bool saveAlignment { get; set; } + public bool saveAlighnByGeometry { get; set; } + public bool saveHorizontalOverflow { get; set; } + public bool saveVerticalOVerflow { get; set; } + public bool saveBestFit { get; set; } + public bool saveMinText { get; set; } + public bool saveMaxText { get; set; } + + private bool _saveColor = true; + public bool saveColor { get { return _saveColor; } set { _saveColor = value; } } + public bool saveMaterial { get; set; } + public bool saveRaycaset { get; set; } + } +} diff --git a/Assets/GTS.GlobalUIFont/Editor/FontData.cs.meta b/Assets/GTS.GlobalTextSystem/Editor/Data/TextOverrides.cs.meta similarity index 83% rename from Assets/GTS.GlobalUIFont/Editor/FontData.cs.meta rename to Assets/GTS.GlobalTextSystem/Editor/Data/TextOverrides.cs.meta index 4621c8b..23926e9 100644 --- a/Assets/GTS.GlobalUIFont/Editor/FontData.cs.meta +++ b/Assets/GTS.GlobalTextSystem/Editor/Data/TextOverrides.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 1b573ef622dee51458dbeaba8e0ea87e +guid: f9906b12c5058584a85846286a469f44 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/GTS.GlobalTextSystem/Editor/EntryPoint.cs b/Assets/GTS.GlobalTextSystem/Editor/EntryPoint.cs new file mode 100644 index 0000000..76443b2 --- /dev/null +++ b/Assets/GTS.GlobalTextSystem/Editor/EntryPoint.cs @@ -0,0 +1,71 @@ +/* +================================================================================ + Product: Unity-Set-Global_UI-Text_Font + Developer: GlassToeStudio@gmail.com + Source: https://github.com/GlassToeStudio/Unity-Set-Global-UI-Text-Font + Company: GlassToeStudio + Website: http://glasstoestudio.weebly.com/ + Date: June 19, 2018 +================================================================================= + MIT License +================================================================================ +*/ + +using UnityEngine; +using UnityEditor; +using UnityEngine.UI; +using GTS.GlobalTextSystem.Tools; +using GTS.GlobalTextSystem.Menus; +using GTS.GlobalTextSystem.Libraries; + +/// +/// Small System that provides useful functionality to Unity's UI Text system. +/// +namespace GTS.GlobalTextSystem +{ + /// + /// The main entry point for the GlobalText System. + /// Handles creating and setting up all class instances for the system to run. + /// + [InitializeOnLoad] + class EntryPoint + { + /// + /// Static constructor. Created when Unity first loads. + /// + static EntryPoint() + { + // Retrieve the saved name of the current global text asset + var textAssetName = EditorPrefs.GetString(StringLibrary.GLOBAL_FONT_KEY, StringLibrary.ARIAL); + + // Load the saved global text asset + var globalTextAsset = AssetProcessor.LoadTextAsset(textAssetName); + + // If, for some reason, there is no text asset, create a default Arial text asset + if(globalTextAsset == null) + { + AssetProcessor.CreateDefaultTextAsset(); + globalTextAsset = AssetProcessor.LoadTextAsset(textAssetName); + } + + // Create the listener for notifications of newly create Text objects + var hierarchyListener = new HierarchyListener(); + + // Grab all, if any, Text objects in the scene + var allTextObjects = Resources.FindObjectsOfTypeAll(typeof(Text)); + if(allTextObjects == null) + { + allTextObjects = Resources.FindObjectsOfTypeAll(typeof(Text)); + } + + // Create and initialize the GlobalFontSettings + new GlobalTextSettings(globalTextAsset, allTextObjects); + + // Initialize the listener for the font settings window + GlobalTextSettingsWindow.hierarchyListener = hierarchyListener; + + // Start listening for the creation of text objects + hierarchyListener.Listen(); + } + } +} diff --git a/Assets/GTS.GlobalUIFont/Editor/GlobalFontUtils.cs.meta b/Assets/GTS.GlobalTextSystem/Editor/EntryPoint.cs.meta similarity index 83% rename from Assets/GTS.GlobalUIFont/Editor/GlobalFontUtils.cs.meta rename to Assets/GTS.GlobalTextSystem/Editor/EntryPoint.cs.meta index cc28cca..6407bcd 100644 --- a/Assets/GTS.GlobalUIFont/Editor/GlobalFontUtils.cs.meta +++ b/Assets/GTS.GlobalTextSystem/Editor/EntryPoint.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 15b9f29a949fb2443ab816d1e9d1d939 +guid: 71043ee9fa5e19640bc00aef7152c828 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/GTS.GlobalTextSystem/Editor/Libraries.meta b/Assets/GTS.GlobalTextSystem/Editor/Libraries.meta new file mode 100644 index 0000000..cb6f75c --- /dev/null +++ b/Assets/GTS.GlobalTextSystem/Editor/Libraries.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 824f578f641972a4b9a823025e73f79c +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/GTS.GlobalTextSystem/Editor/Libraries/PropertyLibrary.cs b/Assets/GTS.GlobalTextSystem/Editor/Libraries/PropertyLibrary.cs new file mode 100644 index 0000000..d9e7630 --- /dev/null +++ b/Assets/GTS.GlobalTextSystem/Editor/Libraries/PropertyLibrary.cs @@ -0,0 +1,178 @@ +/* +================================================================================ + Product: Unity-Set-Global_UI-Text_Font + Developer: GlassToeStudio@gmail.com + Source: https://github.com/GlassToeStudio/Unity-Set-Global-UI-Text-Font + Company: GlassToeStudio + Website: http://glasstoestudio.weebly.com/ + Date: June 19, 2018 +================================================================================= + MIT License +================================================================================ +*/ + +using UnityEngine; +using UnityEditor; +using UnityEngine.UI; +using GTS.GlobalTextSystem.Tools; + +/// +/// Collection of tools and helpers for our global text system. +/// +namespace GTS.GlobalTextSystem.Libraries +{ + /// + /// Helper methods for changing one or all properties for one or all Text objects. + /// + public static class PropertyLibrary + { + // Self explanatory naming. + + public static void ChangeAllFonts() + { + ChangePropertyForAllText(StringLibrary.FONT); + } + + public static void ChangeAllFontStyle() + { + ChangePropertyForAllText(StringLibrary.FONT_STYLE); + } + + public static void ChangeAllFontSize() + { + ChangePropertyForAllText(StringLibrary.FONT_SIZE); + } + + public static void ChangeAllLineSpacing() + { + ChangePropertyForAllText(StringLibrary.LINE_SPACING); + } + + public static void ChangeAllRichText() + { + ChangePropertyForAllText(StringLibrary.RICH_TEXT); + } + + public static void ChangeAllAlignment() + { + ChangePropertyForAllText(StringLibrary.ALIGNMENT); + } + + public static void ChangeAllAlignByGeometry() + { + ChangePropertyForAllText(StringLibrary.ALIGN_BY_GEOMETRY); + } + + public static void ChangeAllHorizontalOverflow() + { + ChangePropertyForAllText(StringLibrary.HORIZONTAL_OVERFLOW); + } + + public static void ChangeAllVerticalOverflow() + { + ChangePropertyForAllText(StringLibrary.VERTICAL_OVERFLOW); + } + + public static void ChangeAllBestFit() + { + ChangePropertyForAllText(StringLibrary.BEST_FIT); + } + + /// + /// Currently does not use reflection. + /// + public static void ChangeAllColor() + { + var textSettings = GlobalTextSettings.TextSettings; + + if(textSettings == null) + { + return; + } + + var allTextObjects = GlobalTextSettings.AllTextObjects; + + foreach(Text t in allTextObjects) + { + Undo.RecordObject(t, "change color"); + t.SetFontColor(textSettings); + } + + } + + public static void ChangeAllMaterial() + { + ChangePropertyForAllText(StringLibrary.MATERIAL); + } + + public static void ChangeAllRaycastTarget() + { + ChangePropertyForAllText(StringLibrary.RAYCAST); + } + + /// + /// Change Every property of the Text to the saved TextData. + /// + public static void ChangeAllProperties(Text textObject) + { + var textSettings = GlobalTextSettings.TextSettings; + + if(textSettings == null) + { + return; + } + + Undo.RecordObject(textObject, "Change all properties"); + + textObject.SetFont(textSettings); + textObject.SetFontSize(textSettings); + textObject.SetFontSize(textSettings); + textObject.lineSpacing = textSettings.lineSpacing; + textObject.supportRichText = textSettings.supportRichText; + + textObject.alignment = textSettings.alignment; + textObject.alignByGeometry = textSettings.alignByGeometry; + textObject.horizontalOverflow = textSettings.horizontalOverflow; + textObject.verticalOverflow = textSettings.verticalOverflow; + textObject.resizeTextForBestFit = textSettings.resizeTextForBestFit; + + textObject.SetFontColor(textSettings); + textObject.material = textSettings.material; + textObject.raycastTarget = textSettings.raycastTarget; + } + + /// + /// Change Text property of this Text object based on property name. + /// + public static void ChangeProperty(this Text t, string key) + { + Undo.RecordObject(t, "change " + key); + var prop = t.GetType().GetProperty(key); + if(GlobalTextSettings.TextSettings.SavedSettings[key] == true) + { + var globalProp = GlobalTextSettings.TextSettings.GetType().GetProperty(key); + prop.SetValue(t, globalProp.GetValue(GlobalTextSettings.TextSettings, null), null); + } + } + + /// + /// Change Text property of every Text object based on property name. + /// + private static void ChangePropertyForAllText(string key) + { + var textSettings = GlobalTextSettings.TextSettings; + + if(textSettings == null) + { + return; + } + + var allTextObjects = GlobalTextSettings.AllTextObjects; + + foreach(Text t in allTextObjects) + { + t.ChangeProperty(key); + } + } + } +} diff --git a/Assets/GTS.GlobalTextSystem/Editor/Libraries/PropertyLibrary.cs.meta b/Assets/GTS.GlobalTextSystem/Editor/Libraries/PropertyLibrary.cs.meta new file mode 100644 index 0000000..e4d86ca --- /dev/null +++ b/Assets/GTS.GlobalTextSystem/Editor/Libraries/PropertyLibrary.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f918501a3ca41254da9cfcc0da4a527b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/GTS.GlobalTextSystem/Editor/Libraries/StringLibrary.cs b/Assets/GTS.GlobalTextSystem/Editor/Libraries/StringLibrary.cs new file mode 100644 index 0000000..584923c --- /dev/null +++ b/Assets/GTS.GlobalTextSystem/Editor/Libraries/StringLibrary.cs @@ -0,0 +1,106 @@ +/* +================================================================================ + Product: Unity-Set-Global_UI-Text_Font + Developer: GlassToeStudio@gmail.com + Source: https://github.com/GlassToeStudio/Unity-Set-Global-UI-Text-Font + Company: GlassToeStudio + Website: http://glasstoestudio.weebly.com/ + Date: June 19, 2018 +================================================================================= + MIT License +================================================================================ +*/ + +/// +/// Collection of tools and helpers for our global text system. +/// +namespace GTS.GlobalTextSystem.Libraries +{ + public class StringLibrary + { + /// The string KEY by which the EditorPrefs saves/loads GlobalFontData name. + public const string GLOBAL_FONT_KEY = "GlobalFontData"; + + /// The string which holds the save path for each GlobalFontData asset. + public const string SAVE_PATH = "/Editor Default Resources/GTS.GlobalTextSettings/"; + + /// Default Font, when not Font has been chosen, or could not be loaded. + public const string ARIAL = "Arial"; + + public const string CONTEXT_MENU_PATH = "CONTEXT/Text/"; + + public const string SYSTEM_MENU_PATH = "GameObject/Gloat Text/"; + + public const string WINDOW_TITLE = "Global Text System/Settings"; + + + #region Text Properties + + public const string FONT = "font"; + + public const string FONT_STYLE = "fontStyle"; + + public const string FONT_SIZE = "fontSize"; + + public const string LINE_SPACING = "lineSpacing"; + + public const string RICH_TEXT = "supportRichText"; + + public const string ALIGNMENT = "alignment"; + + public const string ALIGN_BY_GEOMETRY = "alignByGeometry"; + + public const string HORIZONTAL_OVERFLOW = "horizontalOverflow"; + + public const string VERTICAL_OVERFLOW = "verticalOverflow"; + + public const string BEST_FIT = "resizeTextForBestFit"; + + public const string TEXT_MIN = "resizeTextMinSize"; + + public const string TEXT_MAX = "resizeTextMaxSize"; + + public const string COLOR = "color"; + + public const string MATERIAL = "material"; + + public const string RAYCAST = "raycastTarget"; + + #endregion + + + #region menu headings + + private const string INTRO = "Set to global "; + + public const string MENU_FONT = INTRO + "FONT"; + + public const string MENU_FONT_STYLE = INTRO + "font STYLE"; + + public const string MENU_FONT_SIZE = INTRO + "font SIZE"; + + public const string MENU_LINE_SPACING = INTRO + "LINE SPACING"; + + public const string MENU_RICH_TEXT = INTRO + "RICH TEXT support"; + + public const string MENU_ALIGNMENT = INTRO + "ALIGNMENT"; + + public const string MENU_BY_GEOMETRY = INTRO + "align BY GEOMETRY"; + + public const string MENU_HORIZONTAL = INTRO + "HORIZONTAL overflow"; + + public const string MENU_VERTICAL = INTRO + "VERTICAL overflow"; + + public const string MENU_BEST_FIT = INTRO + "BEST FIT"; + + public const string MENU_FONT_COLOR = INTRO + "font COLOR"; + + public const string MENU_MATERIAL = INTRO + "MATERIAL"; + + public const string MENU_RAYCAST = INTRO + "RAYCAST option"; + + public const string MENU_SET_ALL = "Set to ALL global presets"; + + #endregion + } +} diff --git a/Assets/GTS.GlobalTextSystem/Editor/Libraries/StringLibrary.cs.meta b/Assets/GTS.GlobalTextSystem/Editor/Libraries/StringLibrary.cs.meta new file mode 100644 index 0000000..4a46944 --- /dev/null +++ b/Assets/GTS.GlobalTextSystem/Editor/Libraries/StringLibrary.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a215ed2722b224f4faffd8ec5b9a047c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/GTS.GlobalTextSystem/Editor/Libraries/TextExtensionsLibrary.cs b/Assets/GTS.GlobalTextSystem/Editor/Libraries/TextExtensionsLibrary.cs new file mode 100644 index 0000000..aafab46 --- /dev/null +++ b/Assets/GTS.GlobalTextSystem/Editor/Libraries/TextExtensionsLibrary.cs @@ -0,0 +1,462 @@ +/* +================================================================================ + Product: Unity-Set-Global_UI-Text_Font + Developer: GlassToeStudio@gmail.com + Source: https://github.com/GlassToeStudio/Unity-Set-Global-UI-Text-Font + Company: GlassToeStudio + Website: http://glasstoestudio.weebly.com/ + Date: June 19, 2018 +================================================================================= + MIT License +================================================================================ +*/ + +using System; +using UnityEngine; +using UnityEngine.UI; +using GTS.GlobalTextSystem.Data; + +/// +/// Collection of tools and helpers for our global text system. +/// +namespace GTS.GlobalTextSystem.Libraries +{ + /// + /// Various helper methods for the Text class. Too many really. + /// + public static class TextExtensionsLibrary + { + // Character + + #region SetFont() + + /// + /// Set the Font of this Text object with the passed in value. + /// + public static void SetFont(this Text t, Font font) + { + t.font = font; + } + /// + /// Set the Font of this Text object with the passed in value. + /// + public static void SetFont(this Text t, Text text) + { + t.SetFont(text.font); + } + /// + /// Set the Font of this Text object with the passed in value. + /// + public static void SetFont(this Text t, TextData fontData) + { + t.SetFont(fontData.font); + } + /// + /// Set the Font of this Text object with the passed in value. + /// + public static void SetFont(this Text t, T toValue) + { + t.SetFont(toValue as Font); + } + + #endregion + + #region SetFontStyle() + + /// + /// Set the FontStyle of this Text object with the passed in value. + /// + public static void SetFontStyle(this Text t, FontStyle fontStyle) + { + t.fontStyle = fontStyle; + } + /// + /// Set the FontStyle of this Text object with the passed in value. + /// + public static void SetFontStyle(this Text t, Text text) + { + t.SetFontStyle(text.fontStyle); + } + /// + /// Set the FontStyle of this Text object with the passed in value. + /// + public static void SetFontStyle(this Text t, TextData fontData) + { + t.SetFontStyle(fontData.fontStyle); + } + /// + /// Set the FontStyle of this Text object with the passed in value. + /// + public static void SetFontStyle(this Text t, T toValue) + { + t.SetFontStyle((FontStyle)Enum.Parse(typeof(T), toValue.ToString())); + } + + #endregion + + #region SetFontSize() + + /// + /// Set the FontSize of this Text object with the passed in value. + /// + public static void SetFontSize(this Text t, int fontSize) + { + t.fontSize = fontSize; + } + /// + /// Set the FontSize of this Text object with the passed in value. + /// + public static void SetFontSize(this Text t, Text text) + { + t.SetFontSize(text.fontSize); + } + /// + /// Set the FontSize of this Text object with the passed in value. + /// + public static void SetFontSize(this Text t, TextData fontData) + { + t.SetFontSize(fontData.fontSize); + } + /// + /// Set the FontSize of this Text object with the passed in value. + /// + public static void SetFontSize(this Text t, T toValue) + { + t.SetFontSize(Convert.ToInt32(toValue)); + } + + #endregion + + #region SetLineSpacing() + + /// + /// Set the Line Spacing of this Text object with the passed in value. + /// + public static void SetLineSpacing(this Text t, float lineSpacing) + { + t.lineSpacing = lineSpacing; + } + /// + /// Set the Line Spacing of this Text object with the passed in value. + /// + public static void SetLineSpacing(this Text t, Text text) + { + t.SetLineSpacing(text.lineSpacing); + } + /// + /// Set the Line Spacing of this Text object with the passed in value. + /// + public static void SetLineSpacing(this Text t, TextData fontData) + { + t.SetLineSpacing(fontData.lineSpacing); + } + /// + /// Set the Line Spacing of this Text object with the passed in value. + /// + public static void SetLineSpacing(this Text t, T toValue) + { + t.SetLineSpacing(Convert.ToSingle(toValue)); + } + + #endregion + + #region SetRichText() + + /// + /// Set supportRichText of this Text object with the passed in value. + /// + public static void SetRichText(this Text t, bool supportRichText) + { + t.supportRichText = supportRichText; + } + /// + /// Set supportRichText of this Text object with the passed in value. + /// + public static void SetRichText(this Text t, Text text) + { + t.SetRichText(text.supportRichText); + } + /// + /// Set supportRichText of this Text object with the passed in value. + /// + public static void SetRichText(this Text t, TextData fontData) + { + t.SetRichText(fontData.supportRichText); + } + /// + /// Set supportRichText of this Text object with the passed in value. + /// + public static void SetRichText(this Text t, T toValue) + { + t.SetRichText(Convert.ToBoolean(toValue)); + } + + #endregion + + // Paragraph + + #region SetAlignment() + + /// + /// Set alignment of this Text object with the passed in value. + /// + public static void SetAlignment(this Text t, TextAnchor textAnchor) + { + t.alignment = textAnchor; + } + /// + /// Set alignment of this Text object with the passed in value. + /// + public static void SetAlignment(this Text t, Text text) + { + t.SetAlignment(text.alignment); + } + /// + /// Set alignment of this Text object with the passed in value. + /// + public static void SetAlignment(this Text t, TextData fontData) + { + t.SetAlignment(fontData.alignment); + } + /// + /// Set alignment of this Text object with the passed in value. + /// + public static void SetAlignment(this Text t, T toValue) + { + t.SetAlignment((TextAnchor)Enum.Parse(typeof(T), toValue.ToString())); + } + + #endregion + + #region SetAlignByGeometry() + + /// + /// Set the alignment by geometry property of this Text object with the passed in value. + /// + public static void SetAlignByGeometry(this Text t, bool alignByGeometry) + { + t.alignByGeometry = alignByGeometry; + } + /// + /// Set the alignment by geometry property of this Text object with the passed in value. + /// + public static void SetAlignByGeometry(this Text t, Text text) + { + t.SetAlignByGeometry(text.alignByGeometry); + } + /// + /// Set the alignment by geometry property of this Text object with the passed in value. + /// + public static void SetAlignByGeometry(this Text t, TextData fontData) + { + t.SetAlignByGeometry(fontData.alignByGeometry); + } + /// + /// Set the alignment by geometry property of this Text object with the passed in value. + /// + public static void SetAlignByGeometry(this Text t, T toValue) + { + t.SetAlignByGeometry(Convert.ToBoolean(toValue)); + } + + #endregion + + #region SetHorizontalOverflow() + + /// + /// Set the horizontal overflow mode of this Text object with the passed in value. + /// + public static void SetHorizontalOverflow(this Text t, HorizontalWrapMode horizontalOverflow) + { + t.horizontalOverflow = horizontalOverflow; + } + /// + /// Set the horizontal overflow mode of this Text object with the passed in value. + /// + public static void SetHorizontalOverflow(this Text t, Text text) + { + t.SetHorizontalOverflow(text.horizontalOverflow); + } + /// + /// Set the horizontal overflow mode of this Text object with the passed in value. + /// + public static void SetHorizontalOverflow(this Text t, TextData fontData) + { + t.SetHorizontalOverflow(fontData.horizontalOverflow); + } + /// + /// Set the horizontal overflow mode of this Text object with the passed in value. + /// + public static void SetHorizontalOverflow(this Text t, T toValue) + { + t.SetHorizontalOverflow((HorizontalWrapMode)Enum.Parse(typeof(T), toValue.ToString())); + } + + #endregion + + #region SetVerticalOverflow() + + /// + /// Set the vertical overflow mode of this Text object with the passed in value. + /// + public static void SetVerticalOverflow(this Text t, VerticalWrapMode verticalOverflow) + { + t.verticalOverflow = verticalOverflow; + } + /// + /// Set the vertical overflow mode of this Text object with the passed in value. + /// + public static void SetVerticalOverflow(this Text t, Text text) + { + t.SetVerticalOverflow(text.verticalOverflow); + } + /// + /// Set the vertical overflow mode of this Text object with the passed in value. + /// + public static void SetVerticalOverflow(this Text t, TextData fontData) + { + t.SetVerticalOverflow(fontData.verticalOverflow); + } + /// + /// Set the vertical overflow mode of this Text object with the passed in value. + /// + public static void SetVerticalOverflow(this Text t, T toValue) + { + t.SetVerticalOverflow((VerticalWrapMode)Enum.Parse(typeof(T), toValue.ToString())); + } + + #endregion + + #region SetBestFit() + + /// + /// Set the resize for best fit property of this Text object with the passed in value. + /// + public static void SetBestFit(this Text t, bool resizeTextForBestFit) + { + t.resizeTextForBestFit = resizeTextForBestFit; + } + /// + /// Set the resize for best fit property of this Text object with the passed in value. + /// + public static void SetBestFit(this Text t, Text text) + { + t.SetBestFit(text.resizeTextForBestFit); + } + /// + /// Set the resize for best fit property of this Text object with the passed in value. + /// + public static void SetBestFit(this Text t, TextData fontData) + { + t.SetBestFit(fontData.resizeTextForBestFit); + } + /// + /// Set the resize for best fit property of this Text object with the passed in value. + /// + public static void SetBestFit(this Text t, T toValue) + { + t.SetBestFit(Convert.ToBoolean(toValue)); + } + + #endregion + + #region SetFontColor() + + /// + /// Set the Color of this Text object with the passed in value. + /// + public static void SetFontColor(this Text t, Color color) + { + t.color = color; + } + /// + /// Set the Color of this Text object with the passed in value. + /// + public static void SetFontColor(this Text t, Text text) + { + t.SetFontColor(text.color); + } + /// + /// Set the Color of this Text object with the passed in value. + /// + public static void SetFontColor(this Text t, TextData fontData) + { + t.SetFontColor(fontData.color); + } + /// + /// Set the Color of this Text object with the passed in value. + /// + public static void SetFontColor(this Text t, T toValue) + { + t.SetFontColor((Color)Convert.ChangeType(toValue, typeof(Color))); + } + + #endregion + + #region SetMaterial() + + /// + /// Set the material of this Text object with the passed in value. + /// + public static void SetMaterial(this Text t, Material material) + { + t.material = material; + } + /// + /// Set the material of this Text object with the passed in value. + /// + public static void SetMaterial(this Text t, Text text) + { + t.SetMaterial(text.material); + } + /// + /// Set the material of this Text object with the passed in value. + /// + public static void SetMaterial(this Text t, TextData fontData) + { + t.SetMaterial(fontData.material); + } + /// + /// Set the material of this Text object with the passed in value. + /// + public static void SetMaterial(this Text t, T toValue) + { + t.SetMaterial((Material)Convert.ChangeType(toValue, typeof(Material))); + } + + #endregion + + #region SetRaycastTarget() + + /// + /// Set the raycast target property of this Text object with the passed in value. + /// + public static void SetRaycastTarget(this Text t, bool raycastTarget) + { + t.raycastTarget = raycastTarget; + } + /// + /// Set the raycast target property of this Text object with the passed in value. + /// + public static void SetRaycastTarget(this Text t, Text text) + { + t.SetRaycastTarget(text.raycastTarget); + } + /// + /// Set the raycast target property of this Text object with the passed in value. + /// + public static void SetRaycastTarget(this Text t, TextData fontData) + { + t.SetRaycastTarget(fontData.raycastTarget); + } + /// + /// Set the raycast target property of this Text object with the passed in value. + /// + public static void SetRaycastTarget(this Text t, T toValue) + { + t.SetRaycastTarget(Convert.ToBoolean(toValue)); + } + + #endregion + } +} diff --git a/Assets/GTS.GlobalTextSystem/Editor/Libraries/TextExtensionsLibrary.cs.meta b/Assets/GTS.GlobalTextSystem/Editor/Libraries/TextExtensionsLibrary.cs.meta new file mode 100644 index 0000000..89dd233 --- /dev/null +++ b/Assets/GTS.GlobalTextSystem/Editor/Libraries/TextExtensionsLibrary.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0fe3eb7adce8845429e27330275c1ce7 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/GTS.GlobalTextSystem/Editor/Menus.meta b/Assets/GTS.GlobalTextSystem/Editor/Menus.meta new file mode 100644 index 0000000..de03e11 --- /dev/null +++ b/Assets/GTS.GlobalTextSystem/Editor/Menus.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 51c0130b287117449ae8cb3b5f11b847 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/GTS.GlobalTextSystem/Editor/Menus/ContextMenus.cs b/Assets/GTS.GlobalTextSystem/Editor/Menus/ContextMenus.cs new file mode 100644 index 0000000..962e6de --- /dev/null +++ b/Assets/GTS.GlobalTextSystem/Editor/Menus/ContextMenus.cs @@ -0,0 +1,128 @@ +/*StringLibrary.CONTEXT_MENU_PATH +================================================================================ + Product: Unity-Set-Global_UI-Text_Font + Developer: GlassToeStudio@gmail.com + Source: https://github.com/GlassToeStudio/Unity-Set-Global-UI-Text-Font + Company: GlassToeStudio + Website: http://glasstoestudio.weebly.com/ + Date: June 19, 2018 +================================================================================= + MIT License +================================================================================ +*/ + +using UnityEditor; +using UnityEngine.UI; +using GTS.GlobalTextSystem.Libraries; + +/// +/// Menus for controlling the properties of one or all Text objects. +/// +namespace GTS.GlobalTextSystem.Menus +{ + class ContextMenus + { + + #region Context MenuItems + + [MenuItem(StringLibrary.CONTEXT_MENU_PATH + StringLibrary.MENU_FONT)] + private static void SetToGlobalFont(MenuCommand menuCommand) + { + var thisText = menuCommand.context as Text; + thisText.ChangeProperty(StringLibrary.FONT); + } + + [MenuItem(StringLibrary.CONTEXT_MENU_PATH + StringLibrary.MENU_FONT_STYLE)] + private static void SetToGlobalFontStyle(MenuCommand menuCommand) + { + var thisText = menuCommand.context as Text; + thisText.ChangeProperty(StringLibrary.FONT_STYLE); + } + + [MenuItem(StringLibrary.CONTEXT_MENU_PATH + StringLibrary.MENU_FONT_SIZE)] + private static void SetToGlobalFontSize(MenuCommand menuCommand) + { + var thisText = menuCommand.context as Text; + thisText.ChangeProperty(StringLibrary.FONT_SIZE); + } + + [MenuItem(StringLibrary.CONTEXT_MENU_PATH + StringLibrary.MENU_LINE_SPACING)] + private static void SetToGlobalLineSpacing(MenuCommand menuCommand) + { + var thisText = menuCommand.context as Text; + thisText.ChangeProperty(StringLibrary.LINE_SPACING); + } + + [MenuItem(StringLibrary.CONTEXT_MENU_PATH + StringLibrary.MENU_RICH_TEXT)] + private static void SetToGlobalRichTextSupport(MenuCommand menuCommand) + { + var thisText = menuCommand.context as Text; + thisText.ChangeProperty(StringLibrary.RICH_TEXT); + } + + [MenuItem(StringLibrary.CONTEXT_MENU_PATH + StringLibrary.MENU_ALIGNMENT)] + private static void SetToGlobalalignment(MenuCommand menuCommand) + { + var thisText = menuCommand.context as Text; + thisText.ChangeProperty(StringLibrary.ALIGNMENT); + } + + [MenuItem(StringLibrary.CONTEXT_MENU_PATH + StringLibrary.MENU_BY_GEOMETRY)] + private static void SetToGlobalAlignByGeometry(MenuCommand menuCommand) + { + var thisText = menuCommand.context as Text; + thisText.ChangeProperty(StringLibrary.ALIGN_BY_GEOMETRY); + } + + [MenuItem(StringLibrary.CONTEXT_MENU_PATH + StringLibrary.MENU_HORIZONTAL)] + private static void SetToGlobalHorizontalOverflow(MenuCommand menuCommand) + { + var thisText = menuCommand.context as Text; + thisText.ChangeProperty(StringLibrary.HORIZONTAL_OVERFLOW); + } + + [MenuItem(StringLibrary.CONTEXT_MENU_PATH + StringLibrary.MENU_VERTICAL)] + private static void SetToGlobalVerticalOverflow(MenuCommand menuCommand) + { + var thisText = menuCommand.context as Text; + thisText.ChangeProperty(StringLibrary.VERTICAL_OVERFLOW); + } + + [MenuItem(StringLibrary.CONTEXT_MENU_PATH + StringLibrary.MENU_BEST_FIT)] + private static void SetToGlobalBestFit(MenuCommand menuCommand) + { + var thisText = menuCommand.context as Text; + thisText.ChangeProperty(StringLibrary.BEST_FIT); + } + + [MenuItem(StringLibrary.CONTEXT_MENU_PATH + StringLibrary.MENU_FONT_COLOR)] + private static void SetToGlobalColor(MenuCommand menuCommand) + { + var thisText = menuCommand.context as Text; + thisText.ChangeProperty(StringLibrary.COLOR); + } + + [MenuItem(StringLibrary.CONTEXT_MENU_PATH + StringLibrary.MENU_MATERIAL)] + private static void SetToGlobalMaterial(MenuCommand menuCommand) + { + var thisText = menuCommand.context as Text; + thisText.ChangeProperty(StringLibrary.MATERIAL); + } + + [MenuItem(StringLibrary.CONTEXT_MENU_PATH + StringLibrary.MENU_RAYCAST)] + private static void SetToGlobalRaycastOption(MenuCommand menuCommand) + { + var thisText = menuCommand.context as Text; + thisText.ChangeProperty(StringLibrary.RAYCAST); + } + + [MenuItem(StringLibrary.CONTEXT_MENU_PATH +StringLibrary.MENU_SET_ALL, false, 110)] + private static void ChangeToAllGlobalPresets(MenuCommand menuCommand) + { + var thisText = menuCommand.context as Text; + PropertyLibrary.ChangeAllProperties(thisText); + } + + #endregion + } +} diff --git a/Assets/GTS.GlobalTextSystem/Editor/Menus/ContextMenus.cs.meta b/Assets/GTS.GlobalTextSystem/Editor/Menus/ContextMenus.cs.meta new file mode 100644 index 0000000..137088b --- /dev/null +++ b/Assets/GTS.GlobalTextSystem/Editor/Menus/ContextMenus.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: dfa424026fbb6094d9695e9295e51995 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/GTS.GlobalTextSystem/Editor/Menus/GlobalTextSettingsWindow.cs b/Assets/GTS.GlobalTextSystem/Editor/Menus/GlobalTextSettingsWindow.cs new file mode 100644 index 0000000..5f0646d --- /dev/null +++ b/Assets/GTS.GlobalTextSystem/Editor/Menus/GlobalTextSettingsWindow.cs @@ -0,0 +1,314 @@ +/* +================================================================================ + Product: Unity-Set-Global_UI-Text_Font + Developer: GlassToeStudio@gmail.com + Source: https://github.com/GlassToeStudio/Unity-Set-Global-UI-Text-Font + Company: GlassToeStudio + Website: http://glasstoestudio.weebly.com/ + Date: June 19, 2018 +================================================================================= + MIT License +================================================================================ +*/ + +using UnityEngine; +using UnityEditor; +using GTS.GlobalTextSystem.Tools; +using GTS.GlobalTextSystem.Libraries; + +/// +/// Menus for controlling the properties of one or all Text objects. +/// +namespace GTS.GlobalTextSystem.Menus +{ + /// + /// Custom Window to adjust all Text in the scene. + /// + public class GlobalTextSettingsWindow : EditorWindow + { + /// Name of the current Text asset, to be displayed in the Window. + private static string fontDisplayName = StringLibrary.ARIAL; + + public static HierarchyListener hierarchyListener { private get; set; } + + /// + /// Show and initialize the custom Global Text Settings window.. + /// + [MenuItem(StringLibrary.WINDOW_TITLE)] + private static void ShowWindow() + { + GlobalTextSettingsWindow w = GetWindow(true, "Global Text Settings", true); + + w.minSize = new Vector2(200, 400); + w.maxSize = new Vector2(200, 400); + + //w.autoRepaintOnSceneChange = true; + + GlobalTextSettings.UpdateTextObjects(); + + // Display current Font name. + if(GlobalTextSettings.TextSettings != null) + { + if(GlobalTextSettings.TextSettings.font != null) + { + fontDisplayName = GlobalTextSettings.TextSettings.font.name; + } + } + else + { + fontDisplayName = StringLibrary.ARIAL; + } + } + + /// + /// Draw the window and its components. Listen for Button Clicks. + /// + private void OnGUI() + { + // Show Global Font Name + EditorGUILayout.LabelField("Global Font: ", fontDisplayName); + + ResetFontButton(); + + SelectFont(); + + OnFontSelectorClosed(); + + ChangeAllFontsButton(); + + ChangeAllFontsColorRealTime(); + + ChangeAllFontSizeButton(); + + CloseWindowButton(); + + //TODO: Debug Only + DeletePrefsButton(); + + + } + + /// + /// Listens for ObjectSelectorClosed Event. Will Get/Set the global font. + /// + private void OnFontSelectorClosed() + { + if(Event.current.commandName == "ObjectSelectorClosed") + { + if(EditorGUIUtility.GetObjectPickerObject() != null) + { + var selectedFont = (Font)EditorGUIUtility.GetObjectPickerObject(); + + if(selectedFont == null) + { + Debug.LogError("No Font Assets Found!"); + } + + SetGlobalFontData(selectedFont); + + fontDisplayName = selectedFont.name; + } + + RepaintAll(); + + // May or may not be listening, depending on the Text asset that is chosen. + hierarchyListener.Listen(); + } + } + + /// + /// Checks if a TextData assets is created, else it creates one. + /// + private void SetGlobalFontData(Font selectedFont) + { + GlobalTextSettings.TextSettings = AssetProcessor.SetGlobalFont(selectedFont); + GlobalTextSettings.UpdateProperties(); + RepaintAll(); + } + + + #region buttons + + /// + /// Reset to Unity's standard font, "Arial". + /// + private void ResetFontButton() + { + EditorGUILayout.Space(); + + if(GUILayout.Button("Reset Font")) + { + var selctedFont = StringLibrary.ARIAL; + + AssetProcessor.CreateDefaultTextAsset(); + GlobalTextSettings.TextSettings = AssetProcessor.LoadTextAsset(selctedFont); + + hierarchyListener.Listen(); + + fontDisplayName = selctedFont; + RepaintAll(); + } + } + + /// + /// Open a Font selector and select a Font to use for the Text Asset Settings. + /// + private void SelectFont() + { + EditorGUILayout.Space(); + + GUILayout.Label("Select Font"); + + if(GlobalTextSettings.TextSettings != null) + { + EditorGUILayout.ObjectField(GlobalTextSettings.TextSettings.font, typeof(Font), true); + RepaintAll(); + } + else + { + EditorGUILayout.ObjectField(null, typeof(Font), true); + RepaintAll(); + } + } + + /// + /// Change the fonts of all Text Objects in the scene. + /// + private void ChangeAllFontsButton() + { + EditorGUILayout.Space(); + + if(GUILayout.Button("Change All Fonts In Scene")) + { + PropertyLibrary.ChangeAllFonts(); + RepaintAll(); + } + + } + + /// + /// Change the font color of all Text objects in the scene, in real-time. + /// + private void ChangeAllFontsColorRealTime() + { + EditorGUILayout.Space(); + + GUILayout.Label("Change All Fonts Color In Scene"); + Selection.activeObject = GlobalTextSettings.TextSettings; + if(GlobalTextSettings.TextSettings != null) + { + // Allows us to use the Color Picker to change color. + if(Event.current.commandName == "ColorPickerChanged") + { + GlobalTextSettings.TextSettings.color = EditorGUILayout.ColorField(GlobalTextSettings.TextSettings.color); + + PropertyLibrary.ChangeAllColor(); + } + // Allows us to use the dropper to change color. + else if(Event.current.commandName == "EyeDropperClicked") + { + GlobalTextSettings.TextSettings.color = EditorGUILayout.ColorField(GlobalTextSettings.TextSettings.color); + + PropertyLibrary.ChangeAllColor(); + } + else + { + // Do not change color when a new TextData is loaded. + EditorGUILayout.ColorField(GlobalTextSettings.TextSettings.color); + } + RepaintAll(); + } + else + { + // No TextData, show Black. + EditorGUILayout.ColorField(Color.black); + RepaintAll(); + } + + + } + + /// + /// Change the FontSize of every Text in the scene. + /// + private void ChangeAllFontSizeButton() + { + EditorGUILayout.Space(); + + if(GUILayout.Button("Change All Fonts Size In Scene")) + { + PropertyLibrary.ChangeAllFontSize(); + RepaintAll(); + } + + if(GlobalTextSettings.TextSettings != null) + { + GlobalTextSettings.TextSettings.fontSize = EditorGUILayout.IntField(GlobalTextSettings.TextSettings.fontSize); + } + else + { + EditorGUILayout.IntField(0); + } + } + + /// + /// Close this window + /// + private void CloseWindowButton() + { + EditorGUILayout.Space(); + + if(GUILayout.Button("Close")) + { + RepaintAll(); + this.Close(); + } + + } + + /// + /// TODO: Need to figure out what to repaint... + /// Make sure we repaint when changes happen... + /// + private void RepaintAll() + { + if(SceneView.lastActiveSceneView != null) + { + SceneView.lastActiveSceneView.Repaint(); + } + if(SceneView.currentDrawingSceneView != null) + { + SceneView.currentDrawingSceneView.Repaint(); + } + + SceneView.RepaintAll(); + EditorApplication.RepaintAnimationWindow(); + EditorApplication.RepaintHierarchyWindow(); + EditorApplication.RepaintProjectWindow(); + + UnityEditorInternal.InternalEditorUtility.RepaintAllViews(); + + Repaint(); + } + + #endregion + + #region debug + + /// + /// Debug Only: Delete EditorPrefs. + /// + private void DeletePrefsButton() + { + EditorGUILayout.Space(); + + if(GUILayout.Button("Delete Editor Prefs")) + { + EditorPrefs.SetString(StringLibrary.GLOBAL_FONT_KEY, string.Empty); + RepaintAll(); + } + } + + #endregion + } +} \ No newline at end of file diff --git a/Assets/GTS.GlobalTextSystem/Editor/Menus/GlobalTextSettingsWindow.cs.meta b/Assets/GTS.GlobalTextSystem/Editor/Menus/GlobalTextSettingsWindow.cs.meta new file mode 100644 index 0000000..05eb673 --- /dev/null +++ b/Assets/GTS.GlobalTextSystem/Editor/Menus/GlobalTextSettingsWindow.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 3768b3c145a908b48903d012a6f7e173 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/GTS.GlobalTextSystem/Editor/Menus/SystemMenus.cs b/Assets/GTS.GlobalTextSystem/Editor/Menus/SystemMenus.cs new file mode 100644 index 0000000..250a96e --- /dev/null +++ b/Assets/GTS.GlobalTextSystem/Editor/Menus/SystemMenus.cs @@ -0,0 +1,226 @@ +/* +================================================================================ + Product: Unity-Set-Global_UI-Text_Font + Developer: GlassToeStudio@gmail.com + Source: https://github.com/GlassToeStudio/Unity-Set-Global-UI-Text-Font + Company: GlassToeStudio + Website: http://glasstoestudio.weebly.com/ + Date: June 19, 2018 +================================================================================= + MIT License +================================================================================ +*/ + +using UnityEditor; +using UnityEngine; +using UnityEngine.UI; +using GTS.GlobalTextSystem.Libraries; + +/// +/// Menus for controlling the properties of one or all Text objects. +/// +namespace GTS.GlobalTextSystem.Menus +{ + class SystemMenus + { + #region Menu Items + + [MenuItem(StringLibrary.SYSTEM_MENU_PATH + StringLibrary.MENU_SET_ALL, priority = 138)] + private static void SetTextToCustom() + { + PropertyLibrary.ChangeAllProperties(Selection.activeGameObject.GetComponent()); + } + + [MenuItem(StringLibrary.SYSTEM_MENU_PATH + StringLibrary.MENU_FONT)] + private static void SetTextToGlobalFont() + { + var thisText = Selection.activeGameObject.GetComponent(); + thisText.ChangeProperty(StringLibrary.FONT); + } + + [MenuItem(StringLibrary.SYSTEM_MENU_PATH + StringLibrary.MENU_FONT_STYLE)] + private static void SetToGlobalFontStyle() + { + var thisText = Selection.activeGameObject.GetComponent(); + thisText.ChangeProperty(StringLibrary.FONT_STYLE); + } + + [MenuItem(StringLibrary.SYSTEM_MENU_PATH + StringLibrary.MENU_FONT_SIZE)] + private static void SetToGlobalFontSize() + { + var thisText = Selection.activeGameObject.GetComponent(); + thisText.ChangeProperty(StringLibrary.FONT_SIZE); + } + + [MenuItem(StringLibrary.SYSTEM_MENU_PATH + StringLibrary.MENU_LINE_SPACING)] + private static void SetToGlobalLineSpacing() + { + var thisText = Selection.activeGameObject.GetComponent(); + thisText.ChangeProperty(StringLibrary.LINE_SPACING); + } + + [MenuItem(StringLibrary.SYSTEM_MENU_PATH + StringLibrary.MENU_RICH_TEXT)] + private static void SetToGlobalRichTextSupport() + { + var thisText = Selection.activeGameObject.GetComponent(); + thisText.ChangeProperty(StringLibrary.RICH_TEXT); + } + + [MenuItem(StringLibrary.SYSTEM_MENU_PATH + StringLibrary.MENU_ALIGNMENT)] + private static void SetToGlobalalignment() + { + var thisText = Selection.activeGameObject.GetComponent(); + thisText.ChangeProperty(StringLibrary.ALIGNMENT); + } + + [MenuItem(StringLibrary.SYSTEM_MENU_PATH + StringLibrary.MENU_BY_GEOMETRY)] + private static void SetToGlobalAlignByGeometry() + { + var thisText = Selection.activeGameObject.GetComponent(); + thisText.ChangeProperty(StringLibrary.ALIGN_BY_GEOMETRY); + } + + [MenuItem(StringLibrary.SYSTEM_MENU_PATH + StringLibrary.MENU_HORIZONTAL)] + private static void SetToGlobalHorizontalOverflow() + { + var thisText = Selection.activeGameObject.GetComponent(); + thisText.ChangeProperty(StringLibrary.HORIZONTAL_OVERFLOW); + } + + [MenuItem(StringLibrary.SYSTEM_MENU_PATH + StringLibrary.MENU_VERTICAL)] + private static void SetToGlobalVerticalOverflow() + { + var thisText = Selection.activeGameObject.GetComponent(); + thisText.ChangeProperty(StringLibrary.VERTICAL_OVERFLOW); + } + + [MenuItem(StringLibrary.SYSTEM_MENU_PATH + StringLibrary.MENU_BEST_FIT)] + private static void SetToGlobalBestFit() + { + var thisText = Selection.activeGameObject.GetComponent(); + thisText.ChangeProperty(StringLibrary.BEST_FIT); + } + + [MenuItem(StringLibrary.SYSTEM_MENU_PATH + StringLibrary.MENU_FONT_COLOR)] + private static void SetToGlobalColor() + { + var thisText = Selection.activeGameObject.GetComponent(); + thisText.ChangeProperty(StringLibrary.COLOR); + } + + [MenuItem(StringLibrary.SYSTEM_MENU_PATH + StringLibrary.MENU_MATERIAL)] + private static void SetToGlobalMaterial() + { + var thisText = Selection.activeGameObject.GetComponent(); + thisText.ChangeProperty(StringLibrary.MATERIAL); + } + + [MenuItem(StringLibrary.SYSTEM_MENU_PATH + StringLibrary.MENU_RAYCAST)] + private static void SetToGlobalRaycastOption() + { + var thisText = Selection.activeGameObject.GetComponent(); + thisText.ChangeProperty(StringLibrary.RAYCAST); + } + + #endregion + + + #region menu item validators + + [MenuItem(StringLibrary.SYSTEM_MENU_PATH + StringLibrary.MENU_SET_ALL, priority = 138, validate = true)] + private static bool SetTextToCustomValidator() + { + return isTextObject(); + } + + [MenuItem(StringLibrary.SYSTEM_MENU_PATH + StringLibrary.MENU_FONT, priority = 138, validate = true)] + private static bool SetTextToGlobalFontValidator() + { + return isTextObject(); + } + + [MenuItem(StringLibrary.SYSTEM_MENU_PATH + StringLibrary.MENU_FONT_STYLE, priority = 138, validate = true)] + private static bool SetToGlobalFontStyleValidator() + { + return isTextObject(); + } + + [MenuItem(StringLibrary.SYSTEM_MENU_PATH + StringLibrary.MENU_FONT_SIZE, priority = 138, validate = true)] + private static bool SetToGlobalFontSizeValidator() + { + return isTextObject(); + } + + [MenuItem(StringLibrary.SYSTEM_MENU_PATH + StringLibrary.MENU_LINE_SPACING, priority = 138, validate = true)] + private static bool SetToGlobalLineSpacingValidator() + { + return isTextObject(); + } + + [MenuItem(StringLibrary.SYSTEM_MENU_PATH + StringLibrary.MENU_RICH_TEXT, priority = 138, validate = true)] + private static bool SetToGlobalRichTextSupportValidator() + { + return isTextObject(); + } + + [MenuItem(StringLibrary.SYSTEM_MENU_PATH + StringLibrary.MENU_ALIGNMENT, priority = 138, validate = true)] + private static bool SetToGlobalalignmentValidator() + { + return isTextObject(); + } + + [MenuItem(StringLibrary.SYSTEM_MENU_PATH + StringLibrary.MENU_BY_GEOMETRY, priority = 138, validate = true)] + private static bool SetToGlobalAlignByGeometryValidator() + { + return isTextObject(); + } + + [MenuItem(StringLibrary.SYSTEM_MENU_PATH + StringLibrary.MENU_HORIZONTAL, priority = 138, validate = true)] + private static bool SetToGlobalHorizontalOverflowValidator() + { + return isTextObject(); + } + + [MenuItem(StringLibrary.SYSTEM_MENU_PATH + StringLibrary.MENU_VERTICAL, priority = 138, validate = true)] + private static bool SetToGlobalVerticalOverflowValidator() + { + return isTextObject(); + } + + [MenuItem(StringLibrary.SYSTEM_MENU_PATH + StringLibrary.MENU_BEST_FIT, priority = 138, validate = true)] + private static bool SetToGlobalBestFitValidator() + { + return isTextObject(); + } + + [MenuItem(StringLibrary.SYSTEM_MENU_PATH + StringLibrary.MENU_FONT_COLOR, priority = 138, validate = true)] + private static bool SetToGlobalColorValidator() + { + return isTextObject(); + + } + + [MenuItem(StringLibrary.SYSTEM_MENU_PATH + StringLibrary.MENU_MATERIAL, priority = 138, validate = true)] + private static bool SetToGlobalMaterialValidator() + { + return isTextObject(); + } + + [MenuItem(StringLibrary.SYSTEM_MENU_PATH + StringLibrary.MENU_RAYCAST, priority = 138, validate = true)] + private static bool SetToGlobalRaycastOptionValidator() + { + return isTextObject(); + } + + #endregion + + private static bool isTextObject() + { + if(Selection.activeGameObject == null) + { + return false; + } + return (Selection.activeGameObject.GetComponent() != null); + } + } +} diff --git a/Assets/GTS.GlobalTextSystem/Editor/Menus/SystemMenus.cs.meta b/Assets/GTS.GlobalTextSystem/Editor/Menus/SystemMenus.cs.meta new file mode 100644 index 0000000..05eb708 --- /dev/null +++ b/Assets/GTS.GlobalTextSystem/Editor/Menus/SystemMenus.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 10ea208f45a547b479754794c84a7173 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/GTS.GlobalTextSystem/Editor/Tools.meta b/Assets/GTS.GlobalTextSystem/Editor/Tools.meta new file mode 100644 index 0000000..e18f66b --- /dev/null +++ b/Assets/GTS.GlobalTextSystem/Editor/Tools.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: a7dc94239ef418245b678af2f4c7cb3c +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/GTS.GlobalTextSystem/Editor/Tools/AssetProcessor.cs b/Assets/GTS.GlobalTextSystem/Editor/Tools/AssetProcessor.cs new file mode 100644 index 0000000..ac9ab6f --- /dev/null +++ b/Assets/GTS.GlobalTextSystem/Editor/Tools/AssetProcessor.cs @@ -0,0 +1,107 @@ +/* +================================================================================ + Product: Unity-Set-Global_UI-Text_Font + Developer: GlassToeStudio@gmail.com + Source: https://github.com/GlassToeStudio/Unity-Set-Global-UI-Text-Font + Company: GlassToeStudio + Website: http://glasstoestudio.weebly.com/ + Date: June 19, 2018 +================================================================================= + MIT License +================================================================================ +*/ + +using System.IO; +using UnityEngine; +using UnityEditor; +using GTS.GlobalTextSystem.Data; +using GTS.GlobalTextSystem.Libraries; + +/// +/// Collection of tools and helpers for our global text system. +/// +namespace GTS.GlobalTextSystem.Tools +{ + /// + /// Some utility functions to Load, Save, and Create TextData assets. + /// + public static class AssetProcessor + { + #region public methods + + /// + /// Set the passed in Font as the Global Font and create a TextData asset. + /// Return the the TextData asset of the same name. + /// + public static TextData SetGlobalFont(Font selectedFont) + { + if(!FileExists(selectedFont.name)) + { + SaveFontAsset(selectedFont); + } + + EditorPrefs.SetString(StringLibrary.GLOBAL_FONT_KEY, selectedFont.name); + + return LoadTextAsset(selectedFont.name); + } + + /// + /// Load a TextData object from StringLibrary.SAVE_PATH + /// + public static TextData LoadTextAsset(string assetName) + { + TextData data = (TextData)EditorGUIUtility.Load( + string.Format( + "{0}{1}{2}{3}", "Assets", StringLibrary.SAVE_PATH, assetName, ".asset") + ); + + return data; + } + + #endregion + + + #region private methods + + /// + /// Check if the current TextData asset exists. + /// + private static bool FileExists(string fileName) + { + return File.Exists(string.Format("{0}{1}{2}.asset", Application.dataPath, StringLibrary.SAVE_PATH, fileName)); + } + + /// + /// Create a TextData asset from the passed in Font, and save the name in EditorPrefs. + /// + private static void SaveFontAsset(Font font) + { + EditorPrefs.SetString(StringLibrary.GLOBAL_FONT_KEY, font.name); + + var fontDataAsset = ScriptableObject.CreateInstance(); + + fontDataAsset.font = font; + + AssetDatabase.CreateAsset( + fontDataAsset, + string.Format( + "{0}{1}{2}.asset", "Assets", StringLibrary.SAVE_PATH, font.name) + ); + + AssetDatabase.SaveAssets(); + + AssetDatabase.Refresh(); + } + + /// + /// Create a FontAsset for built-in Arial font. + /// + public static void CreateDefaultTextAsset() + { + Font f = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font; + SaveFontAsset(f); + } + + #endregion + } +} \ No newline at end of file diff --git a/Assets/GTS.GlobalTextSystem/Editor/Tools/AssetProcessor.cs.meta b/Assets/GTS.GlobalTextSystem/Editor/Tools/AssetProcessor.cs.meta new file mode 100644 index 0000000..616f71f --- /dev/null +++ b/Assets/GTS.GlobalTextSystem/Editor/Tools/AssetProcessor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 66820c555d235a94fb300b52f136d4db +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/GTS.GlobalTextSystem/Editor/Tools/GlobalTextSettings.cs b/Assets/GTS.GlobalTextSystem/Editor/Tools/GlobalTextSettings.cs new file mode 100644 index 0000000..e82f971 --- /dev/null +++ b/Assets/GTS.GlobalTextSystem/Editor/Tools/GlobalTextSettings.cs @@ -0,0 +1,58 @@ +/* +================================================================================ + Product: Unity-Set-Global_UI-Text_Font + Developer: GlassToeStudio@gmail.com + Source: https://github.com/GlassToeStudio/Unity-Set-Global-UI-Text-Font + Company: GlassToeStudio + Website: http://glasstoestudio.weebly.com/ + Date: June 19, 2018 +================================================================================= + MIT License +================================================================================ +*/ + +using UnityEngine; +using UnityEngine.UI; +using System.Reflection; +using GTS.GlobalTextSystem.Data; + +/// +/// Small System that provides useful functionality to Unity's UI Text system. +/// +namespace GTS.GlobalTextSystem.Tools +{ + /// + /// Holds static references for our GlobalTextAsset and Text Objects. + /// + public class GlobalTextSettings + { + /// The Global Data to apply to all Text objects. + public static TextData TextSettings { get; set; } + + public static PropertyInfo[] Properties; + + /// Always up-to-date list of all Text objects in the scene. + public static object[] AllTextObjects { get; set; } + + /// + /// Holds static references for our GlobalTextAsset and Text Objects. + /// + public GlobalTextSettings(TextData textSettings, object[] allTextObjects) + { + TextSettings = textSettings; + AllTextObjects = allTextObjects; + + Properties = TextSettings.GetType().GetProperties(); + } + + public static void UpdateProperties() + { + Properties = TextSettings.GetType().GetProperties(); + } + + public static void UpdateTextObjects() + { + AllTextObjects = Resources.FindObjectsOfTypeAll(typeof(Text)); + } + } +} \ No newline at end of file diff --git a/Assets/GTS.GlobalTextSystem/Editor/Tools/GlobalTextSettings.cs.meta b/Assets/GTS.GlobalTextSystem/Editor/Tools/GlobalTextSettings.cs.meta new file mode 100644 index 0000000..ec47028 --- /dev/null +++ b/Assets/GTS.GlobalTextSystem/Editor/Tools/GlobalTextSettings.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8ebad3adf9805ad40a52c66d2596f9d7 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/GTS.GlobalTextSystem/Editor/Tools/HierarchyListener.cs b/Assets/GTS.GlobalTextSystem/Editor/Tools/HierarchyListener.cs new file mode 100644 index 0000000..b9a5aa8 --- /dev/null +++ b/Assets/GTS.GlobalTextSystem/Editor/Tools/HierarchyListener.cs @@ -0,0 +1,159 @@ +/* +================================================================================ + Product: Unity-Set-Global_UI-Text_Font + Developer: GlassToeStudio@gmail.com + Source: https://github.com/GlassToeStudio/Unity-Set-Global-UI-Text-Font + Company: GlassToeStudio + Website: http://glasstoestudio.weebly.com/ + Date: June 19, 2018 +================================================================================= + MIT License +================================================================================ +*/ + +using UnityEngine; +using UnityEditor; +using UnityEngine.UI; +using GTS.GlobalTextSystem.Libraries; + +/// +/// Small System that provides useful functionality to Unity's UI Text system. +/// +namespace GTS.GlobalTextSystem.Tools +{ + /// + /// Listen for the creation of new Text objects, change their font to the global font. + /// + public class HierarchyListener + { + /// True when listening for hierarchy changes. + private bool isListening = false; + private bool justHeard = false; + + /// + /// Listen for new text objects to be created, as long as we have some global data saved. + /// + public void Listen() + { + // Nothing to change the font to + if(GlobalTextSettings.TextSettings == null) + { + StopListening(); + return; + } + + // No need to listen of the default font is Arial + //if(GlobalTextSettings.TextSettings.name == StringLibrary.ARIAL) + //{ + // StopListening(); + // return; + //} + + StartListening(); + } + + #region event + + /// + /// Get newly created Text asset and get/set its font. + /// + private void OnHierarchyChanged() + { + // For some reason, OnHierarchyChanged is called twice. + if(justHeard == true) + { + justHeard = false; + return; + } + + justHeard = true; + + // Do not run while in play mode! + if(Application.isEditor && !Application.isPlaying) + { + if(!IsValidObject() || GlobalTextSettings.TextSettings == null) + { + return; + } + + // New text object created, update the static list of all Text objects. + GlobalTextSettings.UpdateTextObjects(); + + var newText = Selection.activeGameObject.GetComponentInChildren(true); + + foreach(var key in GlobalTextSettings.TextSettings.SavedSettings.Keys) + { + newText.ChangeProperty(key); + } + } + } + + #endregion + + + + #region private methods + + /// + /// Subscribe to the hierarchyChanged Event. isListening = true; + /// + private void StartListening() + { + if(!isListening) + { + #if UNITY_2018_1_OR_NEWER + EditorApplication.hierarchyChanged += OnHierarchyChanged; + + #else + EditorApplication.hierarchyWindowChanged += OnHierarchyChanged; + + #endif + + isListening = true; + } + } + + /// + /// Un-subscribe from the hierarchyChanged Event. isListening = false; + /// + private void StopListening() + { + if(isListening) + { + #if UNITY_2018_1_OR_NEWER + EditorApplication.hierarchyChanged -= OnHierarchyChanged; + + #else + EditorApplication.hierarchyWindowChanged -= OnHierarchyChanged; + + #endif + + isListening = false; + } + } + + /// + /// Checks that we have a created object (we could be deleting objects) + /// and that the object, or its children, have Text. + /// + private bool IsValidObject() + { + if(Selection.activeGameObject == null) + { + // We deleted an object update the static list of all Text objects. + GlobalTextSettings.UpdateTextObjects(); + + return false; + } + + if(Selection.activeGameObject.GetComponentInChildren(true) == null) + { + return false; + } + + return true; + } + + #endregion + } +} \ No newline at end of file diff --git a/Assets/GTS.GlobalTextSystem/Editor/Tools/HierarchyListener.cs.meta b/Assets/GTS.GlobalTextSystem/Editor/Tools/HierarchyListener.cs.meta new file mode 100644 index 0000000..1a67ebb --- /dev/null +++ b/Assets/GTS.GlobalTextSystem/Editor/Tools/HierarchyListener.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: cd6934d1b469bdd43b25f5eda49e858a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/GTS.GlobalUIFont/Editor/FontData.cs b/Assets/GTS.GlobalUIFont/Editor/FontData.cs deleted file mode 100644 index 2d32faf..0000000 --- a/Assets/GTS.GlobalUIFont/Editor/FontData.cs +++ /dev/null @@ -1,49 +0,0 @@ -/* -================================================================================ - Product: Unity-Set-Global_UI-Text_Font - Developer: GlassToeStudio@gmail.com - Source: https://github.com/GlassToeStudio/Unity-Set-Global-UI-Text-Font - Company: GlassToeStudio - Website: http://glasstoestudio.weebly.com/ - Date: June 19, 2018 -================================================================================= - MIT License -================================================================================ -*/ - -using UnityEngine; - -/// -/// Small System to change the global font from "Arial" to another font of your choosing. -/// -namespace GTS.GlobalUIFont -{ - /// - /// ScriptableObject to hold the GlobalFontData. - /// - public class FontData : ScriptableObject - { - //[TextArea] - //public string text; - - /// - /// The font to be used as the Global UI text font. - /// - [Header("Character")] - public Font font; - //public FontStyle fontStyle; - //public int fontSize; - //public float lineSpacing; - //public bool richText; - - //[Header("Paragraph")] - //public TextAnchor alignment; - //public bool alignByGeometry; - //public HorizontalWrapMode horizontalOverflow; - //public VerticalWrapMode verticalOverflow; - //public bool bestFit; - public Color color; - //public Material material; - //public bool RayCastTarget; - } -} \ No newline at end of file diff --git a/Assets/GTS.GlobalUIFont/Editor/GlobalFontManager.cs b/Assets/GTS.GlobalUIFont/Editor/GlobalFontManager.cs deleted file mode 100644 index 28baf87..0000000 --- a/Assets/GTS.GlobalUIFont/Editor/GlobalFontManager.cs +++ /dev/null @@ -1,253 +0,0 @@ -/* -================================================================================ - Product: Unity-Set-Global_UI-Text_Font - Developer: GlassToeStudio@gmail.com - Source: https://github.com/GlassToeStudio/Unity-Set-Global-UI-Text-Font - Company: GlassToeStudio - Website: http://glasstoestudio.weebly.com/ - Date: June 19, 2018 -================================================================================= - MIT License -================================================================================ -*/ - -using UnityEngine; -using UnityEditor; -using UnityEngine.UI; - -/// -/// Small System to change the global font from "Arial" to another font of your choosing. -/// -namespace GTS.GlobalUIFont -{ - /// - /// Class that will check every Text asset's Font - /// to see if it is the GlobalFontData. - /// - [InitializeOnLoad] - class GlobalFontManager :Editor - { - #region properties - /// - /// Get or Set the Global Font to be used for Every Text Object. - /// - public static FontData GlobalFontData { get; set; } - - /// - /// Only returns true of GlobalFontData is found and legit. - /// - public static bool IsInit { get; set; } - - /// - /// - /// - public static string globalFontName { get; set; } - - #endregion - - #region init - - /// - /// Default static constructor. - /// - static GlobalFontManager() - { - Init(); - } - - /// - /// Load the GlobalFontData FontData (if it exists) and subscribe to the - /// EditorApplication.hierarchyChanged Event. - /// - public static void Init() - { - globalFontName = EditorPrefs.GetString(GlobalFontUtils.GLOBAL_FONT_KEY, GlobalFontUtils.ARIAL); - - // Load GlobalFontData - GlobalFontData = GlobalFontUtils.LoadGlobalFont(globalFontName); - - if(GlobalFontData == null) - { - //Debug.LogWarning( - // "Global FontData not found! Please select one from Fonts/Select Global Font window!." - // ); - - return; - } - else if(GlobalFontData.font == null) - { - Debug.LogWarning( - "Global Font not found! Please select one from Fonts/Select Global Font window!." - ); - - return; - } - - if(GlobalFontData.name == GlobalFontUtils.ARIAL) - { - StopListening(); - return; - } - - StartListening(); - } - - #endregion - - #region Event - - /// - /// Get all Text assets in scene and get/set their font. - /// - private static void OnHierarchyChanged() - { - // Do not run while in play mode! - if(Application.isEditor && !Application.isPlaying) - { - if(!IsSelectionCriteriaMet() || !IsGlobalFontCriteriaMet()) - { - return; - } - - Selection.activeGameObject.GetComponentInChildren(true).font = GlobalFontData.font; - } - } - - #endregion - - #region public methods - - /// - /// Loop through every Text object in the scene and change its font. - /// - public static void ChangeAllFonts() - { - if(IsGlobalFontCriteriaMet()) - { - var textCount = 0; - var fontChangedCount = 0; - - // All text objects in scene. - var allTextObjects = Resources.FindObjectsOfTypeAll(typeof(Text)); - - foreach(Text t in allTextObjects) - { - textCount++; - - if(t.font != GlobalFontData.font) - { - fontChangedCount++; - - t.font = GlobalFontData.font; - } - } - - Debug.Log( - string.Format( - "{0} Total Text objects found. {1} Total fonts changed!", - textCount, - fontChangedCount - )); - } - } - - #endregion - - #region private methods - - /// - /// Subscribe to the hierarchyChanged Event. IsInit = true; - /// - private static void StartListening() - { - if(!IsInit) - { - #if UNITY_2018_1_OR_NEWER - - EditorApplication.hierarchyChanged += OnHierarchyChanged; - - #else - - EditorApplication.hierarchyWindowChanged += OnHierarchyChanged; - - #endif - - IsInit = true; - } - } - - /// - /// Unsubscribe from the hierarchyChanged Event. IsInit = false; - /// - private static void StopListening() - { - if(IsInit) - { - #if UNITY_2018_1_OR_NEWER - - EditorApplication.hierarchyChanged -= OnHierarchyChanged; - - #else - - EditorApplication.hierarchyWindowChanged -= OnHierarchyChanged; - - #endif - IsInit = false; - } - } - - /// - /// Checks that we have a created object (we could be deleting objects) - /// And that the object, or its children, have Text. - /// - private static bool IsSelectionCriteriaMet() - { - if(Selection.activeGameObject == null) - { - return false; - } - - if(Selection.activeGameObject.GetComponentInChildren(true) == null) - { - return false; - } - - return true; - } - - /// - /// Make sure we have set some Global Font Settings. - /// - private static bool IsGlobalFontCriteriaMet() - { - if(GlobalFontData == null) - { - if(globalFontName == GlobalFontUtils.ARIAL) - { - return true; - } - - //Debug.LogError( - // "GlobalFontData is null, Have you set it?" - // ); - - return false; - } - - if(GlobalFontData.font == null) - { - StopListening(); - - Debug.LogError( - "GlobalFont is null, did you delete the asset?" - ); - - return false; - } - - return true; - } - - #endregion - } -} \ No newline at end of file diff --git a/Assets/GTS.GlobalUIFont/Editor/GlobalFontManagerWindow.cs b/Assets/GTS.GlobalUIFont/Editor/GlobalFontManagerWindow.cs deleted file mode 100644 index 9031cb1..0000000 --- a/Assets/GTS.GlobalUIFont/Editor/GlobalFontManagerWindow.cs +++ /dev/null @@ -1,199 +0,0 @@ -/* -================================================================================ - Product: Unity-Set-Global_UI-Text_Font - Developer: GlassToeStudio@gmail.com - Source: https://github.com/GlassToeStudio/Unity-Set-Global-UI-Text-Font - Company: GlassToeStudio - Website: http://glasstoestudio.weebly.com/ - Date: June 19, 2018 -================================================================================= - MIT License -================================================================================ -*/ - -using System.IO; -using UnityEngine; -using UnityEditor; - -/// -/// Small System to change the global font from "Arial" to another font of your choosing. -/// -namespace GTS.GlobalUIFont -{ - /// - /// Custom Window to set the Global Font. - /// - public class GlobalFontManagerWindow : EditorWindow - { - #region fields - - /// - /// Name of the Global Font, to be displayed in the Window. - /// - private static string fontDisplayName = GlobalFontUtils.ARIAL; - - #endregion - - #region init - - /// - /// Show and initialize the custom Global Font Selection window.. - /// - [MenuItem("Global Font/Settings")] - private static void ShowWindow() - { - GlobalFontManagerWindow w = GetWindow(false, "Global UI Font", true); - w.minSize = new Vector2(200, 110); - w.maxSize = new Vector2(200, 110); - - // Display current Font name. - if(GlobalFontManager.GlobalFontData != null) - { - if(GlobalFontManager.GlobalFontData.font != null) - { - fontDisplayName = GlobalFontManager.GlobalFontData.font.name; - } - } - else - { - fontDisplayName = GlobalFontUtils.ARIAL; - } - } - - /// - /// Draw the window and its components. Listen for Button CLicks. - /// - private void OnGUI() - { - // Show Global Font Name - EditorGUILayout.LabelField("Global Font: ", fontDisplayName); - - SelectFontButton(); - - ResetFontButton(); - - ChangeAllFontsButton(); - - OnSelectorClosed(); - - //TODO: Debug Only - DeletePrefsButton(); - } - - #endregion - - #region private methods - - /// - /// Listens for ObjectSelectorClosedEvent. - /// Will Get/Set the global font. - /// - private void OnSelectorClosed() - { - if(Event.current.commandName == "ObjectSelectorClosed") - { - if(EditorGUIUtility.GetObjectPickerObject() != null) - { - var selectedFont = (Font)EditorGUIUtility.GetObjectPickerObject(); - - SetGlobalFontData(selectedFont); - - fontDisplayName = selectedFont.name; - } - } - } - - /// - /// Checks if a FontData assets is created, else it creates one. - /// - /// - private void SetGlobalFontData(Font selectedFont) - { - if(!File.Exists(string.Format("{0}{1}{2}.asset", Application.dataPath, GlobalFontUtils.SAVE_PATH, selectedFont.name))) - { - GlobalFontUtils.SaveGlobalFont(selectedFont); - GlobalFontManager.Init(); - } - else - { - if(!GlobalFontManager.IsInit) - { - EditorPrefs.SetString(GlobalFontUtils.GLOBAL_FONT_KEY, selectedFont.name); - GlobalFontManager.Init(); - } - else - { - GlobalFontManager.GlobalFontData = GlobalFontUtils.LoadGlobalFont(selectedFont.name); - } - } - } - - #endregion - - #region buttons - - /// - /// Open a Font selector and select a Font. - /// - private void SelectFontButton() - { - EditorGUILayout.Space(); - - if(GUILayout.Button("Select Font")) - { - EditorGUIUtility.ShowObjectPicker(null, true, "", GUIUtility.GetControlID(FocusType.Passive) + 100); - } - } - - /// - /// Reset to Unity standard font, "Arial". - /// - private void ResetFontButton() - { - EditorGUILayout.Space(); - - if(GUILayout.Button("Reset Font")) - { - var selctedFont = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font; - - SetGlobalFontData(selctedFont); - - fontDisplayName = selctedFont.name; - } - } - - /// - /// Find all Text in the scene and change its font. - /// - private void ChangeAllFontsButton() - { - EditorGUILayout.Space(); - - if(GUILayout.Button("Change All Fonts In Scene")) - { - GlobalFontManager.ChangeAllFonts(); - SceneView.lastActiveSceneView.Repaint(); - UnityEditorInternal.InternalEditorUtility.RepaintAllViews(); - } - } - - #region debug - /// - /// Debug Only: Delete EditorPrefs. - /// - private void DeletePrefsButton() - { - EditorGUILayout.Space(); - - //if(GUILayout.Button("Delete Editor Prefs")) - //{ - // Debug.Log("Before: " + EditorPrefs.GetString(GlobalFontUtils.GLOBAL_FONT_KEY, GlobalFontUtils.ARIAL)); - // EditorPrefs.DeleteAll(); - // Debug.Log("After: " + EditorPrefs.GetString(GlobalFontUtils.GLOBAL_FONT_KEY, GlobalFontUtils.ARIAL)); - //} - } - #endregion - - #endregion - } -} \ No newline at end of file diff --git a/Assets/GTS.GlobalUIFont/Editor/GlobalFontUtils.cs b/Assets/GTS.GlobalUIFont/Editor/GlobalFontUtils.cs deleted file mode 100644 index e39fdb9..0000000 --- a/Assets/GTS.GlobalUIFont/Editor/GlobalFontUtils.cs +++ /dev/null @@ -1,105 +0,0 @@ -/* -================================================================================ - Product: Unity-Set-Global_UI-Text_Font - Developer: GlassToeStudio@gmail.com - Source: https://github.com/GlassToeStudio/Unity-Set-Global-UI-Text-Font - Company: GlassToeStudio - Website: http://glasstoestudio.weebly.com/ - Date: June 19, 2018 -================================================================================= - MIT License -================================================================================ -*/ - -using UnityEngine; -using UnityEditor; - -/// -/// Small System to change the global font from "Arial" to another font of your choosing. -/// -namespace GTS.GlobalUIFont -{ - /// - /// Some utility functions to load and save FontData assets. - /// - public static class GlobalFontUtils - { - #region constants - - /// - /// The string KEY by which the EditorPrefs saves/loads GlobalFontData name. - /// - public const string GLOBAL_FONT_KEY = "GlobalFontData"; - - /// - /// The string which holds the save path for each GlobalFontData asset. - /// - public const string SAVE_PATH = "/Editor Default Resources/GTS.GlobalUIFontSettings/"; - - public const string ARIAL = "Arial"; - - #endregion - - #region public methods - - /// - /// Load a FontData object from "Default Editor Resources". - /// returns: FontData - /// - public static FontData LoadGlobalFont(string globalFontName) - { - if(globalFontName == string.Empty) - { - //Debug.LogWarning("No Global Font Asset Saved!"); - return null; - } - - EditorPrefs.SetString(GLOBAL_FONT_KEY, globalFontName); - - FontData data = (FontData)EditorGUIUtility.Load( - string.Format( - "{0}{1}{2}{3}", "Assets", SAVE_PATH, globalFontName, ".asset") - ); - - return data; - } - - /// - /// Save the currently selected FontData, GlobalFontData, and save the name in EditorPrefs. - /// - public static void SaveGlobalFont(Font f) - { - EditorPrefs.SetString(GLOBAL_FONT_KEY, f.name); - - CreateFontDataAsset(f); - } - - #endregion - - #region private methods - - /// - /// Create, Save, and Return a new FontData asset. - /// - private static void CreateFontDataAsset(Font f) - { - var fontDataAsset = ScriptableObject.CreateInstance(); - - fontDataAsset.font = f; - - AssetDatabase.CreateAsset( - fontDataAsset, - string.Format( - "{0}{1}{2}.asset", "Assets", SAVE_PATH, f.name) - ); - - AssetDatabase.SaveAssets(); - - AssetDatabase.Refresh(); - - Resources.UnloadUnusedAssets(); - } - - #endregion - } -} \ No newline at end of file diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index 8514e47..8710747 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -138,15 +138,15 @@ RectTransform: m_GameObject: {fileID: 204619188} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 0.9999995, y: 0.9999995, z: 0.9999995} + m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 1759118045} m_RootOrder: 3 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_AnchorMin: {x: 0, y: 0.5} - m_AnchorMax: {x: 1, y: 0.5} - m_AnchoredPosition: {x: 0, y: 6.169998} - m_SizeDelta: {x: 0, y: 115.600006} + m_AnchorMin: {x: 0, y: 0.33} + m_AnchorMax: {x: 1, y: 0.55667067} + m_AnchoredPosition: {x: 0, y: -0.06298828} + m_SizeDelta: {x: 0, y: 1.1259995} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &204619190 MonoBehaviour: @@ -160,8 +160,8 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: m_Material: {fileID: 0} - m_Color: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 1} - m_RaycastTarget: 1 + m_Color: {r: 0.049038816, g: 0.12940678, b: 0.3584906, a: 1} + m_RaycastTarget: 0 m_OnCullStateChanged: m_PersistentCalls: m_Calls: [] @@ -172,12 +172,12 @@ MonoBehaviour: m_FontSize: 30 m_FontStyle: 0 m_BestFit: 0 - m_MinSize: 1 + m_MinSize: 0 m_MaxSize: 60 m_Alignment: 4 m_AlignByGeometry: 0 - m_RichText: 1 - m_HorizontalOverflow: 0 + m_RichText: 0 + m_HorizontalOverflow: 1 m_VerticalOverflow: 0 m_LineSpacing: 1 m_Text: Thing... @@ -272,7 +272,7 @@ GameObject: - component: {fileID: 296909621} - component: {fileID: 296909620} m_Layer: 5 - m_Name: Button + m_Name: ThisButton m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -292,10 +292,10 @@ RectTransform: m_Father: {fileID: 1759118045} m_RootOrder: 4 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_AnchorMin: {x: 0, y: 0.5} - m_AnchorMax: {x: 1, y: 0.5} - m_AnchoredPosition: {x: -0.00048828125, y: -98} - m_SizeDelta: {x: -372, y: 59.8} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 1, y: 0.33} + m_AnchoredPosition: {x: 0.49951172, y: 2.5} + m_SizeDelta: {x: -371, y: -39.199997} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &296909620 MonoBehaviour: @@ -344,7 +344,7 @@ MonoBehaviour: m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 0} m_GameObject: {fileID: 296909618} - m_Enabled: 0 + m_Enabled: 1 m_EditorHideFlags: 0 m_Script: {fileID: -765806418, guid: f70555f144d8491a825f0804e09c671c, type: 3} m_Name: @@ -531,10 +531,10 @@ RectTransform: m_Father: {fileID: 1759118045} m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_AnchorMin: {x: 0, y: 0.5} - m_AnchorMax: {x: 1, y: 0.5} - m_AnchoredPosition: {x: 0.00061035156, y: 111.88} - m_SizeDelta: {x: 0.8200073, y: 76} + m_AnchorMin: {x: 0, y: 0.7534661} + m_AnchorMax: {x: 1, y: 1} + m_AnchoredPosition: {x: 0.00048828125, y: -1.1199951} + m_SizeDelta: {x: 0.8200073, y: 2} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &1277601097 MonoBehaviour: @@ -548,8 +548,8 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: m_Material: {fileID: 0} - m_Color: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 1} - m_RaycastTarget: 1 + m_Color: {r: 0.049038816, g: 0.12940678, b: 0.3584906, a: 1} + m_RaycastTarget: 0 m_OnCullStateChanged: m_PersistentCalls: m_Calls: [] @@ -560,14 +560,14 @@ MonoBehaviour: m_FontSize: 60 m_FontStyle: 0 m_BestFit: 0 - m_MinSize: 1 - m_MaxSize: 60 + m_MinSize: 0 + m_MaxSize: 80 m_Alignment: 4 m_AlignByGeometry: 0 - m_RichText: 1 + m_RichText: 0 m_HorizontalOverflow: 0 m_VerticalOverflow: 0 - m_LineSpacing: 1 + m_LineSpacing: 0 m_Text: Glass Toe Studio --- !u!222 &1277601098 CanvasRenderer: @@ -586,7 +586,7 @@ GameObject: - component: {fileID: 1328994479} - component: {fileID: 1328994478} m_Layer: 5 - m_Name: Text + m_Name: Even this button. m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -622,8 +622,8 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: m_Material: {fileID: 0} - m_Color: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 1} - m_RaycastTarget: 1 + m_Color: {r: 0.049038816, g: 0.12940678, b: 0.3584906, a: 1} + m_RaycastTarget: 0 m_OnCullStateChanged: m_PersistentCalls: m_Calls: [] @@ -634,17 +634,15 @@ MonoBehaviour: m_FontSize: 20 m_FontStyle: 0 m_BestFit: 0 - m_MinSize: 2 - m_MaxSize: 40 + m_MinSize: 1 + m_MaxSize: 20 m_Alignment: 4 m_AlignByGeometry: 0 m_RichText: 0 m_HorizontalOverflow: 0 m_VerticalOverflow: 0 - m_LineSpacing: 1 - m_Text: 'Even This - - Button' + m_LineSpacing: 0 + m_Text: Even this button. --- !u!222 &1328994479 CanvasRenderer: m_ObjectHideFlags: 0 @@ -804,15 +802,15 @@ RectTransform: m_GameObject: {fileID: 1866162985} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 0.9999995, y: 0.9999995, z: 0.9999995} + m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 1759118045} m_RootOrder: 2 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_AnchorMin: {x: 0, y: 0.5} - m_AnchorMax: {x: 1, y: 0.5} - m_AnchoredPosition: {x: -0.00048828125, y: 52} - m_SizeDelta: {x: 0, y: 106.5} + m_AnchorMin: {x: 0, y: 0.55667067} + m_AnchorMax: {x: 1, y: 0.7433353} + m_AnchoredPosition: {x: -0.00048828125, y: 0.7000122} + m_SizeDelta: {x: 0, y: 0.40000153} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &1866162987 MonoBehaviour: @@ -826,8 +824,8 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: m_Material: {fileID: 0} - m_Color: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 1} - m_RaycastTarget: 1 + m_Color: {r: 0.049038816, g: 0.12940678, b: 0.3584906, a: 1} + m_RaycastTarget: 0 m_OnCullStateChanged: m_PersistentCalls: m_Calls: [] @@ -838,14 +836,14 @@ MonoBehaviour: m_FontSize: 40 m_FontStyle: 0 m_BestFit: 0 - m_MinSize: 1 + m_MinSize: 0 m_MaxSize: 60 m_Alignment: 4 m_AlignByGeometry: 0 - m_RichText: 1 + m_RichText: 0 m_HorizontalOverflow: 0 m_VerticalOverflow: 0 - m_LineSpacing: 1 + m_LineSpacing: 0 m_Text: Global UI Font --- !u!222 &1866162988 CanvasRenderer: diff --git a/Images/ColorChangeRealTime.gif b/Images/ColorChangeRealTime.gif new file mode 100644 index 0000000..b8ef6a3 Binary files /dev/null and b/Images/ColorChangeRealTime.gif differ diff --git a/Images/CustomEditor.gif b/Images/CustomEditor.gif new file mode 100644 index 0000000..5567a47 Binary files /dev/null and b/Images/CustomEditor.gif differ diff --git a/Images/RealTimeColorChange.gif b/Images/RealTimeColorChange.gif new file mode 100644 index 0000000..de9a12f Binary files /dev/null and b/Images/RealTimeColorChange.gif differ diff --git a/ProjectSettings/PresetManager.asset b/ProjectSettings/PresetManager.asset index 820e662..3ff1177 100644 --- a/ProjectSettings/PresetManager.asset +++ b/ProjectSettings/PresetManager.asset @@ -25,3 +25,11 @@ PresetManager: defaultPresets: - m_Preset: {fileID: 2655988077585873504, guid: 7a99f8aa944efe94cb9bd74562b7d5f9, type: 2} + - type: + m_NativeTypeID: 114 + m_ManagedTypePPtr: {fileID: 708705254, guid: f70555f144d8491a825f0804e09c671c, + type: 3} + m_ManagedTypeFallback: + defaultPresets: + - m_Preset: {fileID: 2655988077585873504, guid: f277a7e23d96419409f7b9e38421a59d, + type: 2} diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index 490788e..a73720b 100644 --- a/ProjectSettings/ProjectSettings.asset +++ b/ProjectSettings/ProjectSettings.asset @@ -12,8 +12,8 @@ PlayerSettings: targetDevice: 2 useOnDemandResources: 0 accelerometerFrequency: 60 - companyName: DefaultCompany - productName: Unity-Set-Global-UI-Text-Font + companyName: GlassToeStudio + productName: UnityGlobalTextSystem defaultCursor: {fileID: 0} cursorHotspot: {x: 0, y: 0} m_SplashScreenBackgroundColor: {r: 0.13725491, g: 0.12156863, b: 0.1254902, a: 1} diff --git a/ProjectSettings/QualitySettings.asset b/ProjectSettings/QualitySettings.asset index b9320b3..a554813 100644 --- a/ProjectSettings/QualitySettings.asset +++ b/ProjectSettings/QualitySettings.asset @@ -174,17 +174,4 @@ QualitySettings: asyncUploadBufferSize: 4 resolutionScalingFixedDPIFactor: 1 excludedTargetPlatforms: [] - m_PerPlatformDefaultQuality: - Android: 2 - Nintendo 3DS: 5 - Nintendo Switch: 5 - PS4: 5 - PSP2: 2 - Standalone: 5 - Tizen: 2 - WebGL: 3 - WiiU: 5 - Windows Store Apps: 5 - XboxOne: 5 - iPhone: 2 - tvOS: 2 + m_PerPlatformDefaultQuality: {} diff --git a/README.md b/README.md index 24d1c70..4e21245 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ -# Unity-Set-Global-UI-Text-Font +# Unity Global Text System + +--- --- @@ -14,7 +16,7 @@ When a new UI Text (even if the Text is a Child, ex: Button) it will have the fo ## Getting Started --- * Select a Font that is in your project to be the Global Font. - * This can be set from **"Global Font/Settings"** + * This can be set from **"Global Text System/Settings"** * Now, when a UI Text is added, it will have this font. **Additional Options** @@ -26,19 +28,49 @@ When a new UI Text (even if the Text is a Child, ex: Button) it will have the fo

- Add New Text With Your Font:
-
+ Add New Text With Your Font: +

+ +--- + +

+
+ +

+ +

+ Select any property to override via the custom editor: +

+ +--- + +

+
+

-![CreateNewText.gif](https://github.com/GlassToeStudio/UnityGlobalTextSystem/blob/master/Images/CreateNewText.gif) +

+ Update All Text +

+---

- Update All Text
-
+
+

-![ChangeAllFontsInScene.gif](https://github.com/GlassToeStudio/UnityGlobalTextSystem/blob/master/Images/ChangeAllFontsInScene.gif) + +

+ See changes in real-time +

+ +--- + +

+
+ +

### Prerequisites @@ -55,7 +87,7 @@ If contributing, be sure to have `git` installed. ### Installing --- -To use the project, all you need is to [Download the latest release](https://github.com/GlassToeStudio/Unity-Set-Global-UI-Text-Font/releases) and import the package into your Unity project. +To use the project, all you need is to [Download the latest release](https://github.com/GlassToeStudio/UnityGlobalTextSystem/releases) and import the package into your Unity project. Alternately you can Clone the repo using: