/// <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 input module that is used to detect input from VR pointers.</returns>
        protected virtual VRTK4_VRInputModule SetEventSystem()
        {
            EventSystem eventSystem = EventSystem.current;

            if (eventSystem == null)
            {
                eventSystem = VRTK4_EventSystem.Instance;
            }

            if (eventSystem == null)
            {
                Debug.LogError(
                    string.Format("{0} REQUIRED_COMPONENT_MISSING_FROM_SCENE {1}", nameof(VRTK4_UIPointer),
                                  "EventSystem"),
                    gameObject);
                return(null);
            }

            var eventSystemGameObject = eventSystem.gameObject;

            if (eventSystem.GetType() != typeof(VRTK4_EventSystem))
            {
                // remove old system, put vrtk 4
                var listOfTypes = new List <System.Type>();
                foreach (var baseInputModule in eventSystemGameObject.GetComponents <BaseInputModule>())
                {
                    listOfTypes.Add(baseInputModule.GetType());
                    baseInputModule.enabled = false;
                    GameObject.DestroyImmediate(baseInputModule);
                }

                eventSystem.enabled = false;
                GameObject.DestroyImmediate(eventSystem);
                var eventSystemTyped = VRTK4_EventSystem.Instance;
                if (eventSystemTyped == null)
                {
                    eventSystemGameObject.AddComponent <VRTK4_EventSystem>();
                }

                foreach (var itemType in listOfTypes)
                {
                    eventSystemGameObject.AddComponent(itemType);
                }
            }

            VRTK4_VRInputModule needed = VRTK4_EventSystem.Instance.VRInputModule;

            if (needed == null)
            {
                needed = eventSystemGameObject.GetComponent <VRTK4_VRInputModule>();
                if (needed == null)
                {
                    needed = eventSystemGameObject.AddComponent <VRTK4_VRInputModule>();
                }

                VRTK4_EventSystem.Instance.InitializeWithVRModule(needed);
            }

            return(needed);
        }
        protected virtual void ConfigureEventSystem()
        {
            if (cachedVRInputModule == null)
            {
                cachedVRInputModule = SetEventSystem();
            }

            if (VRTK4_EventSystem.Instance != null && cachedVRInputModule != null)
            {
                if (pointerEventData == null)
                {
                    pointerEventData = new PointerEventData(VRTK4_EventSystem.Instance);
                }

                if (!cachedVRInputModule.Pointers.Contains(this))
                {
                    cachedVRInputModule.Pointers.Add(this);
                }
            }
        }
Beispiel #3
0
        protected override void OnEnable()
        {
            previousEventSystem = EventSystem.current;
            if (previousEventSystem != null)
            {
                previousEventSystem.enabled = false;
                CopyValuesFrom(previousEventSystem, this);
            }

            if (vrInputModule == null)
            {
                vrInputModule = gameObject.GetComponent <VRTK4_VRInputModule>();
                if (vrInputModule == null)
                {
                    vrInputModule = gameObject.AddComponent <VRTK4_VRInputModule>();
                }
            }

            base.OnEnable();
            StartCoroutine(SetEventSystemOfBaseInputModulesAfterFrameDelay(this));
        }
Beispiel #4
0
 public void InitializeWithVRModule(VRTK4_VRInputModule module)
 {
     vrInputModule = module;
 }