Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- row & col étant des int
- public void AssignCardinalNeighborsDirect()
- {
- for (int y = 0; y < m_Rows; y++)
- for (int x = 0; x < m_Cols; x++)
- {
- var s = GetFromListByXY(x, y);
- if (!s) continue;
- s.m_NeighbourRight = GetFromListByXY(x + 1, y);
- s.m_NeighbourLeft = GetFromListByXY(x - 1, y);
- s.m_NeighbourUp = GetFromListByXY(x, y + 1);
- s.m_NeighbourDown = GetFromListByXY(x, y - 1);
- s.SetNameAndNeighbours();
- }
- }
- --------------------------------------------
- private int IndexOf(int x, int y) => y * m_Cols + x;
- private InventorySlot GetFromListByXY(int x, int y)
- {
- if (x < 0 || x >= m_Cols || y < 0 || y >= m_Rows) return null;
- int i = IndexOf(x, y);
- if (i < 0 || i >= allInventorySlot.Count) return null;
- return allInventorySlot[i];
- }
Advertisement
Add Comment
Please, Sign In to add comment