com.wallstop-studios.unity-helpers 2.0.0-rc74.7 → 2.0.0-rc74.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -352,25 +352,32 @@
352
352
  }
353
353
  );
354
354
 
355
- int cropWidth;
356
- int cropHeight;
357
- if (!hasVisible)
355
+ int origMinX = minX;
356
+ int origMinY = minY;
357
+ int origMaxX = maxX;
358
+ int origMaxY = maxY;
359
+
360
+ int visibleMinX = minX;
361
+ int visibleMinY = minY;
362
+ int visibleMaxX = maxX;
363
+ int visibleMaxY = maxY;
364
+
365
+ if (hasVisible)
358
366
  {
359
- cropWidth = 1;
360
- cropHeight = 1;
361
- minX = 0;
362
- minY = 0;
367
+ visibleMinX -= _leftPadding;
368
+ visibleMinY -= _bottomPadding;
369
+ visibleMaxX += _rightPadding;
370
+ visibleMaxY += _topPadding;
363
371
  }
364
372
  else
365
373
  {
366
- minX -= _leftPadding;
367
- minY -= _bottomPadding;
368
- maxX += _rightPadding;
369
- maxY += _topPadding;
370
- cropWidth = maxX - minX + 1;
371
- cropHeight = maxY - minY + 1;
374
+ visibleMinX = visibleMinY = 0;
375
+ visibleMaxX = visibleMaxY = 0;
372
376
  }
373
377
 
378
+ int cropWidth = visibleMaxX - visibleMinX + 1;
379
+ int cropHeight = visibleMaxY - visibleMinY + 1;
380
+
374
381
  if (_onlyNecessary && (!hasVisible || (cropWidth == width && cropHeight == height)))
375
382
  {
376
383
  return null;
@@ -384,21 +391,33 @@
384
391
  cropHeight,
385
392
  y =>
386
393
  {
387
- int sourceYOffset = (y + minY) * width;
388
- int destYOffset = y * cropWidth;
394
+ int destRow = y * cropWidth;
389
395
  for (int x = 0; x < cropWidth; ++x)
390
396
  {
391
- int sourceIndex = sourceYOffset + x + minX;
392
- Color32 sourcePixel;
393
- if (sourceIndex < 0 || pixels.Length <= sourceIndex)
397
+ int srcX = visibleMinX + x;
398
+ int srcY = visibleMinY + y;
399
+
400
+ bool insideOriginal =
401
+ srcX >= origMinX
402
+ && srcX <= origMaxX
403
+ && srcY >= origMinY
404
+ && srcY <= origMaxY;
405
+
406
+ if (insideOriginal)
394
407
  {
395
- sourcePixel = Color.clear;
408
+ if (0 <= srcX && srcX < width && 0 <= srcY && srcY < height)
409
+ {
410
+ croppedPixels[destRow + x] = pixels[srcY * width + srcX];
411
+ }
412
+ else
413
+ {
414
+ croppedPixels[destRow + x] = Color.clear;
415
+ }
396
416
  }
397
417
  else
398
418
  {
399
- sourcePixel = pixels[sourceIndex];
419
+ croppedPixels[destRow + x] = Color.clear;
400
420
  }
401
- croppedPixels[destYOffset + x] = sourcePixel;
402
421
  }
403
422
  }
404
423
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "com.wallstop-studios.unity-helpers",
3
- "version": "2.0.0-rc74.7",
3
+ "version": "2.0.0-rc74.8",
4
4
  "displayName": "Unity Helpers",
5
5
  "description": "Various Unity Helper Library",
6
6
  "dependencies": {},
@@ -61,5 +61,6 @@
61
61
 
62
62
 
63
63
 
64
+
64
65
 
65
66