コード例 #1
0
        public InputDeviceProfile()
        {
            Name = "";
            Meta = "";

            AnalogMappings = new InputControlMapping[0];
            ButtonMappings = new InputControlMapping[0];

            IncludePlatforms = new string[0];
            ExcludePlatforms = new string[0];
        }
コード例 #2
0
        protected static InputControlMapping RightStickDownMapping(InputControlSource analog)
        {
            InputControlMapping inputControlMapping = new InputControlMapping();

            inputControlMapping.Handle      = "Right Stick Down";
            inputControlMapping.Target      = InputControlType.RightStickDown;
            inputControlMapping.Source      = analog;
            inputControlMapping.SourceRange = InputRange.ZeroToOne;
            inputControlMapping.TargetRange = InputRange.ZeroToOne;
            return(inputControlMapping);
        }
コード例 #3
0
        protected static InputControlMapping DPadDownMapping2(InputControlSource analog)
        {
            InputControlMapping inputControlMapping = new InputControlMapping();

            inputControlMapping.Handle      = "DPad Down";
            inputControlMapping.Target      = InputControlType.DPadDown;
            inputControlMapping.Source      = analog;
            inputControlMapping.SourceRange = InputRange.ZeroToMinusOne;
            inputControlMapping.TargetRange = InputRange.ZeroToOne;
            return(inputControlMapping);
        }
コード例 #4
0
        protected static InputControlMapping LeftStickUpMapping(InputControlSource analog)
        {
            InputControlMapping inputControlMapping = new InputControlMapping();

            inputControlMapping.Handle      = "Left Stick Up";
            inputControlMapping.Target      = InputControlType.LeftStickUp;
            inputControlMapping.Source      = analog;
            inputControlMapping.SourceRange = InputRange.ZeroToMinusOne;
            inputControlMapping.TargetRange = InputRange.ZeroToOne;
            return(inputControlMapping);
        }
コード例 #5
0
		public UnityInputDeviceProfile()
		{
			Name = "";
			Meta = "";

			sensitivity = 1.0f;
			lowerDeadZone = 0.2f;
			upperDeadZone = 0.9f;

			AnalogMappings = new InputControlMapping[0];
			ButtonMappings = new InputControlMapping[0];
		}
コード例 #6
0
        protected static InputControlMapping RightTriggerMapping(InputControlSource analog)
        {
            InputControlMapping inputControlMapping = new InputControlMapping();

            inputControlMapping.Handle                 = "Right Trigger";
            inputControlMapping.Target                 = InputControlType.RightTrigger;
            inputControlMapping.Source                 = analog;
            inputControlMapping.SourceRange            = InputRange.MinusOneToOne;
            inputControlMapping.TargetRange            = InputRange.ZeroToOne;
            inputControlMapping.IgnoreInitialZeroValue = true;
            return(inputControlMapping);
        }
コード例 #7
0
        public UnityInputDeviceProfile()
        {
            Name = "";
            Meta = "";

            sensitivity   = 1.0f;
            lowerDeadZone = 0.2f;
            upperDeadZone = 0.9f;

            AnalogMappings = new InputControlMapping[0];
            ButtonMappings = new InputControlMapping[0];
        }
コード例 #8
0
		public InputDeviceProfile()
		{
			Name = "";
			Meta = "";

			AnalogMappings = new InputControlMapping[0];
			ButtonMappings = new InputControlMapping[0];

			SupportedPlatforms = new string[0];

			MinUnityVersion = new VersionInfo( 3, 0, 0, 0 );
			MaxUnityVersion = new VersionInfo( 9, 0, 0, 0 );
		}
コード例 #9
0
        public InputDeviceProfile()
        {
            Name = "";
            Meta = "";

            AnalogMappings = new InputControlMapping[0];
            ButtonMappings = new InputControlMapping[0];

            SupportedPlatforms = new string[0];

            MinUnityVersion = new VersionInfo(3);
            MaxUnityVersion = new VersionInfo(9);
        }
コード例 #10
0
 public InputDeviceProfile()
 {
     Name                 = string.Empty;
     Meta                 = string.Empty;
     AnalogMappings       = new InputControlMapping[0];
     ButtonMappings       = new InputControlMapping[0];
     IncludePlatforms     = new string[0];
     ExcludePlatforms     = new string[0];
     MinSystemBuildNumber = 0;
     MaxSystemBuildNumber = 0;
     DeviceClass          = InputDeviceClass.Unknown;
     DeviceStyle          = InputDeviceStyle.Unknown;
 }
コード例 #11
0
        public InputDeviceProfile()
        {
            Name = "";
            Meta = "";

            AnalogMappings = new InputControlMapping[0];
            ButtonMappings = new InputControlMapping[0];

            IncludePlatforms = new string[0];
            ExcludePlatforms = new string[0];

            MinSystemBuildNumber = 0;
            MaxSystemBuildNumber = 0;
        }
コード例 #12
0
        public UnityInputDeviceProfile()
        {
            Name = "";
            Meta = "";

            sensitivity   = 1.0f;
            lowerDeadZone = 0.2f;
            upperDeadZone = 0.9f;

            AnalogMappings = new InputControlMapping[0];
            ButtonMappings = new InputControlMapping[0];

            MinUnityVersion = new VersionInfo(3);
            MaxUnityVersion = new VersionInfo(9);
        }
コード例 #13
0
		public UnityInputDeviceProfile()
		{
			Name = "";
			Meta = "";

			sensitivity = 1.0f;
			lowerDeadZone = 0.2f;
			upperDeadZone = 0.9f;

			AnalogMappings = new InputControlMapping[0];
			ButtonMappings = new InputControlMapping[0];

			MinUnityVersion = new VersionInfo( 3 );
			MaxUnityVersion = new VersionInfo( 9 );
		}
コード例 #14
0
 public override void Update(ulong updateTick, float deltaTime)
 {
     if (skipUpdateFrames > 0)
     {
         skipUpdateFrames--;
         return;
     }
     if (Native.GetDeviceState(Handle, out IntPtr deviceState))
     {
         Marshal.Copy(deviceState, buttons, 0, buttons.Length);
         deviceState = new IntPtr(deviceState.ToInt64() + buttons.Length * 2);
         Marshal.Copy(deviceState, analogs, 0, analogs.Length);
     }
     if (IsKnown)
     {
         int analogCount = profile.AnalogCount;
         for (int i = 0; i < analogCount; i++)
         {
             InputControlMapping inputControlMapping = profile.AnalogMappings[i];
             float        value   = inputControlMapping.Source.GetValue(this);
             InputControl control = GetControl(inputControlMapping.Target);
             if (!inputControlMapping.IgnoreInitialZeroValue || !control.IsOnZeroTick || !Utility.IsZero(value))
             {
                 float value2 = inputControlMapping.MapValue(value);
                 control.UpdateWithValue(value2, updateTick, deltaTime);
             }
         }
         int buttonCount = profile.ButtonCount;
         for (int j = 0; j < buttonCount; j++)
         {
             InputControlMapping inputControlMapping2 = profile.ButtonMappings[j];
             bool state = inputControlMapping2.Source.GetState(this);
             UpdateWithState(inputControlMapping2.Target, state, updateTick, deltaTime);
         }
     }
     else
     {
         for (int k = 0; k < NumUnknownButtons; k++)
         {
             UpdateWithState((InputControlType)(500 + k), ReadRawButtonState(k), updateTick, deltaTime);
         }
         for (int l = 0; l < NumUnknownAnalogs; l++)
         {
             UpdateWithValue((InputControlType)(400 + l), ReadRawAnalogValue(l), updateTick, deltaTime);
         }
     }
 }
コード例 #15
0
        public UnknownUnityDeviceProfile(string joystickName)
        {
            Name = "Unknown Device";
            if (joystickName != "")
            {
                Name += " (" + joystickName + ")";
            }

            Meta          = "";
            Sensitivity   = 1.0f;
            LowerDeadZone = 0.2f;
            UpperDeadZone = 0.9f;

            SupportedPlatforms = null;
            JoystickNames      = new[] { joystickName };

            AnalogMappings = new InputControlMapping[UnityInputDevice.MaxAnalogs + 4];

            // I've yet to encounter a device that doesn't have this mapping.
            AnalogMappings[0] = LeftStickLeftMapping(Analog0);
            AnalogMappings[1] = LeftStickRightMapping(Analog0);
            AnalogMappings[2] = LeftStickUpMapping(Analog1);
            AnalogMappings[3] = LeftStickDownMapping(Analog1);

            for (int i = 0; i < UnityInputDevice.MaxAnalogs; i++)
            {
                AnalogMappings[i + 4] = new InputControlMapping {
                    Handle = "Analog " + i,
                    Source = Analog(i),
                    Target = InputControlType.Analog0 + i
                };
            }

            ButtonMappings = new InputControlMapping[UnityInputDevice.MaxButtons];
            for (int i = 0; i < UnityInputDevice.MaxButtons; i++)
            {
                ButtonMappings[i] = new InputControlMapping {
                    Handle = "Button " + i,
                    Source = Button(i),
                    Target = InputControlType.Button0 + i
                };
            }
        }
コード例 #16
0
		public UnknownUnityDeviceProfile( string joystickName )
		{
			Name = "Unknown Device";
			if (joystickName != "")
			{
				Name += " (" + joystickName + ")";
			}

			Meta = "";
			Sensitivity = 1.0f;
			LowerDeadZone = 0.2f;
			UpperDeadZone = 0.9f;

			SupportedPlatforms = null;
			JoystickNames = new[] { joystickName };

			AnalogMappings = new InputControlMapping[ UnityInputDevice.MaxAnalogs + 4 ];

			// I've yet to encounter a device that doesn't have this mapping.
			AnalogMappings[0] = LeftStickLeftMapping( Analog0 );
			AnalogMappings[1] = LeftStickRightMapping( Analog0 );
			AnalogMappings[2] = LeftStickUpMapping( Analog1 );
			AnalogMappings[3] = LeftStickDownMapping( Analog1 );

			for (int i = 0; i < UnityInputDevice.MaxAnalogs; i++)
			{
				AnalogMappings[i + 4] = new InputControlMapping {
					Handle = "Analog " + i,
					Source = Analog( i ),
					Target = InputControlType.Analog0 + i
				};
			}

			ButtonMappings = new InputControlMapping[ UnityInputDevice.MaxButtons ];
			for (int i = 0; i < UnityInputDevice.MaxButtons; i++)
			{
				ButtonMappings[i] = new InputControlMapping {
					Handle = "Button " + i,
					Source = Button( i ),
					Target = InputControlType.Button0 + i
				};
			}
		}
コード例 #17
0
ファイル: CustomProfile.cs プロジェクト: HoneyTribe/Labirynth
		public CustomProfile()
		{
			Name = "Custom profile";
			Meta = "Handles action not assigned to the device";
			
			SupportedPlatforms = new[]
			{
				"Windows",
				"Mac",
				"Linux"
			};
			
			Sensitivity = 1.0f;
			LowerDeadZone = 0.0f;
			
			ButtonMappings = new[]
			{
				new InputControlMapping
				{
					Handle = "Action1",
					Target = InputControlType.Action1,
					Source = KeyCodeButton( KeyCode.Return )
				},
				new InputControlMapping
				{
					Handle = "Action2",
					Target = InputControlType.Action2,
					Source = MouseButton0
				},
				new InputControlMapping
				{
					Handle = "Action3",
					Target = InputControlType.Action3,
					Source = MouseButton1
				}
			};

			AnalogMappings = new InputControlMapping[0];
		}
コード例 #18
0
        public UnityUnknownDeviceProfile( string joystickName )
        {
            Name = "Unknown Device";
            if (joystickName != "")
            {
                Name += " (" + joystickName + ")";
            }

            Meta = "";
            Sensitivity = 1.0f;
            LowerDeadZone = 0.2f;

            SupportedPlatforms = null;
            JoystickNames = new[] { joystickName };

            AnalogMappings = new InputControlMapping[ UnityInputDevice.MaxAnalogs ];
            for (int i = 0; i < UnityInputDevice.MaxAnalogs; i++)
            {
                AnalogMappings[i] = new InputControlMapping
                {
                    Handle = "Analog " + i,
                    Source = Analog( i ),
                    Target = InputControlTarget.Analog0 + i
                };
            }

            ButtonMappings = new InputControlMapping[ UnityInputDevice.MaxButtons ];
            for (int i = 0; i < UnityInputDevice.MaxButtons; i++)
            {
                ButtonMappings[i] = new InputControlMapping
                {
                    Handle = "Button " + i,
                    Source = Button( i ),
                    Target = InputControlTarget.Button0 + i
                };
            }
        }
コード例 #19
0
        public UnityUnknownDeviceProfile(string joystickName)
        {
            Name = "Unknown Device";
            if (joystickName != "")
            {
                Name += " (" + joystickName + ")";
            }

            Meta          = "";
            Sensitivity   = 1.0f;
            LowerDeadZone = 0.2f;

            SupportedPlatforms = null;
            JoystickNames      = new[] { joystickName };

            AnalogMappings = new InputControlMapping[UnityInputDevice.MaxAnalogs];
            for (int i = 0; i < UnityInputDevice.MaxAnalogs; i++)
            {
                AnalogMappings[i] = new InputControlMapping
                {
                    Handle = "Analog " + i,
                    Source = Analog(i),
                    Target = InputControlType.Analog0 + i
                };
            }

            ButtonMappings = new InputControlMapping[UnityInputDevice.MaxButtons];
            for (int i = 0; i < UnityInputDevice.MaxButtons; i++)
            {
                ButtonMappings[i] = new InputControlMapping
                {
                    Handle = "Button " + i,
                    Source = Button(i),
                    Target = InputControlType.Button0 + i
                };
            }
        }
コード例 #20
0
        public GyroProfile()
        {
            Name = "Gyroscope";
            Meta = "Gyroscope on iOS.";

            // This profile only works on mobile.
            SupportedPlatforms = new[]
            {
                "iPhone",
                "Android"
            };

            ButtonMappings = new InputControlMapping[]
            {
            };

            AnalogMappings = new[]
            {
                new InputControlMapping
                {
                    Handle = "Move X",
                    Target = InputControlTarget.LeftStickX,
                    Source = new UnityGyroAxisSource( UnityGyroAxisSource.GyroAxis.X ),
                    Raw    = true,
                    Scale  = 3.0f
                },
                new InputControlMapping
                {
                    Handle = "Move Y",
                    Target = InputControlTarget.LeftStickY,
                    Source = new UnityGyroAxisSource( UnityGyroAxisSource.GyroAxis.Y ),
                    Raw    = true,
                    Scale  = 3.0f
                },
            };
        }
コード例 #21
0
 public override void Update(ulong updateTick, float deltaTime)
 {
     if (IsKnown)
     {
         int analogCount = profile.AnalogCount;
         for (int i = 0; i < analogCount; i++)
         {
             InputControlMapping inputControlMapping = profile.AnalogMappings[i];
             float        value   = inputControlMapping.Source.GetValue(this);
             InputControl control = GetControl(inputControlMapping.Target);
             if (!inputControlMapping.IgnoreInitialZeroValue || !control.IsOnZeroTick || !Utility.IsZero(value))
             {
                 float value2 = inputControlMapping.MapValue(value);
                 control.UpdateWithValue(value2, updateTick, deltaTime);
             }
         }
         int buttonCount = profile.ButtonCount;
         for (int j = 0; j < buttonCount; j++)
         {
             InputControlMapping inputControlMapping2 = profile.ButtonMappings[j];
             bool state = inputControlMapping2.Source.GetState(this);
             UpdateWithState(inputControlMapping2.Target, state, updateTick, deltaTime);
         }
     }
     else
     {
         for (int k = 0; k < NumUnknownButtons; k++)
         {
             UpdateWithState((InputControlType)(500 + k), ReadRawButtonState(k), updateTick, deltaTime);
         }
         for (int l = 0; l < NumUnknownAnalogs; l++)
         {
             UpdateWithValue((InputControlType)(400 + l), ReadRawAnalogValue(l), updateTick, deltaTime);
         }
     }
 }
コード例 #22
0
ファイル: TestInputManager.cs プロジェクト: Cyberbanan/LD29
    void TestInputMapping( InputControlMapping.Range sourceRange, InputControlMapping.Range targetRange, bool invert, float expectA, float expectB, float expectC )
    {
        var mapping = new InputControlMapping() {
            SourceRange = sourceRange,
            TargetRange = targetRange,
            Invert      = invert
        };

        float input;
        float value;

        string sr = "Complete";
        if (sourceRange == InputControlMapping.Range.Negative)
            sr = "Negative";
        else
        if (sourceRange == InputControlMapping.Range.Positive)
            sr = "Positive";

        string tr = "Complete";
        if (targetRange == InputControlMapping.Range.Negative)
            tr = "Negative";
        else
        if (targetRange == InputControlMapping.Range.Positive)
            tr = "Positive";

        input = -1.0f;
        value = mapping.MapValue( input );
        if (Mathf.Abs( value - expectA ) > Single.Epsilon)
        {
            Debug.LogError( "Input of " + input + " got value of " + value + " instead of " + expectA + " (SR = " + sr + ", TR = " + tr + ")" );
        }

        input = 0.0f;
        value = mapping.MapValue( input );
        if (Mathf.Abs( value - expectB ) > Single.Epsilon)
        {
            Debug.LogError( "Input of " + input + " got value of " + value + " instead of " + expectB + " (SR = " + sr + ", TR = " + tr + ")" );
        }

        input = 1.0f;
        value = mapping.MapValue( input );
        if (Mathf.Abs( value - expectC ) > Single.Epsilon)
        {
            Debug.LogError( "Input of " + input + " got value of " + value + " instead of " + expectC + " (SR = " + sr + ", TR = " + tr + ")" );
        }
    }
コード例 #23
0
        protected static InputControlMapping CreateMapping(string handleName, string targetName, string sourceName)
        {
            bool isAnalog = sourceName.StartsWith("Analog");

            InputControlType targetEnum = (InputControlType)System.Enum.Parse(typeof(InputControlType), targetName);

            InputControlSource source;
            if(isAnalog)
            {
                source = CreateAnalog(sourceName);
            }
            else
            {
                source = CreateButton(sourceName);
            }

            var mapping = new InputControlMapping
            {
                Handle = handleName,
                Target = targetEnum,
                Source = source
            };

            return mapping;
        }
コード例 #24
0
        internal void Initialize(uint deviceHandle, NativeDeviceInfo deviceInfo, NativeInputDeviceProfile deviceProfile)
        {
            Handle         = deviceHandle;
            Info           = deviceInfo;
            profile        = deviceProfile;
            base.SortOrder = (int)(1000 + Handle);
            NativeDeviceInfo info = Info;

            numUnknownButtons = Math.Min((int)info.numButtons, 20);
            NativeDeviceInfo info2 = Info;

            numUnknownAnalogs = Math.Min((int)info2.numAnalogs, 20);
            NativeDeviceInfo info3 = Info;

            buttons = new short[info3.numButtons];
            NativeDeviceInfo info4 = Info;

            analogs             = new short[info4.numAnalogs];
            base.AnalogSnapshot = null;
            ClearInputState();
            ClearControls();
            if (IsKnown)
            {
                string name = profile.Name;
                if (name == null)
                {
                    NativeDeviceInfo info5 = Info;
                    name = info5.name;
                }
                base.Name = name;
                string text = profile.Meta;
                if (text == null)
                {
                    NativeDeviceInfo info6 = Info;
                    text = info6.name;
                }
                base.Meta        = text;
                base.DeviceClass = profile.DeviceClass;
                base.DeviceStyle = profile.DeviceStyle;
                int analogCount = profile.AnalogCount;
                for (int i = 0; i < analogCount; i++)
                {
                    InputControlMapping inputControlMapping = profile.AnalogMappings[i];
                    InputControl        inputControl        = AddControl(inputControlMapping.Target, inputControlMapping.Handle);
                    inputControl.Sensitivity   = Mathf.Min(profile.Sensitivity, inputControlMapping.Sensitivity);
                    inputControl.LowerDeadZone = Mathf.Max(profile.LowerDeadZone, inputControlMapping.LowerDeadZone);
                    inputControl.UpperDeadZone = Mathf.Min(profile.UpperDeadZone, inputControlMapping.UpperDeadZone);
                    inputControl.Raw           = inputControlMapping.Raw;
                    inputControl.Passive       = inputControlMapping.Passive;
                }
                int buttonCount = profile.ButtonCount;
                for (int j = 0; j < buttonCount; j++)
                {
                    InputControlMapping inputControlMapping2 = profile.ButtonMappings[j];
                    InputControl        inputControl2        = AddControl(inputControlMapping2.Target, inputControlMapping2.Handle);
                    inputControl2.Passive = inputControlMapping2.Passive;
                }
            }
            else
            {
                base.Name = "Unknown Device";
                NativeDeviceInfo info7 = Info;
                base.Meta = info7.name;
                for (int k = 0; k < NumUnknownButtons; k++)
                {
                    AddControl((InputControlType)(500 + k), "Button " + k);
                }
                for (int l = 0; l < NumUnknownAnalogs; l++)
                {
                    AddControl((InputControlType)(400 + l), "Analog " + l, 0.2f, 0.9f);
                }
            }
            skipUpdateFrames = 1;
        }