示例#1
0
        public void Uninitialize()
        {
            if (!m_IsInitialized)
            {
                return;
            }

            m_DeviceManager  = null;
            m_ProfileManager = null;

            NativeInputSystem.onDeviceDiscovered -= CreateNativeInputDevice;

            m_IsInitialized = false;
        }
        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;
        }
示例#3
0
        public void Initialize(InputDeviceManager deviceManager, InputDeviceProfileManager profileManager)
        {
            if (m_IsInitialized)
            {
                return;
            }

            m_DeviceManager  = deviceManager;
            m_ProfileManager = profileManager;

            // Rebuild any devices that still retain device records through serialization, even though we lost the device reference
            List <NativeDeviceRecord> nativeDeviceRecords = new List <NativeDeviceRecord>(m_NativeDevices);

            m_NativeDevices.Clear();
            for (var i = 0; i < nativeDeviceRecords.Count; i++)
            {
                CreateNativeInputDevice(nativeDeviceRecords[i].deviceInfo);
            }

            // Hook into notifications for when the native runtime discovers new devices.
            NativeInputSystem.onDeviceDiscovered += CreateNativeInputDevice;

            m_IsInitialized = true;
        }