A game about forced loneliness, made by TACStudios
at master 127 lines 4.3 kB view raw
1using UnityEngine; 2using UnityEngine.UI; 3using UnityEditor; 4 5namespace TMPro.EditorUtilities 6{ 7 8 [CustomEditor(typeof(TextMeshProUGUI), true), CanEditMultipleObjects] 9 public class TMP_EditorPanelUI : TMP_BaseEditorPanel 10 { 11 static readonly GUIContent k_RaycastTargetLabel = new GUIContent("Raycast Target", "Whether the text blocks raycasts from the Graphic Raycaster."); 12 static readonly GUIContent k_MaskableLabel = new GUIContent("Maskable", "Determines if the text object will be affected by UI Mask."); 13 14 SerializedProperty m_RaycastTargetProp; 15 private SerializedProperty m_MaskableProp; 16 17 protected override void OnEnable() 18 { 19 base.OnEnable(); 20 m_RaycastTargetProp = serializedObject.FindProperty("m_RaycastTarget"); 21 m_MaskableProp = serializedObject.FindProperty("m_Maskable"); 22 } 23 24 protected override void DrawExtraSettings() 25 { 26 Rect rect = EditorGUILayout.GetControlRect(false, 24); 27 28 if (GUI.Button(rect, new GUIContent("<b>Extra Settings</b>"), TMP_UIStyleManager.sectionHeader)) 29 Foldout.extraSettings = !Foldout.extraSettings; 30 31 GUI.Label(rect, (Foldout.extraSettings ? k_UiStateLabel[0] : k_UiStateLabel[1]), TMP_UIStyleManager.rightLabel); 32 if (Foldout.extraSettings) 33 { 34 35 DrawMargins(); 36 37 DrawGeometrySorting(); 38 39 DrawIsTextObjectScaleStatic(); 40 41 DrawRichText(); 42 43 DrawRaycastTarget(); 44 45 DrawMaskable(); 46 47 DrawParsing(); 48 49 DrawEmojiFallbackSupport(); 50 51 DrawSpriteAsset(); 52 53 DrawStyleSheet(); 54 55 DrawFontFeatures(); 56 57 DrawPadding(); 58 59 } 60 } 61 62 protected void DrawRaycastTarget() 63 { 64 EditorGUI.BeginChangeCheck(); 65 EditorGUILayout.PropertyField(m_RaycastTargetProp, k_RaycastTargetLabel); 66 if (EditorGUI.EndChangeCheck()) 67 { 68 // Change needs to propagate to the child sub objects. 69 Graphic[] graphicComponents = m_TextComponent.GetComponentsInChildren<Graphic>(); 70 for (int i = 1; i < graphicComponents.Length; i++) 71 graphicComponents[i].raycastTarget = m_RaycastTargetProp.boolValue; 72 73 m_HavePropertiesChanged = true; 74 } 75 } 76 77 protected void DrawMaskable() 78 { 79 if (m_MaskableProp == null) 80 return; 81 82 EditorGUI.BeginChangeCheck(); 83 EditorGUILayout.PropertyField(m_MaskableProp, k_MaskableLabel); 84 if (EditorGUI.EndChangeCheck()) 85 { 86 m_TextComponent.maskable = m_MaskableProp.boolValue; 87 88 // Change needs to propagate to the child sub objects. 89 MaskableGraphic[] maskableGraphics = m_TextComponent.GetComponentsInChildren<MaskableGraphic>(); 90 for (int i = 1; i < maskableGraphics.Length; i++) 91 maskableGraphics[i].maskable = m_MaskableProp.boolValue; 92 93 m_HavePropertiesChanged = true; 94 } 95 } 96 97 // Method to handle multi object selection 98 protected override bool IsMixSelectionTypes() 99 { 100 GameObject[] objects = Selection.gameObjects; 101 if (objects.Length > 1) 102 { 103 for (int i = 0; i < objects.Length; i++) 104 { 105 if (objects[i].GetComponent<TextMeshProUGUI>() == null) 106 return true; 107 } 108 } 109 return false; 110 } 111 protected override void OnUndoRedo() 112 { 113 int undoEventId = Undo.GetCurrentGroup(); 114 int lastUndoEventId = s_EventId; 115 116 if (undoEventId != lastUndoEventId) 117 { 118 for (int i = 0; i < targets.Length; i++) 119 { 120 //Debug.Log("Undo & Redo Performed detected in Editor Panel. Event ID:" + Undo.GetCurrentGroup()); 121 TMPro_EventManager.ON_TEXTMESHPRO_UGUI_PROPERTY_CHANGED(true, targets[i] as TextMeshProUGUI); 122 s_EventId = undoEventId; 123 } 124 } 125 } 126 } 127}