Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. private bool IsOverlap(Vector3 position)
  2. {
  3. InventoryCell cell = GetCell(position);
  4. if (cell == null || cell.IsLocked) return true;
  5.  
  6. overlappingCells = new List<InventoryCell> { cell };
  7. overlappingInventory = cell.Inventory;
  8.  
  9. int width = overlappingInventory.Grid.GetLength(0);
  10. int height = overlappingInventory.Grid.GetLength(1);
  11. //Debug.Log($"w: {width} - h: {height}");
  12.  
  13. System.Diagnostics.Stopwatch timer = System.Diagnostics.Stopwatch.StartNew();
  14.  
  15. for (int x = 0; x < width; x++)
  16. {
  17. for (int y = 0; y < height; y++)
  18. {
  19. if (overlappingInventory.Grid[x, y].Equals(cell))
  20. {
  21. Vector2Int sizeVector = InventoryUtility.GetItemSizeInArray(size) + Vector2Int.one;
  22.  
  23. int w = isOriginalSize ? sizeVector.x : sizeVector.y;
  24. int h = isOriginalSize ? sizeVector.y : sizeVector.x;
  25. //Debug.Log($"w: {w} / h: {h}");
  26.  
  27. for (int i = 0; i < w; i++)
  28. {
  29. for (int j = 0; j < h; j++)
  30. {
  31. InventoryCell cellToAdd = overlappingInventory.Grid[x + i, y + j];
  32. if (cellToAdd.IsLocked) return true;
  33.  
  34. if (!overlappingCells.Contains(cellToAdd))
  35. overlappingCells.Add(cellToAdd);
  36. }
  37. }
  38. //останавливал и здесь, дебажит всеравно 0 мс
  39. break;
  40. }
  41. }
  42. }
  43.  
  44. timer.Stop();
  45. Debug.Log($"{timer.ElapsedMilliseconds} ms");
  46.  
  47. return false;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement