示例#1
0
        public static void DrawCapsule2D(Vector3 center, float rotationDeg, float height, float radius, int capSegments, Color color, bool depthTest = true, Style style = Style.Wireframe)
        {
            if (height < MathUtil.Epsilon || radius < MathUtil.Epsilon)
            {
                return;
            }

            Mesh mesh = null;

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

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

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

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

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

            Graphics.DrawMesh(mesh, center, Quaternion.AngleAxis(rotationDeg, Vector3.forward), material, 0, null, 0, materialProperties, false, false, false);
        }