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 DoVerticalAligmentControl(Rect position, SerializedProperty alignment) { TextAnchor ta = (TextAnchor)alignment.intValue; VerticalTextAligment verticalTextAligment = GetVerticalAlignment(ta); bool topAlign = (verticalTextAligment == VerticalTextAligment.Top); bool middleAlign = (verticalTextAligment == VerticalTextAligment.Middle); bool bottomAlign = (verticalTextAligment == VerticalTextAligment.Bottom); if (alignment.hasMultipleDifferentValues) { foreach (var obj in alignment.serializedObject.targetObjects) { TextEx text = obj as TextEx; TextAnchor textAlignment = text.alignment; verticalTextAligment = GetVerticalAlignment(textAlignment); topAlign = topAlign || (verticalTextAligment == VerticalTextAligment.Top); middleAlign = middleAlign || (verticalTextAligment == VerticalTextAligment.Middle); bottomAlign = bottomAlign || (verticalTextAligment == VerticalTextAligment.Bottom); } } position.width = kAlignmentButtonWidth; // position.x += position.width; EditorGUI.BeginChangeCheck(); EditorToggle(position, topAlign, topAlign ? Styles.m_TopAlignTextActive : Styles.m_TopAlignText, Styles.alignmentButtonLeft); if (EditorGUI.EndChangeCheck()) { SetVerticalAlignment(alignment, VerticalTextAligment.Top); } position.x += position.width; EditorGUI.BeginChangeCheck(); EditorToggle(position, middleAlign, middleAlign ? Styles.m_MiddleAlignTextActive : Styles.m_MiddleAlignText, Styles.alignmentButtonMid); if (EditorGUI.EndChangeCheck()) { SetVerticalAlignment(alignment, VerticalTextAligment.Middle); } position.x += position.width; EditorGUI.BeginChangeCheck(); EditorToggle(position, bottomAlign, bottomAlign ? Styles.m_BottomAlignTextActive : Styles.m_BottomAlignText, Styles.alignmentButtonRight); if (EditorGUI.EndChangeCheck()) { SetVerticalAlignment(alignment, VerticalTextAligment.Bottom); } }
private static void DoVerticalAligmentControl(Rect position, SerializedProperty alignment) { VerticalTextAligment verticalAlignment = GetVerticalAlignment((TextAnchor)alignment.intValue); bool flag = verticalAlignment == VerticalTextAligment.Top; bool flag2 = verticalAlignment == VerticalTextAligment.Middle; bool flag3 = verticalAlignment == VerticalTextAligment.Bottom; if (alignment.hasMultipleDifferentValues) { foreach (UnityEngine.Object obj2 in alignment.serializedObject.targetObjects) { Text text = obj2 as Text; verticalAlignment = GetVerticalAlignment(text.alignment); flag = flag || (verticalAlignment == VerticalTextAligment.Top); flag2 = flag2 || (verticalAlignment == VerticalTextAligment.Middle); flag3 = flag3 || (verticalAlignment == VerticalTextAligment.Bottom); } } position.width = 20f; EditorGUI.BeginChangeCheck(); EditorToggle(position, flag, !flag ? Styles.m_TopAlignText : Styles.m_TopAlignTextActive, Styles.alignmentButtonLeft); if (EditorGUI.EndChangeCheck()) { SetVerticalAlignment(alignment, VerticalTextAligment.Top); } position.x += position.width; EditorGUI.BeginChangeCheck(); EditorToggle(position, flag2, !flag2 ? Styles.m_MiddleAlignText : Styles.m_MiddleAlignTextActive, Styles.alignmentButtonMid); if (EditorGUI.EndChangeCheck()) { SetVerticalAlignment(alignment, VerticalTextAligment.Middle); } position.x += position.width; EditorGUI.BeginChangeCheck(); EditorToggle(position, flag3, !flag3 ? Styles.m_BottomAlignText : Styles.m_BottomAlignTextActive, Styles.alignmentButtonRight); if (EditorGUI.EndChangeCheck()) { SetVerticalAlignment(alignment, VerticalTextAligment.Bottom); } }
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); }
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) { foreach (var obj in alignment.serializedObject.targetObjects) { Text text = obj as Text; HorizontalTextAligment currentHorizontalAligment = GetHorizontalAlignment(text.alignment); Undo.RecordObject(text, "Vertical Alignment"); text.alignment = GetAnchor(verticalAlignment, currentHorizontalAligment); EditorUtility.SetDirty(obj); } }
/// <summary> /// Displays the vertical aligment control. /// </summary> /// <param name="position">Position.</param> /// <param name="property">Property.</param> private void DisplayVerticalAligmentControl(Rect position, SerializedProperty property) { TextAnchor intValue = (TextAnchor)property.intValue; VerticalTextAligment verticalAlignment = intValue.GetVerticalAlignment(); bool flag = verticalAlignment == VerticalTextAligment.Top; bool flag2 = verticalAlignment == VerticalTextAligment.Middle; bool flag3 = verticalAlignment == VerticalTextAligment.Bottom; if (property.hasMultipleDifferentValues) { Object[] targetObjects = property.serializedObject.targetObjects; for (int i = 0; i < targetObjects.Length; i++) { Object obj = targetObjects [i]; TextAnchor alignment2 = (TextAnchor) new SerializedObject(obj).FindProperty(property.propertyPath).enumValueIndex; verticalAlignment = alignment2.GetVerticalAlignment(); flag = flag || verticalAlignment == VerticalTextAligment.Top; flag2 = flag2 || verticalAlignment == VerticalTextAligment.Middle; flag3 = flag3 || verticalAlignment == VerticalTextAligment.Bottom; } } position.width = 20f; EditorGUI.BeginChangeCheck(); EditorToggle( position, !flag ? s_Styles.GetStaticFieldValue <GUIContent>("m_TopAlignText") : s_Styles.GetStaticFieldValue <GUIContent>("m_TopAlignTextActive"), flag, s_Styles.GetStaticFieldValue <GUIStyle>("alignmentButtonLeft") ); if (EditorGUI.EndChangeCheck()) { this.SetVerticalAlignment(property, VerticalTextAligment.Top); } position.x += position.width; EditorGUI.BeginChangeCheck(); EditorToggle( position, !flag2 ? s_Styles.GetStaticFieldValue <GUIContent>("m_MiddleAlignText") : s_Styles.GetStaticFieldValue <GUIContent>("m_MiddleAlignTextActive"), flag2, s_Styles.GetStaticFieldValue <GUIStyle>("alignmentButtonMid") ); if (EditorGUI.EndChangeCheck()) { SetVerticalAlignment(property, VerticalTextAligment.Middle); } position.x += position.width; EditorGUI.BeginChangeCheck(); EditorToggle( position, !flag3 ? s_Styles.GetStaticFieldValue <GUIContent>("m_BottomAlignText") : s_Styles.GetStaticFieldValue <GUIContent>("m_BottomAlignTextActive"), flag3, s_Styles.GetStaticFieldValue <GUIStyle>("alignmentButtonRight") ); if (EditorGUI.EndChangeCheck()) { SetVerticalAlignment(property, VerticalTextAligment.Bottom); } }
/// <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 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); } }
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; }