void Draw() { EditorGUIUtility.labelWidth = 100; gradientPreviewRect = new Rect(borderSize, borderSize, position.width - borderSize * 2, 25); keyInteractiveRect = new Rect(borderSize, gradientPreviewRect.yMax + borderSize, gradientPreviewRect.width, borderSize + keyHeight); GUI.DrawTexture(gradientPreviewRect, gradient.GetTexture((int)gradientPreviewRect.width)); var keyRectHeight = DrawKeys(); Rect settingsRect = new Rect(borderSize, keyRectHeight + borderSize, position.width - borderSize * 2, position.height + 100); DrawSettings(settingsRect); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { if (gradient == null) { var obj = fieldInfo.GetValue(property.serializedObject.targetObject); gradient = obj as PowerGradient; //cannot get instance if (gradient == null) { EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label); return; } } Event guiEvent = Event.current; EditorGUI.BeginProperty(position, label, property); { position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label); var textureRect = new Rect(position.x, position.y, position.width - 40, position.height); var copyButtonRect = new Rect(textureRect.xMax + 1, textureRect.y, 20, textureRect.height); var pasteButtonRect = new Rect(copyButtonRect.xMax, textureRect.y, 20, textureRect.height); if (guiEvent.type == EventType.Repaint) { GUIStyle gradientStyle = new GUIStyle(); gradientStyle.normal.background = gradient.GetTexture((int)position.width); GUI.Label(textureRect, GUIContent.none, gradientStyle); GUI.Button(copyButtonRect, NAME_COPY); GUI.Button(pasteButtonRect, NAME_PASTE); } else { HandleAction(guiEvent, gradient, property, ref textureRect, ref copyButtonRect, ref pasteButtonRect); } } EditorGUI.EndProperty(); }