private void MoveCardFromDeckToKaKu(int cardId) { UINormalCard cardFromDeck = cardGrid.transform.Find("" + cardId).GetComponent <UINormalCard>(); if (cardFromDeck.CardNum <= 0) { Debug.LogError("Move failed, the Card has wrong num!"); return; } cardFromDeck.CardNum -= 1; if (cardFromDeck.CardNum == 0) { Destroy(cardFromDeck.gameObject); } UINormalCard cardToKaKu = kakuGrid.transform.Find("" + cardId).GetComponent <UINormalCard>(); cardToKaKu.CardNum += 1; kakuGrid.repositionNow = true; cardGrid.repositionNow = true; for (int i = 0; i < tempDeck.Count; i++) { if (tempDeck[i].CardId == cardId) { tempDeck.RemoveAt(i); break; } } }
public static void GetNormalCard(Transform parent, int cardId, int count, Vector3 eulerAngles, Vector3 scale, Vector3 pos, Action <UINormalCard> callback) { ItemTableSetting cardData = ItemTableSettings.Get(cardId); if (cardData == null) { Debug.LogError("非法ID:" + cardId); return; } UIItemTableSetting uiItem = UIItemTableSettings.Get(1); ResourceManager.LoadGameObject(uiItem.Path, (p, u, go) => { go.transform.parent = parent; go.transform.localEulerAngles = eulerAngles; go.transform.localScale = scale; go.transform.position = pos; go.SetActive(true); UINormalCard normalCard = go.GetComponent <UINormalCard>(); normalCard.SetCard(cardId, count); if (callback != null) { callback(normalCard); } }, (p, u) => { Debug.LogError("加载失败!"); }); }
private void MoveCardFromKaKuToDeck(int cardId) { UINormalCard cardFromKaKu = kakuGrid.transform.Find("" + cardId).GetComponent <UINormalCard>(); if (cardFromKaKu.CardNum <= 0) { Debug.LogError("Move failed, the Card has wrong num!"); return; } cardFromKaKu.CardNum -= 1; bool isFoud = false; for (int i = 0; i < tempDeck.Count; i++) { if (tempDeck[i].CardId == cardId) { isFoud = true; break; } } if (isFoud == false) { GameObject item = Instantiate(CardInstence); item.SetActive(true); int id = cardId; item.name = "" + id; item.AddComponent <UIDragScrollView>(); item.GetComponent <UINormalCard>().SetCard(id); UIEventListener.Get(item).onDragStart = OnCardDragStart; UIEventListener.Get(item).onDrag = OnCardDrag; UIEventListener.Get(item).onDragEnd = OnCardDragEnd; item.transform.SetParent(cardGrid.transform, false); item.transform.localPosition = new Vector3(); item.transform.localScale = cardScale; } else { UINormalCard cardToDeck = cardGrid.transform.Find("" + cardId).GetComponent <UINormalCard>(); cardToDeck.CardNum += 1; } kakuGrid.repositionNow = true; cardGrid.repositionNow = true; for (int i = 0; i < tempDeck.Count; i++) { bool isFind = false; for (int j = 0; j < KaKu.Count; j++) { if (KaKu[j].CardId == cardId && KaKu[j] != tempDeck[i]) { isFind = true; tempDeck.Add(KaKu[j]); break; } } if (isFind) { break; } } }