コード例 #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);
        }
コード例 #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);
        }