Vuforia虚拟按钮

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Vuforia
{
    public class VirtualButtonTest : MonoBehaviour, IVirtualButtonEventHandler
    {
        public VirtualButtonBehaviour[] vbs;
        public GameObject cube;
        public GameObject sphere;
        void Start()
        {
        }

        void OnEnable()
        {
            for (int i = 0; i < vbs.Length; ++i)
            {
                //在虚拟按钮中注册TrackableBehaviour事件
                vbs[i].RegisterEventHandler(this);
            }
        }
        void OnDisable()
        {
            for (int i = 0; i < vbs.Length; ++i)
            {
                //在虚拟按钮中删除TrackableBehaviour事件
                vbs[i].UnregisterEventHandler(this);
            }
        }
        void Update()
        {

        }
        public void OnButtonPressed(VirtualButtonBehaviour vb)
        {
            switch (vb.VirtualButtonName)
            {
                case "showCube":
                    cube.SetActive(true);
                    break;
                case "showSphere":
                    sphere.SetActive(true);
                    break;
            }
        }

        public void OnButtonReleased(VirtualButtonBehaviour vb)
        {
            switch (vb.VirtualButtonName)
            {
                case "showCube":
                    cube.SetActive(false);
                    break;
                case "showSphere":
                    sphere.SetActive(false);
                    break;
            }
        }
    }
}

Vuforia虚拟按钮_第1张图片

Vuforia虚拟按钮_第2张图片

你可能感兴趣的:(unity,C#)