@@ -13,29 +13,33 @@ public partial class InputManager : MonoBehaviour
1313 Dictionary < int , SensorType > _instanceID2SensorTypeMappingTable = new ( ) ;
1414 void UpdateMousePosition ( )
1515 {
16- if ( Input . GetMouseButton ( 0 ) )
16+ Input . multiTouchEnabled = true ;
17+ if ( Input . touchCount > 0 )
1718 {
18- Vector3 cubeRay = Camera . main . ScreenToWorldPoint ( Input . mousePosition ) ;
19- var ray = new Ray ( cubeRay , Vector3 . forward ) ;
20- var ishit = Physics . Raycast ( ray , out var hitInfo ) ;
19+ Debug . Log ( Input . touchCount ) ;
20+ var touches = Input . touches ;
2121
2222 Dictionary < SensorType , SensorStatus > oldSensorsState = _sensors . ToDictionary ( s => s . Type , s => s . Status ) ;
2323 Dictionary < SensorType , SensorStatus > newSensorsState = _sensors . ToDictionary ( s => s . Type , x => SensorStatus . Off ) ;
2424
25- if ( ishit )
25+ foreach ( var touch in touches )
2626 {
27- var id = hitInfo . colliderInstanceID ;
28- if ( _instanceID2SensorTypeMappingTable . TryGetValue ( id , out var type ) )
27+ if ( touch . phase == TouchPhase . Ended || touch . phase == TouchPhase . Canceled )
2928 {
30- newSensorsState [ type ] = SensorStatus . On ;
29+ continue ;
30+ }
31+ Vector3 cubeRay = Camera . main . ScreenToWorldPoint ( touch . position ) ;
32+ var ray = new Ray ( cubeRay , Vector3 . forward ) ;
33+ var ishit = Physics . Raycast ( ray , out var hitInfo ) ;
34+ if ( ishit )
35+ {
36+ var id = hitInfo . colliderInstanceID ;
37+ if ( _instanceID2SensorTypeMappingTable . TryGetValue ( id , out var type ) )
38+ {
39+ newSensorsState [ type ] = SensorStatus . On ;
40+ }
3141 }
3242 }
33- else
34- {
35- foreach ( var s in _sensors . AsSpan ( ) )
36- SetSensorState ( s . Type , SensorStatus . Off ) ;
37- }
38-
3943 /*var x = Input.mousePosition.x / Screen.width * 2 - 1;
4044 var y = Input.mousePosition.y / Screen.width * 2 - 1;
4145 var distance = Math.Sqrt(x * x + y * y);
@@ -125,6 +129,31 @@ void UpdateMousePosition()
125129 newSensorsState[SensorType.C] = SensorStatus.On;
126130 }*/
127131
132+ foreach ( var pair in newSensorsState )
133+ {
134+ var type = pair . Key ;
135+ var nState = newSensorsState [ type ] ;
136+ var oState = oldSensorsState [ type ] ;
137+ if ( oState != nState )
138+ SetSensorState ( type , nState ) ;
139+ }
140+ } else if ( Input . GetMouseButton ( 0 ) )
141+ {
142+ Dictionary < SensorType , SensorStatus > oldSensorsState = _sensors . ToDictionary ( s => s . Type , s => s . Status ) ;
143+ Dictionary < SensorType , SensorStatus > newSensorsState = _sensors . ToDictionary ( s => s . Type , x => SensorStatus . Off ) ;
144+
145+ Vector3 cubeRaym = Camera . main . ScreenToWorldPoint ( Input . mousePosition ) ;
146+ var raym = new Ray ( cubeRaym , Vector3 . forward ) ;
147+ var ishitm = Physics . Raycast ( raym , out var hitInfom ) ;
148+ if ( ishitm )
149+ {
150+ var id = hitInfom . colliderInstanceID ;
151+ if ( _instanceID2SensorTypeMappingTable . TryGetValue ( id , out var type ) )
152+ {
153+ newSensorsState [ type ] = SensorStatus . On ;
154+ }
155+ }
156+
128157 foreach ( var pair in newSensorsState )
129158 {
130159 var type = pair . Key ;
0 commit comments