|
22 | 22 | using VirtualTexturing = UnityEngine.Rendering.VirtualTexturing; |
23 | 23 | using PreviewMaterialType = UnityEditor.EditorGUIUtility.PreviewType; |
24 | 24 | using System.Linq; |
| 25 | +using System.Reflection; |
25 | 26 | using Unity.Profiling; |
26 | 27 |
|
27 | 28 | namespace UnityEditor |
@@ -820,9 +821,14 @@ static EventType GetEventTypeForControlAllowDisabledContextMenuPaste(Event evt, |
820 | 821 | return EventType.Ignore; |
821 | 822 | } |
822 | 823 |
|
| 824 | + internal static string DoTextField(RecycledTextEditor editor, int id, Rect position, string text, GUIStyle style, string allowedletters, out bool changed, bool reset, bool multiline, bool passwordField) |
| 825 | + { |
| 826 | + return DoTextField(editor, id, position, text, style, allowedletters, out changed, reset, multiline, passwordField, null); |
| 827 | + } |
| 828 | + |
823 | 829 | // Should we select all text from the current field when the mouse goes up? |
824 | 830 | // (We need to keep track of this to support both SwipeSelection & initial click selects all) |
825 | | - internal static string DoTextField(RecycledTextEditor editor, int id, Rect position, string text, GUIStyle style, string allowedletters, out bool changed, bool reset, bool multiline, bool passwordField) |
| 831 | + internal static string DoTextField(RecycledTextEditor editor, int id, Rect position, string text, GUIStyle style, string allowedletters, out bool changed, bool reset, bool multiline, bool passwordField, GUIStyle cancelButtonStyle) |
826 | 832 | { |
827 | 833 | Event evt = Event.current; |
828 | 834 |
|
@@ -1236,7 +1242,10 @@ internal static string DoTextField(RecycledTextEditor editor, int id, Rect posit |
1236 | 1242 | } |
1237 | 1243 | } |
1238 | 1244 |
|
1239 | | - EditorGUIUtility.AddCursorRect(position, MouseCursor.Text); |
| 1245 | + var cursorRect = position; |
| 1246 | + if (cancelButtonStyle != null && !String.IsNullOrEmpty(text)) |
| 1247 | + cursorRect.width -= cancelButtonStyle.fixedWidth; |
| 1248 | + EditorGUIUtility.AddCursorRect(cursorRect, MouseCursor.Text); |
1240 | 1249 | } |
1241 | 1250 |
|
1242 | 1251 | if (!editor.IsEditingControl(id)) |
@@ -1697,6 +1706,13 @@ internal static string TextFieldInternal(int id, Rect position, string text, GUI |
1697 | 1706 | return text; |
1698 | 1707 | } |
1699 | 1708 |
|
| 1709 | + internal static string TextFieldInternal(int id, Rect position, string text, GUIStyle style, GUIStyle cancelButtonStyle) |
| 1710 | + { |
| 1711 | + bool dummy; |
| 1712 | + text = DoTextField(s_RecycledEditor, id, IndentedRect(position), text, style, null, out dummy, false, false, false, cancelButtonStyle); |
| 1713 | + return text; |
| 1714 | + } |
| 1715 | + |
1700 | 1716 | internal static string TextFieldInternal(Rect position, string text, GUIStyle style) |
1701 | 1717 | { |
1702 | 1718 | int id = GUIUtility.GetControlID(s_TextFieldHash, FocusType.Keyboard, position); |
@@ -1754,7 +1770,7 @@ internal static string ToolbarSearchField(int id, Rect position, string text, GU |
1754 | 1770 | s_RecycledEditor.text = text = ""; |
1755 | 1771 | GUI.changed = true; |
1756 | 1772 | } |
1757 | | - text = DoTextField(s_RecycledEditor, id, textRect, text, searchFieldStyle, null, out dummy, false, false, false); |
| 1773 | + text = DoTextField(s_RecycledEditor, id, textRect, text, searchFieldStyle, null, out dummy, false, false, false, cancelButtonStyle); |
1758 | 1774 | GUI.Button(buttonRect, GUIContent.none, cancelButtonStyle); |
1759 | 1775 |
|
1760 | 1776 | return text; |
@@ -6988,7 +7004,22 @@ internal static bool DefaultPropertyField(Rect position, SerializedProperty prop |
6988 | 7004 | case SerializedPropertyType.Color: |
6989 | 7005 | { |
6990 | 7006 | BeginChangeCheck(); |
6991 | | - Color newColor = ColorField(position, label, property.colorValue); |
| 7007 | + bool showAlpha = true; |
| 7008 | + bool hdr = false; |
| 7009 | + |
| 7010 | + var propertyFieldInfo = ScriptAttributeUtility.GetFieldInfoFromProperty(property, out var propertyType); |
| 7011 | + if (propertyFieldInfo != null) |
| 7012 | + { |
| 7013 | + var attributes = propertyFieldInfo.GetCustomAttributes<ColorUsageAttribute>(false).ToArray(); |
| 7014 | + if (attributes.Length > 0) |
| 7015 | + { |
| 7016 | + var attribute = attributes[0]; |
| 7017 | + showAlpha = attribute.showAlpha; |
| 7018 | + hdr = attribute.hdr; |
| 7019 | + } |
| 7020 | + } |
| 7021 | + |
| 7022 | + Color newColor = ColorField(position, label, property.colorValue, true, showAlpha, hdr); |
6992 | 7023 | if (EndChangeCheck()) |
6993 | 7024 | { |
6994 | 7025 | property.colorValue = newColor; |
|
0 commit comments