简体   繁体   English

Vuforia + Unity:按下UI按钮时,在AR中实例化模型

[英]Vuforia + Unity : Instantiate model in AR when UI Button pressed

I know this is a really simple question but I can't figure out how to archive this: 我知道这是一个非常简单的问题,但我不知道如何将其归档:

I have a UI button in my scene and I want Vuforia to instantiate one AR Model ONLY when I press a button. 我的场景中有一个UI按钮,我希望Vuforia仅在按下按钮时实例化一个AR模型。

Following the tutorial on the net I was able to instantiate a model on the screen when I touch it but I need to know how to set up Vuforia for archive the same result only when I press a button. 在网上学习完本教程之后,我能够在触摸屏幕时在屏幕上实例化一个模型,但是我需要知道如何设置Vuforia以仅在按下按钮时将相同的结果存档。

I have to disable the "Anchor Input Listener Behaviour"? 我必须禁用“锚输入侦听器行为”吗? And then? 接着?

I want to call for the PositionContentAtPlaneAnchor but I can't figure out how to call it in the right way in the OnClick field of the button. 我想调用PositionContentAtPlaneAnchor,但是我无法在按钮的OnClick字段中弄清楚如何正确调用它。 I need to make a custom script for this? 我需要为此制作一个自定义脚本吗?

Thanks for any answer. 感谢您的回答。

Ok, sorry for the delay. 好的,抱歉。

I deduce that you are working with the ground plane, if you have the Ground Plane Stage and the Plane Finder in the scene and works, we're at a good point. 我推断出您正在使用地平面,如果您在场景中使用了Ground Plane StagePlane Finder并且可以工作,那么我们处于最佳状态。

Now, you must only add a button to the scene and into the script add something like this: 现在,您仅需在场景中添加一个按钮,然后在脚本中添加如下所示的内容:

public PlaneFinderBehaviour plane;

void Start()
{
    ...
    buttonOnTheScene.onClick.AddListener(TaskOnClick);
    ...
}

void TaskOnClick()
{
    Vector2 aPosition = new Vector2(0,0);
    ...
    plane.PerformHitTest(aPosition);
}

What does it mean? 这是什么意思?

First of all, you must move the Plane Finder from Hierarchy to the script variable, so we have a reference to the plane into the script. 首先,必须将“ Plane Finder从“层次结构”移动到脚本变量,因此我们在脚本中有一个对平面的引用。

Then when you click (or tap) on the button you simulate the click (or tap) on the display with the PerformHitTest . 然后,当您单击(或点击)按钮时,您可以使用PerformHitTest在显示屏上模拟单击(或点击)。

If you're wondering why my question in the comment, it's because the Plane Finder Behaviour Script has two modes type: Interactive and Automatic. 如果您想知道为什么在评论中提出我的问题,那是因为“ Plane Finder Behaviour Script具有两种模式类型:“交互”和“自动”。 The Interactive intercept the tap on the display and shows the object (on the ground plane) in the exact position of the tap, the automatic shows the object in the center of the plane. 交互式控件在显示屏上拦截水龙头,并在水龙头的确切位置显示对象(在地面上),自动在水平面中心显示对象。

So if you want the object in an exact position you can pass a Vector2 position in the PerformHitTest and if you want to show an object programmatically or do something when it shows the object you can call a custom method OnInteractiveHitTest . 因此,如果您希望对象处于精确位置,则可以在Vector2中传递Vector2位置,并且如果您希望以编程方式显示对象或在对象显示时执行某些操作,则可以调用自定义方法OnInteractiveHitTest

That's all. 就这样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM