Quantcast
Channel: Answers by "chmodseven"
Viewing all articles
Browse latest Browse all 8

Answer by chmodseven

$
0
0
I came across this thread while trying to solve this myself, and while the solution works well the first time you apply it, I wanted it to be toggleable and ran into an issue where wireframe mode would not display properly after the first time. Eventually I solved it, so here's a toggleable version (press "Z", in this example, or alter the isInWireframeMode variable in the Inspector or via code) that might help someone else down the track. It doesn't need two cameras or depth setting hacks like other solutions I've seen - just attach to the regular camera. You can set your own preferred background color for the wireframe mode in the inspector if you don't want black, although the white for the foreground lines apparently can't be changed without digging into GL code more extensively. Enjoy! using UnityEngine; [RequireComponent (typeof (Camera))] public class WireframeViewer : MonoBehaviour { public Color wireframeBackgroundColor = Color.black; public bool isInWireframeMode; private Camera cam; private CameraClearFlags origCameraClearFlags; private Color origBackgroundColor; private bool previousMode; private void Start () { cam = GetComponent (); origCameraClearFlags = cam.clearFlags; origBackgroundColor = cam.backgroundColor; previousMode = isInWireframeMode; } private void Update () { if (Input.GetKeyDown (KeyCode.Z)) { isInWireframeMode = !isInWireframeMode; } if (isInWireframeMode == previousMode) { return; } previousMode = isInWireframeMode; if (isInWireframeMode) { origCameraClearFlags = cam.clearFlags; origBackgroundColor = cam.backgroundColor; cam.clearFlags = CameraClearFlags.Color; cam.backgroundColor = wireframeBackgroundColor; } else { cam.clearFlags = origCameraClearFlags; cam.backgroundColor = origBackgroundColor; } } private void OnPreRender () { if (isInWireframeMode) { GL.wireframe = true; } } private void OnPostRender () { if (isInWireframeMode) { GL.wireframe = false; } } }

Viewing all articles
Browse latest Browse all 8

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>