public void RepositionHand() { RectTransform rect = this.GetComponent <RectTransform>(); float width = rect.rect.width; float spacing = width / player.CardCount(); float startX = -width / 2 + spacing / 2; for (int i = 0; i < player.CardCount(); ++i) { CardVisual c = cardVisuals[i]; c.GetComponent <RectTransform>().anchoredPosition = new Vector3(startX + i * spacing, 0.0f, 0.0f); } CurrentCard = 0; }
public override void CreateHand() { for (int i = 0; i < player.CardCount(); ++i) { CardVisual c = Instantiate <CardVisual>(cardWithControlPrefab); c.transform.SetParent(this.transform, false); c.transform.SetSiblingIndex(i); c.card = player.CardAt(i); CardControl cc = c.GetComponent <CardControl>(); cc.parentHand = this; cardVisuals.Add(c); } lastHandCount = cardVisuals.Count; }
private void OnDrag() { if (pointerOver) { cardDragged.GetComponent <RectTransform>().position = Input.mousePosition; cardDragged.transform.SetAsLastSibling(); foreach (GridCell gc in gameGrid) { gc.RefreshVisuals(); } } else { cardDragged.GetComponent <RectTransform>().position = new Vector3(1000000, 1000000, 0); RaycastHit hit; Ray cameraRay = Camera.main.ScreenPointToRay(Input.mousePosition); GridCell mouseTargetCell = null; // omg kill me this code is so hacky if (Physics.Raycast(cameraRay, out hit)) { GridCellVisual gcv = hit.transform.gameObject.GetComponent <GridCellVisual>(); if (gcv == null) { return; } foreach (GridCell gc in gameGrid) { if (gc.visual == gcv) { mouseTargetCell = gc; break; } } } if (mouseTargetCell == null) { return; } // Hover correct pattern foreach (GridCell gc in gameGrid) { gc.RefreshVisuals(); } for (int i = 0; i < 25; i++) { if (!cardDragged.cardType.tile.tiles[i]) { continue; } int dx = (i % 5) - 2; int dy = (i / 5) - 2; int x = mouseTargetCell.gridLocation.x - dx; int y = mouseTargetCell.gridLocation.y - dy; if (x < 0 || y < 0 || x >= gameGrid.size.x || y >= gameGrid.size.y) { continue; } gameGrid[x, y].visual.setHoverState(); } } }