Skip to content

Commit aea4afd

Browse files
committed
feat(SDK): ability to synchronise the play area transform on sdk switch
A new checkbox on the SDK Setup Switcher that when checked will synchronise the play area transform to the previous play area transform when the SDK is switched. This is useful when wanting to move the play area around with the Simulator and then switch to an SDK of an actual HMD and be in the position of where the Simulator was moved to.
1 parent 93a3251 commit aea4afd

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

Assets/VRTK/Source/Scripts/Utilities/SDK/VRTK_SDKSetupSwitcher.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public class VRTK_SDKSetupSwitcher : MonoBehaviour
3838
private Button cancelButton;
3939
[SerializeField]
4040
private Button chooseButton;
41+
[SerializeField]
42+
private bool playareaSync = true;
4143

4244
protected enum ViewingState
4345
{
@@ -47,6 +49,7 @@ protected enum ViewingState
4749

4850
private VRTK_SDKManager sdkManager;
4951
private readonly List<GameObject> chooseButtonGameObjects = new List<GameObject>();
52+
private Transform currentPlayarea;
5053

5154
protected virtual void Awake()
5255
{
@@ -79,6 +82,14 @@ protected virtual void OnDisable()
7982
protected virtual void OnLoadedSetupChanged(VRTK_SDKManager sender, VRTK_SDKManager.LoadedSetupChangeEventArgs e)
8083
{
8184
Show(ViewingState.Status);
85+
if (playareaSync && currentPlayarea != null)
86+
{
87+
Transform newPlayarea = VRTK_DeviceFinder.PlayAreaTransform();
88+
newPlayarea.transform.position = currentPlayarea.transform.position;
89+
newPlayarea.transform.rotation = currentPlayarea.transform.rotation;
90+
VRTK_SharedMethods.SetGlobalScale(newPlayarea, currentPlayarea.transform.lossyScale);
91+
}
92+
currentPlayarea = VRTK_DeviceFinder.PlayAreaTransform();
8293
}
8394

8495
protected virtual void OnSwitchButtonClick()
@@ -130,7 +141,7 @@ protected virtual void AddSelectionButtons()
130141
VRTK_SDKSetup loadedSetup = sdkManager.loadedSetup;
131142
if (loadedSetup != null)
132143
{
133-
GameObject chooseNoneButton = (GameObject)Instantiate(chooseButton.gameObject, chooseButton.transform.parent);
144+
GameObject chooseNoneButton = Instantiate(chooseButton.gameObject, chooseButton.transform.parent);
134145
chooseNoneButton.GetComponentInChildren<Text>().text = "None";
135146
chooseNoneButton.name = "ChooseNoneButton";
136147
chooseNoneButton.SetActive(true);
@@ -151,7 +162,7 @@ protected virtual void AddSelectionButtons()
151162
continue;
152163
}
153164

154-
GameObject chooseButtonCopy = (GameObject)Instantiate(chooseButton.gameObject, chooseButton.transform.parent);
165+
GameObject chooseButtonCopy = Instantiate(chooseButton.gameObject, chooseButton.transform.parent);
155166
chooseButtonCopy.GetComponentInChildren<Text>().text = setup.name;
156167
chooseButtonCopy.name = string.Format("Choose{0}Button", setup.name);
157168
chooseButtonCopy.SetActive(true);

0 commit comments

Comments
 (0)