public void DrawPreview(CosineGradient grad) { _material.SetVector("_CoeffsA", grad.coeffsA); _material.SetVector("_CoeffsB", grad.coeffsB); _material.SetVector("_CoeffsC", grad.coeffsC2); _material.SetVector("_CoeffsD", grad.coeffsD2); EditorGUI.DrawPreviewTexture( GUILayoutUtility.GetRect(128, 32), EditorGUIUtility.whiteTexture, _material ); }
public void DrawPreview(CosineGradient grad) { if (_material == null) { _material = new Material(Shader.Find(PreviewShaderName)); _material.hideFlags = HideFlags.DontSave; } _material.SetMatrix("_Gradient", grad); EditorGUI.DrawPreviewTexture (_rect, EditorGUIUtility.whiteTexture, _material); }
public void DrawGraph(CosineGradient grad) { _rectGraph = GUILayoutUtility.GetRect(128, 80); // Background DrawRect(0, 0, 1, 1, 0.1f, 0.4f); // Horizontal line var lineColor = Color.white * 0.4f; DrawLine(0, 0.5f, 1, 0.5f, lineColor); // Vertical lines DrawLine(0.25f, 0, 0.25f, 1, lineColor); DrawLine(0.50f, 0, 0.50f, 1, lineColor); DrawLine(0.75f, 0, 0.75f, 1, lineColor); // R/G/B curves DrawGradientCurve(grad.redCoeffs, Color.red); DrawGradientCurve(grad.greenCoeffs, Color.green); DrawGradientCurve(grad.blueCoeffs, Color.blue); }
OnGUI(Rect rect, SerializedProperty prop, GUIContent label) { // Graph drawer object lazy initialization if (_graph == null) { _graph = new CosineGradientGraphDrawer(); } // -- Data retrieval // RGB component properties var rprop = prop.FindPropertyRelative("R"); var gprop = prop.FindPropertyRelative("G"); var bprop = prop.FindPropertyRelative("B"); // RGB component values var rvalue = ReadFloat4AsVector4(rprop); var gvalue = ReadFloat4AsVector4(gprop); var bvalue = ReadFloat4AsVector4(bprop); // Gradient reconstruction var gradient = new CosineGradient { R = rvalue, G = gvalue, B = bvalue }; // -- GUI // Basic constants var labelWidth = EditorGUIUtility.labelWidth; var lineHeight = EditorGUIUtility.singleLineHeight; var lineSpace = EditorGUIUtility.standardVerticalSpacing; // Draw the prefix label. rect.height = lineHeight; EditorGUI.LabelField(rect, label); // Calculate the graph area. rect.x += labelWidth; rect.width -= labelWidth; rect.height = lineHeight * 2 + lineSpace; _graph.SetRect(rect); // Graph: Background _graph.DrawPreview(gradient); // Graph: Horizontal line var lineColor = Color.white * 0.4f; //_graph.DrawLine(0, 0, 1, 0, lineColor); _graph.DrawLine(0, 0.5f, 1, 0.5f, lineColor); //_graph.DrawLine(0, 1, 1, 1, lineColor); // Graph: Vertical lines //_graph.DrawLine( 0, 0, 0, 1, lineColor); _graph.DrawLine(0.25f, 0, 0.25f, 1, lineColor); _graph.DrawLine(0.50f, 0, 0.50f, 1, lineColor); _graph.DrawLine(0.75f, 0, 0.75f, 1, lineColor); //_graph.DrawLine( 1, 0, 1, 1, lineColor); // Graph: R/G/B curves _graph.DrawGradientCurve(rvalue, Color.red); _graph.DrawGradientCurve(gvalue, Color.green); _graph.DrawGradientCurve(bvalue, Color.blue); // Calculate the field edit area. rect.height = lineHeight; rect.y += lineHeight * 2 + lineSpace * 2; // Minimize the label width. EditorGUIUtility.labelWidth = 12; // Cancel indentation. var indent = EditorGUI.indentLevel; EditorGUI.indentLevel = 0; // Red EditorGUI.PropertyField(rect, rprop, GUIContent.none); rect.y += lineHeight + lineSpace; // Green EditorGUI.PropertyField(rect, gprop, GUIContent.none); rect.y += lineHeight + lineSpace; // Blue EditorGUI.PropertyField(rect, bprop, GUIContent.none); // Recover the original label width and indent level. EditorGUIUtility.labelWidth = labelWidth; EditorGUI.indentLevel = indent; }