我正在尝试将FBX模型动态添加到场景中,并将以下组件添加到通过FBX模型创建的主GameObject的子对象中:
MeshCollider(我使用sharedMesh变量为此添加了一个网格)
ManipulationHandler
NearInteractionGrabbable
当我在Unity中测试功能时,它可以正常工作。当我部署到HoloLens 2时,仅不需要“凸=真”的对象即可工作。
[这让我觉得当将其设置在hololens 2上时,设置凸= true无效。
这是我的代码,供您参考有关如何使事情正常进行的内容:
void Start()
{
//Grab object from Resources/Objects using provided unique identifier
//I'm instantiating like this because I'm setting the parent to another GameObject in the original code and I got errors if I didn't do it this way
GameObject go = Instantiate(Resources.Load<GameObject>("Objects/" + objectId));
//Loop through child objects of model
for (int i = 0; i < go.transform.childCount; i++)
{
AddManipulationComponents(go.transform.GetChild(i).gameObject);
}
}
void AddManipulationComponents(GameObject item)
{
//Get MeshFilter so I can set the mesh of it to the sharedMesh of the MeshCollider
MeshFilter meshFilter = item.GetComponent<MeshFilter>();
//Only Add MeshCollider components if there's a mesh on the object.
if (meshFilter != null)
{
Mesh mesh = item.GetComponent<MeshFilter>().mesh;
if (mesh != null)
{
//Add MeshCollider
MeshCollider collider = item.EnsureComponent<MeshCollider>();
//A lot of components are curved and need convex set to false
collider.convex = true;
//Add NearInteractionGrabbable
item.EnsureComponent<NearInteractionGrabbable>();
//Add ManipulationHandler
item.EnsureComponent<ManipulationHandler>();
//Set mesh to MeshCollider
collider.sharedMesh = mesh;
}
}
//If current component has children, then loop through those.
if (item.transform.childCount > 0)
{
for (int i = 0; i < item.transform.childCount; i++)
{
AddManipulationComponents(item.transform.GetChild(i).gameObject);
}
}
}
当我通过Unity运行它时,它可以工作,但是当我构建它并部署到HoloLens 2时,它不能完全工作。我的意思是,只有3或4个子对象可以实际工作,而它们恰好是平面对象。它使我认为MeshCollider中的“凸”变量表现不理想。
任何人都可以解决此问题吗?
这是它通过统一运作的照片(我裁剪了专有信息:]