Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public struct SlotRect
- {
- public Vector2 bottomLeft;
- public Vector2 topRight;
- public SlotRect(Vector2 bl, Vector2 tr)
- {
- bottomLeft = bl;
- topRight = tr;
- }
- public bool Contains(Vector2 point)
- {
- return point.x >= bottomLeft.x && point.x <= topRight.x &&
- point.y >= bottomLeft.y && point.y <= topRight.y;
- }
- }
- public int nbSlotsX;
- public int nbSlotsY;
- public float totalSizeX;
- public float totalSizeY;
- public float slotSizeX;
- public float slotSizeY;
- private SlotRect[,] slotGrid;
- private void NoMoellonageGrid()
- {
- slotGrid = new SlotRect[nbSlotsX, nbSlotsY];
- float centerX = totalSizeX / 2f;
- float centerY = totalSizeY / 2f;
- for (int x = 0; x < nbSlotsX; x++)
- {
- for (int y = 0; y < nbSlotsY; y++)
- {
- float startX = -centerX + x * slotSizeX;
- float endX = startX + slotSizeX;
- float startY = -centerY + y * slotSizeY;
- float endY = startY + slotSizeY;
- slotGrid[x, y] = new SlotRect(new Vector2(startX, startY), new Vector2(endX, endY));
- }
- }
- }
- public bool TryGetSlotIndex(Vector2 localPoint, out Vector2Int slotIndex)
- {
- for (int x = 0; x < nbSlotsX; x++)
- {
- for (int y = 0; y < nbSlotsY; y++)
- {
- if (slotGrid[x, y].Contains(localPoint))
- {
- slotIndex = new Vector2Int(x, y);
- return true;
- }
- }
- }
- slotIndex = new Vector2Int(-1, -1);
- return false;
- }
- // et t'use genre Grid.TryGetSlotIndex(); avec RectTransformUtility.ScreenPointToLocalPointInRectangle (comme sur la Doc oui oui Kappa ) pour récup' la pos' du cursor, puis out le slot
Advertisement
Add Comment
Please, Sign In to add comment