官方链接:空间网格 | PICO 开发者平台
注意:该功能只能打包成APK在PICO 4 Ultra上真机运行,无法通过串流或PICO developer center在PC上运行。使用之前要开启视频透视。
在 Inspector 窗口中的 PXR_Manager (Script) 面板上,勾选 Spatial Mesh 选框。
新建一个空物体名为SpatialMesh,添加PXR_Spatial Mesh Manager组件(生成网格)、SeethroughManager代码(开启透视)、SpatialMesh代码(发射球)
PXR_Spatial Mesh Manager中的Mesh Prefab 至少需要包含 Mesh Filter 组件。如果想显示扫描到的网格,则还需包含 Mesh Renderer 组件。
/
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.Linq;
public class SpatialMesh : MonoBehaviour
{
public Text text;
private static SpatialMesh _instance = null;
public GameObject gun;
public GameObject ballPrefab;
public Transform firePoint;
public static SpatialMesh Instance
{
get
{
if (_instance == null)
{
_instance = FindObjectOfType<SpatialMesh>();
}
return _instance;
}
}
int pressCount = 0;
bool _previousTrigger = false;
private void Update()
{
var rightHandDevice = UnityEngine.XR.InputDevices.GetDeviceAtXRNode(UnityEngine.XR.XRNode.RightHand);
bool triggerValue;
bool suc = rightHandDevice.TryGetFeatureValue(UnityEngine.XR.CommonUsages.triggerButton, out triggerValue);
if(suc)
{
if (triggerValue != _previousTrigger && triggerValue)
{
Debug.Log("Trigger button is pressed.");
pressCount++;
if (pressCount > 10000)
{
pressCount = 0;
}
text.text = pressCount.ToString();
var obj = GameObject.CreatePrimitive(PrimitiveType.Sphere);
obj.transform.position = firePoint.position;
obj.SetActive(true);
obj.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);
obj.AddComponent<Rigidbody>().velocity = gun.transform.forward*10;
}
_previousTrigger = triggerValue;
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.XR.PXR;
public class SeethroughManager : MonoBehaviour
{
void Start()
{
PXR_Manager.EnableVideoSeeThrough = true;
}
}