Version: 2017.1

SurfaceObserver.RequestMeshAsync

切换到手册
public bool RequestMeshAsync (XR.WSA.SurfaceData dataRequest, XR.WSA.SurfaceObserver.SurfaceDataReadyDelegate onDataReady);

参数

dataRequest 用于烘培指定表面的请求数据包。
onDataReady 烘培完此表面后调用的回调。

返回

bool 如果请求失败,则返回 false,失败的原因通常是指定了无效的表面 ID。

描述

调用 RequestMeshAsync 可启动特定表面网格数据的烘培流程。系统可能需要用多个帧才能生成此数据。系统将通过指定的 SurfaceDataReadyDelegate 提供烘培数据。如果 dataRequest 中指定的参数无效,此方法将抛出 ArgumentNullExcpetion 和 ArgumentException。

如果要绘制 RequestMeshAsync 返回的网格,建议您禁用阴影投射并在 MeshRenderer 上获得阴影,以提高性能。

using UnityEditor;
using UnityEngine;
using UnityEngine.VR.WSA;

public class ExampleScript : MonoBehaviour { // Request a new Surface's data given the SurfaceId and the SurfaceObserver. void RequestMeshData(SurfaceId id, SurfaceObserver observer) { // create a new GameObject to hold the new Surface with all the appropriate components GameObject newSurface = new GameObject("Surface-" + id.handle); // fill out the SurfaceData struct in order to call RequestMeshAsync SurfaceData sd; sd.id = id; sd.outputMesh = newSurface.AddComponent<MeshFilter>(); sd.outputAnchor = newSurface.AddComponent<WorldAnchor>(); sd.outputCollider = newSurface.AddComponent<MeshCollider>(); sd.trianglesPerCubicMeter = 300.0f; sd.bakeCollider = true; // make the request if (observer.RequestMeshAsync(sd, NewSurfaceBaked)) { // New surface request is in the queue and the specified callback will be invoked at a later frame. } else { // New surface request has failed. No callback for this request will be issued. } }

void NewSurfaceBaked(SurfaceData sd, bool outputWritten, float elapsedBakeTimeSeconds) { if (outputWritten) { // Request completed successfully } else { // Request has failed. } } }