Beispiel #1
0
        // ------------------------------------------------------------------------
        // end: box


        // rect
        // ------------------------------------------------------------------------

        // draw a rectangle on the XZ plane centered at origin in object space, dimensions = (X dimension, Z dimension)
        public static void DrawRect(Vector3 center, Quaternion rotation, Vector2 dimensions, Color color, bool depthTest = true, Style style = Style.Wireframe)
        {
            if (dimensions.x < MathUtil.Epsilon || dimensions.y < MathUtil.Epsilon)
            {
                return;
            }

            Mesh mesh = null;

            switch (style)
            {
            case Style.Wireframe:
                mesh = PrimitiveMeshFactory.RectWireframe();
                break;

            case Style.SolidColor:
                mesh = PrimitiveMeshFactory.RectSolidColor();
                break;

            case Style.FlatShaded:
            case Style.SmoothShaded:
                mesh = PrimitiveMeshFactory.RectFlatShaded();
                break;
            }
            if (mesh == null)
            {
                return;
            }

            Material material = GetMaterial(style, depthTest, false);
            MaterialPropertyBlock materialProperties = GetMaterialPropertyBlock();

            materialProperties.SetColor("_Color", color);
            materialProperties.SetVector("_Dimensions", new Vector4(dimensions.x, 1.0f, dimensions.y, 0.0f));
            materialProperties.SetFloat("_ZBias", (style == Style.Wireframe) ? s_wireframeZBias : 0.0f);

            Graphics.DrawMesh(mesh, center, rotation, material, 0, null, 0, materialProperties, false, false, false);
        }