public void AddPokerTriggerOnClick(MonoBehaviour target, PokerCard poker, string mothName) { var trigger = GetUiEventTrigger(poker); var ed = GetEventDelegate(target, poker, mothName); EventDelegate.Add(trigger.onClick, ed); }
protected EventDelegate GetEventDelegate(MonoBehaviour target, PokerCard poker, string mothName) { var ed = new EventDelegate(target, mothName); ed.parameters[0] = new EventDelegate.Parameter(poker, "PokerCard"); return(ed); }
/// <summary> /// 检测扑克个数 /// </summary> protected virtual void InitPokerList() { if (CardsList.Count == CardCount) { return; } if (CardsList.Count > CardCount) { //删除多余的牌 int count = CardsList.Count - CardCount; for (int i = 0; i < count; i++) { var temp = CardsList[i]; CardsList.Remove(temp); Destroy(temp); } } else { int count = CardCount - CardsList.Count; for (int i = 0; i < count; i++) { PokerCard clone = Instantiate(CardPrefab); clone.transform.parent = PokerParent; clone.name = "poker " + i; clone.transform.localScale = Vector3.one * .6f; clone.GetComponent <PokerCard>().SetCardDepth(130 + i * 2); CardsList.Add(clone); } } }
public override void OnDragOverCard(PokerCard card) { if (_isFinish) { return; } OnClickCard(card); }
/// <summary> /// 代理添加事件,当点击每道的牌时 /// </summary> /// <param name="card"></param> void OnClickLinePoker(PokerCard card) { if (!_isFinish) { return; } ExchangeCard(card); }
/// <summary> /// 设置一张牌,包括大小,显示层级等信息 /// </summary> /// <param name="card"></param> public void SetOneCard(PokerCard card) { card.name = "line"; card.transform.parent = PokerParent.transform; card.transform.localScale = Vector3.one * 0.6f; card.SetCardDepth(BaseDepth + CardList.Count * 4); CardList.Add(card); //不可点击 card.gameObject.SetActive(false); }
/// <summary> /// 点击扑克按钮 /// </summary> /// <param name="card"></param> public override void OnClickCard(PokerCard card) { bool selected = !card.IsSelect; //反选牌 SelectCard(card, selected); if (!selected) { _selectInfo.Dun.Cards.Remove(card.Id); } }
/// <summary> /// 更换两张牌的位置 /// </summary> public void ExchangePokersPosition(PokerCard poker1, PokerCard poker2) { if (poker1 == null || poker2 == null) { return; } Facade.Instance <MusicManager>().Play("select"); Vector3 tempPos = poker1.transform.localPosition; poker1.MoveTo(poker1.transform.localPosition, poker2.transform.localPosition); poker2.MoveTo(poker2.transform.localPosition, tempPos); }
/// <summary> /// 将牌变为选择的方案牌型 /// </summary> /// <param name="intList"></param> void ChoisePlane(List <int> intList) { //第一次选择的时候不用换牌,直接赋值 if (_lastList == null || _lastList.Count == 0) { for (int i = 0; i < intList.Count; i++) { PokerCard ca = CardsList[i].GetComponent <PokerCard>(); ca.SetCardId(intList[i]); ca.SetCardFront(); } return; } List <int> tempList = _lastList.GetRange(0, 13); if (intList.Count != tempList.Count) { YxDebug.LogError("码牌数据错误"); return; } bool change = false; for (int i = 0; i < tempList.Count; i++) { int index = i; var tempObj = CardsList[i]; if (intList[i] != tempList[i]) { index = tempList.IndexOf(intList[i]); CardsList[i] = CardsList[index]; CardsList[index] = tempObj; int tempInt = tempList[i]; tempList[i] = tempList[index]; tempList[index] = tempInt; --i; change = true; } PokerCard card = tempObj.GetComponent <PokerCard>(); card.MoveTo(CardsList[index].transform.localPosition, RepositionCard(index)); } if (change) { Facade.Instance <MusicManager>().Play("select"); } _lastList = tempList; ResetSelectedCards(); }
void ResetSelectedCards() { if (_selectPok1 != null) { _selectPok1.SetCardSelected(false); _selectPok1 = null; } if (_selectPok2 != null) { _selectPok2.SetCardSelected(false); _selectPok2 = null; } }
/// <summary> /// 获取扑克在数组中的索引 /// </summary> /// <param name="cardList"></param> /// <param name="card"></param> /// <param name="from"></param> /// <returns></returns> int GetPokerIndex(List <PokerCard> cardList, PokerCard card, int from) { int count = cardList.Count; for (int i = from; i < count; i++) { if (cardList[i].Equals(card)) { return(i); } } return(0); }
public void Reset() { _dealing = false; foreach (GameObject poker in _pokerList) { poker.SetActive(false); PokerCard pokerCard = poker.GetComponent <PokerCard>(); pokerCard.SetCardId(0); pokerCard.SetCardFront(); } _pokerCounter = 0; ShootItemList.Clear(); StopAllCoroutines(); }
/// <summary> /// 逐行展示手牌 /// </summary> /// <param name="line">行数</param> /// <param name="cardValueList">牌</param> /// <param name="type">牌型</param> public void ShowHandPoker(int line, List <int> cardValueList, CardType type) { int beginIndex = 0; int count = 0; InitRange(line, ref beginIndex, ref count); List <PokerCard> curShowCards = new List <PokerCard>(); //设置显示手牌 for (int i = 0; i < UserCardList.Count; i++) { GameObject obj = UserCardList[i]; if (i >= beginIndex && i < beginIndex + count) { obj.transform.localScale = Vector3.one * (_scale + .1f); PokerCard card = obj.GetComponent <PokerCard>(); card.SetCardDepth(100 + i * 2); card.SetCardId(cardValueList[i]); card.SetCardFront(); curShowCards.Add(card); } else { obj.transform.localScale = Vector3.one * _scale; obj.GetComponent <PokerCard>().SetCardDepth(i * 2); } } string typeName; if (line == 0 && type == CardType.santiao) { typeName = "chongsan"; } else if (line == 1 && type == CardType.hulu) { typeName = "zhongdunhulu"; } else { typeName = type.ToString(); } App.GetGameManager <SssGameManager>().PlayOnesSound(typeName, Info.Seat); HandCardsType.ShowType(line, typeName); //显示手牌牌型 StartCoroutine(HideHandPoker(line, beginIndex, count)); }
private void ExchangeCard(PokerCard card) { if (_selectPok1 == null) { _selectPok1 = card; _selectPok1.SetCardSelected(true); return; } if (_selectPok2 == null) { if (_selectPok1.Equals(card)) { ResetSelectedCards(); return; } _selectPok2 = card; } int cardId1 = _selectPok1.Id; int cardId2 = _selectPok2.Id; int len = Lines.Length; for (int i = 0; i < len; i++) { var lineInfo = Lines[i].LineInfo; var valList = lineInfo.Dun.Cards; int count = valList.Count; for (int j = 0; j < count; j++) { if (valList[j] == cardId1) { valList[j] = cardId2; GetLineInfo(valList, i); continue; } if (valList[j] == cardId2) { valList[j] = cardId1; GetLineInfo(valList, i); } } } ResetSelectedCards(); }
public override void OnClickCard(PokerCard card) { if (_selectPok1 == null) { _selectPok1 = card; _selectPok1.SetCardSelected(true); return; } if (_selectPok2 == null) { if (_selectPok1.Equals(card)) { ResetSelectedCards(); return; } _selectPok2 = card; } int index1 = CardsList.IndexOf(_selectPok1); int index2 = CardsList.IndexOf(_selectPok2); List <int> tempList = new List <int>(_lastList); int tempInt = tempList[index1]; tempList[index1] = tempList[index2]; tempList[index2] = tempInt; ExchangePokersPosition(_selectPok1, _selectPok2); var tempObj = CardsList[index1]; CardsList[index1] = CardsList[index2]; CardsList[index2] = tempObj; _lastList = tempList; foreach (ChoiseItem item in _choiseItems) { item.SelectMark.SetActive(false); } _lastChoiseItem = null; ResetSelectedCards(); }
IEnumerator HideHandPoker(int line, int beginIndex, int count) { yield return(new WaitForSeconds(1.5f)); HandCardsType.HideType(line); for (int i = 0; i < count; i++) { int index = beginIndex + i; if (index >= UserCardList.Count || UserCardList[index] == null) { break; } GameObject obj = UserCardList[index]; PokerCard poker = obj.GetComponent <PokerCard>(); poker.transform.localScale = Vector3.one * _scale; poker.SetCardDepth((beginIndex + i) * 2); } StopAllCoroutines(); }
public override void Reset() { _selectPok1 = null; _selectPok2 = null; _lastList = null; foreach (var card in CardsList) { var pokerCard = card.GetComponent <PokerCard>(); pokerCard.SetCardId(0); pokerCard.SetCardFront(); } _curCardValList.Clear(); foreach (ChoiseItem item in _choiseItems) { if (item != null) { item.Reset(); } } }
/// <summary> /// 选牌 /// </summary> /// <param name="card"></param> /// <param name="isSelect"></param> void SelectCard(PokerCard card, bool isSelect) { card.IsSelect = isSelect; if (isSelect) { MoveYTo(card.transform, 10); var selectCards = _selectInfo.SelectedCards; if (!selectCards.Contains(card)) { selectCards.Add(card); } var dunCards = _selectInfo.Dun.Cards; if (!dunCards.Contains(card.Id)) { dunCards.Add(card.Id); } } else { MoveYTo(card.transform, 0); _selectInfo.SelectedCards.Remove(card); } }
/// <summary> /// 初始化每道 /// </summary> private void InitLines() { int len = Lines.Length; for (int i = 0; i < len; i++) { var line = Lines[i]; var btn = line.SelectBtn; //初始化选择按钮点击按钮事件 if (btn != null) { CreateEventDelegate(this, "OnClickSelectBtn", btn, i); } //初始化取消按钮点击按钮事件 btn = line.ReselectBtn; if (btn != null) { CreateEventDelegate(this, "OnClickReselectBtn", btn, i); } int count = i == 0 ? 3 : 5; if (line.CardList.Count == count) { continue; //已经有这么多牌了 无需创建牌 } for (int j = 0; j < count; j++) { PokerCard poker = Instantiate(CardPrefab); AddPokerTriggerOnClick(this, poker, "OnClickLinePoker"); line.SetOneCard(poker); } line.ParentReposition(); } }
public virtual void OnDragOverCard(PokerCard card) { }
public virtual void OnClickCard(PokerCard card) { }
protected UIEventTrigger GetUiEventTrigger(PokerCard card) { return(card.GetComponentInChildren <UIEventTrigger>()); }
public void AddPokerEvent(PokerCard poker) { AddPokerTriggerOnClick(this, poker, "OnClickCard"); AddPokerTriggerOnDragOver(this, poker, "OnDragOverCard"); }