Unity和Vuforia:目標圖像ID和GUI Windows - Unity and Vuforia: Target Image ID and GUI Windows -开发者知识库

Unity和Vuforia:目標圖像ID和GUI Windows - Unity and Vuforia: Target Image ID and GUI Windows -开发者知识库,第1张

I'm using Unity and Vuforia to make a secret project for my tabletop RPG group. Right now I'm running into an issue of lack of references and removed web pages on Vuforia's site.

我正在使用Unity和Vuforia為我的桌面RPG組制作一個秘密項目。現在我遇到了一個缺乏參考的問題,並刪除了Vuforia網站上的網頁。

Currently, my issue is this: I want to track up to 5 target images and, when scanned, have each of them to create their own individual GUI Window that tracks with the image in the UI. I have part of it working, I can track all the images, but only 1 window appears at a time. I know the actual images work because I have placeholder 3d objects included for debugging.

目前,我的問題是:我想跟蹤最多5個目標圖像,並且在掃描時,讓每個圖像創建自己的個人GUI窗口,跟蹤UI中的圖像。我有一部分工作,我可以跟蹤所有圖像,但一次只出現一個窗口。我知道實際的圖像是有效的,因為我有包含占位符的3d對象用於調試。

The script I used for the base for the GUI Windows: https://developer.vuforia.com/forum/faq/unity-how-can-i-popup-gui-button-when-target-detected

我用作GUI Windows基礎的腳本:https://developer.vuforia.com/forum/faq/unity-how-can-i-popup-gui-button-when-target-detected

I think my problem lies in the OnTrackableStateChanged() (Lines 19-32 link; 28-43 my code below). I need to alter it so it can take into account multiple target images. Then again I could be SUPER wrong because any references on Vuforia's API site or forums has been removed. Does anyone have a possible idea on what I can do to accomplish my goal? I'm currently thinking using the getID() function and then, somehow, having OnTrackableStateChange() check if the changed ID was different than the original idea. But again, I could be overlooking a simpler solution.

我認為我的問題在於OnTrackableStateChanged()(第19-32行鏈接;下面是我的代碼28-43)。我需要改變它,以便它可以考慮多個目標圖像。然后我再次出錯,因為Vuforia的API網站或論壇上的任何引用都已被刪除。有沒有人對我能做些什么來實現我的目標有所了解?我目前正在考慮使用getID()函數,然后,不知何故,讓OnTrackableStateChange()檢查更改后的ID是否與原始想法不同。但同樣,我可能會忽略一個更簡單的解決方案。

If this isn't clear I can try to be elaborate a bit more. Below is the code I'm using that uses components from the link above. Thank you for the help. :

如果不清楚,我可以嘗試更詳細一點。下面是我正在使用的代碼,它使用上面鏈接中的組件。感謝您的幫助。 :

using UnityEngine;
using System.Collections;

public class ButtonPopup : MonoBehaviour, Vuforia.ITrackableEventHandler
{

    private Vuforia.TrackableBehaviour mTrackableBehaviour;

    private bool mShowGUIWindow = false;
    private TargetScreenCoords coordinateScript;
    public int ID;
    private Rect mWindowRect;
    public string Name;
    public int Health;
    public string Status;
    public bool Villain;


    void Start()
    {
        mTrackableBehaviour = GetComponent<Vuforia.TrackableBehaviour>();
        if (mTrackableBehaviour)
        {
            mTrackableBehaviour.RegisterTrackableEventHandler(this);            
        }
    }

    public void OnTrackableStateChanged(
                                    Vuforia.TrackableBehaviour.Status previousStatus,
                                    Vuforia.TrackableBehaviour.Status newStatus)
    {

        if (newStatus == Vuforia.TrackableBehaviour.Status.DETECTED ||
            newStatus == Vuforia.TrackableBehaviour.Status.TRACKED)
        {
            mShowGUIWindow = true;
        }
        else
        {
            mShowGUIWindow = false;

        }
    }

    void OnGUI()
    {
        coordinateScript = GetComponent<TargetScreenCoords>();
        mWindowRect = new Rect(coordinateScript.screenPoint.x, Mathf.Abs(coordinateScript.screenPoint.y), 120, 100);

        if (Villain == true)
        {
            GUI.backgroundColor = Color.red;
        }
        if (Villain == false)
        {
            GUI.backgroundColor = Color.green;
        }
        if (mShowGUIWindow)
        {
            mWindowRect = GUI.Window(ID, mWindowRect, DoMyWindow, "ID:"   ID);
        }
    }

    void DoMyWindow(int windowID)
    {
        GUI.Label(new Rect(10, 20, 100, 60), new GUIContent("Name: "   Name   "\nHealth: "   Health   "\nStatus: "   Status));
        if (GUI.Button(new Rect(10, 70, 100, 20), "Edit Button"))
        {
            print("Got a click");
            Villain = !Villain;
        }

    }
}

Thanks again for the help/ideas.

再次感謝您的幫助/想法。

1 个解决方案

#1


0  

The first question is, if you want to track those 5 targets simultaneously? If yes, remember that you need to specify it in the ARCamera configuration. Set Max Simultaneous Tracked Images to 5 under the ARCamer object in scene.

第一個問題是,如果你想同時追蹤這5個目標嗎?如果是,請記住您需要在ARCamera配置中指定它。在場景中的ARCamer對象下將Max Simultaneous Tracked Images設置為5。

Under each ImageTarget you should also have a Trackable Event Handler script. By default it is DefaultTrackableEventHandler. In this script you have 2 private methods OnTrackingFound() and OnTrackingLost(). Try to add there 3rd foreach loop where you will enable/disable your GUI object type (Canvas or something like that).

在每個ImageTarget下,您還應該有一個Trackable Event Handler腳本。默認情況下,它是DefaultTrackableEventHandler。在此腳本中,您有2個私有方法OnTrackingFound()和OnTrackingLost()。嘗試添加第3個foreach循環,您將啟用/禁用GUI對象類型(Canvas或類似的東西)。

最佳答案:

本文经用户投稿或网站收集转载,如有侵权请联系本站。

发表评论

0条回复