Eonirr

Untitled

Dec 5th, 2025
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. row & col étant des int
  2.  
  3.  
  4. public void AssignCardinalNeighborsDirect()
  5. {
  6. for (int y = 0; y < m_Rows; y++)
  7. for (int x = 0; x < m_Cols; x++)
  8. {
  9. var s = GetFromListByXY(x, y);
  10. if (!s) continue;
  11.  
  12. s.m_NeighbourRight = GetFromListByXY(x + 1, y);
  13. s.m_NeighbourLeft = GetFromListByXY(x - 1, y);
  14. s.m_NeighbourUp = GetFromListByXY(x, y + 1);
  15. s.m_NeighbourDown = GetFromListByXY(x, y - 1);
  16.  
  17. s.SetNameAndNeighbours();
  18. }
  19. }
  20.  
  21. --------------------------------------------
  22.  
  23. private int IndexOf(int x, int y) => y * m_Cols + x;
  24.  
  25. private InventorySlot GetFromListByXY(int x, int y)
  26. {
  27. if (x < 0 || x >= m_Cols || y < 0 || y >= m_Rows) return null;
  28. int i = IndexOf(x, y);
  29. if (i < 0 || i >= allInventorySlot.Count) return null;
  30. return allInventorySlot[i];
  31. }
Advertisement
Add Comment
Please, Sign In to add comment