bool isSurfaceDetected = true;
if (isSurfaceDetected) {
Session.GetTrackables<TrackedPlane> (_newPlanes, TrackableQueryFilter.New);
// Iterate over planes found in this frame and instantiate corresponding GameObjects to visualize them.
foreach (var curPlane in _newPlanes) {
// 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.
var planeObject = Instantiate (plane, Vector3.zero, Quaternion.identity,
transform);
planeObject.GetComponent<DetectedPlaneVisualizer> ().Initialize (curPlane);
// Debug.Log ("test....");
// Apply a random color and grid rotation.
// planeObject.GetComponent<Renderer>().material.SetColor("_GridColor", new Color(Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f)));
// planeObject.GetComponent<Renderer>().material.SetFloat("_UvRotation", Random.Range(0.0f, 360.0f));
//
}
在画布中创建一个停止按钮并附加到方法下方
public void StopTrack()
{
// Make isSurfaceDetected to false to disable plane detection code
isSurfaceDetected = false;
// Tag DetectedPlaneVisualizer prefab to Plane(or anything else)
GameObject[] anyName = GameObject.FindGameObjectsWithTag ("Plane");
// In DetectedPlaneVisualizer we have multiple polygons so we need to loop and diable DetectedPlaneVisualizer script attatched to that prefab.
for (int i = 0; i < anyName.Length; i++)
{
anyName[i].GetComponent<DetectedPlaneVisualizer> ().enabled = false;
}
}
3 回答
最初创建bool以限制表面检测代码并最初使bool变为true .
在画布中创建一个停止按钮并附加到方法下方
确保停止按钮方法在ARController中
您可以通过禁用平面生成器预制或任何用于检测和显示这些平面的预制件来执行此操作 . 单击按钮时,将GameObject的活动状态设置为false,如下所示
DetectedPlanePrefab是GameObject . 这是我所知道的最简单的方法 .
我假设您正在使用 DetectedPlaneGenerator 类来检测GoogleARCore包中提供的平面以实现统一 .
在其Update()方法中:以下代码片段负责平面检测,并在实例化此平面预制件之后 .
它使用 DetectedPlane 这是其他三个可跟踪的一个,使用 GetTrackables 方法搜索平面 .
要启用/禁用此平面检测,只需在Update()中放置一个bool检查,然后您可以以任何方式处理它,我添加了两个新方法,以便您可以添加按钮调用以启用和禁用它 .
您可以进一步处理通过禁用此脚本所附加到的组件的所有子对象来实例化的planePrefab,因为这些预制件被实例化为其子gameObjects .