Example #1
0
 // When we reset, we want to create a new set of InputDevices for native devices in the
 // system. Use the old manager's list to create the devices from.
 public void RecreateNativeDevicesFrom(NativeInputDeviceManager oldManager)
 {
     for (int i = 0; i < oldManager.m_NativeDevices.Count; i++)
     {
         var record = oldManager.m_NativeDevices[i];
         CreateNativeInputDevice(record.deviceInfo);
     }
 }
        protected void Initialize()
        {
            if (m_IsInitialized)
            {
                return;
            }

            if (deviceManager == null)
            {
                deviceManager = new InputDeviceManager();
            }

            if (eventManager == null)
            {
                eventManager = new InputEventManager();
            }

            if (nativeDeviceManager == null)
            {
                nativeDeviceManager = new NativeInputDeviceManager();
            }

            #if UNITY_EDITOR
            // Clean up profiles used by devices. We don't serialize profiles but let InputDeviceManager
            // re-create them after domain reloads.
            profileManager.ConsolidateProfilesWithThoseUsedByDevices(deviceManager.devices);
            #endif

            nativeDeviceManager.Initialize(deviceManager, profileManager);

            nativeEventManager = new NativeInputEventManager();
            nativeEventManager.Initialize(eventManager, nativeDeviceManager);
            nativeEventManager.onReceivedEvents += OnProcessEvents;

            eventManager.rewriters.children.Add(
                new InputHandlerCallback {
                processEvent = deviceManager.RemapEvent
            });
            eventManager.consumers.children.Insert(0, deviceManager);

            NativeInputSystem.onUpdate += OnUpdate;

            currentUpdateType = NativeInputUpdateType.EndBeforeRender;

            m_IsInitialized = true;
        }
        internal static void Reset()
        {
            // Grab the manager for native devices as we want those to survive the reset.
            NativeInputDeviceManager oldNativeDeviceManager = null;

            if (s_Input != null)
            {
                oldNativeDeviceManager = s_Input.nativeDeviceManager;
            }

            // Also, we want all profiles to survive the reset.
            InputDeviceProfileManager oldProfileManager = null;

            if (s_Input != null)
            {
                oldProfileManager = s_Input.profileManager;
            }

            // And we want no native events still going to the old native event manager.
            if (s_Input != null)
            {
                s_Input.nativeEventManager.Uninitialize();
            }

            // Create blank input system state.
            s_Input           = ScriptableObject.CreateInstance <InputSystemManager>();
            s_Input.hideFlags = HideFlags.HideAndDontSave;

            // Hand existing profiles over to the new profile manager. We can't simply replace
            // the profile manager with the old one because InputSystemManager has already wired
            // up state using the new profile manager.
            if (oldProfileManager != null)
            {
                s_Input.profileManager.StealProfilesFrom(oldProfileManager);
            }

            // Recreate native devices, if we had them before.
            if (oldNativeDeviceManager != null)
            {
                s_Input.nativeDeviceManager.RecreateNativeDevicesFrom(oldNativeDeviceManager);
                oldNativeDeviceManager.Uninitialize();
            }
        }