示例#1
0
        /// <summary>
        /// The RemoveEventSystem resets the Unity EventSystem back to the original state before the VRTK_EventSystemVRInput was swapped for it.
        /// </summary>
        public virtual void RemoveEventSystem()
        {
            var eventSystem = FindObjectOfType <EventSystem>();

            if (!eventSystem)
            {
                Debug.LogError("A VRTK_UIPointer requires an EventSystem");
                return;
            }

#if UNITY_5_5_OR_NEWER
            //remove the custom non-pausing event system
            if (eventSystem is VRTK_NonPausingEventSystem)
            {
                var nonPausingEventSystem = eventSystem;
                eventSystem = eventSystem.gameObject.GetComponent <EventSystem>();

                nonPausingEventSystem.enabled = false;
                Destroy(nonPausingEventSystem);

                eventSystem.enabled = true;
                VRTK_NonPausingEventSystem.SetEventSystemOfBaseInputModules(eventSystem);
            }
#endif

            //re-enable existing standalone input module
            var standaloneInputModule = eventSystem.gameObject.GetComponent <StandaloneInputModule>();
            if (!standaloneInputModule.enabled)
            {
                standaloneInputModule.enabled = true;
            }

            //remove the custom event system
            var eventSystemInput = eventSystem.GetComponent <VRTK_EventSystemVRInput>();
            if (eventSystemInput)
            {
                Destroy(eventSystemInput);
            }
        }
示例#2
0
        /// <summary>
        /// The SetEventSystem method is used to set up the global Unity event system for the UI pointer. It also handles disabling the existing Standalone Input Module that exists on the EventSystem and adds a custom VRTK Event System VR Input component that is required for interacting with the UI with VR inputs.
        /// </summary>
        /// <param name="eventSystem">The global Unity event system to be used by the UI pointers.</param>
        /// <returns>A custom event system input class that is used to detect input from VR pointers.</returns>
        public virtual VRTK_EventSystemVRInput SetEventSystem(EventSystem eventSystem)
        {
            if (!eventSystem)
            {
                Debug.LogError("A VRTK_UIPointer requires an EventSystem");
                return(null);
            }

            //disable existing standalone input module
            var standaloneInputModule = eventSystem.gameObject.GetComponent <StandaloneInputModule>();

            if (standaloneInputModule.enabled)
            {
                standaloneInputModule.enabled = false;
            }

            //if it doesn't already exist, add the custom event system
            var eventSystemInput = eventSystem.GetComponent <VRTK_EventSystemVRInput>();

            if (!eventSystemInput)
            {
                eventSystemInput = eventSystem.gameObject.AddComponent <VRTK_EventSystemVRInput>();
                eventSystemInput.Initialise();
            }

#if UNITY_5_5_OR_NEWER
            //if it doesn't already exist, add the custom non-pausing event system
            var nonPausingEventSystem = eventSystem.gameObject.GetComponent <VRTK_NonPausingEventSystem>();
            if (!nonPausingEventSystem && VRTK_NonPausingEventSystem.EventSystemPausesOnApplicationFocusLost(eventSystem))
            {
                eventSystem.enabled   = false;
                nonPausingEventSystem = eventSystem.gameObject.AddComponent <VRTK_NonPausingEventSystem>();
                nonPausingEventSystem.CopyValuesFrom(eventSystem);
                VRTK_NonPausingEventSystem.SetEventSystemOfBaseInputModules(nonPausingEventSystem);
            }
#endif

            return(eventSystemInput);
        }