- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我们正在为 Go 开发视频播放器应用。我们构建了一个简单的 raycaster 脚本来在用户指向 UI 按钮元素并拉动触发器时触发 onClick 事件:
bool triggerPulled = OVRInput.GetDown(OVRInput.Button.PrimaryIndexTrigger);
if (Physics.Raycast(transform.position, transform.forward, out hit, 1000))
{
if ( triggerPulled )
{
// if we hit a button
Button button = hit.transform.gameObject.GetComponent<Button>();
if (button != null)
{
button.onClick.Invoke();
}
}
....
}
我们非常希望能够使用激光指示器和按钮来操纵 UI slider ,但不清楚是否存在我们可以触发的类似事件以实现适当的行为。我们可以调用 onValueChanged
来更改值,但这并不能真正为我们提供我们想要的滑动行为,只有在我们知道结束位置后才能设置新值。
有人对如何解决这个问题有好的想法吗?
最佳答案
Oculus Integration有一个名为 OVRInputModule.cs
的脚本。我相信这是为您正在尝试做的事情而设计的。为了做到这一点,有几个步骤。结果的 GIF。
为此,我将代码分成三个脚本; ControllerInfo
、ControllerPointer
和 SetUITransformRay
。
Controller 信息只是一个确保脚本始终具有正确信息的类。
using UnityEngine;
using static OVRInput;
public class ControllerInfo : MonoBehaviour {
[SerializeField]
private Transform trackingSpace;
public static Transform TRACKING_SPACE;
public static Controller CONTROLLER;
public static GameObject CONTROLLER_DATA_FOR_RAYS;
private void Start () {
TRACKING_SPACE = trackingSpace;
}
private void Update()
{
CONTROLLER = ((GetConnectedControllers() & (Controller.LTrackedRemote | Controller.RTrackedRemote) & Controller.LTrackedRemote) != Controller.None) ? Controller.LTrackedRemote : Controller.RTrackedRemote;
}
}
ControllerPointer
从 Controller 绘制一条线。这表示 Controller 指向的方式。将其添加到 LineRenderer
。
using UnityEngine;
using UnityEngine.EventSystems;
using static OVRInput;
[RequireComponent(typeof(LineRenderer))]
public class ControllerPointer : MonoBehaviour
{
[SerializeField]
private SetUITransformRay uiRays;
private LineRenderer pointerLine;
private GameObject tempPointerVals;
private void Start()
{
tempPointerVals = new GameObject();
tempPointerVals.transform.parent = transform;
tempPointerVals.name = "tempPointerVals";
pointerLine = gameObject.GetComponent<LineRenderer>();
pointerLine.useWorldSpace = true;
ControllerInfo.CONTROLLER_DATA_FOR_RAYS = tempPointerVals;
uiRays.SetUIRays();
}
private void LateUpdate()
{
Quaternion rotation = GetLocalControllerRotation(ControllerInfo.CONTROLLER);
Vector3 position = GetLocalControllerPosition(ControllerInfo.CONTROLLER);
Vector3 pointerOrigin = ControllerInfo.TRACKING_SPACE.position + position;
Vector3 pointerProjectedOrientation = ControllerInfo.TRACKING_SPACE.position + (rotation * Vector3.forward);
PointerEventData pointerData = new PointerEventData(EventSystem.current);
Vector3 pointerDrawStart = pointerOrigin - pointerProjectedOrientation * 0.05f;
Vector3 pointerDrawEnd = pointerOrigin + pointerProjectedOrientation * 500.0f;
pointerLine.SetPosition(0, pointerDrawStart);
pointerLine.SetPosition(1, pointerDrawEnd);
tempPointerVals.transform.position = pointerDrawStart;
tempPointerVals.transform.rotation = rotation;
}
}
SetUITransformRay
将自动为 OVRInputModule
射线设置 Controller 。这是必需的,因为通常您的场景中有两个 Controller ;一左一右。有关如何设置的更多信息,请参阅下面的完整方法。将此组件添加到添加 Canvas 时生成的 EventSystem
。
using UnityEngine;
using UnityEngine.EventSystems;
public class SetUITransformRay : MonoBehaviour
{
[SerializeField]
private OVRInputModule inputModule;
[SerializeField]
private OVRGazePointer gazePointer;
public void SetUIRays()
{
inputModule.rayTransform = ControllerInfo.CONTROLLER_DATA_FOR_RAYS.transform;
gazePointer.rayTransform = ControllerInfo.CONTROLLER_DATA_FOR_RAYS.transform;
}
}
使用步骤
第一步)场景设置
导入 Oculus 集成包。将 OVRCameraRig
拖到您的场景中。将 OVRTrackedRemote
拖入左右 anchor 。根据 anchor 将每个 Remote 设置为左侧或右侧。
第 2 步)设置 Canvas 和事件系统。
在 Canvas 上,
在事件系统上,
步骤 3) 设置正确的对象
创建3个对象; Controller Manager
、Controller Pointer
和 OVRGazePointer
。
对于 OVRGazePointer
,我只是快速进入 UI 的示例场景,Oculus\VR\Scenes
,并在那里预制了 OVRGazePointer
.
在 Controller Pointer 上,有一个 LineRenderer
。这有两个点,不管在哪里。它使用世界空间。它的宽度为 0.005。
只有两个点,使用世界空间非常重要。这是因为 ControllerPointer
脚本依赖于这两个设置。
关于c# - Unity VR 中的 slider ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50765762/
我正在尝试使用 div 和 javascript 创建一个简单的 slider 。我设置了一个包含六个图像的 div 和一个箭头,每次单击它时,该箭头都会将包含图像的容器拍摄为 528px(每个图像的
我使用flexslider,当我按照他们网站上的说明操作时,它不适用于多个 slider ,这是代码: 我需要在两个 slider 上都有一个 Controller 导航,说明如下: http://w
这是一个困难的问题,我一直在努力让它发挥作用。它确实起作用了一半,但我认为逻辑是问题所在。下面我会解释一下情况和问题。 情况:想要使用 slider Controller 来选择房间内可以占用的成人、
我制作了一个简单的 slider ,它适用于普通表格,但是当我尝试将该 slider 用于我的自定义 Bootstrap 表格时,只有第一个、第三个 slider 出现,而不是第二个和第四个。 var
我正在使用 Bootstrap slider http://seiyria.com/bootstrap-slider/对于贷款产生者。这里没问题。 但是我必须使用相同的 slider ,一个位于顶部,
我正在使用光滑的 slider 。我在页面上有三个 slider ,它们都有相同的类和光滑的选项。但是,我想要三个不同的灵活“autoplaySpeed”选项,或者为所有三个 slider 分别添加随
我试图用 Slider2 和 Slider3 的总和来更新 Slider1 的值,但它只显示 Slider1 或 Slider2 的值,以移动的为准。我在更新 Slider1 的值时犯了一些错误。 H
我使用 css 和 html 以及 jQuery 创建了一个 slider 。该 slider 与下一个按钮配合使用效果很好,但与上一个按钮配合使用效果不佳。 假设我在第一张幻灯片上有五个元素,总共有
我正在制作一个包含多个 slider 的页面,其中 slider 的数量和选项根据用户的不同而不同。我遇到一个问题,所有 slider 都已创建并显示,但只有最后一个 slider 是可拖动的。 简单
我正在尝试获取 jQuery-UI slider 的当前值在 JavaScript 函数中,它不起作用。如果我这样做 $("#someParticularDOMObject").find(".sl
我正在尝试在 JQuery UI 中的 slider 的 slide 和 change 事件上同时更新多个 slider 。 我有如下代码: $(function() { var totalS
我正在使用来自 Filament 组的 jQuery UI slider ,它将 SELECT 元素转换为 slider 。它工作正常。现在我想使用 JavaScript 以编程方式将 slider
是否可以在 NIVO SLIDER 中将幻灯片设为链接? 最佳答案 嗯,不知道是不是一样,但是...... 我在 IE 所有版本中的链接都有问题,其他浏览器工作正常,通过添加解决: backgroun
在我的项目中,我使用了光滑的 slider 插件(http://kenwheeler.github.io/slick/) 我需要更改单词的默认点导航。单击单词后应更改幻灯片。 最佳答案 这是更新的代码
我正在使用 nivo slider (默认主题),我将上一个和下一个箭头定位在图像旁边(不是在图像顶部),我想知道是否有一种方法可以始终显示下一个和上一个箭头(现在箭头仅在您将鼠标悬停在图像上时显示)
我正在使用 Slider在我的 javaFX 项目中,我有一个 Label当我移动 slider 时会更新。 我想要 Label在我拖动 Slider 时进行更新不仅在拖放时。 这是我的代码: be
我有一个事件站点,一页上有 3 个光滑的 slider ,通常光滑的 slider 不会初始化,而是我只看到所有的图像,有时如果我刷新它们都开始工作。 https://au.hairandme.com
我想让每年一定数量的海龟(由 slider 控制)死亡。到目前为止,我明白了,它可能非常简单,但我似乎无法使其发挥作用。多谢! to hunting let huntedturtles (count
我有一个带背景图像的全宽 slider 。 slider 高度根据图像进行响应,因此它始终在屏幕的一侧到另一侧显示 100% 的图像。 现在我尝试将内容(文本)放置在 slider 内,使其位于内容网
我对 Swiper slider 有一些问题。当我滚动到 slider 的末尾时,可以看到一些空白区域。 http://take.ms/siqXj swiper = new Swiper(profil
我是一名优秀的程序员,十分优秀!