EventSystem.currentSelectedGameObject
Add Scale Geometry Slider to Preset
Remove Bob Length adjust from Pendulum
Connect and Disconnect Bob
using UnityEngine; using System.Collections; using VRTK; public class ShowHide_UI : MonoBehaviour { bool isShown = true; public VRTK_ControllerEvents ctrl_1_events; public VRTK_ControllerEvents ctrl_2_events; public HMD_Ctrl_Tracking hmd_Track; public bool bFloor_isShown = true; public GameObject Floor; private CanvasGroup floor_CG; public float ui_dist; public float ui_vert_offset; // Use this for initialization void Start () { ctrl_1_events.ApplicationMenuPressed += new ControllerInteractionEventHandler(DoApplicationMenuPressed); ctrl_2_events.ApplicationMenuPressed += new ControllerInteractionEventHandler(DoApplicationMenuPressed); floor_CG = Floor.GetComponent<CanvasGroup>(); } void onApplicationQuit() { } // Update is called once per frame void Update () { } private void DoApplicationMenuPressed(object sender, ControllerInteractionEventArgs e) { if (!isShown) { ShowMenu(); } else { HideMenu(); } } public void Toggle_Show_Floor() { if(bFloor_isShown) { Hide_Floor(); } else { Show_Floor(); } } private void Hide_Floor() { bFloor_isShown = false; StopCoroutine("TweenFloorAlpha"); StartCoroutine("TweenFloorAlpha", bFloor_isShown); } private void Show_Floor() { bFloor_isShown = true; StopCoroutine("TweenFloorAlpha"); StartCoroutine("TweenFloorAlpha", bFloor_isShown); } private IEnumerator TweenFloorAlpha(bool show) { float targetAlpha = 0; float Dir = -1; if (show) { targetAlpha = 1; Dir = 1; } int i = 0; //Sanity check for infinite loops while (i < 250 && ((show && floor_CG.alpha < targetAlpha) || (!show && floor_CG.alpha > targetAlpha))) { floor_CG.alpha += Dir * Time.deltaTime * 0.5f; //Tweening function - 2 sec yield return true; i++; } floor_CG.alpha = Dir * targetAlpha; StopCoroutine("TweenFloorAlpha"); } private void Set_UI_Transform() { Transform hmd_trans = hmd_Track.get_HMD_Transform(); if (hmd_trans != null) { Vector3 fwd = hmd_trans.forward; fwd.y = 0f; fwd.Normalize(); Quaternion q = Quaternion.LookRotation(fwd, Vector3.up); transform.rotation = q; transform.transform.position = hmd_trans.position + fwd * ui_dist + Vector3.up*ui_vert_offset; } } public void ShowMenu() { Set_UI_Transform(); isShown = true; StopCoroutine("TweenMenuScale"); StartCoroutine("TweenMenuScale", isShown); } public void HideMenu() { isShown = false; StopCoroutine("TweenMenuScale"); StartCoroutine("TweenMenuScale", isShown); } //Simple tweening for menu, scales linearly from 0 to 1 and 1 to 0 private IEnumerator TweenMenuScale(bool show) { float targetScale = 0; Vector3 Dir = -1 * Vector3.one; if (show) { targetScale = 1; Dir = Vector3.one; } int i = 0; //Sanity check for infinite loops while (i < 250 && ((show && transform.localScale.x < targetScale) || (!show && transform.localScale.x > targetScale))) { transform.localScale += Dir * Time.deltaTime * 2f; //Tweening function - currently 0.25 second linear yield return true; i++; } transform.localScale = Dir * targetScale; StopCoroutine("TweenMenuScale"); } }