@@ -379,46 +379,72 @@ private void UpdateIdle()
379
379
380
380
private void UpdateUVMapping ( )
381
381
{
382
- Vector2 tiling = currentMaterial != null ? currentMaterial . mainTextureScale : new Vector2 ( 1.0f , 1.0f ) ;
383
- Vector2 uvTestValue ;
384
382
mesh . GetUVs ( 0 , uvs ) ;
385
383
uvsOrig . Clear ( ) ;
386
384
uvsOrig . AddRange ( uvs ) ;
387
- float scaleUVDelta = 0.0f ;
388
- Vector2 scaleUVCentroid = Vector2 . zero ;
389
- float currentContactRatio = 0.0f ;
390
385
386
+ Vector2 offsetUVDelta = new Vector2 ( - totalUVOffset . x , totalUVOffset . y ) ;
387
+
388
+ // Scale
391
389
if ( ScaleActive )
392
390
{
393
- scaleUVCentroid = GetDisplayedUVCentroid ( uvs ) ;
394
- currentContactRatio = GetUVScaleFromTouches ( ) ;
395
- scaleUVDelta = currentContactRatio / previousContactRatio ;
391
+ var scaleUVCentroid = GetDisplayedUVCentroid ( uvs ) ;
392
+ var currentContactRatio = GetUVScaleFromTouches ( ) ;
393
+ var scaleUVDelta = currentContactRatio / previousContactRatio ;
396
394
previousContactRatio = currentContactRatio ;
397
395
398
396
currentScale = totalUVScale . x / scaleUVDelta ;
399
397
400
398
// Test for scale limits
401
399
if ( currentScale > minScale && currentScale < maxScale )
402
400
{
403
- // Track total scale
404
- totalUVScale /= scaleUVDelta ;
405
- for ( int i = 0 ; i < uvs . Count ; ++ i )
401
+ var scaleAndScrollUVDeltas = new List < Vector2 > ( ) ;
402
+ for ( int i = 0 ; i < uvs . Count ; i ++ )
406
403
{
407
- // This is where zoom is applied if Active
408
- uvs [ i ] = ( ( uvs [ i ] - scaleUVCentroid ) / scaleUVDelta ) + scaleUVCentroid ;
404
+ Vector2 adjustedScaleUVDelta = ( ( uvs [ i ] - scaleUVCentroid ) / scaleUVDelta ) + scaleUVCentroid - uvs [ i ] ;
405
+ scaleAndScrollUVDeltas . Add ( adjustedScaleUVDelta + offsetUVDelta ) ;
409
406
}
407
+ UpdateUV ( uvs , scaleAndScrollUVDeltas ) ;
408
+
409
+ Vector2 upperLeft = uvs [ UpperLeftQuadIndex ] ;
410
+ Vector2 upperRight = uvs [ UpperRightQuadIndex ] ;
411
+ Vector2 lowerLeft = uvs [ LowerLeftQuadIndex ] ;
412
+ totalUVScale . x = upperRight . x - upperLeft . x ;
413
+ totalUVScale . y = upperLeft . y - lowerLeft . y ;
410
414
}
411
415
}
416
+ else
417
+ {
418
+ // Scroll
419
+ UpdateUVWithScroll ( uvs , offsetUVDelta ) ;
420
+ }
421
+
422
+ mesh . SetUVs ( 0 , uvs ) ;
423
+ }
424
+
425
+ private void UpdateUVWithScroll ( List < Vector2 > uvs , Vector2 uvDelta )
426
+ {
427
+ var uvDeltas = new List < Vector2 > ( ) ;
428
+ for ( int i = 0 ; i < uvs . Count ; i ++ )
429
+ {
430
+ uvDeltas . Add ( uvDelta ) ;
431
+ }
432
+
433
+ UpdateUV ( uvs , uvDeltas , true ) ;
434
+ }
435
+
436
+ private void UpdateUV ( List < Vector2 > uvs , List < Vector2 > uvDeltas , bool scrollOnly = false )
437
+ {
438
+ Vector2 tiling = currentMaterial != null ? currentMaterial . mainTextureScale : new Vector2 ( 1.0f , 1.0f ) ;
412
439
413
- // Test for pan limits
414
- Vector2 uvDelta = new Vector2 ( totalUVOffset . x , - totalUVOffset . y ) ;
415
440
if ( ! unlimitedPan )
416
441
{
417
442
bool xLimited = false ;
418
443
bool yLimited = false ;
419
- for ( int i = 0 ; i < uvs . Count ; ++ i )
444
+
445
+ for ( int i = 0 ; i < uvs . Count ; i ++ )
420
446
{
421
- uvTestValue = uvs [ i ] - uvDelta ;
447
+ var uvTestValue = uvs [ i ] + uvDeltas [ i ] ;
422
448
if ( uvTestValue . x > tiling . x * maxPanHorizontal || uvTestValue . x < - ( tiling . x * maxPanHorizontal ) )
423
449
{
424
450
xLimited = true ;
@@ -429,20 +455,28 @@ private void UpdateUVMapping()
429
455
}
430
456
}
431
457
432
- for ( int i = 0 ; i < uvs . Count ; ++ i )
458
+ if ( scrollOnly )
459
+ {
460
+ for ( int i = 0 ; i < uvs . Count ; ++ i )
461
+ {
462
+ uvs [ i ] = new Vector2 ( xLimited ? uvs [ i ] . x : uvs [ i ] . x + uvDeltas [ i ] . x , yLimited ? uvs [ i ] . y : uvs [ i ] . y + uvDeltas [ i ] . y ) ;
463
+ }
464
+ }
465
+ else if ( ! xLimited && ! yLimited )
433
466
{
434
- uvs [ i ] = new Vector2 ( xLimited ? uvs [ i ] . x : uvs [ i ] . x - uvDelta . x , yLimited ? uvs [ i ] . y : uvs [ i ] . y - uvDelta . y ) ;
467
+ for ( int i = 0 ; i < uvs . Count ; ++ i )
468
+ {
469
+ uvs [ i ] += uvDeltas [ i ] ;
470
+ }
435
471
}
436
472
}
437
473
else
438
474
{
439
475
for ( int i = 0 ; i < uvs . Count ; ++ i )
440
476
{
441
- uvs [ i ] -= uvDelta ;
477
+ uvs [ i ] += uvDeltas [ i ] ;
442
478
}
443
479
}
444
-
445
- mesh . SetUVs ( 0 , uvs ) ;
446
480
}
447
481
448
482
private float GetUVScaleFromTouches ( )
0 commit comments