public void DrawHistogram(Rect rect)
            {
                Styles.reusableLabel.text = maxCountString;
                var xMargin = Mathf.Max(Styles.labelStyleUpperRight.CalcSize(Styles.reusableLabel).x, kMinMargin);

                GUI.Label(new Rect(rect.x, rect.y, xMargin, kMinMargin), Styles.reusableLabel, Styles.labelStyleUpperRight);
                GUI.Label(new Rect(rect.x, rect.yMax - 2 * kMinMargin, xMargin, kMinMargin), Styles.zeroLabel, Styles.labelStyleLowerRight);

                Styles.reusableLabel.text = maxCountString;
                GUI.Label(new Rect(rect.xMax - xMargin, rect.yMin, xMargin, kMinMargin), Styles.reusableLabel, Styles.labelStyleUpperLeft);
                GUI.Label(new Rect(rect.xMax - xMargin, rect.yMax - 2 * kMinMargin, xMargin, kMinMargin), Styles.zeroLabel, Styles.labelStyleLowerLeft);

                GUI.Label(new Rect(rect.x + xMargin, rect.yMax - kMinMargin, kMinMargin, kMinMargin), Styles.oneLabel, Styles.labelStyleUpperLeft);
                Styles.reusableLabel.text = countsLengthString;
                GUI.Label(new Rect(rect.xMax - xMargin - 3 * kMinMargin, rect.yMax - kMinMargin, 3 * kMinMargin, kMinMargin), Styles.reusableLabel, Styles.labelStyleUpperRight);

                GUI.Label(new Rect(rect.x + kMinMargin, rect.yMax - kMinMargin, rect.width - 2 * kMinMargin, kMinMargin), Styles.xAxisLabel, Styles.labelStyleUpperCenter);

                rect.xMin = rect.xMin + xMargin;
                rect.xMax = rect.xMax - xMargin;
                rect.yMax = rect.yMax - kMinMargin;
                var translation = new Vector3(rect.x, rect.y, 0f);
                var scale       = new Vector3(rect.width, rect.height, 1f);
                var matrix      = GUI.matrix *
                                  Matrix4x4.Translate(translation) *
                                  Matrix4x4.Scale(scale);

                HistogramMaterial.SetPass(0);
                Graphics.DrawMeshNow(histogramMesh, matrix);
            }
Beispiel #2
0
            public void DrawHistogram(Rect rect)
            {
                var pixelWidth  = Mathf.FloorToInt(rect.width * EditorGUIUtility.pixelsPerPoint);
                var pixelHeight = Mathf.FloorToInt(rect.height * EditorGUIUtility.pixelsPerPoint);

                if (pixelWidth != histogramTexture.width || pixelHeight != histogramTexture.height)
                {
                    if (histogramTexture.IsCreated())
                    {
                        histogramTexture.Release();
                    }
                    histogramTexture.width  = pixelWidth;
                    histogramTexture.height = pixelHeight;
                    histogramTexture.Create();
                }

                Styles.reusableLabel.text = maxCountString;
                var xMargin = Mathf.Max(Styles.labelStyleUpperRight.CalcSize(Styles.reusableLabel).x, kMinMargin);

                GUI.Label(new Rect(rect.x, rect.y, xMargin, kMinMargin), Styles.reusableLabel, Styles.labelStyleUpperRight);
                GUI.Label(new Rect(rect.x, rect.yMax - 2 * kMinMargin, xMargin, kMinMargin), Styles.zeroLabel, Styles.labelStyleLowerRight);

                Styles.reusableLabel.text = maxCountString;
                GUI.Label(new Rect(rect.xMax - xMargin, rect.yMin, xMargin, kMinMargin), Styles.reusableLabel, Styles.labelStyleUpperLeft);
                GUI.Label(new Rect(rect.xMax - xMargin, rect.yMax - 2 * kMinMargin, xMargin, kMinMargin), Styles.zeroLabel, Styles.labelStyleLowerLeft);

                GUI.Label(new Rect(rect.x + xMargin, rect.yMax - kMinMargin, kMinMargin, kMinMargin), Styles.oneLabel, Styles.labelStyleUpperLeft);
                Styles.reusableLabel.text = countsLengthString;
                GUI.Label(new Rect(rect.xMax - xMargin - 3 * kMinMargin, rect.yMax - kMinMargin, 3 * kMinMargin, kMinMargin), Styles.reusableLabel, Styles.labelStyleUpperRight);

                GUI.Label(new Rect(rect.x + kMinMargin, rect.yMax - kMinMargin, rect.width - 2 * kMinMargin, kMinMargin), Styles.xAxisLabel, Styles.labelStyleUpperCenter);

                rect.xMin += xMargin;
                rect.xMax -= xMargin;
                rect.yMax -= kMinMargin;
                var oldTarget = RenderTexture.active;

                Graphics.SetRenderTarget(histogramTexture);
                GL.Clear(true, true, new Color(0f, 0f, 0f, 0f));
                GL.PushMatrix();
                GL.LoadOrtho();
                HistogramMaterial.SetPass(0);
                Graphics.DrawMeshNow(histogramMesh, Matrix4x4.identity);
                GL.PopMatrix();
                Graphics.SetRenderTarget(oldTarget);
                GUI.DrawTexture(rect, histogramTexture);
            }