Curved UI - VR Ready Solution To Bend Warp Your Canvas在VRTK中的使用解决方案

这篇博客讲述了在VR环境中使用CurvedUI插件遇到的交互难题,通过结合SteamVR和VRTK,尝试实现曲面UI的点击交互。作者分享了在不能直接点击按钮的情况下,如何通过监听射线交互来模拟按钮点击的解决方案,具体涉及VRTK_UICanvas的使用和事件转发的脚本实现。
摘要由CSDN通过智能技术生成

最近有一个项目效果,要使用曲面UI。就选择了受欢迎度比较高的CurvedUI这个插件。配合上SteamVR和VRTK一起使用。版本使用的是Curved UI - VR Ready Solution To Bend Warp Your Canvas3.0+steamVR1.2.2+VRTK3.2.0
插件链接
导入三个插件后,打开CurvedUI的demo场景,发现并不能如愿以偿。研究未果之后,选择了另一种方案。如果你也没找到合适的方案可以使用以下;
直接复制并打开CurvedUI的demo场景,然后隐藏掉SteamVRPrefabs和场景中的射线模型CurvedUILaserPointer,并将VRTK的那一套拿过来添加上。
在这里插入图片描述
在这里插入图片描述
这里设置完成后,在canvas上添加可进行UI交互的VRTK_UICanvas;运行程序发现并不能进行点击。这里我使用的是讲button的事件转发,在射线进行交互点击的时候,模拟了按钮Button的点击;脚本挂在Button身上。
在这里插入图片描述

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using VRTK;

public class CurvedUITest : MonoBehaviour
{
    public VRTK_Pointer _Pointer;

    private GameObject EnterPanel;

    
    // Start is called before the first frame update
    void Start()
    {
    	EnterPanel = gameObject.transform.parent.gameObject;
        _Pointer.DestinationMarkerEnter += PointerEnter;
        _Pointer.DestinationMarkerExit += PointerExit;
        _Pointer.DestinationMarkerHover += PointerHover;
        _Pointer.DestinationMarkerSet += PointerSet;

        gameObject.GetComponent<Button>().onClick.AddListener(EnterButtonClick);

    }

    private void PointerSet(object sender, DestinationMarkerEventArgs e)
    {
        ExecuteEvents.Execute(gameObject, new PointerEventData(EventSystem.current), ExecuteEvents.pointerClickHandler);
        //关键代码(按钮本身,当前按钮事件,按钮绑定的事件)
    }

    private void PointerHover(object sender, DestinationMarkerEventArgs e)
    {
        //print("射线停留");
    }

    private void PointerExit(object sender, DestinationMarkerEventArgs e)
    {
        //print("射线退出");
    }

    private void PointerEnter(object sender, DestinationMarkerEventArgs e)
    {
       // print("射线进入");
    }

    public void EnterButtonClick()
    {
        EnterPanel.SetActive(false);
    }

    private void OnDisable()
    {
        _Pointer.DestinationMarkerEnter -= PointerEnter;
        _Pointer.DestinationMarkerExit -= PointerExit;
        _Pointer.DestinationMarkerHover -= PointerHover;
        _Pointer.DestinationMarkerSet -= PointerSet;
    }
    
}

修改下手柄的交互按键。就Ok了!

2016.12.08更新的1.8版: The only true curved user interface system on asset store. Based on uGUI canvas for best compatibility. Interact with your curved canvas using ✔ Mouse ✔ Gaze ✔ Vive Controllers ✔ Oculus Touch ✔ Daydream Controller +Your own control method. Just pass Ray for input direction and a Bool for button state to CurvedUI Input Module and it will handle the rest. All with 10-seconds setup. An all-in-one VR interface package designed for the new Unity GUI system. Bends the Canvas in world space, allowing the player to view and interact with it from any angle. Create intricate designs, while still using the same uGUI workflow you're used to! Enrich your VR project with UI that will fully immerse your players. Get that Minority Report feel with curved, interactive screens. Features ✔ Easy set-up - takes less than 10 seconds! ✔ 180 degree Cylindrical mapping to wrap your interface around the player. ✔ Ring mapping to instantly create circular shapes from ordinary assets. ✔ Semisphere mapping for that space helmet feel. ✔ Perfect for Rift, GearVR, Vive, Cardboard and any other VR headset. ✔ Great in 2D ✔ Out-of-the-box Gaze Controller. ✔ World Space Mouse Controller included. ✔ Ray Controller for all your handheld pointing device needs. ✔ Dedicated Vive support. ✔ Dedicated Oculus Touch support. ✔ Fully interactive from any angle. ✔ Optimized to reduce poly count. ✔ Works on mobile. ✔ Works in Unity Personal Edition. ✔ Comes with a broad selection of small code snippets to let you get the most out of added functionalities.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值