// TO IMPLEMENT LATER /*private void ApplyDeckStyleTransformToCards(int indexStart, int indexEnd, List<TransformData> t) * { * for (int index = indexStart; index <= indexEnd; index++) * { * ApplyDeckStyleTransformToCard(index, t[index]); * } * }*/ #endregion public void Shuffle() { for (int i = 0; i < _spots.Count; i++) { TabletopDeckSpot temp = _spots[i]; int randomIndex = Random.Range(i, _spots.Count); _spots[i] = _spots[randomIndex]; _spots[randomIndex] = temp; } // Get new scatter data for (int i = 0; i < _spots.Count; i++) { _spots[i].scatterData = style.GenerateScatter(); } // Lay down cards LayDown(gradually: false); }
/// <summary> /// Adds a list of cards to the deck. /// </summary> /// <param name="cards">Cards.</param> /// <param name="index">Position on the deck. <c>0</c> is bottom, <c>-1</c> is top, <c>-2</c> is second from top and so on.</param> /// <param name="gradually">If <c>false</c> the animations have no delay.</param> public void AddCards(List <GameObject> cards, int index = -1, bool gradually = true) { // Remove spots with cards already in deck, so they will go to their new spot foreach (GameObject card in cards) { _spots.RemoveAll(spot => spot.card == card); } // Clamp and add cards to deck (start from top of index is negative) // // Example with 4 cards: // // [ ][ ][ ][ ] // Index: 0 1 2 3 4 // Negative index: -5 -4 -3 -2 -1 index = Mathf.Clamp(index, -_spots.Count - 1, _spots.Count); List <TabletopDeckSpot> newSpots = new List <TabletopDeckSpot>(); for (int i = 0; i < cards.Count; i++) { TabletopDeckSpot newSpot = new TabletopDeckSpot(cards[i]); newSpots.Add(newSpot); // Save this deck to card cards[i].GetComponent <TabletopCard>().deck = gameObject; // Generate new scatter data for new cards newSpot.scatterData = style.GenerateScatter(); } if (index >= 0) { _spots.InsertRange(index, newSpots); } else { _spots.InsertRange(_spots.Count + index + 1, newSpots); } // Lay down cards in table LayDown(index, gradually); }
public void RemoveCard(GameObject card, bool gradually = true) { // Find with spot contains the card TabletopDeckSpot s = _spots.Find(spot => spot.card == card); if (s == null) { Debug.LogWarning("Trying to remove a card not in deck."); return; } // Remeber index int index = _spots.IndexOf(s); // Remove spot _spots.Remove(s); card.GetComponent <TabletopCard>().deck = null; // Lay down cards in table LayDown(index - 1, gradually); }