如何使用Unity停止平面检测并删除ARCore 1.9中的所有平面?

问题描述 投票:2回答:1

我想在屏幕上点击以显示模型。当检测到平面时,我点击设备屏幕以显示模型。当场景中显示的平面笨拙并再次检测到平面时,会出现此问题。类似于ARkit是否有任何事件可以从场景中删除锚点。当我通过触摸将模型放置在检测到的平面上时,我正在呼吁关闭平面检测并删除平面的方法。它不起作用。下面给出代码。

//Method call to turn of plane detection n delete already detected planes
 DetectedPlaneGenerator.DPGenaratorInstance.DeletePlanes();

检测到的平面生成器类,在其中编写了用于关闭平面检测并删除已找到的平面的方法。

 public class DetectedPlaneGenerator : MonoBehaviour
{
    /// <summary>
    /// A prefab for tracking and visualizing detected planes.
    /// </summary>
    public GameObject DetectedPlanePrefab;
    GameObject planeObject;
    public Text Msgtxt;

    /// <summary>
    /// A list to hold new planes ARCore began tracking in the current frame. This object is
    /// used across the application to avoid per-frame allocations.
    /// </summary>
    private List<DetectedPlane> m_NewPlanes = new List<DetectedPlane>();

    /// <summary>
    /// The Unity Update method.
    /// </summary>
    /// 

    public static DetectedPlaneGenerator DPGenaratorInstance;



    private void Start()
    {
        DPGenaratorInstance = this;
    }
    public void Update()
    {
        // Check that motion tracking is tracking.
        if (Session.Status != SessionStatus.Tracking)
        {
            return;
        }

        // Iterate over planes found in this frame and instantiate corresponding GameObjects to
        // visualize them.
        Session.GetTrackables<DetectedPlane>(m_NewPlanes, TrackableQueryFilter.New);
        for (int i = 0; i < m_NewPlanes.Count; i++)
        {
            // Instantiate a plane visualization prefab and set it to track the new plane. The
            // transform is set to the origin with an identity rotation since the mesh for our
            // prefab is updated in Unity World coordinates.
             planeObject =
                Instantiate(DetectedPlanePrefab, Vector3.zero, Quaternion.identity, transform);
            planeObject.GetComponent<DetectedPlaneVisualizer>().Initialize(m_NewPlanes[i]);
        }
    }


    public void DeletePlanes()
    {
        StopTracking();
        for (int i = 0; i < m_NewPlanes.Count; i++)
        {
            Destroy(planeObject);
        }

    }


    public void StopTracking()
    {
        int i = 0;
        //Msgtxt.text = i.ToString();

        foreach (GameObject plane in GameObject.FindGameObjectsWithTag("Plane"))
        {
            Renderer r = plane.GetComponent<Renderer>();
            DetectedPlaneVisualizer t = plane.GetComponent<DetectedPlaneVisualizer>();
            r.enabled = false;
            t.enabled = false;
           // Msgtxt.text = i.ToString();
            i++;//to check whether it is looping-no luck
        }


    }

}
c# android unity3d arcore
1个回答
-1
投票

查看此视频,希望对您有所帮助https://youtu.be/qTSDPkPyPqs

© www.soinside.com 2019 - 2024. All rights reserved.