Example #1
0
        public ActionMapInput CreateActionMapInput(ActionMap map, InputDevice device)
        {
            // Check for improper use of action maps first
            if (device != null && !IsValidActionMapForDevice(map, device))
            {
                return(null);
            }

            var devices = device == null?GetSystemDevices() : new List <InputDevice>
            {
                device
            };

            var actionMapInput = ActionMapInput.Create(map);

            // It's possible that there are no suitable control schemes for the device that is being initialized,
            // so ActionMapInput can't be marked active
            var successfulInitialization = false;

            if (actionMapInput.TryInitializeWithDevices(devices))
            {
                successfulInitialization = true;
            }
            else
            {
                // For two-handed tools, the single device won't work, so collect the devices from the action map
                devices = InputUtils.CollectInputDevicesFromActionMaps(new List <ActionMap>()
                {
                    map
                });
                if (actionMapInput.TryInitializeWithDevices(devices))
                {
                    successfulInitialization = true;
                }
            }

            if (successfulInitialization)
            {
                actionMapInput.autoReinitialize = false;

                // Resetting AMIs cause all AMIs (active or not) that use the same sources to be reset, which causes
                // problems (e.g. dropping objects because wasJustPressed becomes true when reset)
                actionMapInput.resetOnActiveChanged = false;
                actionMapInput.active = true;
            }

            return(actionMapInput);
        }