Ejemplo n.º 1
0
        private void DrawStairPreview(Rect rect)
        {
            // Calculate an appropriate world space to UI scale for the diagram
            float depthTotal  = stepDepthProp.floatValue * 2 + stepDepthSpacingProp.floatValue;
            float heightTotal = stepHeightProp.floatValue * 2 + stepHeightSpacingProp.floatValue;
            float uiScale     = Mathf.Min(150 / depthTotal, 60 / heightTotal);

            // Offset the center of the diagram to fit better
            Vector2 centerOffset = rect.center + new Vector2(0, 10);

            // Draw white background
            //Graphics.DrawTexture(rect, EditorGUIUtility.whiteTexture);

            // Step size and spacing in UI space
            Vector2 stepUISize    = new Vector2(stepDepthProp.floatValue * uiScale, stepHeightProp.floatValue * uiScale);
            Vector2 stepUISpacing = new Vector2(stepDepthSpacingProp.floatValue * uiScale, stepHeightSpacingProp.floatValue * uiScale);

            // Tint boxes blue
            GUI.color = new Color(0, 0.7f, 1f);

            // Draw bottom left step
            Rect stepRect1 = new Rect(centerOffset.x, centerOffset.y, stepUISize.x, stepUISize.y);

            stepRect1.center += new Vector2(-stepUISize.x - stepUISpacing.x / 2f, stepUISpacing.y / 2f);
            GUI.Box(stepRect1, new GUIContent());

            // Draw top right step
            Rect stepRect2 = new Rect(centerOffset.x, centerOffset.y, stepUISize.x, stepUISize.y);

            stepRect2.center += new Vector2(stepUISpacing.x / 2f, -stepUISize.y - stepUISpacing.y / 2f);
            GUI.Box(stepRect2, new GUIContent());

            // Draw depth spacing lines
            GUI.color = Color.grey;

            Rect drawRect = new Rect(stepRect1.xMax, stepRect2.yMin - 20, 1, 18);

            GUI.DrawTexture(drawRect, EditorGUIUtility.whiteTexture);

            drawRect = new Rect(stepRect2.xMin, stepRect2.yMin - 20, 1, 18);
            GUI.DrawTexture(drawRect, EditorGUIUtility.whiteTexture);

            // Draw height spacing lines
            drawRect = new Rect(stepRect1.xMin - 20, stepRect1.yMin, 18, 1);
            GUI.DrawTexture(drawRect, EditorGUIUtility.whiteTexture);

            drawRect = new Rect(stepRect1.xMin - 20, stepRect2.yMax, 18, 1);
            GUI.DrawTexture(drawRect, EditorGUIUtility.whiteTexture);

            // Draw text annotations
            SabreGUILayout.DrawAnchoredLabel(stepDepthProp.floatValue.ToString(), new Vector2(stepRect1.center.x, stepRect1.yMax), new Vector2(30, 20), TextAnchor.UpperCenter);
            SabreGUILayout.DrawAnchoredLabel(stepHeightProp.floatValue.ToString(), new Vector2(stepRect1.xMax, stepRect1.center.y), new Vector2(30, 20), TextAnchor.MiddleLeft);

            SabreGUILayout.DrawAnchoredLabel(stepDepthSpacingProp.floatValue.ToString(), new Vector2((stepRect1.xMax + stepRect2.xMin) / 2f, stepRect2.yMin - 20), new Vector2(30, 20), TextAnchor.LowerCenter);
            SabreGUILayout.DrawAnchoredLabel(stepHeightSpacingProp.floatValue.ToString(), new Vector2(stepRect1.xMin - 20, (stepRect1.yMin + stepRect2.yMax) / 2f), new Vector2(30, 20), TextAnchor.MiddleRight);

            // Reset GUI tints for rest of UI
            GUI.color = Color.white;
        }