private static TextAnchor GetAnchor(VerticalTextAligment verticalTextAligment, HorizontalTextAligment horizontalTextAligment) { TextAnchor ac = TextAnchor.UpperLeft; switch (horizontalTextAligment) { case HorizontalTextAligment.Left: switch (verticalTextAligment) { case VerticalTextAligment.Bottom: ac = TextAnchor.LowerLeft; break; case VerticalTextAligment.Middle: ac = TextAnchor.MiddleLeft; break; default: ac = TextAnchor.UpperLeft; break; } break; case HorizontalTextAligment.Center: switch (verticalTextAligment) { case VerticalTextAligment.Bottom: ac = TextAnchor.LowerCenter; break; case VerticalTextAligment.Middle: ac = TextAnchor.MiddleCenter; break; default: ac = TextAnchor.UpperCenter; break; } break; default: switch (verticalTextAligment) { case VerticalTextAligment.Bottom: ac = TextAnchor.LowerRight; break; case VerticalTextAligment.Middle: ac = TextAnchor.MiddleRight; break; default: ac = TextAnchor.UpperRight; break; } break; } return(ac); }
private static void SetVerticalAlignment(SerializedProperty alignment, VerticalTextAligment verticalAlignment) { HorizontalTextAligment currentHorizontalAligment = GetHorizontalAlignment((TextAnchor)alignment.enumValueIndex); alignment.enumValueIndex = (int)GetAnchor(verticalAlignment, currentHorizontalAligment); alignment.serializedObject.ApplyModifiedProperties(); }
private static void SetVerticalAlignment(SerializedProperty alignment, VerticalTextAligment verticalAlignment) { foreach (var obj in alignment.serializedObject.targetObjects) { Text3DRenderer text = obj as Text3DRenderer; HorizontalTextAligment currentHorizontalAligment = GetHorizontalAlgiment(text.Alignment); Undo.RecordObject(text, "Vertical Alignment"); text.Alignment = GetAnchor(verticalAlignment, currentHorizontalAligment); EditorUtility.SetDirty(obj); } }
private static void SetVerticalAlignment(SerializedProperty alignment, VerticalTextAligment verticalAlignment) { foreach (UnityEngine.Object obj2 in alignment.serializedObject.targetObjects) { Text objectToUndo = obj2 as Text; HorizontalTextAligment horizontalAlignment = GetHorizontalAlignment(objectToUndo.alignment); Undo.RecordObject(objectToUndo, "Vertical Alignment"); objectToUndo.alignment = GetAnchor(verticalAlignment, horizontalAlignment); EditorUtility.SetDirty(obj2); } }
// We can't go through serialzied properties here since we're showing two controls for a single SerializzedProperty. private static void SetHorizontalAlignment(SerializedProperty alignment, HorizontalTextAligment horizontalAlignment) { foreach (var obj in alignment.serializedObject.targetObjects) { IMCText text = obj as IMCText; VerticalTextAligment currentVerticalAligment = GetVerticalAlgiment(text.alignment); Undo.RecordObject(text, "Horizontal Alignment"); text.alignment = GetAnchor(currentVerticalAligment, horizontalAlignment); EditorUtility.SetDirty(obj); } }
/// <summary> /// Sets the vertical alignment. /// </summary> /// <param name="property">Property.</param> /// <param name="verticalAlignment">Vertical alignment.</param> private void SetVerticalAlignment(SerializedProperty property, VerticalTextAligment verticalAlignment) { foreach (Object obj in property.serializedObject.targetObjects) { HorizontalTextAligment horizontalAlignment = ((TextAnchor)property.enumValueIndex).GetHorizontalAlignment(); Undo.RecordObject(obj, "Vertical Alignment"); property.enumValueIndex = (int)TextAnchorX.GetAnchor(verticalAlignment, horizontalAlignment); EditorUtility.SetDirty(obj); } }
private static void DoHorizontalAligmentControl(Rect position, SerializedProperty alignment) { TextAnchor ta = (TextAnchor)alignment.intValue; HorizontalTextAligment horizontalAlignment = GetHorizontalAlignment(ta); bool leftAlign = (horizontalAlignment == HorizontalTextAligment.Left); bool centerAlign = (horizontalAlignment == HorizontalTextAligment.Center); bool rightAlign = (horizontalAlignment == HorizontalTextAligment.Right); if (alignment.hasMultipleDifferentValues) { foreach (var obj in alignment.serializedObject.targetObjects) { TextEx text = obj as TextEx; horizontalAlignment = GetHorizontalAlignment(text.alignment); leftAlign = leftAlign || (horizontalAlignment == HorizontalTextAligment.Left); centerAlign = centerAlign || (horizontalAlignment == HorizontalTextAligment.Center); rightAlign = rightAlign || (horizontalAlignment == HorizontalTextAligment.Right); } } position.width = kAlignmentButtonWidth; EditorGUI.BeginChangeCheck(); EditorToggle(position, leftAlign, leftAlign ? Styles.m_LeftAlignTextActive : Styles.m_LeftAlignText, Styles.alignmentButtonLeft); if (EditorGUI.EndChangeCheck()) { SetHorizontalAlignment(alignment, HorizontalTextAligment.Left); } position.x += position.width; EditorGUI.BeginChangeCheck(); EditorToggle(position, centerAlign, centerAlign ? Styles.m_CenterAlignTextActive : Styles.m_CenterAlignText, Styles.alignmentButtonMid); if (EditorGUI.EndChangeCheck()) { SetHorizontalAlignment(alignment, HorizontalTextAligment.Center); } position.x += position.width; EditorGUI.BeginChangeCheck(); EditorToggle(position, rightAlign, rightAlign ? Styles.m_RightAlignTextActive : Styles.m_RightAlignText, Styles.alignmentButtonRight); if (EditorGUI.EndChangeCheck()) { SetHorizontalAlignment(alignment, HorizontalTextAligment.Right); } }
private static void DoHorizontalAligmentControl(Rect position, SerializedProperty alignment) { HorizontalTextAligment horizontalAlignment = GetHorizontalAlignment((TextAnchor)alignment.intValue); bool flag = horizontalAlignment == HorizontalTextAligment.Left; bool flag2 = horizontalAlignment == HorizontalTextAligment.Center; bool flag3 = horizontalAlignment == HorizontalTextAligment.Right; if (alignment.hasMultipleDifferentValues) { foreach (UnityEngine.Object obj2 in alignment.serializedObject.targetObjects) { Text text = obj2 as Text; horizontalAlignment = GetHorizontalAlignment(text.alignment); flag = flag || (horizontalAlignment == HorizontalTextAligment.Left); flag2 = flag2 || (horizontalAlignment == HorizontalTextAligment.Center); flag3 = flag3 || (horizontalAlignment == HorizontalTextAligment.Right); } } position.width = 20f; EditorGUI.BeginChangeCheck(); EditorToggle(position, flag, !flag ? Styles.m_LeftAlignText : Styles.m_LeftAlignTextActive, Styles.alignmentButtonLeft); if (EditorGUI.EndChangeCheck()) { SetHorizontalAlignment(alignment, HorizontalTextAligment.Left); } position.x += position.width; EditorGUI.BeginChangeCheck(); EditorToggle(position, flag2, !flag2 ? Styles.m_CenterAlignText : Styles.m_CenterAlignTextActive, Styles.alignmentButtonMid); if (EditorGUI.EndChangeCheck()) { SetHorizontalAlignment(alignment, HorizontalTextAligment.Center); } position.x += position.width; EditorGUI.BeginChangeCheck(); EditorToggle(position, flag3, !flag3 ? Styles.m_RightAlignText : Styles.m_RightAlignTextActive, Styles.alignmentButtonRight); if (EditorGUI.EndChangeCheck()) { SetHorizontalAlignment(alignment, HorizontalTextAligment.Right); } }
private static TextAnchor GetAnchor(VerticalTextAligment verticalTextAligment, HorizontalTextAligment horizontalTextAligment) { TextAnchor ac = TextAnchor.UpperLeft; switch (horizontalTextAligment) { case HorizontalTextAligment.Left: switch (verticalTextAligment) { case VerticalTextAligment.Bottom: ac = TextAnchor.LowerLeft; break; case VerticalTextAligment.Middle: ac = TextAnchor.MiddleLeft; break; default: ac = TextAnchor.UpperLeft; break; } break; case HorizontalTextAligment.Center: switch (verticalTextAligment) { case VerticalTextAligment.Bottom: ac = TextAnchor.LowerCenter; break; case VerticalTextAligment.Middle: ac = TextAnchor.MiddleCenter; break; default: ac = TextAnchor.UpperCenter; break; } break; default: switch (verticalTextAligment) { case VerticalTextAligment.Bottom: ac = TextAnchor.LowerRight; break; case VerticalTextAligment.Middle: ac = TextAnchor.MiddleRight; break; default: ac = TextAnchor.UpperRight; break; } break; } return ac; }
// We can't go through serialized properties here since we're showing two controls for a single SerializzedProperty. private static void SetHorizontalAlignment(SerializedProperty alignment, HorizontalTextAligment horizontalAlignment) { foreach (var obj in alignment.serializedObject.targetObjects) { Text text = obj as Text; VerticalTextAligment currentVerticalAligment = GetVerticalAlignment(text.alignment); Undo.RecordObject(text, "Horizontal Alignment"); text.alignment = GetAnchor(currentVerticalAligment, horizontalAlignment); EditorUtility.SetDirty(obj); } }
private static TextAnchor GetAnchor(VerticalTextAligment verticalTextAligment, HorizontalTextAligment horizontalTextAligment) { if (horizontalTextAligment != HorizontalTextAligment.Left) { if (horizontalTextAligment == HorizontalTextAligment.Center) { if (verticalTextAligment != VerticalTextAligment.Bottom) { if (verticalTextAligment == VerticalTextAligment.Middle) { return(TextAnchor.MiddleCenter); } return(TextAnchor.UpperCenter); } return(TextAnchor.LowerCenter); } if (verticalTextAligment != VerticalTextAligment.Bottom) { if (verticalTextAligment == VerticalTextAligment.Middle) { return(TextAnchor.MiddleRight); } } else { return(TextAnchor.LowerRight); } return(TextAnchor.UpperRight); } if (verticalTextAligment != VerticalTextAligment.Bottom) { if (verticalTextAligment == VerticalTextAligment.Middle) { return(TextAnchor.MiddleLeft); } return(TextAnchor.UpperLeft); } return(TextAnchor.LowerLeft); }
/// <summary> /// Displays the horizontal aligment control. /// </summary> /// <param name="position">Position.</param> /// <param name="property">Property.</param> private void DisplayHorizontalAligmentControl(Rect position, SerializedProperty property) { TextAnchor intValue = (TextAnchor)property.intValue; HorizontalTextAligment horizontalAlignment = intValue.GetHorizontalAlignment(); bool flag = horizontalAlignment == HorizontalTextAligment.Left; bool flag2 = horizontalAlignment == HorizontalTextAligment.Center; bool flag3 = horizontalAlignment == HorizontalTextAligment.Right; if (property.hasMultipleDifferentValues) { Object[] targetObjects = property.serializedObject.targetObjects; for (int i = 0; i < targetObjects.Length; i++) { Object obj = targetObjects [i]; UnityEngine.UI.Text text = obj as UnityEngine.UI.Text; horizontalAlignment = text.alignment.GetHorizontalAlignment(); flag = flag || horizontalAlignment == HorizontalTextAligment.Left; flag2 = flag2 || horizontalAlignment == HorizontalTextAligment.Center; flag3 = flag3 || horizontalAlignment == HorizontalTextAligment.Right; } } position.width = 20f; EditorGUI.BeginChangeCheck(); EditorToggle( position, !flag ? s_Styles.GetStaticFieldValue <GUIContent>("m_LeftAlignText") : s_Styles.GetStaticFieldValue <GUIContent>("m_LeftAlignTextActive"), flag, s_Styles.GetStaticFieldValue <GUIStyle>("alignmentButtonLeft") ); if (EditorGUI.EndChangeCheck()) { SetHorizontalAlignment(property, HorizontalTextAligment.Left); } position.x += position.width; EditorGUI.BeginChangeCheck(); EditorToggle( position, !flag2 ? s_Styles.GetStaticFieldValue <GUIContent>("m_CenterAlignText") : s_Styles.GetStaticFieldValue <GUIContent>("m_CenterAlignTextActive"), flag2, s_Styles.GetStaticFieldValue <GUIStyle>("alignmentButtonMid") ); if (EditorGUI.EndChangeCheck()) { SetHorizontalAlignment(property, HorizontalTextAligment.Center); } position.x += position.width; EditorGUI.BeginChangeCheck(); EditorToggle( position, !flag3 ? s_Styles.GetStaticFieldValue <GUIContent>("m_RightAlignText") : s_Styles.GetStaticFieldValue <GUIContent>("m_RightAlignTextActive"), flag3, s_Styles.GetStaticFieldValue <GUIStyle>("alignmentButtonRight") ); if (EditorGUI.EndChangeCheck()) { this.SetHorizontalAlignment(property, HorizontalTextAligment.Right); } }
/// <summary> /// Creates a TextAnchor from vertical and horizontal components. /// </summary> /// <returns>The TextAnchor.</returns> /// <param name="vertical">Vertical.</param> /// <param name="horizontal">Horizontal.</param> public static TextAnchor GetAnchor(VerticalTextAligment vertical, HorizontalTextAligment horizontal) { TextAnchor result; if (horizontal != HorizontalTextAligment.Left) { if (horizontal != HorizontalTextAligment.Center) { if (vertical != VerticalTextAligment.Middle) { if (vertical != VerticalTextAligment.Bottom) { result = TextAnchor.UpperRight; } else { result = TextAnchor.LowerRight; } } else { result = TextAnchor.MiddleRight; } } else { if (vertical != VerticalTextAligment.Middle) { if (vertical != VerticalTextAligment.Bottom) { result = TextAnchor.UpperCenter; } else { result = TextAnchor.LowerCenter; } } else { result = TextAnchor.MiddleCenter; } } } else { if (vertical != VerticalTextAligment.Middle) { if (vertical != VerticalTextAligment.Bottom) { result = TextAnchor.UpperLeft; } else { result = TextAnchor.LowerLeft; } } else { result = TextAnchor.MiddleLeft; } } return(result); }
private static void SetHorizontalAlignment(SerializedProperty alignment, HorizontalTextAligment horizontalAlignment) { foreach (UnityEngine.Object obj2 in alignment.serializedObject.targetObjects) { Text objectToUndo = obj2 as Text; VerticalTextAligment verticalAlignment = GetVerticalAlignment(objectToUndo.alignment); Undo.RecordObject(objectToUndo, "Horizontal Alignment"); objectToUndo.alignment = GetAnchor(verticalAlignment, horizontalAlignment); EditorUtility.SetDirty(obj2); } }
private static TextAnchor GetAnchor(VerticalTextAligment verticalTextAligment, HorizontalTextAligment horizontalTextAligment) { if (horizontalTextAligment != HorizontalTextAligment.Left) { if (horizontalTextAligment == HorizontalTextAligment.Center) { if (verticalTextAligment != VerticalTextAligment.Bottom) { if (verticalTextAligment == VerticalTextAligment.Middle) { return TextAnchor.MiddleCenter; } return TextAnchor.UpperCenter; } return TextAnchor.LowerCenter; } if (verticalTextAligment != VerticalTextAligment.Bottom) { if (verticalTextAligment == VerticalTextAligment.Middle) { return TextAnchor.MiddleRight; } } else { return TextAnchor.LowerRight; } return TextAnchor.UpperRight; } if (verticalTextAligment != VerticalTextAligment.Bottom) { if (verticalTextAligment == VerticalTextAligment.Middle) { return TextAnchor.MiddleLeft; } return TextAnchor.UpperLeft; } return TextAnchor.LowerLeft; }