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 );
}
}
這樣就實現了場景的跳轉。