public static void DefaultColorPickerHandler(UIColorField colorField, UIColorPicker popup, ref bool overridden) { UIPanel panel = popup.GetComponent <UIPanel>(); overridden = true; panel.height = 250; CreateUIElement <UITextField>(out UITextField textField, panel.transform, "ColorText", new Vector4(15, 225, 200, 20)); UiTextFieldDefaults(textField); textField.normalBgSprite = "TextFieldPanel"; textField.maxLength = 6; textField.eventTextChanged += (x, y) => { if (popup && textField.text.Length == 6) { try { Color32 targetColor = ColorExtensions.FromRGB(((UITextField)x).text); colorField.selectedColor = targetColor; ((UITextField)x).textColor = Color.white; ((UITextField)x).text = targetColor.ToRGB(); } catch { ((UITextField)x).textColor = Color.red; } } }; popup.eventColorUpdated += (x) => textField.text = ((Color32)x).ToRGB(); textField.text = ((Color32)popup.color).ToRGB(); InitCircledButton(panel, out UIButton clearButton, "Niet", (x, y) => { colorField.selectedColor = Color.clear; textField.text = ""; }, null, 20); clearButton.relativePosition = new Vector3(220, 225); clearButton.color = Color.red; }
public static void DefaultColorPickerHandler(UIColorField colorField, UIColorPicker popup, ref bool overridden) { if (!overridden) { UIPanel panel = popup.GetComponent <UIPanel>(); overridden = true; panel.height = 250; CreateUIElement(out UITextField textField, panel.transform, "ColorText", new Vector4(15, 225, 200, 20)); UiTextFieldDefaults(textField); textField.normalBgSprite = "TextFieldPanel"; textField.maxLength = 6; textField.eventTextChanged += (x, y) => { if (Event.current.isKey && !alreadyOnHandler) { try { alreadyOnHandler = true; if (popup && textField.text.Length == 6) { try { Color32 targetColor = ColorExtensions.FromRGB(((UITextField)x).text); if (popup.color != targetColor) { popup.color = targetColor; var selStart = ((UITextField)x).selectionStart; var selEnd = ((UITextField)x).selectionEnd; colorField.selectedColor = targetColor; ((UITextField)x).textColor = Color.white; ((UITextField)x).text = targetColor.ToRGB(); colorField.GetType().GetMethod("OnSelectedColorChanged", RedirectorUtils.allFlags).Invoke(colorField, new object[0]); ((UITextField)x).selectionStart = selStart; ((UITextField)x).selectionEnd = selEnd; } } catch { ((UITextField)x).textColor = Color.red; } } else { ((UITextField)x).textColor = Color.red; } } finally { alreadyOnHandler = false; } } }; popup.eventColorUpdated += (x) => textField.text = ((Color32)x).ToRGB(); textField.text = ((Color32)popup.color).ToRGB(); InitCircledButton(panel, out UIButton clearButton, "Niet", (x, y) => { colorField.selectedColor = Color.clear; textField.text = ""; }, null, 20); clearButton.relativePosition = new Vector3(220, 225); clearButton.color = Color.red; } }