@@ -235,33 +235,18 @@ Vector2 GetSelectionStat(Vector2 pos1, Vector2 pos2)
235235 Vector2 rst = Vector2 . zero ;
236236 float pixelCount = 0 ;
237237
238+ // transform mouse screen space to world space
238239 Vector3 mousePos1 = m_camera . ScreenToWorldPoint ( pos1 ) ;
239240 Vector3 mousePos2 = m_camera . ScreenToWorldPoint ( pos2 ) ;
240241
241242 Vector2 minMousePos = new Vector2 ( Math . Min ( mousePos1 . x , mousePos2 . x ) , Math . Min ( mousePos1 . z , mousePos2 . z ) ) ;
242243 Vector2 maxMousePos = new Vector2 ( Math . Max ( mousePos1 . x , mousePos2 . x ) , Math . Max ( mousePos1 . z , mousePos2 . z ) ) ;
244+ Rect worldRect = Rect . MinMaxRect ( minMousePos . x , minMousePos . y , maxMousePos . x , maxMousePos . y ) ;
243245
244246 for ( var index = 0 ; index < terrains . Length ; index ++ )
245247 {
246- int resolution = InfluenceMapTeam1 [ index ] . Resolution ;
247- Vector3 terrainPos = terrains [ index ] . GetPosition ( ) ;
248- Vector2 terrain2DPos = new Vector2 ( terrainPos . x , terrainPos . z ) ;
249-
250- Vector2 localMin2D = ( minMousePos - terrain2DPos ) / terrains [ index ] . terrainData . size . x * resolution ;
251- Vector2 localMax2D = ( maxMousePos - terrain2DPos ) / terrains [ index ] . terrainData . size . x * resolution ;
252-
253- float xMin = Mathf . Ceil ( Mathf . Clamp ( localMin2D . x , 0f , resolution ) ) ;
254- float yMin = Mathf . Ceil ( Mathf . Clamp ( localMin2D . y , 0f , resolution ) ) ;
255- float xMax = Mathf . Ceil ( Mathf . Clamp ( localMax2D . x , 0f , resolution ) ) ;
256- float yMax = Mathf . Ceil ( Mathf . Clamp ( localMax2D . y , 0f , resolution ) ) ;
257-
258- Rect localRect = new Rect ( xMin , yMin , xMax - xMin , yMax - yMin ) ;
259-
260- if ( ( int ) localRect . width * ( int ) localRect . height == 0 )
261- continue ;
262-
263- Color [ ] colors1 = InfluenceMapTeam1 [ index ] . GetDatas ( localRect ) ;
264- Color [ ] colors2 = InfluenceMapTeam2 [ index ] . GetDatas ( localRect ) ;
248+ Color [ ] colors1 = InfluenceMapTeam1 [ index ] . GetDatasInWorld ( worldRect ) ;
249+ Color [ ] colors2 = InfluenceMapTeam2 [ index ] . GetDatasInWorld ( worldRect ) ;
265250
266251 if ( colors1 == null || colors2 == null || colors1 . Length != colors2 . Length )
267252 continue ;
0 commit comments