Example #1
0
        public bool Remap(GenericControlEvent controlEvent)
        {
            var floatEvent = controlEvent as GenericControlEvent <float>;

            if (floatEvent == null)
            {
                return(false);
            }

            var eventNeg = InputSystem.CreateEvent <GenericControlEvent <float> >();

            eventNeg.device          = floatEvent.device;
            eventNeg.controlIndex    = targetIndexNeg;
            eventNeg.value           = floatEvent.value;
            eventNeg.time            = floatEvent.time;
            eventNeg.value           = Mathf.InverseLerp(fromRangeNeg.min, fromRangeNeg.max, eventNeg.value);
            eventNeg.alreadyRemapped = true;
            InputSystem.ExecuteEvent(eventNeg);

            var eventPos = InputSystem.CreateEvent <GenericControlEvent <float> >();

            eventPos.device          = floatEvent.device;
            eventPos.controlIndex    = targetIndexPos;
            eventPos.value           = floatEvent.value;
            eventPos.time            = floatEvent.time;
            eventPos.value           = Mathf.InverseLerp(fromRangePos.min, fromRangePos.max, eventPos.value);
            eventPos.alreadyRemapped = true;
            InputSystem.ExecuteEvent(eventPos);

            return(true);
        }
Example #2
0
        public bool Remap(GenericControlEvent controlEvent)
        {
            var floatEvent = controlEvent as FloatValueEvent;

            if (floatEvent == null)
            {
                return(false);
            }

            var up    = InputSystem.CreateEvent <GenericControlEvent <float> >();
            var down  = InputSystem.CreateEvent <GenericControlEvent <float> >();
            var left  = InputSystem.CreateEvent <GenericControlEvent <float> >();
            var right = InputSystem.CreateEvent <GenericControlEvent <float> >();

            up.device = down.device = left.device = right.device = floatEvent.device;
            up.time   = down.time = left.time = right.time = floatEvent.time;

            up.alreadyRemapped = down.alreadyRemapped = left.alreadyRemapped = right.alreadyRemapped = true;

            left.controlIndex  = targetIndexLeft;
            right.controlIndex = targetIndexRight;
            down.controlIndex  = targetIndexDown;
            up.controlIndex    = targetIndexUp;

            int index = floatEvent.rawValue - startingIndex;

            switch (index)
            {
            case 0: up.value = 1.0f; break;

            case 1: up.value = 1.0f; right.value = 1.0f; break;

            case 2: right.value = 1.0f; break;

            case 3: right.value = 1.0f; down.value = 1.0f; break;

            case 4: down.value = 1.0f; break;

            case 5: down.value = 1.0f; left.value = 1.0f; break;

            case 6: left.value = 1.0f; break;

            case 7: left.value = 1.0f; up.value = 1.0f; break;
            }

            InputSystem.ExecuteEvent(up);
            InputSystem.ExecuteEvent(down);
            InputSystem.ExecuteEvent(left);
            InputSystem.ExecuteEvent(right);

            return(true);
        }
        public override bool RemapEvent(InputEvent inputEvent)
        {
            GenericControlEvent controlEvent = inputEvent as GenericControlEvent;

            if (controlEvent != null)
            {
                IControlMapping controlMapping = null;
                if (m_Mappings.TryGetValue(controlEvent.controlIndex, out controlMapping))
                {
                    return(controlMapping.Remap(controlEvent));
                }
            }

            return(base.RemapEvent(inputEvent));
        }
        public bool RemapEvent(InputEvent inputEvent)
        {
            if (inputEvent.device == null)
            {
                return(false);
            }

            GenericControlEvent genericEvent = inputEvent as GenericControlEvent;

            if (genericEvent != null && genericEvent.alreadyRemapped)
            {
                return(false);
            }

            return(inputEvent.device.RemapEvent(inputEvent));
        }
        public virtual bool ProcessEventIntoState(InputEvent inputEvent, InputState intoState)
        {
            GenericControlEvent controlEvent = inputEvent as GenericControlEvent;

            if (controlEvent == null)
            {
                return(false);
            }

            var control = intoState.controls[controlEvent.controlIndex];

            if (!control.enabled)
            {
                return(false);
            }
            controlEvent.CopyValueToControl(control);
            return(true);
        }
Example #6
0
        public bool Remap(GenericControlEvent controlEvent)
        {
            if (targetIndex == -1)
            {
                return(false);
            }

            controlEvent.controlIndex = targetIndex;

            var floatEvent = controlEvent as GenericControlEvent <float>;

            if (floatEvent == null)
            {
                return(false);
            }

            floatEvent.value = Mathf.InverseLerp(fromRange.min, fromRange.max, floatEvent.value);
            floatEvent.value = Mathf.Lerp(toRange.min, toRange.max, floatEvent.value);
            return(false);
        }
        private GenericControlEvent GetControlResetEventForControl(InputControl control)
        {
            Type genericType = control.GetType();

            while (genericType.BaseType != typeof(InputControl))
            {
                genericType = genericType.BaseType;
            }
            if (genericType.GetGenericTypeDefinition() != typeof(InputControl <>))
            {
                return(null);
            }
            Type genericArgumentType = genericType.GetGenericArguments()[0];
            Type eventType           = typeof(GenericControlEvent <>).MakeGenericType(new System.Type[] { genericArgumentType });
            GenericControlEvent evt  = (GenericControlEvent)Activator.CreateInstance(eventType);

            evt.controlIndex = control.index;
            evt.CopyDefaultValueFromControl(control);
            evt.time = Time.time;
            return(evt);
        }