Set up EOL extension for repo.

This commit is contained in:
Rene Damm 2015-08-11 15:43:09 +02:00
Родитель 2363857dfb
Коммит 0a0d4f9706
56 изменённых файлов: 1228 добавлений и 1181 удалений

47
.hgeol Normal file
Просмотреть файл

@ -0,0 +1,47 @@
[repository]
native = LF
[patterns]
**.py = LF
**.pl = LF
**.pm = LF
**.t = LF
**.it = LF
**.h = LF
**.cpp = LF
**.cs = LF
**.c = LF
**.txt = LF
**.bindings = LF
**.sh = LF
**.jam = LF
**.as = LF
**.boo = LF
**.java = LF
**.js = LF
Makefile = LF
**.shader = LF
**.cginc = LF
**.glslinc = LF
**.mm = LF
Repositories.ini = LF
.hgignore = LF
## keep CRLF's in sync with .editorconfig
# vs can handle these as lf, but really wants them as crlf
**.vcproj = CRLF
**.vcxproj = CRLF
**.vcxproj.filters = CRLF
**.csproj = CRLF
**.sln = CRLF
**.sln.template = CRLF
**.bat = CRLF
**.cmd = CRLF
**.xaml = CRLF
# the text templating parser will actually fail on lf, inexplicably setting every #line directive as '1'
**.tt = CRLF
**.t4 = CRLF
**.ttinclude = CRLF
[eol]
only-consistent = False

Просмотреть файл

@ -29,23 +29,23 @@ public class CharacterInputController
//Debug.Log( string.Format( "lookX = {0}, lookY = {1}", lookX, lookY ) );
var fire = _controlMapInstance[ fireControl ].boolValue;
if ( fire )
{
var currentTime = Time.time;
var timeElapsedSinceLastShot = currentTime - _timeOfLastShot;
if ( timeElapsedSinceLastShot > timeBetweenShots )
{
_timeOfLastShot = currentTime;
Fire();
}
if ( fire )
{
var currentTime = Time.time;
var timeElapsedSinceLastShot = currentTime - _timeOfLastShot;
if ( timeElapsedSinceLastShot > timeBetweenShots )
{
_timeOfLastShot = currentTime;
Fire();
}
}
}
private void Fire()
{
var newProjectile = Instantiate( projectile );
newProjectile.transform.position = transform.position;
newProjectile.transform.rotation = transform.rotation;
newProjectile.GetComponent< Rigidbody >().AddForce( transform.forward * 2.0f );
}
}
private void Fire()
{
var newProjectile = Instantiate( projectile );
newProjectile.transform.position = transform.position;
newProjectile.transform.rotation = transform.rotation;
newProjectile.GetComponent< Rigidbody >().AddForce( transform.forward * 2.0f );
}
}

Просмотреть файл

@ -1,9 +1,9 @@
using UnityEngine;
using UnityEngine.InputNew;
using UnityEditor;
using System.Collections.Generic;
using Assets.Utilities;
using System.Collections.Generic;
using Assets.Utilities;
public static class CreateDemoAssets
{
[ MenuItem( "Tools/Create Input Map Asset" ) ]
@ -48,7 +48,7 @@ public static class CreateDemoAssets
{
new InputControlDescriptor
{
deviceType = typeof( Pointer )
deviceType = typeof( Pointer )
, controlIndex = ( int ) PointerControl.PositionY
}
}
@ -67,30 +67,30 @@ public static class CreateDemoAssets
var fire = ScriptableObject.CreateInstance< ControlMapEntry >();
fire.controlData = new InputControlData
{
name = "Fire"
, controlType = InputControlType.Button
};
fire.bindings = new List< ControlBinding >
{
new ControlBinding
{
sources = new List< InputControlDescriptor >
{
new InputControlDescriptor
{
deviceType = typeof( Pointer )
, controlIndex = ( int ) PointerControl.LeftButton
}
, new InputControlDescriptor
{
deviceType = typeof( Gamepad )
, controlIndex = ( int ) GamepadControl.ButtonA
}
}
}
};
entries.Add( fire );
{
name = "Fire"
, controlType = InputControlType.Button
};
fire.bindings = new List< ControlBinding >
{
new ControlBinding
{
sources = new List< InputControlDescriptor >
{
new InputControlDescriptor
{
deviceType = typeof( Pointer )
, controlIndex = ( int ) PointerControl.LeftButton
}
, new InputControlDescriptor
{
deviceType = typeof( Gamepad )
, controlIndex = ( int ) GamepadControl.ButtonA
}
}
}
};
entries.Add( fire );
controlMap.entries = entries;
controlMap.schemes = new List< string > { "default" };
@ -99,21 +99,21 @@ public static class CreateDemoAssets
AssetDatabase.CreateAsset( controlMap, path );
AssetDatabase.AddObjectToAsset( lookX, path );
AssetDatabase.AddObjectToAsset( lookY, path );
AssetDatabase.AddObjectToAsset( look, path );
AssetDatabase.AddObjectToAsset( look, path );
AssetDatabase.AddObjectToAsset( fire, path );
}
[ MenuItem( "Tools/Create Device Profile Asset" ) ]
public static void CreateDeviceProfileAsset()
{
var profile = ScriptableObject.CreateInstance< GamepadProfile >();
profile.AddDeviceName( "Generic Gamepad" );
profile.SetMappingsCount( EnumHelpers.GetValueCount< GamepadControl >() );
profile.SetMapping( ( int ) GamepadControl.ButtonA, GamepadControl.ButtonB );
profile.SetMapping( ( int ) GamepadControl.ButtonB, GamepadControl.ButtonA );
const string path = "Assets/FakepadProfile.asset";
AssetDatabase.CreateAsset( profile, path );
}
[ MenuItem( "Tools/Create Device Profile Asset" ) ]
public static void CreateDeviceProfileAsset()
{
var profile = ScriptableObject.CreateInstance< GamepadProfile >();
profile.AddDeviceName( "Generic Gamepad" );
profile.SetMappingsCount( EnumHelpers.GetValueCount< GamepadControl >() );
profile.SetMapping( ( int ) GamepadControl.ButtonA, GamepadControl.ButtonB );
profile.SetMapping( ( int ) GamepadControl.ButtonB, GamepadControl.ButtonA );
const string path = "Assets/FakepadProfile.asset";
AssetDatabase.CreateAsset( profile, path );
}
}

Просмотреть файл

@ -1,16 +1,16 @@
using UnityEngine;
using UnityEngine.InputNew;
using UnityEngine;
using UnityEngine.InputNew;
public class ExecuteAllEvents
: MonoBehaviour
{
public void Update()
{
InputSystem.ExecuteEvents();
}
public void FixedUpdate()
{
InputSystem.ExecuteEvents();
: MonoBehaviour
{
public void Update()
{
InputSystem.ExecuteEvents();
}
public void FixedUpdate()
{
InputSystem.ExecuteEvents();
}
}

Просмотреть файл

@ -1,118 +1,118 @@
using UnityEngine;
using UnityEngine.InputNew;
public class GamepadInputToEvents
: MonoBehaviour
{
#region Public Methods
public void Update()
{
SendButtonEvents();
SendAxisEvents();
}
#endregion
#region Non-Public Methods
private void SendAxisEvents()
{
var leftThumbstickX_1 = Input.GetAxis( "LeftThumbstickX_1" );
if ( leftThumbstickX_1 != _lastLeftThumbstickX[ 0 ] )
SendEvent( 0, GamepadControl.LeftThumbstickX, leftThumbstickX_1 );
var leftThumbstickY_1 = Input.GetAxis( "LeftThumbstickY_1" );
if ( leftThumbstickY_1 != _lastLeftThumbstickY[ 0 ] )
SendEvent( 0, GamepadControl.LeftThumbstickY, leftThumbstickY_1 );
var rightThumbstickX_1 = Input.GetAxis( "RightThumbstickX_1" );
if ( rightThumbstickX_1 != _lastRightThumbstickX[ 0 ] )
SendEvent( 0, GamepadControl.RightThumbstickX, rightThumbstickX_1 );
var rightThumbstickY_1 = Input.GetAxis( "RightThumbstickY_1" );
if ( rightThumbstickY_1 != _lastRightThumbstickY[ 0 ] )
SendEvent( 0, GamepadControl.LeftThumbstickY, rightThumbstickY_1 );
////FIXME: for some reason, LeftTrigger_1 responds to both left and right trigger; Unity bug??
var leftTrigger_1 = Input.GetAxis( "LeftTrigger_1" );
if ( leftTrigger_1 != _lastLeftTrigger[ 0 ] )
SendEvent( 0, GamepadControl.LeftTrigger, leftTrigger_1 );
var rightTrigger_1 = Input.GetAxis( "RightTrigger_1" );
if ( rightTrigger_1 != _lastRightTrigger[ 0 ] )
SendEvent( 0, GamepadControl.RightTrigger, rightTrigger_1 );
_lastLeftThumbstickX[ 0 ] = leftThumbstickX_1;
_lastLeftThumbstickY[ 0 ] = leftThumbstickY_1;
_lastRightThumbstickX[ 0 ] = rightThumbstickX_1;
_lastRightThumbstickY[ 0 ] = rightThumbstickY_1;
_lastLeftTrigger[ 0 ] = leftTrigger_1;
_lastRightTrigger[ 0 ] = rightTrigger_1;
}
private void SendButtonEvents()
{
if ( Input.GetKeyDown( KeyCode.JoystickButton0 ) )
SendEvent( 0, GamepadControl.ButtonA, 1.0f );
if ( Input.GetKeyUp( KeyCode.JoystickButton0 ) )
SendEvent( 0, GamepadControl.ButtonA, 0.0f );
if ( Input.GetKeyDown( KeyCode.JoystickButton1 ) )
SendEvent( 0, GamepadControl.ButtonB, 1.0f );
if ( Input.GetKeyUp( KeyCode.JoystickButton1 ) )
SendEvent( 0, GamepadControl.ButtonB, 0.0f );
if ( Input.GetKeyDown( KeyCode.JoystickButton2 ) )
SendEvent( 0, GamepadControl.ButtonX, 1.0f );
if ( Input.GetKeyUp( KeyCode.JoystickButton2 ) )
SendEvent( 0, GamepadControl.ButtonX, 0.0f );
if ( Input.GetKeyDown( KeyCode.JoystickButton3 ) )
SendEvent( 0, GamepadControl.ButtonY, 1.0f );
if ( Input.GetKeyUp( KeyCode.JoystickButton3 ) )
SendEvent( 0, GamepadControl.ButtonY, 0.0f );
if ( Input.GetKeyDown( KeyCode.JoystickButton4 ) )
SendEvent( 0, GamepadControl.LeftShoulder, 1.0f );
if ( Input.GetKeyUp( KeyCode.JoystickButton4 ) )
SendEvent( 0, GamepadControl.LeftShoulder, 0.0f );
if ( Input.GetKeyDown( KeyCode.JoystickButton5 ) )
SendEvent( 0, GamepadControl.RightShoulder, 1.0f );
if ( Input.GetKeyUp( KeyCode.JoystickButton5 ) )
SendEvent( 0, GamepadControl.RightShoulder, 0.0f );
if ( Input.GetKeyDown( KeyCode.JoystickButton6 ) )
SendEvent( 0, GamepadControl.Back, 1.0f );
if ( Input.GetKeyUp( KeyCode.JoystickButton6 ) )
SendEvent( 0, GamepadControl.Back, 0.0f );
if ( Input.GetKeyDown( KeyCode.JoystickButton7 ) )
SendEvent( 0, GamepadControl.Start, 1.0f );
if ( Input.GetKeyUp( KeyCode.JoystickButton7 ) )
SendEvent( 0, GamepadControl.Start, 0.0f );
if ( Input.GetKeyDown( KeyCode.JoystickButton8 ) )
SendEvent( 0, GamepadControl.LeftThumbstickPress, 1.0f );
if ( Input.GetKeyUp( KeyCode.JoystickButton8 ) )
SendEvent( 0, GamepadControl.LeftThumbstickPress, 0.0f );
if ( Input.GetKeyDown( KeyCode.JoystickButton9 ) )
SendEvent( 0, GamepadControl.RightThumbstickPress, 1.0f );
if ( Input.GetKeyUp( KeyCode.JoystickButton9 ) )
SendEvent( 0, GamepadControl.RightThumbstickPress, 0.0f );
}
private void SendEvent( int deviceIndex, GamepadControl controlIndex, float value )
{
var inputEvent = InputSystem.CreateEvent< GenericControlEvent >();
inputEvent.deviceType = typeof( Gamepad );
inputEvent.deviceIndex = deviceIndex;
inputEvent.controlIndex = ( int ) controlIndex;
inputEvent.value = value;
Debug.Log( inputEvent );
InputSystem.QueueEvent( inputEvent );
}
#endregion
#region Fields
private readonly float[] _lastLeftThumbstickX = new float[ 8 ];
private readonly float[] _lastLeftThumbstickY = new float[ 8 ];
private readonly float[] _lastRightThumbstickX = new float[ 8 ];
private readonly float[] _lastRightThumbstickY = new float[ 8 ];
private readonly float[] _lastLeftTrigger = new float[ 8 ];
private readonly float[] _lastRightTrigger = new float[ 8 ];
#endregion
using UnityEngine;
using UnityEngine.InputNew;
public class GamepadInputToEvents
: MonoBehaviour
{
#region Public Methods
public void Update()
{
SendButtonEvents();
SendAxisEvents();
}
#endregion
#region Non-Public Methods
private void SendAxisEvents()
{
var leftThumbstickX_1 = Input.GetAxis( "LeftThumbstickX_1" );
if ( leftThumbstickX_1 != _lastLeftThumbstickX[ 0 ] )
SendEvent( 0, GamepadControl.LeftThumbstickX, leftThumbstickX_1 );
var leftThumbstickY_1 = Input.GetAxis( "LeftThumbstickY_1" );
if ( leftThumbstickY_1 != _lastLeftThumbstickY[ 0 ] )
SendEvent( 0, GamepadControl.LeftThumbstickY, leftThumbstickY_1 );
var rightThumbstickX_1 = Input.GetAxis( "RightThumbstickX_1" );
if ( rightThumbstickX_1 != _lastRightThumbstickX[ 0 ] )
SendEvent( 0, GamepadControl.RightThumbstickX, rightThumbstickX_1 );
var rightThumbstickY_1 = Input.GetAxis( "RightThumbstickY_1" );
if ( rightThumbstickY_1 != _lastRightThumbstickY[ 0 ] )
SendEvent( 0, GamepadControl.LeftThumbstickY, rightThumbstickY_1 );
////FIXME: for some reason, LeftTrigger_1 responds to both left and right trigger; Unity bug??
var leftTrigger_1 = Input.GetAxis( "LeftTrigger_1" );
if ( leftTrigger_1 != _lastLeftTrigger[ 0 ] )
SendEvent( 0, GamepadControl.LeftTrigger, leftTrigger_1 );
var rightTrigger_1 = Input.GetAxis( "RightTrigger_1" );
if ( rightTrigger_1 != _lastRightTrigger[ 0 ] )
SendEvent( 0, GamepadControl.RightTrigger, rightTrigger_1 );
_lastLeftThumbstickX[ 0 ] = leftThumbstickX_1;
_lastLeftThumbstickY[ 0 ] = leftThumbstickY_1;
_lastRightThumbstickX[ 0 ] = rightThumbstickX_1;
_lastRightThumbstickY[ 0 ] = rightThumbstickY_1;
_lastLeftTrigger[ 0 ] = leftTrigger_1;
_lastRightTrigger[ 0 ] = rightTrigger_1;
}
private void SendButtonEvents()
{
if ( Input.GetKeyDown( KeyCode.JoystickButton0 ) )
SendEvent( 0, GamepadControl.ButtonA, 1.0f );
if ( Input.GetKeyUp( KeyCode.JoystickButton0 ) )
SendEvent( 0, GamepadControl.ButtonA, 0.0f );
if ( Input.GetKeyDown( KeyCode.JoystickButton1 ) )
SendEvent( 0, GamepadControl.ButtonB, 1.0f );
if ( Input.GetKeyUp( KeyCode.JoystickButton1 ) )
SendEvent( 0, GamepadControl.ButtonB, 0.0f );
if ( Input.GetKeyDown( KeyCode.JoystickButton2 ) )
SendEvent( 0, GamepadControl.ButtonX, 1.0f );
if ( Input.GetKeyUp( KeyCode.JoystickButton2 ) )
SendEvent( 0, GamepadControl.ButtonX, 0.0f );
if ( Input.GetKeyDown( KeyCode.JoystickButton3 ) )
SendEvent( 0, GamepadControl.ButtonY, 1.0f );
if ( Input.GetKeyUp( KeyCode.JoystickButton3 ) )
SendEvent( 0, GamepadControl.ButtonY, 0.0f );
if ( Input.GetKeyDown( KeyCode.JoystickButton4 ) )
SendEvent( 0, GamepadControl.LeftShoulder, 1.0f );
if ( Input.GetKeyUp( KeyCode.JoystickButton4 ) )
SendEvent( 0, GamepadControl.LeftShoulder, 0.0f );
if ( Input.GetKeyDown( KeyCode.JoystickButton5 ) )
SendEvent( 0, GamepadControl.RightShoulder, 1.0f );
if ( Input.GetKeyUp( KeyCode.JoystickButton5 ) )
SendEvent( 0, GamepadControl.RightShoulder, 0.0f );
if ( Input.GetKeyDown( KeyCode.JoystickButton6 ) )
SendEvent( 0, GamepadControl.Back, 1.0f );
if ( Input.GetKeyUp( KeyCode.JoystickButton6 ) )
SendEvent( 0, GamepadControl.Back, 0.0f );
if ( Input.GetKeyDown( KeyCode.JoystickButton7 ) )
SendEvent( 0, GamepadControl.Start, 1.0f );
if ( Input.GetKeyUp( KeyCode.JoystickButton7 ) )
SendEvent( 0, GamepadControl.Start, 0.0f );
if ( Input.GetKeyDown( KeyCode.JoystickButton8 ) )
SendEvent( 0, GamepadControl.LeftThumbstickPress, 1.0f );
if ( Input.GetKeyUp( KeyCode.JoystickButton8 ) )
SendEvent( 0, GamepadControl.LeftThumbstickPress, 0.0f );
if ( Input.GetKeyDown( KeyCode.JoystickButton9 ) )
SendEvent( 0, GamepadControl.RightThumbstickPress, 1.0f );
if ( Input.GetKeyUp( KeyCode.JoystickButton9 ) )
SendEvent( 0, GamepadControl.RightThumbstickPress, 0.0f );
}
private void SendEvent( int deviceIndex, GamepadControl controlIndex, float value )
{
var inputEvent = InputSystem.CreateEvent< GenericControlEvent >();
inputEvent.deviceType = typeof( Gamepad );
inputEvent.deviceIndex = deviceIndex;
inputEvent.controlIndex = ( int ) controlIndex;
inputEvent.value = value;
Debug.Log( inputEvent );
InputSystem.QueueEvent( inputEvent );
}
#endregion
#region Fields
private readonly float[] _lastLeftThumbstickX = new float[ 8 ];
private readonly float[] _lastLeftThumbstickY = new float[ 8 ];
private readonly float[] _lastRightThumbstickX = new float[ 8 ];
private readonly float[] _lastRightThumbstickY = new float[ 8 ];
private readonly float[] _lastLeftTrigger = new float[ 8 ];
private readonly float[] _lastRightTrigger = new float[ 8 ];
#endregion
}

Просмотреть файл

@ -6,8 +6,8 @@ public class InputManager
{
public InputDeviceProfile[] profiles;
public void Awake()
{
InputSystem.Initialize( profiles );
public void Awake()
{
InputSystem.Initialize( profiles );
}
}

Просмотреть файл

@ -1,11 +1,11 @@
using System;
namespace UnityEngine.InputNew
{
using System;
namespace UnityEngine.InputNew
{
[ Serializable ]
public class ButtonAxisSource
{
public InputControlDescriptor negative;
public InputControlDescriptor positive;
}
}
}

Просмотреть файл

@ -1,8 +1,8 @@
using System;
using System.Collections.Generic;
namespace UnityEngine.InputNew
{
using System;
using System.Collections.Generic;
namespace UnityEngine.InputNew
{
[ Serializable ]
public class ControlBinding
{
@ -12,5 +12,5 @@ namespace UnityEngine.InputNew
public float gravity = 1000;
public float sensitivity = 1000;
public bool snap = true;
}
}
}

Просмотреть файл

@ -1,43 +1,43 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace UnityEngine.InputNew
{
using System;
using System.Collections.Generic;
using System.Linq;
namespace UnityEngine.InputNew
{
public class ControlMap
: ScriptableObject
{
public List< ControlMapEntry > entries;
public List< string > schemes;
public void OnEnable()
{
if ( entries != null )
{
for ( var i = 0; i < entries.Count; ++ i )
{
entries[ i ].controlIndex = i;
}
}
public void OnEnable()
{
if ( entries != null )
{
for ( var i = 0; i < entries.Count; ++ i )
{
entries[ i ].controlIndex = i;
}
}
}
public IEnumerable< Type > GetUsedDeviceType( int controlSchemeIndex )
{
if ( entries == null )
return Enumerable.Empty< Type >();
var deviceTypes = new HashSet< Type >();
foreach ( var entry in entries )
{
var binding = entry.bindings[ controlSchemeIndex ];
foreach ( var source in binding.sources )
deviceTypes.Add( source.deviceType );
////TODO: button axes
}
return deviceTypes;
public IEnumerable< Type > GetUsedDeviceType( int controlSchemeIndex )
{
if ( entries == null )
return Enumerable.Empty< Type >();
var deviceTypes = new HashSet< Type >();
foreach ( var entry in entries )
{
var binding = entry.bindings[ controlSchemeIndex ];
foreach ( var source in binding.sources )
deviceTypes.Add( source.deviceType );
////TODO: button axes
}
return deviceTypes;
}
}
}
}
}

Просмотреть файл

@ -1,36 +1,36 @@
using System;
using System.Collections.Generic;
namespace UnityEngine.InputNew
{
using System;
using System.Collections.Generic;
namespace UnityEngine.InputNew
{
public class ControlMapEntry
: ScriptableObject
{
#region Public Properties
public InputControlData controlData
{
get { return _controlData; }
set
{
_controlData = value;
name = _controlData.name;
}
}
// This is one entry for each control scheme (matching indices).
public List< ControlBinding > bindings;
[ NonSerialized ]
public int controlIndex;
#endregion
#region Fields
[ SerializeField ]
private InputControlData _controlData;
#endregion
}
{
#region Public Properties
public InputControlData controlData
{
get { return _controlData; }
set
{
_controlData = value;
name = _controlData.name;
}
}
// This is one entry for each control scheme (matching indices).
public List< ControlBinding > bindings;
[ NonSerialized ]
public int controlIndex;
#endregion
#region Fields
[ SerializeField ]
private InputControlData _controlData;
#endregion
}
}

Просмотреть файл

@ -1,8 +1,8 @@
using System;
using System.Collections.Generic;
namespace UnityEngine.InputNew
{
using System;
using System.Collections.Generic;
namespace UnityEngine.InputNew
{
public class ControlMapInstance
: InputControlProvider
{
@ -12,7 +12,7 @@ namespace UnityEngine.InputNew
(
ControlMap controlMap
, int controlSchemeIndex
, List< InputControlData > controls
, List< InputControlData > controls
, List< InputState > deviceStates
)
: base( controls )
@ -28,12 +28,12 @@ namespace UnityEngine.InputNew
public void Activate()
{
var treeNode = new InputEventTree
{
name = "Map"
, processInput = ProcessEvent
};
InputSystem.eventTree.children.Add( treeNode );
var treeNode = new InputEventTree
{
name = "Map"
, processInput = ProcessEvent
};
InputSystem.eventTree.children.Add( treeNode );
}
public override bool ProcessEvent( InputEvent inputEvent )
@ -43,10 +43,10 @@ namespace UnityEngine.InputNew
// Update device state (if event actually goes to one of the devices we talk to).
foreach ( var deviceState in _deviceStates )
////FIXME: should refer to proper type
if ( ( ( InputDevice ) deviceState.controlProvider ).ProcessEventIntoState( inputEvent, deviceState ) )
{
consumed = true;
break;
if ( ( ( InputDevice ) deviceState.controlProvider ).ProcessEventIntoState( inputEvent, deviceState ) )
{
consumed = true;
break;
}
if ( !consumed )
@ -55,64 +55,64 @@ namespace UnityEngine.InputNew
////REVIEW: this probably needs to be done as a post-processing step after all events have been received
// Synchronize the ControlMapInstance's own state.
for ( var entryIndex = 0; entryIndex < _controlMap.entries.Count; ++ entryIndex)
{
var entry = _controlMap.entries[ entryIndex ];
if ( entry.bindings == null || entry.bindings.Count == 0 )
continue;
var binding = entry.bindings[ controlSchemeIndex ];
var controlValue = 0.0f;
foreach ( var source in binding.sources )
{
var deviceState = GetDeviceStateForDeviceType( source.deviceType );
var value = deviceState[ source.controlIndex ].floatValue;
if ( Mathf.Abs( value ) > Mathf.Abs( controlValue ) )
controlValue = value;
}
////TODO: support button axes
state.SetCurrentValue( entryIndex, controlValue );
{
var entry = _controlMap.entries[ entryIndex ];
if ( entry.bindings == null || entry.bindings.Count == 0 )
continue;
var binding = entry.bindings[ controlSchemeIndex ];
var controlValue = 0.0f;
foreach ( var source in binding.sources )
{
var deviceState = GetDeviceStateForDeviceType( source.deviceType );
var value = deviceState[ source.controlIndex ].floatValue;
if ( Mathf.Abs( value ) > Mathf.Abs( controlValue ) )
controlValue = value;
}
////TODO: support button axes
state.SetCurrentValue( entryIndex, controlValue );
}
return true;
}
#endregion
#region Non-Public Methods
private InputState GetDeviceStateForDeviceType( Type deviceType )
{
foreach ( var deviceState in _deviceStates )
if ( deviceType.IsInstanceOfType( deviceState.controlProvider ) )
return deviceState;
throw new ArgumentException( "deviceType" );
}
#endregion
#region Public Properties
public int controlSchemeIndex { get; private set; }
public InputControl this[ ControlMapEntry entry ]
{
get
{
return state[ entry.controlIndex ];
}
}
#endregion
#region Fields
}
#endregion
#region Non-Public Methods
private InputState GetDeviceStateForDeviceType( Type deviceType )
{
foreach ( var deviceState in _deviceStates )
if ( deviceType.IsInstanceOfType( deviceState.controlProvider ) )
return deviceState;
throw new ArgumentException( "deviceType" );
}
#endregion
#region Public Properties
public int controlSchemeIndex { get; private set; }
public InputControl this[ ControlMapEntry entry ]
{
get
{
return state[ entry.controlIndex ];
}
}
#endregion
#region Fields
private readonly ControlMap _controlMap;
private readonly List< InputState > _deviceStates;
#endregion
}
}
}
}

Просмотреть файл

@ -1,9 +1,9 @@
using System.Collections.Generic;
using System.Linq;
using Assets.Utilities;
namespace UnityEngine.InputNew
{
using System.Collections.Generic;
using System.Linq;
using Assets.Utilities;
namespace UnityEngine.InputNew
{
public class Gamepad
: Joystick
{
@ -14,52 +14,52 @@ namespace UnityEngine.InputNew
{
}
#endregion
public static InputDevice CreateDefault()
{
var controls = Enumerable.Repeat( new InputControlData(), EnumHelpers.GetValueCount< GamepadControl >() ).ToList();
// Compounds.
controls[ ( int ) GamepadControl.LeftThumbstick ] = new InputControlData
{
name = "LeftThumbstick"
, controlType = InputControlType.Vector2
, componentControlIndices = new int[ 2 ] { ( int ) GamepadControl.LeftThumbstickX, ( int ) GamepadControl.LeftThumbstickY }
};
controls[ ( int ) GamepadControl.RightThumbstick ] = new InputControlData
{
name = "RightThumbstick"
, controlType = InputControlType.Vector2
, componentControlIndices = new int[ 2 ] { ( int ) GamepadControl.RightThumbstickX, ( int ) GamepadControl.RightThumbstickY }
};
////TODO: dpad (more complicated as the source is buttons which need to be translated into a vector)
// Buttons.
controls[ ( int ) GamepadControl.ButtonA ] = new InputControlData { name = "A", controlType = InputControlType.Button };
controls[ ( int ) GamepadControl.ButtonB ] = new InputControlData { name = "B", controlType = InputControlType.Button };
controls[ ( int ) GamepadControl.ButtonX ] = new InputControlData { name = "X", controlType = InputControlType.Button };
controls[ ( int ) GamepadControl.ButtonY ] = new InputControlData { name = "Y", controlType = InputControlType.Button };
controls[ ( int ) GamepadControl.Start ] = new InputControlData { name = "Start", controlType = InputControlType.Button };
controls[ ( int ) GamepadControl.Back ] = new InputControlData { name = "Back", controlType = InputControlType.Button };
controls[ ( int ) GamepadControl.LeftThumbstickPress ] = new InputControlData { name = "LeftThumbstickPress", controlType = InputControlType.Button };
controls[ ( int ) GamepadControl.RightThumbstickPress ] = new InputControlData { name = "RightThumbstickPress", controlType = InputControlType.Button };
controls[ ( int ) GamepadControl.DpadUp ] = new InputControlData { name = "DpadUp", controlType = InputControlType.Button };
controls[ ( int ) GamepadControl.DpadDown ] = new InputControlData { name = "DpadDown", controlType = InputControlType.Button };
controls[ ( int ) GamepadControl.DpadLeft ] = new InputControlData { name = "DpadLeft", controlType = InputControlType.Button };
controls[ ( int ) GamepadControl.DpadRight ] = new InputControlData { name = "DpadRight", controlType = InputControlType.Button };
controls[ ( int ) GamepadControl.LeftShoulder ] = new InputControlData { name = "LeftShoulder", controlType = InputControlType.Button };
controls[ ( int ) GamepadControl.RightShoulder ] = new InputControlData { name = "RightShoulder", controlType = InputControlType.Button };
// Axes.
controls[ ( int ) GamepadControl.LeftThumbstickX ] = new InputControlData { name = "LeftThumbstickX", controlType = InputControlType.AbsoluteAxis };
controls[ ( int ) GamepadControl.LeftThumbstickY ] = new InputControlData { name = "LeftThumbstickY", controlType = InputControlType.AbsoluteAxis };
controls[ ( int ) GamepadControl.RightThumbstickX ] = new InputControlData { name = "RightThumbstickX", controlType = InputControlType.AbsoluteAxis };
controls[ ( int ) GamepadControl.RightThumbstickY ] = new InputControlData { name = "RightThumbstickY", controlType = InputControlType.AbsoluteAxis };
controls[ ( int ) GamepadControl.LeftTrigger ] = new InputControlData { name = "LeftTrigger", controlType = InputControlType.AbsoluteAxis };
controls[ ( int ) GamepadControl.RightTrigger ] = new InputControlData { name = "RightTrigger", controlType = InputControlType.AbsoluteAxis };
return new Gamepad( "Generic Gamepad", controls );
}
}
#endregion
public static InputDevice CreateDefault()
{
var controls = Enumerable.Repeat( new InputControlData(), EnumHelpers.GetValueCount< GamepadControl >() ).ToList();
// Compounds.
controls[ ( int ) GamepadControl.LeftThumbstick ] = new InputControlData
{
name = "LeftThumbstick"
, controlType = InputControlType.Vector2
, componentControlIndices = new int[ 2 ] { ( int ) GamepadControl.LeftThumbstickX, ( int ) GamepadControl.LeftThumbstickY }
};
controls[ ( int ) GamepadControl.RightThumbstick ] = new InputControlData
{
name = "RightThumbstick"
, controlType = InputControlType.Vector2
, componentControlIndices = new int[ 2 ] { ( int ) GamepadControl.RightThumbstickX, ( int ) GamepadControl.RightThumbstickY }
};
////TODO: dpad (more complicated as the source is buttons which need to be translated into a vector)
// Buttons.
controls[ ( int ) GamepadControl.ButtonA ] = new InputControlData { name = "A", controlType = InputControlType.Button };
controls[ ( int ) GamepadControl.ButtonB ] = new InputControlData { name = "B", controlType = InputControlType.Button };
controls[ ( int ) GamepadControl.ButtonX ] = new InputControlData { name = "X", controlType = InputControlType.Button };
controls[ ( int ) GamepadControl.ButtonY ] = new InputControlData { name = "Y", controlType = InputControlType.Button };
controls[ ( int ) GamepadControl.Start ] = new InputControlData { name = "Start", controlType = InputControlType.Button };
controls[ ( int ) GamepadControl.Back ] = new InputControlData { name = "Back", controlType = InputControlType.Button };
controls[ ( int ) GamepadControl.LeftThumbstickPress ] = new InputControlData { name = "LeftThumbstickPress", controlType = InputControlType.Button };
controls[ ( int ) GamepadControl.RightThumbstickPress ] = new InputControlData { name = "RightThumbstickPress", controlType = InputControlType.Button };
controls[ ( int ) GamepadControl.DpadUp ] = new InputControlData { name = "DpadUp", controlType = InputControlType.Button };
controls[ ( int ) GamepadControl.DpadDown ] = new InputControlData { name = "DpadDown", controlType = InputControlType.Button };
controls[ ( int ) GamepadControl.DpadLeft ] = new InputControlData { name = "DpadLeft", controlType = InputControlType.Button };
controls[ ( int ) GamepadControl.DpadRight ] = new InputControlData { name = "DpadRight", controlType = InputControlType.Button };
controls[ ( int ) GamepadControl.LeftShoulder ] = new InputControlData { name = "LeftShoulder", controlType = InputControlType.Button };
controls[ ( int ) GamepadControl.RightShoulder ] = new InputControlData { name = "RightShoulder", controlType = InputControlType.Button };
// Axes.
controls[ ( int ) GamepadControl.LeftThumbstickX ] = new InputControlData { name = "LeftThumbstickX", controlType = InputControlType.AbsoluteAxis };
controls[ ( int ) GamepadControl.LeftThumbstickY ] = new InputControlData { name = "LeftThumbstickY", controlType = InputControlType.AbsoluteAxis };
controls[ ( int ) GamepadControl.RightThumbstickX ] = new InputControlData { name = "RightThumbstickX", controlType = InputControlType.AbsoluteAxis };
controls[ ( int ) GamepadControl.RightThumbstickY ] = new InputControlData { name = "RightThumbstickY", controlType = InputControlType.AbsoluteAxis };
controls[ ( int ) GamepadControl.LeftTrigger ] = new InputControlData { name = "LeftTrigger", controlType = InputControlType.AbsoluteAxis };
controls[ ( int ) GamepadControl.RightTrigger ] = new InputControlData { name = "RightTrigger", controlType = InputControlType.AbsoluteAxis };
return new Gamepad( "Generic Gamepad", controls );
}
}
}

Просмотреть файл

@ -1,5 +1,5 @@
namespace UnityEngine.InputNew
{
namespace UnityEngine.InputNew
{
public enum GamepadControl
{
LeftThumbstick, // Compound control (vector2)
@ -34,5 +34,5 @@ namespace UnityEngine.InputNew
LeftThumbstickPress,
RightThumbstickPress,
}
}
}

Просмотреть файл

@ -1,18 +1,18 @@
using Assets.Utilities;
namespace UnityEngine.InputNew
{
public class GamepadProfile
: JoystickProfile
{
#region Public Methods
public void SetMapping( int sourceControlIndex, GamepadControl targetControlIndex, string displayName = null, Sprite displayIcon = null )
{
SetMapping( sourceControlIndex, ( int ) targetControlIndex, displayName, displayIcon );
}
#endregion
}
}
using Assets.Utilities;
namespace UnityEngine.InputNew
{
public class GamepadProfile
: JoystickProfile
{
#region Public Methods
public void SetMapping( int sourceControlIndex, GamepadControl targetControlIndex, string displayName = null, Sprite displayIcon = null )
{
SetMapping( sourceControlIndex, ( int ) targetControlIndex, displayName, displayIcon );
}
#endregion
}
}

Просмотреть файл

@ -1,22 +1,22 @@
namespace UnityEngine.InputNew
{
namespace UnityEngine.InputNew
{
public class GenericControlEvent
: InputEvent
{
#region Public Methods
public override string ToString()
{
return string.Format( "{0} index={1} value={2}", base.ToString(), controlIndex, value );
}
#endregion
#region Public Properties
: InputEvent
{
#region Public Methods
public override string ToString()
{
return string.Format( "{0} index={1} value={2}", base.ToString(), controlIndex, value );
}
#endregion
#region Public Properties
public int controlIndex { get; set; }
public float value { get; set; }
#endregion
}
}
}

Просмотреть файл

@ -1,7 +1,7 @@
namespace UnityEngine.InputNew
{
namespace UnityEngine.InputNew
{
public class GestureEvent
: InputEvent
{
}
}
}

Просмотреть файл

@ -1,7 +1,7 @@
using System.Collections.Generic;
namespace UnityEngine.InputNew
{
using System.Collections.Generic;
namespace UnityEngine.InputNew
{
public interface IInputConsumer
{
string name { get; }
@ -9,5 +9,5 @@ namespace UnityEngine.InputNew
IList< IInputConsumer > children { get; }
ProcessInputDelegate processInput { get; set; }
}
}
}

Просмотреть файл

@ -1,7 +1,7 @@
using System.Collections.Generic;
namespace UnityEngine.InputNew
{
using System.Collections.Generic;
namespace UnityEngine.InputNew
{
/// <summary>
/// An object that exposes a specific configuration of input controls.
/// </summary>
@ -9,5 +9,5 @@ namespace UnityEngine.InputNew
{
////REVIEW: this should be readonly but not sure ReadOnlyCollection from .NET 2 is good enough
IList< InputControlData > controls { get; }
}
}
}

Просмотреть файл

@ -1,7 +1,7 @@
using System;
namespace UnityEngine.InputNew
{
using System;
namespace UnityEngine.InputNew
{
public struct InputControl
{
#region Constructors
@ -64,5 +64,5 @@ namespace UnityEngine.InputNew
private InputState _state;
#endregion
}
}
}

Просмотреть файл

@ -1,12 +1,12 @@
using System;
namespace UnityEngine.InputNew
{
using System;
namespace UnityEngine.InputNew
{
[ Serializable ]
public struct InputControlData
{
public string name;
public InputControlType controlType;
public int[] componentControlIndices;
}
}
}

Просмотреть файл

@ -1,7 +1,7 @@
using System;
namespace UnityEngine.InputNew
{
using System;
namespace UnityEngine.InputNew
{
[ Serializable ]
public struct InputControlDescriptor
{
@ -9,23 +9,23 @@ namespace UnityEngine.InputNew
public Type deviceType
{
get
{
if ( _cachedDeviceType == null )
_cachedDeviceType = Type.GetType( _deviceTypeName );
return _cachedDeviceType;;
get
{
if ( _cachedDeviceType == null )
_cachedDeviceType = Type.GetType( _deviceTypeName );
return _cachedDeviceType;;
}
set
{
_cachedDeviceType = value;
_deviceTypeName = _cachedDeviceType.AssemblyQualifiedName;
set
{
_cachedDeviceType = value;
_deviceTypeName = _cachedDeviceType.AssemblyQualifiedName;
}
}
[ SerializeField ]
private string _deviceTypeName;
private string _deviceTypeName;
private Type _cachedDeviceType;
}
}
}

Просмотреть файл

@ -1,7 +1,7 @@
using System.Collections.Generic;
namespace UnityEngine.InputNew
{
using System.Collections.Generic;
namespace UnityEngine.InputNew
{
public class InputControlProvider
: IInputControlProvider
{
@ -17,20 +17,20 @@ namespace UnityEngine.InputNew
#region Public Methods
public virtual bool ProcessEvent( InputEvent inputEvent )
{
lastEventTime = inputEvent.time;
var consumed = false;
var genericEvent = inputEvent as GenericControlEvent;
if ( genericEvent != null )
{
consumed |= _state.SetCurrentValue( genericEvent.controlIndex, genericEvent.value );
}
return consumed;
}
public virtual bool ProcessEvent( InputEvent inputEvent )
{
lastEventTime = inputEvent.time;
var consumed = false;
var genericEvent = inputEvent as GenericControlEvent;
if ( genericEvent != null )
{
consumed |= _state.SetCurrentValue( genericEvent.controlIndex, genericEvent.value );
}
return consumed;
}
#endregion
@ -57,5 +57,5 @@ namespace UnityEngine.InputNew
private readonly List< InputControlData > _controls;
#endregion
}
}
}

Просмотреть файл

@ -1,5 +1,5 @@
namespace UnityEngine.InputNew
{
namespace UnityEngine.InputNew
{
public enum InputControlType
{
Button,
@ -9,5 +9,5 @@ namespace UnityEngine.InputNew
Vector3,
Vector4,
Quaternion,
}
}
}

Просмотреть файл

@ -1,12 +1,12 @@
using System.Collections.Generic;
// TODO
// X device need to have some kind of identification string
// X create fakepad profile asset
// - look for matching profile on device registration
namespace UnityEngine.InputNew
{
using System.Collections.Generic;
// TODO
// X device need to have some kind of identification string
// X create fakepad profile asset
// - look for matching profile on device registration
namespace UnityEngine.InputNew
{
public abstract class InputDevice
: InputControlProvider
{
@ -20,19 +20,19 @@ namespace UnityEngine.InputNew
#endregion
#region Public Methods
public sealed override bool ProcessEvent( InputEvent inputEvent )
{
ProcessEventIntoState( inputEvent, state );
return false;
}
public virtual bool ProcessEventIntoState( InputEvent inputEvent, InputState intoState )
{
return base.ProcessEvent( inputEvent );
}
#region Public Methods
public sealed override bool ProcessEvent( InputEvent inputEvent )
{
ProcessEventIntoState( inputEvent, state );
return false;
}
public virtual bool ProcessEventIntoState( InputEvent inputEvent, InputState intoState )
{
return base.ProcessEvent( inputEvent );
}
public virtual bool RemapEvent( InputEvent inputEvent )
{
if ( profile != null )
@ -40,16 +40,16 @@ namespace UnityEngine.InputNew
return false;
}
#endregion
#region Public Properties
public bool connected { get; internal set; }
public InputDeviceProfile profile { get; set; }
public string deviceName { get; private set; }
#endregion
}
}
#endregion
#region Public Properties
public bool connected { get; internal set; }
public InputDeviceProfile profile { get; set; }
public string deviceName { get; private set; }
#endregion
}
}

Просмотреть файл

@ -1,8 +1,8 @@
using System;
using System.Collections.Generic;
namespace UnityEngine.InputNew
{
using System;
using System.Collections.Generic;
namespace UnityEngine.InputNew
{
internal class InputDeviceManager
{
#region Constructors
@ -11,11 +11,11 @@ namespace UnityEngine.InputNew
{
// In the prototype, just create a set of default devices. In the real thing, these would be registered
// and configured by the platform layer according to what's really available on the system.
var mouse = Mouse.CreateDefault();
var keyboard = Keyboard.CreateDefault();
var touchscreen = Touchscreen.CreateDefault();
var gamepad = Gamepad.CreateDefault();
var mouse = Mouse.CreateDefault();
var keyboard = Keyboard.CreateDefault();
var touchscreen = Touchscreen.CreateDefault();
var gamepad = Gamepad.CreateDefault();
RegisterDevice( mouse );
RegisterDevice( keyboard );
RegisterDevice( touchscreen );
@ -31,38 +31,38 @@ namespace UnityEngine.InputNew
AssignDeviceProfile (device);
RegisterDeviceInternal( device.GetType(), device );
HandleDeviceConnectDisconnect( device, true );
}
public void RegisterProfile( InputDeviceProfile profile )
{
_profiles.Add( profile );
}
public InputDevice GetMostRecentlyUsedDevice( Type deviceType )
{
for ( var i = _leastToMostRecentlyUsedDevices.Count - 1; i >= 0; -- i )
{
var device = _leastToMostRecentlyUsedDevices[ i ];
if ( deviceType.IsInstanceOfType( device ) )
return device;
}
return null;
}
public TDevice GetMostRecentlyUsedDevice< TDevice >()
where TDevice : InputDevice
{
return ( TDevice ) GetMostRecentlyUsedDevice( typeof ( TDevice ) );
}
public List< InputDevice > GetDevicesOfType( Type deviceType )
{
List< InputDevice > list;
_devices.TryGetValue( deviceType, out list );
return list;
}
}
public void RegisterProfile( InputDeviceProfile profile )
{
_profiles.Add( profile );
}
public InputDevice GetMostRecentlyUsedDevice( Type deviceType )
{
for ( var i = _leastToMostRecentlyUsedDevices.Count - 1; i >= 0; -- i )
{
var device = _leastToMostRecentlyUsedDevices[ i ];
if ( deviceType.IsInstanceOfType( device ) )
return device;
}
return null;
}
public TDevice GetMostRecentlyUsedDevice< TDevice >()
where TDevice : InputDevice
{
return ( TDevice ) GetMostRecentlyUsedDevice( typeof ( TDevice ) );
}
public List< InputDevice > GetDevicesOfType( Type deviceType )
{
List< InputDevice > list;
_devices.TryGetValue( deviceType, out list );
return list;
}
public InputDevice LookupDevice( Type deviceType, int deviceIndex )
{
List< InputDevice > list;
@ -71,10 +71,10 @@ namespace UnityEngine.InputNew
return null;
return list[ deviceIndex ];
}
////REVIEW: an alternative to these two methods is to hook every single device into the event tree independently; may be better
}
////REVIEW: an alternative to these two methods is to hook every single device into the event tree independently; may be better
public bool ProcessEvent( InputEvent inputEvent )
{
// Look up device.
@ -87,24 +87,24 @@ namespace UnityEngine.InputNew
return false;
// Update most-recently-used status.
for ( var currentType = inputEvent.deviceType; currentType != typeof( InputDevice ); currentType = currentType.BaseType )
{
var mostRecentlyUsedDeviceOfType = GetMostRecentlyUsedDevice( currentType );
if ( mostRecentlyUsedDeviceOfType != device )
{
_leastToMostRecentlyUsedDevices.Remove( device );
_leastToMostRecentlyUsedDevices.Add( device );
//fire event
break;
}
for ( var currentType = inputEvent.deviceType; currentType != typeof( InputDevice ); currentType = currentType.BaseType )
{
var mostRecentlyUsedDeviceOfType = GetMostRecentlyUsedDevice( currentType );
if ( mostRecentlyUsedDeviceOfType != device )
{
_leastToMostRecentlyUsedDevices.Remove( device );
_leastToMostRecentlyUsedDevices.Add( device );
//fire event
break;
}
}
// Let device process event.
// Let device process event.
return device.ProcessEvent( inputEvent );
}
}
public bool RemapEvent( InputEvent inputEvent )
{
// Look up device.
@ -114,79 +114,79 @@ namespace UnityEngine.InputNew
// Let device remap event.
return device.RemapEvent( inputEvent );
}
public void DisconnectDevice( InputDevice device )
{
if ( !device.connected )
return;
HandleDeviceConnectDisconnect( device, false );
}
public void ReconnectDevice( InputDevice device )
{
if ( device.connected )
return;
HandleDeviceConnectDisconnect( device, true );
}
#endregion
#region Non-Public Methods
private void AssignDeviceProfile( InputDevice device )
{
device.profile = FindDeviceProfile( device );
}
private InputDeviceProfile FindDeviceProfile( InputDevice device )
{
foreach ( var profile in _profiles )
{
if ( profile.deviceNames != null )
{
foreach ( var deviceName in profile.deviceNames )
if ( string.Compare( deviceName, device.deviceName, StringComparison.InvariantCulture ) == 0 )
return profile;
}
}
return null;
}
private void RegisterDeviceInternal( Type deviceType, InputDevice device )
{
List< InputDevice > list;
if ( !_devices.TryGetValue( deviceType, out list ) )
{
list = new List< InputDevice >();
_devices[ deviceType ] = list;
}
list.Add( device );
_leastToMostRecentlyUsedDevices.Add( device );
var baseType = deviceType.BaseType;
if ( baseType != typeof( InputDevice ) )
RegisterDeviceInternal( baseType, device );
}
private void HandleDeviceConnectDisconnect( InputDevice device, bool connected )
{
// Sync state.
device.connected = connected;
// Fire event.
var handler = deviceConnectedDisconnected;
if ( handler != null )
handler( device, connected );
}
#endregion
#region Public Properties
}
public void DisconnectDevice( InputDevice device )
{
if ( !device.connected )
return;
HandleDeviceConnectDisconnect( device, false );
}
public void ReconnectDevice( InputDevice device )
{
if ( device.connected )
return;
HandleDeviceConnectDisconnect( device, true );
}
#endregion
#region Non-Public Methods
private void AssignDeviceProfile( InputDevice device )
{
device.profile = FindDeviceProfile( device );
}
private InputDeviceProfile FindDeviceProfile( InputDevice device )
{
foreach ( var profile in _profiles )
{
if ( profile.deviceNames != null )
{
foreach ( var deviceName in profile.deviceNames )
if ( string.Compare( deviceName, device.deviceName, StringComparison.InvariantCulture ) == 0 )
return profile;
}
}
return null;
}
private void RegisterDeviceInternal( Type deviceType, InputDevice device )
{
List< InputDevice > list;
if ( !_devices.TryGetValue( deviceType, out list ) )
{
list = new List< InputDevice >();
_devices[ deviceType ] = list;
}
list.Add( device );
_leastToMostRecentlyUsedDevices.Add( device );
var baseType = deviceType.BaseType;
if ( baseType != typeof( InputDevice ) )
RegisterDeviceInternal( baseType, device );
}
private void HandleDeviceConnectDisconnect( InputDevice device, bool connected )
{
// Sync state.
device.connected = connected;
// Fire event.
var handler = deviceConnectedDisconnected;
if ( handler != null )
handler( device, connected );
}
#endregion
#region Public Properties
public Pointer pointer
{
get { return GetMostRecentlyUsedDevice< Pointer >(); }
@ -217,26 +217,26 @@ namespace UnityEngine.InputNew
}
}
#endregion
#region Public Events
public DeviceConnectDisconnectEvent deviceConnectedDisconnected;
#endregion
#region Fields
#endregion
#region Public Events
public DeviceConnectDisconnectEvent deviceConnectedDisconnected;
#endregion
#region Fields
private readonly Dictionary< Type, List< InputDevice > > _devices = new Dictionary< Type, List< InputDevice > >();
private readonly List< InputDevice > _leastToMostRecentlyUsedDevices = new List< InputDevice >();
private readonly List< InputDeviceProfile > _profiles = new List< InputDeviceProfile >();
#endregion
#region Inner Types
public delegate void DeviceConnectDisconnectEvent( InputDevice device, bool connected );
#endregion
}
private readonly List< InputDevice > _leastToMostRecentlyUsedDevices = new List< InputDevice >();
private readonly List< InputDeviceProfile > _profiles = new List< InputDeviceProfile >();
#endregion
#region Inner Types
public delegate void DeviceConnectDisconnectEvent( InputDevice device, bool connected );
#endregion
}
}

Просмотреть файл

@ -1,41 +1,41 @@
using System;
using Assets.Utilities;
namespace UnityEngine.InputNew
{
public abstract class InputDeviceProfile
: ScriptableObject
{
#region Public Methods
public abstract void Remap( InputEvent inputEvent );
public void AddSupportedPlatform( string platform )
{
ArrayHelpers.AppendUnique( ref supportedPlatforms, platform );
}
public void AddDeviceName( string deviceName )
{
ArrayHelpers.AppendUnique( ref deviceNames, deviceName );
}
public void AddDeviceRegex( string regex )
{
ArrayHelpers.AppendUnique( ref deviceRegexes, regex );
}
#endregion
#region Public Properties
public string[] supportedPlatforms;
public string[] deviceNames;
public string[] deviceRegexes;
public string lastResortDeviceRegex;
public Version minUnityVersion;
public Version maxUnityVersion;
#endregion
}
using System;
using Assets.Utilities;
namespace UnityEngine.InputNew
{
public abstract class InputDeviceProfile
: ScriptableObject
{
#region Public Methods
public abstract void Remap( InputEvent inputEvent );
public void AddSupportedPlatform( string platform )
{
ArrayHelpers.AppendUnique( ref supportedPlatforms, platform );
}
public void AddDeviceName( string deviceName )
{
ArrayHelpers.AppendUnique( ref deviceNames, deviceName );
}
public void AddDeviceRegex( string regex )
{
ArrayHelpers.AppendUnique( ref deviceRegexes, regex );
}
#endregion
#region Public Properties
public string[] supportedPlatforms;
public string[] deviceNames;
public string[] deviceRegexes;
public string lastResortDeviceRegex;
public Version minUnityVersion;
public Version maxUnityVersion;
#endregion
}
}

Просмотреть файл

@ -1,34 +1,34 @@
using System;
using System;
namespace UnityEngine.InputNew
{
// ------------------------------------------------------------------------
// Events.
// ------------------------------------------------------------------------
public abstract class InputEvent
{
#region Public Methods
public override string ToString()
{
if ( deviceType == null )
return base.ToString();
return string.Format
(
"{0} on {1}:{2} at {3}"
, GetType().Name
, deviceType.Name
, deviceIndex
, time
);
}
#endregion
#region Public Properties
public abstract class InputEvent
{
#region Public Methods
public override string ToString()
{
if ( deviceType == null )
return base.ToString();
return string.Format
(
"{0} on {1}:{2} at {3}"
, GetType().Name
, deviceType.Name
, deviceIndex
, time
);
}
#endregion
#region Public Properties
public float time { get; set; }
public Type deviceType { get; set; }
public int deviceIndex { get; set; }
@ -41,31 +41,31 @@ namespace UnityEngine.InputNew
// -------- from old single file thing
////REVIEW: we may want to store actual state for compounds such that we can do postprocessing on them (like normalize vectors, for example)
// ------------------------------------------------------------------------
// Devices.
// ------------------------------------------------------------------------
////TODO: how deal with compound devices (e.g. gamepads that also have a touchscreen)?
//// create a true CompoundDevice class that is a collection of InputDevices?
////FIXME: currently compounds go in the same array as primitives and thus lead to allocation of state which is useless for them
////REVIEW: have a single Pointer class representing the union of all types of pointer devices or have multiple specific subclasses?
//// also: where to keep the state for "the one" pointer
// ------------------------------------------------------------------------
// Bindings.
// ------------------------------------------------------------------------
// Three different naming approaches:
// 1. ControlMap, ControlMapEntry
// 2. InputActionMap, InputAction
// 3. InputActivityMap, InputActivity
////NOTE: this needs to be proper asset stuff; can't be done in script code only
// ------------------------------------------------------------------------
// System.
// ------------------------------------------------------------------------
////REVIEW: we may want to store actual state for compounds such that we can do postprocessing on them (like normalize vectors, for example)
// ------------------------------------------------------------------------
// Devices.
// ------------------------------------------------------------------------
////TODO: how deal with compound devices (e.g. gamepads that also have a touchscreen)?
//// create a true CompoundDevice class that is a collection of InputDevices?
////FIXME: currently compounds go in the same array as primitives and thus lead to allocation of state which is useless for them
////REVIEW: have a single Pointer class representing the union of all types of pointer devices or have multiple specific subclasses?
//// also: where to keep the state for "the one" pointer
// ------------------------------------------------------------------------
// Bindings.
// ------------------------------------------------------------------------
// Three different naming approaches:
// 1. ControlMap, ControlMapEntry
// 2. InputActionMap, InputAction
// 3. InputActivityMap, InputActivity
////NOTE: this needs to be proper asset stuff; can't be done in script code only
// ------------------------------------------------------------------------
// System.
// ------------------------------------------------------------------------

Просмотреть файл

@ -1,5 +1,5 @@
namespace UnityEngine.InputNew
{
namespace UnityEngine.InputNew
{
internal class InputEventPool
{
#region Public Methods
@ -17,5 +17,5 @@ namespace UnityEngine.InputNew
}
#endregion
}
}
}

Просмотреть файл

@ -1,7 +1,7 @@
using System.Collections.Generic;
namespace UnityEngine.InputNew
{
using System.Collections.Generic;
namespace UnityEngine.InputNew
{
internal class InputEventQueue
{
#region Public Methods
@ -37,22 +37,22 @@ namespace UnityEngine.InputNew
private readonly SortedList< float, InputEvent > _list = new SortedList< float, InputEvent >( new SortInputEventsByTime() );
#endregion
#region Inner Types
private class SortInputEventsByTime
: IComparer< float >
{
public int Compare( float x, float y )
{
if ( x < y )
return -1;
// Avoid duplicate keys in sorted list by always treating equality as greater-than.
return 1;
}
}
#endregion
}
#endregion
#region Inner Types
private class SortInputEventsByTime
: IComparer< float >
{
public int Compare( float x, float y )
{
if ( x < y )
return -1;
// Avoid duplicate keys in sorted list by always treating equality as greater-than.
return 1;
}
}
#endregion
}
}

Просмотреть файл

@ -1,7 +1,7 @@
using System.Collections.Generic;
namespace UnityEngine.InputNew
{
using System.Collections.Generic;
namespace UnityEngine.InputNew
{
internal class InputEventTree
: IInputConsumer
{
@ -52,5 +52,5 @@ namespace UnityEngine.InputNew
private List< IInputConsumer > _children = new List< IInputConsumer >();
#endregion
}
}
}

Просмотреть файл

@ -1,7 +1,7 @@
using System.Collections.Generic;
namespace UnityEngine.InputNew
{
using System.Collections.Generic;
namespace UnityEngine.InputNew
{
public class InputState
{
#region Constructors
@ -98,5 +98,5 @@ namespace UnityEngine.InputNew
private InputControlProvider _controlProvider;
#endregion
}
}
}

Просмотреть файл

@ -1,25 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine.InputNew;
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine.InputNew;
//// - solve mapping of device type names from control maps to device types at runtime
namespace UnityEngine.InputNew
{
namespace UnityEngine.InputNew
{
public static class InputSystem
{
#region Public Methods
#region Public Methods
public static void Initialize( InputDeviceProfile[] profiles )
{
_devices = new InputDeviceManager();
_eventQueue = new InputEventQueue();
_eventPool = new InputEventPool();
foreach ( var profile in profiles )
RegisterProfile( profile );
foreach ( var profile in profiles )
RegisterProfile( profile );
// Set up event tree.
_eventTree = new InputEventTree { name = "Root" };
@ -36,11 +36,11 @@ namespace UnityEngine.InputNew
, processInput = _devices.ProcessEvent
};
_eventTree.children.Add( state );
}
public static void RegisterProfile( InputDeviceProfile profile )
{
_devices.RegisterProfile( profile );
}
public static void RegisterProfile( InputDeviceProfile profile )
{
_devices.RegisterProfile( profile );
}
public static InputDevice LookupDevice( Type deviceType, int deviceIndex )
@ -71,123 +71,123 @@ namespace UnityEngine.InputNew
public static IEnumerable< ControlMapInstance > BindInputs( ControlMap controlMap, bool localMultiplayer = false )
{
for ( var i = 0; i < controlMap.schemes.Count; ++ i )
{
foreach ( var instance in BindInputs( controlMap, localMultiplayer, i ) )
yield return instance;
}
}
public static IEnumerable< ControlMapInstance > BindInputs( ControlMap controlMap, bool localMultiplayer, int controlSchemeIndex )
{
// Gather a mapping of device types to list of bindings that use the given type.
var perDeviceTypeMapEntries = new Dictionary< Type, List< ControlMapEntry > >();
foreach ( var entry in controlMap.entries )
{
if ( entry.bindings == null || entry.bindings.Count == 0 )
continue;
foreach ( var control in entry.bindings[ controlSchemeIndex ].sources )
{
List< ControlMapEntry > entries;
if ( !perDeviceTypeMapEntries.TryGetValue( control.deviceType, out entries ) )
{
entries = new List< ControlMapEntry >();
perDeviceTypeMapEntries[ control.deviceType ] = entries;
}
entries.Add( entry );
}
}
////REVIEW: what to do about disconnected devices here? skip? include? make parameter?
// Create list of controls from InputMap.
var controls = new List< InputControlData >();
foreach ( var entry in controlMap.entries )
{
var control = new InputControlData
{
name = entry.controlData.name
, controlType = entry.controlData.controlType
};
controls.Add( control );
}
if ( localMultiplayer )
{
// Gather available devices for each type of device.
var deviceTypesToAvailableDevices = new Dictionary< Type, List< InputDevice > >();
var minDeviceCountOfType = Int32.MaxValue;
foreach ( var deviceType in perDeviceTypeMapEntries.Keys )
{
var availableDevicesOfType = _devices.GetDevicesOfType( deviceType );
if ( availableDevicesOfType != null )
deviceTypesToAvailableDevices[ deviceType ] = availableDevicesOfType;
minDeviceCountOfType = Mathf.Min( minDeviceCountOfType, availableDevicesOfType != null ? availableDevicesOfType.Count : 0 );
}
// Create map instances according to available devices.
for ( var i = 0; i < minDeviceCountOfType; ++ i )
{
var deviceStates = new List< InputState >();
foreach ( var entry in perDeviceTypeMapEntries )
{
// Take i-th device of current type.
var device = deviceTypesToAvailableDevices[ entry.Key ][ i ];
var state = new InputState( device );
deviceStates.Add( state );
}
yield return new ControlMapInstance( controlMap, controlSchemeIndex, controls, deviceStates );
}
}
else
{
////TODO: make ControlMapInstance hook into MRU device change event and respond by updating its device states
var deviceStates = new List< InputState >();
// Create device states for most recently used device of given types.
foreach ( var entry in perDeviceTypeMapEntries )
{
var device = _devices.GetMostRecentlyUsedDevice( entry.Key );
if ( device == null )
yield break; // Can't satisfy this ControlMap; no available device of given type.
var state = new InputState( device );
deviceStates.Add( state );
}
yield return new ControlMapInstance( controlMap, controlSchemeIndex, controls, deviceStates );
}
{
foreach ( var instance in BindInputs( controlMap, localMultiplayer, i ) )
yield return instance;
}
}
public static IEnumerable< ControlMapInstance > BindInputs( ControlMap controlMap, bool localMultiplayer, int controlSchemeIndex )
{
// Gather a mapping of device types to list of bindings that use the given type.
var perDeviceTypeMapEntries = new Dictionary< Type, List< ControlMapEntry > >();
foreach ( var entry in controlMap.entries )
{
if ( entry.bindings == null || entry.bindings.Count == 0 )
continue;
foreach ( var control in entry.bindings[ controlSchemeIndex ].sources )
{
List< ControlMapEntry > entries;
if ( !perDeviceTypeMapEntries.TryGetValue( control.deviceType, out entries ) )
{
entries = new List< ControlMapEntry >();
perDeviceTypeMapEntries[ control.deviceType ] = entries;
}
entries.Add( entry );
}
}
////REVIEW: what to do about disconnected devices here? skip? include? make parameter?
// Create list of controls from InputMap.
var controls = new List< InputControlData >();
foreach ( var entry in controlMap.entries )
{
var control = new InputControlData
{
name = entry.controlData.name
, controlType = entry.controlData.controlType
};
controls.Add( control );
}
if ( localMultiplayer )
{
// Gather available devices for each type of device.
var deviceTypesToAvailableDevices = new Dictionary< Type, List< InputDevice > >();
var minDeviceCountOfType = Int32.MaxValue;
foreach ( var deviceType in perDeviceTypeMapEntries.Keys )
{
var availableDevicesOfType = _devices.GetDevicesOfType( deviceType );
if ( availableDevicesOfType != null )
deviceTypesToAvailableDevices[ deviceType ] = availableDevicesOfType;
minDeviceCountOfType = Mathf.Min( minDeviceCountOfType, availableDevicesOfType != null ? availableDevicesOfType.Count : 0 );
}
// Create map instances according to available devices.
for ( var i = 0; i < minDeviceCountOfType; ++ i )
{
var deviceStates = new List< InputState >();
foreach ( var entry in perDeviceTypeMapEntries )
{
// Take i-th device of current type.
var device = deviceTypesToAvailableDevices[ entry.Key ][ i ];
var state = new InputState( device );
deviceStates.Add( state );
}
yield return new ControlMapInstance( controlMap, controlSchemeIndex, controls, deviceStates );
}
}
else
{
////TODO: make ControlMapInstance hook into MRU device change event and respond by updating its device states
var deviceStates = new List< InputState >();
// Create device states for most recently used device of given types.
foreach ( var entry in perDeviceTypeMapEntries )
{
var device = _devices.GetMostRecentlyUsedDevice( entry.Key );
if ( device == null )
yield break; // Can't satisfy this ControlMap; no available device of given type.
var state = new InputState( device );
deviceStates.Add( state );
}
yield return new ControlMapInstance( controlMap, controlSchemeIndex, controls, deviceStates );
}
}
// This is for having explicit control over what devices go into a ControlMapInstance.
public static ControlMapInstance BindInputs( ControlMap controlMap, int controlSchemeIndex, IEnumerable< InputDevice > devices )
{
// Create state for every device.
var deviceStates = new List< InputState >();
foreach ( var device in devices )
deviceStates.Add( new InputState( device ) );
// Create list of controls from InputMap.
var controls = new List< InputControlData >();
foreach ( var entry in controlMap.entries )
{
var control = new InputControlData
{
name = entry.controlData.name
, controlType = entry.controlData.controlType
};
controls.Add( control );
}
// Create map instance.
return new ControlMapInstance( controlMap, controlSchemeIndex, controls, deviceStates );
}
public static ControlMapInstance BindInputs( ControlMap controlMap, int controlSchemeIndex, IEnumerable< InputDevice > devices )
{
// Create state for every device.
var deviceStates = new List< InputState >();
foreach ( var device in devices )
deviceStates.Add( new InputState( device ) );
// Create list of controls from InputMap.
var controls = new List< InputControlData >();
foreach ( var entry in controlMap.entries )
{
var control = new InputControlData
{
name = entry.controlData.name
, controlType = entry.controlData.controlType
};
controls.Add( control );
}
// Create map instance.
return new ControlMapInstance( controlMap, controlSchemeIndex, controls, deviceStates );
}
#endregion
#region Non-Public Methods
@ -253,5 +253,5 @@ namespace UnityEngine.InputNew
private static InputEventTree _eventTree;
#endregion
}
}
}

Просмотреть файл

@ -1,19 +1,19 @@
using System.Collections.Generic;
namespace UnityEngine.InputNew
{
// Must be different from Gamepad as the standardized controls for Gamepads don't
// work for joysticks.
public class Joystick
: InputDevice
{
#region Constructors
public Joystick( string deviceName, List< InputControlData > controls )
: base( deviceName, controls )
{
}
#endregion
}
using System.Collections.Generic;
namespace UnityEngine.InputNew
{
// Must be different from Gamepad as the standardized controls for Gamepads don't
// work for joysticks.
public class Joystick
: InputDevice
{
#region Constructors
public Joystick( string deviceName, List< InputControlData > controls )
: base( deviceName, controls )
{
}
#endregion
}
}

Просмотреть файл

@ -1,15 +1,15 @@
using System;
using Assets.Utilities;
namespace UnityEngine.InputNew
{
[ Serializable ]
public struct JoystickControlMapping
{
public int targetIndex;
public Sprite displayIcon;
public string displayName;
public Range fromRange;
public Range toRange;
}
using System;
using Assets.Utilities;
namespace UnityEngine.InputNew
{
[ Serializable ]
public struct JoystickControlMapping
{
public int targetIndex;
public Sprite displayIcon;
public string displayName;
public Range fromRange;
public Range toRange;
}
}

Просмотреть файл

@ -1,45 +1,45 @@
using System;
using Assets.Utilities;
namespace UnityEngine.InputNew
{
public class JoystickProfile
: InputDeviceProfile
{
#region Public Methods
public override void Remap( InputEvent inputEvent )
{
var controlEvent = inputEvent as GenericControlEvent;
if ( controlEvent != null )
{
var mapping = mappings[ controlEvent.controlIndex ];
if ( mapping.targetIndex != -1 )
controlEvent.controlIndex = mapping.targetIndex;
}
}
public void SetMappingsCount( int sourceControlCount )
{
mappings = new JoystickControlMapping[ sourceControlCount ];
}
public void SetMapping( int sourceControlIndex, int targetControlIndex, string displayName = null, Sprite displayIcon = null )
{
mappings[ sourceControlIndex ] = new JoystickControlMapping
{
targetIndex = targetControlIndex
, displayName = displayName
, displayIcon = displayIcon
};
}
#endregion
#region Public Properties
public JoystickControlMapping[] mappings;
#endregion
}
using System;
using Assets.Utilities;
namespace UnityEngine.InputNew
{
public class JoystickProfile
: InputDeviceProfile
{
#region Public Methods
public override void Remap( InputEvent inputEvent )
{
var controlEvent = inputEvent as GenericControlEvent;
if ( controlEvent != null )
{
var mapping = mappings[ controlEvent.controlIndex ];
if ( mapping.targetIndex != -1 )
controlEvent.controlIndex = mapping.targetIndex;
}
}
public void SetMappingsCount( int sourceControlCount )
{
mappings = new JoystickControlMapping[ sourceControlCount ];
}
public void SetMapping( int sourceControlIndex, int targetControlIndex, string displayName = null, Sprite displayIcon = null )
{
mappings[ sourceControlIndex ] = new JoystickControlMapping
{
targetIndex = targetControlIndex
, displayName = displayName
, displayIcon = displayIcon
};
}
#endregion
#region Public Properties
public JoystickControlMapping[] mappings;
#endregion
}
}

Просмотреть файл

@ -1,5 +1,5 @@
namespace UnityEngine.InputNew
{
namespace UnityEngine.InputNew
{
public enum KeyControl
{
A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z,
@ -19,5 +19,5 @@ namespace UnityEngine.InputNew
Backspace,
Tab,
Return,
}
}
}

Просмотреть файл

@ -1,5 +1,5 @@
namespace UnityEngine.InputNew
{
namespace UnityEngine.InputNew
{
public class KeyEvent
: InputEvent
{
@ -12,5 +12,5 @@ namespace UnityEngine.InputNew
public bool isRepeat { get; private set; }
#endregion
}
}
}

Просмотреть файл

@ -1,7 +1,7 @@
using System.Collections.Generic;
namespace UnityEngine.InputNew
{
using System.Collections.Generic;
namespace UnityEngine.InputNew
{
public class Keyboard
: InputDevice
{
@ -23,5 +23,5 @@ namespace UnityEngine.InputNew
}
#endregion
}
}
}

Просмотреть файл

@ -1,7 +1,7 @@
using System.Collections.Generic;
namespace UnityEngine.InputNew
{
using System.Collections.Generic;
namespace UnityEngine.InputNew
{
public class Mouse
: Pointer
{
@ -23,5 +23,5 @@ namespace UnityEngine.InputNew
}
#endregion
}
}
}

Просмотреть файл

@ -1,5 +1,5 @@
namespace UnityEngine.InputNew
{
namespace UnityEngine.InputNew
{
internal enum NativeEventType
{
GenericButton,
@ -8,5 +8,5 @@ namespace UnityEngine.InputNew
KeyUp,
TextInput,
PointerMove,
}
}
}

Просмотреть файл

@ -1,9 +1,9 @@
namespace UnityEngine.InputNew
{
namespace UnityEngine.InputNew
{
internal struct NativeInputEvent
{
public NativeEventType eventType;
public int deviceIndex;
public float time;
}
}
}

Просмотреть файл

@ -1,7 +1,7 @@
using System.Collections.Generic;
namespace UnityEngine.InputNew
{
using System.Collections.Generic;
namespace UnityEngine.InputNew
{
/// <summary>
/// A device that can point at and click on things.
/// </summary>
@ -56,13 +56,13 @@ namespace UnityEngine.InputNew
controls.Add( new InputControlData { name = "PositionX", controlType = InputControlType.RelativeAxis } );
controls.Add( new InputControlData { name = "PositionY", controlType = InputControlType.RelativeAxis } );
controls.Add( new InputControlData { name = "PositionZ", controlType = InputControlType.RelativeAxis } );
controls.Add( new InputControlData { name = "Pressure", controlType = InputControlType.AbsoluteAxis } );
controls.Add( new InputControlData { name = "Tilt", controlType = InputControlType.AbsoluteAxis } );
controls.Add( new InputControlData { name = "Rotation", controlType = InputControlType.AbsoluteAxis } );
controls.Add( new InputControlData { name = "LeftButton", controlType = InputControlType.Button } );
controls.Add( new InputControlData { name = "RightButton", controlType = InputControlType.Button } );
controls.Add( new InputControlData { name = "MiddleButton", controlType = InputControlType.Button } );
controls.Add( new InputControlData { name = "PositionZ", controlType = InputControlType.RelativeAxis } );
controls.Add( new InputControlData { name = "Pressure", controlType = InputControlType.AbsoluteAxis } );
controls.Add( new InputControlData { name = "Tilt", controlType = InputControlType.AbsoluteAxis } );
controls.Add( new InputControlData { name = "Rotation", controlType = InputControlType.AbsoluteAxis } );
controls.Add( new InputControlData { name = "LeftButton", controlType = InputControlType.Button } );
controls.Add( new InputControlData { name = "RightButton", controlType = InputControlType.Button } );
controls.Add( new InputControlData { name = "MiddleButton", controlType = InputControlType.Button } );
return controls;
}
@ -82,5 +82,5 @@ namespace UnityEngine.InputNew
}
#endregion
}
}
}

Просмотреть файл

@ -1,5 +1,5 @@
namespace UnityEngine.InputNew
{
namespace UnityEngine.InputNew
{
public class PointerClickEvent
: PointerEvent
{
@ -8,5 +8,5 @@ namespace UnityEngine.InputNew
public int clickCount { get; set; }
#endregion
}
}
}

Просмотреть файл

@ -1,5 +1,5 @@
namespace UnityEngine.InputNew
{
namespace UnityEngine.InputNew
{
public enum PointerControl
{
Position,
@ -22,5 +22,5 @@ namespace UnityEngine.InputNew
ForwardButton,
BackButton,
}
}
}

Просмотреть файл

@ -1,5 +1,5 @@
namespace UnityEngine.InputNew
{
namespace UnityEngine.InputNew
{
public class PointerEvent
: InputEvent
{
@ -12,5 +12,5 @@ namespace UnityEngine.InputNew
public int displayIndex { get; set; }
#endregion
}
}
}

Просмотреть файл

@ -1,5 +1,5 @@
namespace UnityEngine.InputNew
{
namespace UnityEngine.InputNew
{
public class PointerMoveEvent
: PointerEvent
{
@ -8,5 +8,5 @@ namespace UnityEngine.InputNew
public Vector3 delta { get; set; }
#endregion
}
}
}

Просмотреть файл

@ -1,4 +1,4 @@
namespace UnityEngine.InputNew
{
public delegate bool ProcessInputDelegate( InputEvent inputEvent );
namespace UnityEngine.InputNew
{
public delegate bool ProcessInputDelegate( InputEvent inputEvent );
}

Просмотреть файл

@ -1,7 +1,7 @@
using System.Collections.Generic;
namespace UnityEngine.InputNew
{
using System.Collections.Generic;
namespace UnityEngine.InputNew
{
public abstract class Sensor
: InputDevice
{
@ -13,5 +13,5 @@ namespace UnityEngine.InputNew
}
#endregion
}
}
}

Просмотреть файл

@ -1,8 +1,8 @@
namespace UnityEngine.InputNew
{
namespace UnityEngine.InputNew
{
public class TextEvent
: InputEvent
{
public char text { get; set; }
}
}
}

Просмотреть файл

@ -1,6 +1,6 @@
namespace UnityEngine.InputNew
{
namespace UnityEngine.InputNew
{
public struct Touch
{
}
}
}

Просмотреть файл

@ -1,8 +1,8 @@
namespace UnityEngine.InputNew
{
namespace UnityEngine.InputNew
{
public class TouchEvent
: InputEvent
{
public float diameter { get; set; }
}
}
}

Просмотреть файл

@ -1,7 +1,7 @@
using System.Collections.Generic;
namespace UnityEngine.InputNew
{
using System.Collections.Generic;
namespace UnityEngine.InputNew
{
public class Touchscreen
: Pointer
{
@ -23,5 +23,5 @@ namespace UnityEngine.InputNew
}
#endregion
}
}
}

Просмотреть файл

@ -1,6 +1,6 @@
using UnityEngine;
using UnityEngine.InputNew;
using UnityEngine;
using UnityEngine.InputNew;
public class MouseInputToEvents
: MonoBehaviour
{
@ -10,12 +10,12 @@ public class MouseInputToEvents
SendMoveEvent();
}
private void SendButtonEvents()
{
if ( Input.GetKeyDown( KeyCode.Mouse0 ) )
SendClickEvent( PointerControl.LeftButton, true );
if ( Input.GetKeyUp( KeyCode.Mouse0 ) )
SendClickEvent( PointerControl.LeftButton, false );
private void SendButtonEvents()
{
if ( Input.GetKeyDown( KeyCode.Mouse0 ) )
SendClickEvent( PointerControl.LeftButton, true );
if ( Input.GetKeyUp( KeyCode.Mouse0 ) )
SendClickEvent( PointerControl.LeftButton, false );
}
private void SendMoveEvent()
@ -35,17 +35,17 @@ public class MouseInputToEvents
_lastMousePosition = newMousePosition;
}
private void SendClickEvent( PointerControl controlIndex, bool clicked )
{
////REVIEW: should this be a pointer-specific event type?
var inputEvent = InputSystem.CreateEvent< GenericControlEvent >();
inputEvent.deviceType = typeof( Mouse );
inputEvent.deviceIndex = 0;
inputEvent.controlIndex = ( int ) controlIndex;
inputEvent.value = clicked ? 1.0f : 0.0f;
Debug.Log( inputEvent );
InputSystem.QueueEvent( inputEvent );
}
private void SendClickEvent( PointerControl controlIndex, bool clicked )
{
////REVIEW: should this be a pointer-specific event type?
var inputEvent = InputSystem.CreateEvent< GenericControlEvent >();
inputEvent.deviceType = typeof( Mouse );
inputEvent.deviceIndex = 0;
inputEvent.controlIndex = ( int ) controlIndex;
inputEvent.value = clicked ? 1.0f : 0.0f;
Debug.Log( inputEvent );
InputSystem.QueueEvent( inputEvent );
}
private Vector3 _lastMousePosition;
}

Просмотреть файл

@ -1,37 +1,37 @@
using System;
using System.Linq;
namespace Assets.Utilities
{
public static class ArrayHelpers
{
public static void Resize< T >( ref T[] array, int newSize )
{
if ( array == null )
array = new T[ 1 ];
else
{
var newArray = new T[ newSize ];
Array.Copy( array, newArray, newSize );
array = newArray;
}
}
public static void AppendUnique< T >( ref T[] array, T value )
{
if ( array == null )
{
array = new T[ 1 ];
array[ 0 ] = value;
}
else
{
if ( array.Contains( value ) )
return;
Resize( ref array, array.Length + 1 );
array[ array.Length - 1 ] = value;
}
}
}
using System;
using System.Linq;
namespace Assets.Utilities
{
public static class ArrayHelpers
{
public static void Resize< T >( ref T[] array, int newSize )
{
if ( array == null )
array = new T[ 1 ];
else
{
var newArray = new T[ newSize ];
Array.Copy( array, newArray, newSize );
array = newArray;
}
}
public static void AppendUnique< T >( ref T[] array, T value )
{
if ( array == null )
{
array = new T[ 1 ];
array[ 0 ] = value;
}
else
{
if ( array.Contains( value ) )
return;
Resize( ref array, array.Length + 1 );
array[ array.Length - 1 ] = value;
}
}
}
}

Просмотреть файл

@ -1,19 +1,19 @@
using System;
using System.Linq;
namespace Assets.Utilities
{
public static class EnumHelpers
{
public static int GetNameCount< TEnum >()
{
return Enum.GetNames( typeof( TEnum ) ).Length;
}
public static int GetValueCount< TEnum >()
{
// Slow...
return Enum.GetValues( typeof( TEnum ) ).Cast< TEnum >().Distinct().Count();
}
}
}
using System;
using System.Linq;
namespace Assets.Utilities
{
public static class EnumHelpers
{
public static int GetNameCount< TEnum >()
{
return Enum.GetNames( typeof( TEnum ) ).Length;
}
public static int GetValueCount< TEnum >()
{
// Slow...
return Enum.GetValues( typeof( TEnum ) ).Cast< TEnum >().Distinct().Count();
}
}
}

Просмотреть файл

@ -1,17 +1,17 @@
using System;
namespace Assets.Utilities
{
[ Serializable ]
public struct Range
{
public float min;
public float max;
public Range( float min, float max )
{
this.min = min;
this.max = max;
}
}
using System;
namespace Assets.Utilities
{
[ Serializable ]
public struct Range
{
public float min;
public float max;
public Range( float min, float max )
{
this.min = min;
this.max = max;
}
}
}