Disable/Toggle visualization of tracked planes in ARCore unity

狂风中的少年 提交于 2019-12-01 00:01:39

The sample isn't really designed to hide and show the planes, so you have to add a couple things.

First, there is no collection of the GameObjects that represent the ARCore planes. The easiest way to do this is to add a tag to the game objects:

In the Unity editor, find the TrackedPlaneVisualizer prefab and select it. Then in the property inspector, drop down the Tag dropdown and add a tag named plane.

Next, in the Toggle handler method, you need to find all the game objects with the "plane" tag. Then get both the Renderer and TrackedPlaneVisualizer components and enable or disable them based on the toggle. You need to do both components; the Renderer draws the plane, and the TrackedPlaneVisualizer re-enables the Renderer (ideally it would honor the Renderer's state).

    public void OnTogglePlanes(bool flag) {
        showPlanes = flag;
        foreach (GameObject plane in GameObject.FindGameObjectsWithTag ("plane")) {
            Renderer r = plane.GetComponent<Renderer> ();
            TrackedPlaneVisualizer t = plane.GetComponent<TrackedPlaneVisualizer>();
            r.enabled = flag;
            t.enabled = flag;
        }
    }

You can also do a similar thing where the GameObject is instantiated, so new planes honor the toggle.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!