/// <summary> /// 设置地主 /// </summary> /// <param name="obj"></param> private void OnSetBanker(TransferData data) { List <Poker> pokers = data.GetValue <List <Poker> >("PokerList"); if (pokers == null) { return; } for (int i = 0; i < m_BasePokerList.Count; ++i) { UIPoolManager.Instance.Despawn(m_BasePokerList[i].transform); } m_BasePokerList.Clear(); for (int i = 0; i < pokers.Count; ++i) { UIItemPoker item = SpawnPoker(pokers[i]); item.gameObject.SetParent(m_BasePokerContainer); m_BasePokerList.Add(item); } //if (m_loop == 0) ////{ //m_loop += 1; //m_txtLoop.SafeSetText(string.Format("{0}/{1}", m_loop, m_maxLoop)); //} }
/// <summary> /// 生成牌 /// </summary> /// <param name="poker"></param> /// <returns></returns> private UIItemPoker SpawnPoker(Poker poker) { Transform trans = UIPoolManager.Instance.Spawn("UIItemPoker_DouDiZhu"); UIItemPoker item = trans.GetComponent <UIItemPoker>(); item.Init(poker); return(item); }
/// <summary> /// 当鼠标进入时 /// </summary> /// <param name="item"></param> private void OnHandEnter(UIItemPoker item) { if (!m_isDown) { return; } if (!m_HandList.Contains(item)) { return; } m_SelectPoker.Clear(); for (int i = 0; i < m_HandList.Count; i++) { if (m_HandList[i].Poker.color == item.Poker.color && m_HandList[i].Poker.size == item.Poker.size) { m_TargetSelectPokerIndex = i; //m_EndSelectPoker = m_HandList[i]; break; } } if (m_StartSelectPokerIndex > m_TargetSelectPokerIndex) { for (int i = m_TargetSelectPokerIndex; i <= m_StartSelectPokerIndex; i++) { m_SelectPoker.Add(m_HandList[i]); } } else { for (int i = m_StartSelectPokerIndex; i <= m_TargetSelectPokerIndex; i++) { m_SelectPoker.Add(m_HandList[i]); } } for (int i = 0; i < m_HandList.Count; i++) { bool isExist = false; for (int j = 0; j < m_SelectPoker.Count; j++) { if (m_HandList[i].Poker.color == m_SelectPoker[j].Poker.color && m_HandList[i].Poker.size == m_SelectPoker[j].Poker.size) { isExist = true; m_SelectPoker[j].isGray = true; break; } } if (!isExist) { m_HandList[i].isGray = false; } } }
/// <summary> /// 鼠标抬起时 /// </summary> /// <param name="item"></param> private void OnHandUp(UIItemPoker item) { m_isDown = false; for (int i = 0; i < m_SelectPoker.Count; ++i) { m_SelectPoker[i].isGray = false; } SendNotification("OnDouDiZhuPokerClickUp", m_SelectPoker); }
/// <summary> /// 生成牌 /// </summary> /// <param name="poker"></param> /// <returns></returns> private UIItemPoker SpawnPoker(Poker poker, bool isAddAction = true) { Transform trans = UIPoolManager.Instance.Spawn("UIItemPoker_DouDiZhu"); UIItemPoker item = trans.GetComponent <UIItemPoker>(); item.isBanker = false; item.Init(poker); //item.onClick = OnPokerClick; if (isAddAction) { item.OnPointerDown = OnHandDown; item.OnPointerUp = OnHandUp; item.OnPointerEnter = OnHandEnter; } return(item); }
//private UIItemPoker m_EndSelectPoker; #endregion #region OnHandDown 当按下鼠标时 /// <summary> /// 当按下鼠标时 /// </summary> /// <param name="item"></param> private void OnHandDown(UIItemPoker item) { if (!m_HandList.Contains(item)) { return; } m_isDown = true; m_SelectPoker.Clear(); m_SelectPoker.Add(item); for (int i = 0; i < m_HandList.Count; i++) { if (m_HandList[i].Poker.color == item.Poker.color && m_HandList[i].Poker.size == item.Poker.size) { m_StartSelectPokerIndex = i; break; } } item.isGray = true; }
/// <summary> /// 初始化 /// </summary> /// <param name="obj"></param> private void OnInit(TransferData data) { RoomEntity room = data.GetValue <RoomEntity>("Room"); if (room == null) { return; } for (int i = 0; i < m_BasePokerList.Count; ++i) { UIPoolManager.Instance.Despawn(m_BasePokerList[i].transform); } m_BasePokerList.Clear(); for (int i = 0; i < room.basePoker.Count; ++i) { UIItemPoker item = SpawnPoker(room.basePoker[i]); item.gameObject.SetParent(m_BasePokerContainer); m_BasePokerList.Add(item); } for (int i = 0; i < room.SeatList.Count; ++i) { if (room.SeatList[i].IsPlayer) { bool mustPlay = data.GetValue <bool>("MustPlay"); bool canPlay = data.GetValue <bool>("CanPlay"); SetPlayPokerMenuActive(room.SeatList[i].status == SeatEntity.SeatStatus.PlayPoker, !mustPlay, !canPlay); SetBetMenuActive(room.SeatList[i].status == SeatEntity.SeatStatus.Bet, room.baseScore); m_btnReady.SafeSetActive(room.SeatList[i].status == SeatEntity.SeatStatus.Idle && room.roomStatus == RoomEntity.RoomStatus.Idle); m_btnShowPokerReady.SafeSetActive(room.SeatList[i].status == SeatEntity.SeatStatus.Idle && room.roomStatus == RoomEntity.RoomStatus.Idle); } } m_imgTrustee.SafeSetActive(room.PlayerSeat.IsTrustee); SetShowPokerImage(false); m_txtBaseScore.SafeSetText(room.baseScore.ToString()); }
/// <summary> /// 明牌 /// </summary> /// <param name="data"></param> private void OnShowPoker(TransferData data) { SeatEntity seat = data.GetValue <SeatEntity>("SeatEntity"); if (seat.Index != m_Index) { return; } if (seat.Index == 0) { return; } for (int i = 0; i < seat.pokerList.Count; ++i) { for (int j = 0; j < m_HandList.Count; ++j) { if (seat.pokerList[i].index == m_HandList[j].Poker.index) { UIPoolManager.Instance.Despawn(m_HandList[i].transform); break; } } } List <GameObject> lstPokerTrans = new List <GameObject>(); for (int i = 0; i < seat.pokerList.Count; ++i) { UIItemPoker item = SpawnPoker(seat.pokerList[i]); lstPokerTrans.Add(item.gameObject); item.gameObject.SetActive(false); item.gameObject.SetParent(m_HandContainer); m_HandList.Add(item); } StopAllCoroutines(); StartCoroutine(PlaySetHandPokerActive(lstPokerTrans)); }
/// <summary> /// 开局 /// </summary> /// <param name="obj"></param> private void OnBegin(TransferData data) { RoomEntity room = data.GetValue <RoomEntity>("Room"); if (room == null) { return; } for (int i = 0; i < room.SeatList.Count; ++i) { SeatEntity seat = room.SeatList[i]; if (seat.Index == m_Index) { for (int j = 0; j < m_HandList.Count; ++j) { UIPoolManager.Instance.Despawn(m_HandList[j].transform); } m_HandList.Clear(); m_gender = seat.Gender; for (int j = 0; j < m_PlayPokers.Count; ++j) { UIPoolManager.Instance.Despawn(m_PlayPokers[j].transform); } m_PlayPokers.Clear(); List <GameObject> lstPokerTrans = new List <GameObject>(); for (int j = 0; j < seat.pokerList.Count; ++j) { UIItemPoker item = SpawnPoker(seat.pokerList[j]); lstPokerTrans.Add(item.gameObject); item.gameObject.SetParent(m_HandContainer); item.gameObject.SetActive(false); m_HandList.Add(item); } HandSort(); StartCoroutine(PlaySetHandPokerActive(lstPokerTrans)); if (m_txtOverPlus != null) { m_txtOverPlus.SetNumber(m_HandList.Count.ToString()); } if (m_PokerCount != null) { m_PokerCount.SetNumber(m_HandList.Count.ToString()); } m_imgReady.SafeSetActive(false); m_imgBanker.SafeSetActive(false); m_imgPlayer.SafeSetActive(true); PlayAudio("deal"); } } }
/// <summary> /// 设置地主 /// </summary> /// <param name="obj"></param> private void OnSetBanker(TransferData data) { SeatEntity seat = data.GetValue <SeatEntity>("SeatEntity"); if (seat == null) { return; } if (seat.Index == m_Index) { List <Poker> pokers = data.GetValue <List <Poker> >("PokerList"); if (pokers == null) { return; } if (seat.IsPlayer) { for (int i = 0; i < pokers.Count; ++i) { UIItemPoker item = SpawnPoker(pokers[i]); item.gameObject.SetParent(m_HandContainer); m_HandList.Add(item); } } else { for (int i = 0; i < pokers.Count; ++i) { UIItemPoker item = SpawnPoker(new Poker(pokers[i].index, 0, 0)); item.gameObject.SetParent(m_HandContainer); m_HandList.Add(item); } } HandSort(); for (int j = 0; j < m_HandList.Count; j++) { m_HandList[j].transform.SetSiblingIndex(0); } if (m_txtOverPlus != null) { m_txtOverPlus.SetNumber(m_HandList.Count.ToString()); } if (m_PokerCount != null) { m_PokerCount.SetNumber(m_HandList.Count.ToString()); } } if (m_arrScoreParent) { m_arrScoreParent.gameObject.SetActive(true); } m_imgBanker.SafeSetActive(seat.Index == m_Index); m_imgPlayer.SafeSetActive(seat.Index != m_Index); for (int i = 0; i < m_arrScore.Length; ++i) { m_arrScore[i].SafeSetActive(false); } }
/// <summary> /// 初始化 /// </summary> /// <param name="obj"></param> private void OnInit(TransferData data) { RoomEntity room = data.GetValue <RoomEntity>("Room"); if (room == null) { return; } for (int i = 0; i < room.SeatList.Count; ++i) { SeatEntity seat = room.SeatList[i]; if (seat.Index != m_Index) { continue; } m_gender = seat.Gender; m_Pos = seat.Pos; for (int j = 0; j < m_HandList.Count; ++j) { UIPoolManager.Instance.Despawn(m_HandList[j].transform); } m_HandList.Clear(); for (int j = 0; j < m_PlayPokers.Count; ++j) { UIPoolManager.Instance.Despawn(m_PlayPokers[j].transform); } m_PlayPokers.Clear(); m_txtTotalScore.SafeSetText(seat.totalScore.ToString()); for (int j = 0; j < seat.pokerList.Count; ++j) { UIItemPoker item = SpawnPoker(seat.pokerList[j]); item.gameObject.SetParent(m_HandContainer); m_HandList.Add(item); } HandSort(); for (int j = 0; j < m_HandList.Count; j++) { m_HandList[j].transform.SetSiblingIndex(0); } if (m_txtOverPlus != null) { m_txtOverPlus.SetNumber(m_HandList.Count.ToString()); } if (m_PokerCount != null) { m_PokerCount.SetNumber(m_HandList.Count.ToString()); } if (seat.PreviourPoker != null) { for (int j = seat.PreviourPoker.Count - 1; j >= 0; --j) { UIItemPoker item = SpawnPoker(seat.PreviourPoker[j]); item.gameObject.SetParent(m_PlayPokerContainer); m_PlayPokers.Add(item); item.isBanker = seat.IsBanker; } } m_imgReady.SafeSetActive(room.roomStatus == RoomEntity.RoomStatus.Idle && seat.status == SeatEntity.SeatStatus.Ready); m_imgBanker.SafeSetActive(seat.IsBanker); m_imgPlayer.SafeSetActive(!seat.IsBanker); if (m_arrScoreParent) { m_arrScoreParent.gameObject.SetActive(true); } for (int j = 0; j < m_arrScore.Length; ++j) { m_arrScore[j].SafeSetActive(room.roomStatus == RoomEntity.RoomStatus.Bet && m_arrScore[j].name.ToInt() == seat.bet); } m_imgPass.SafeSetActive(room.roomStatus == RoomEntity.RoomStatus.Gaming && seat.PreviourPoker == null && seat.status == SeatEntity.SeatStatus.Wait); if (seat.status == SeatEntity.SeatStatus.PlayPoker) { m_countDown.SafeSetActive(true); m_countDown.transform.SetParent(m_CountDownContainer); m_countDown.transform.localPosition = Vector3.zero; m_countDown.SetCountDown(seat.unixtime); } } }
/// <summary> /// 播放出牌动画 /// </summary> /// <param name="deviation"></param> private void PlayPokerAnimation(Deck deck, bool isBanker = false) { if (deck.type == DeckType.AABBCC || deck.type == DeckType.ABCDE) { m_PlayPokerContainer.GetComponent <GridLayoutGroup>().enabled = false; for (int i = m_PlayPokers.Count - 1; i >= 0; --i) { m_PlayPokers[i].Init(deck.pokers[i]); UIItemPoker uiItemPoker = m_PlayPokers[i]; if (uiItemPoker != null) { uiItemPoker.image.DOColor(new Color(1, 1, 1, 0), 0.2f).OnComplete(() => { uiItemPoker.image.color = Color.white; }); float deviationMultiple = m_PlayPokers.Count % 2 == 1 ? (m_PlayPokers.Count / 2) : (m_PlayPokers.Count / 2 - 0.5f); uiItemPoker.MovePoker(new Vector3(0, 20, 0), 0.2f, (UIItemPoker item) => { float deviation = (m_PlayPokerContainer.GetComponent <GridLayoutGroup>().cellSize.x + m_PlayPokerContainer.GetComponent <GridLayoutGroup>().spacing.x); item.gameObject.SetParent(m_PlayPokerContainer); item.isBanker = isBanker; item.gameObject.transform.localPosition = new Vector3(-deviationMultiple * deviation, 0, 0); //Debug.LogWarning(uiItemPoker.Poker.ToString()); item.gameObject.transform.SetSiblingIndex(item.gameObject.transform.parent.childCount - 1); Tween tweener = item.gameObject.transform.DOLocalMoveX(item.gameObject.transform.localPosition.x + deviation * item.gameObject.transform.GetSiblingIndex(), 0.5f); tweener.SetEase(Ease.InOutExpo); //Vector3 ScaleVector = new Vector3(0.8f, 0.8f, 0.8f); //Tweener tweenerScale = item.gameObject.transform.DOScale(ScaleVector, 0.1f); //tweenerScale.SetEase(Ease.OutBack); item.gameObject.transform.GetComponent <RectTransform>().sizeDelta = m_PlayPokerContainer.GetComponent <GridLayoutGroup>().cellSize; }); } } } else { m_PlayPokerContainer.GetComponent <GridLayoutGroup>().enabled = true; for (int i = 0; i < m_PlayPokers.Count; ++i) { m_PlayPokers[i].Init(deck.pokers[i]); UIItemPoker uiItemPoker = m_PlayPokers[i]; if (m_Index != 0) { uiItemPoker.transform.SetSiblingIndex(0); } if (m_PlayPokers[i] != null) { uiItemPoker.image.DOColor(new Color(1, 1, 1, 0), 0.2f).OnComplete(() => { uiItemPoker.image.color = Color.white; }); uiItemPoker.MovePoker(new Vector3(0, 20, 0), 0.2f, (UIItemPoker item) => { item.gameObject.SetParent(m_PlayPokerContainer); item.isBanker = isBanker; item.gameObject.transform.localPosition = Vector3.zero; Vector3 ScaleVector = new Vector3(1f, 1f, 1); Tweener tweenerScale = item.gameObject.transform.DOScale(ScaleVector, 0.1f); tweenerScale.SetEase(Ease.OutBack); }); } } } }