Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Unity] 绘制 Capsule Gizmos #23

Open
yangruihan opened this issue Dec 4, 2020 · 0 comments
Open

[Unity] 绘制 Capsule Gizmos #23

yangruihan opened this issue Dec 4, 2020 · 0 comments

Comments

@yangruihan
Copy link
Owner

public static void DrawWireCapsule(Vector3 pos, Quaternion rot, float radius, float height,
    Color color = default(Color))
{
    if (color != default(Color))
        Handles.color = color;

    Matrix4x4 angleMatrix = Matrix4x4.TRS(pos, rot, Handles.matrix.lossyScale);
    using (new Handles.DrawingScope(angleMatrix))
    {
        var pointOffset = (height - (radius * 2)) / 2;

        //draw sideways
        Handles.DrawWireArc(Vector3.up * pointOffset, Vector3.left, Vector3.back, -180, radius);
        Handles.DrawLine(new Vector3(0, pointOffset, -radius), new Vector3(0, -pointOffset, -radius));
        Handles.DrawLine(new Vector3(0, pointOffset, radius), new Vector3(0, -pointOffset, radius));
        Handles.DrawWireArc(Vector3.down * pointOffset, Vector3.left, Vector3.back, 180, radius);
        //draw frontways
        Handles.DrawWireArc(Vector3.up * pointOffset, Vector3.back, Vector3.left, 180, radius);
        Handles.DrawLine(new Vector3(-radius, pointOffset, 0), new Vector3(-radius, -pointOffset, 0));
        Handles.DrawLine(new Vector3(radius, pointOffset, 0), new Vector3(radius, -pointOffset, 0));
        Handles.DrawWireArc(Vector3.down * pointOffset, Vector3.back, Vector3.left, -180, radius);
        //draw center
        Handles.DrawWireDisc(Vector3.up * pointOffset, Vector3.up, radius);
        Handles.DrawWireDisc(Vector3.down * pointOffset, Vector3.up, radius);
    }
}

参考资料:https://forum.unity.com/threads/drawing-capsule-gizmo.354634/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant