HTC VIVE 开发笔记(三)利用SteamVR中的InteractionSystem实现场景中的瞬移及场景跳转

Interaction System from the Lab. 是SteamVR更新后版本中提供的一些VR中基本交互的SDK。

其中就有为业界所采纳的VR场景中的移动方法,瞬移:Teleport.


1)设置Teleport瞬移机制

要让场景能够有瞬移的交互,非常简单,将SteamVR/InteractionSystem/Teleport/Teleporting组件拖进场景即可。接着就可以添加Teleport Point 或者Teleport Area,来实现在场景中的瞬移或者是场景的跳转。

2)设置Teleport Area 和Teleport Point

要建一个teleport area,就在场景中建一个平面,为这个平面添加脚本组件Teleport Area. 而Teleport Point直接拖到场景中就可以进行跳转。

3)使用Teleport Point实现场景的跳转。

也可以设置这个teleport point的属性Teleport Type为Switch To New Scene,并在Switch To Scene属性面板上填上要跳转场景的完整路径。这里还需要将要跳转的场景build在一起File -> Build Settings -> Scenes In Build,把相应的场景拖进去。还需要在Teleport Point脚本中添加一句代码:

Using UnityEngine.SceneManagement;
public void TeleportToScene()
		{
			if ( !string.IsNullOrEmpty( switchToScene ) )
			{
				Debug.Log( "TeleportPoint: Hook up your level loading logic to switch to new scene: " + switchToScene );
                SceneManager.LoadScene(switchToScene);//添加的代码
			}
			else
			{
				Debug.LogError( "TeleportPoint: Invalid scene name to switch to: " + switchToScene );
			}
		}

这样就实现了场景的跳转。

猜你喜欢

转载自blog.csdn.net/u011310341/article/details/78457452