Exemple #1
0
        void OnDespawned()
        {
            this.Dispose();

            stopParticle(chipsParticle);
            stopParticle(allinParticle);
            stopParticle(winParticle);

            // 取消所有动画
            DOTween.Pause(AnimID);

            SpkText.gameObject.SetActive(false);
            hunterParent.SetActive(false);

            lastState = ActionState.None;
            WinCq.SetActive(false);
            ScoreParent.SetActive(true);
            ScoreParent.GetComponent <CanvasGroup>().alpha = 1;
            PlayerAct.SetActive(false, false);
            Avt.GetComponent <CanvasGroup>().alpha = 1;
            Circle.gameObject.SetActive(true);
            RankText.transform.parent.gameObject.SetActive(false);

            Volume.SetActive(false);
            ScoreLabel.gameObject.SetActive(true);
        }
Exemple #2
0
 private void hideWinAnim()
 {
     stopParticle(winParticle);
     DoFade(WinCq, () => {
         ScoreParent.SetActive(true);
     });
     myDelegate.WinEnd();
 }
Exemple #3
0
        private void addEvents()
        {
            player.HeadValue.Subscribe((value) => {
                if (value > 0)
                {
                    hunterParent.SetActive(true);
                    hunterAward.text = _.Num2CnDigit(value);
                }
            }).AddTo(this);

            RxSubjects.ShowCard.Subscribe((e) => {
                var uid = e.Data.String("uid");
                if (uid != player.Uid)
                {
                    return;
                }

                var cards          = e.Data.IL("cards");
                player.SeeCardAnim = true;
                myDelegate.ShowCard(cards);
            }).AddTo(this);

            RxSubjects.ShowAudio.Where(isSelfJson).Subscribe((jsonStr) => {
                Volume.SetActive(true);
                ScoreLabel.gameObject.SetActive(false);
            }).AddTo(this);

            RxSubjects.HideAudio.Where(isSelfJson).Subscribe((_) => {
                Volume.SetActive(false);
                ScoreLabel.gameObject.SetActive(true);
            }).AddTo(this);

            RxSubjects.SendChat.Where(isSelfJson).Subscribe((jsonStr) => {
                var N    = JSON.Parse(jsonStr);
                var text = N["text"].Value;
                SpkText.ShowMessage(text);
            }).AddTo(this);

            theSeat.SeatPos.Subscribe((pos) => {
                SpkText.ChangePos(pos);
                PlayerAct.ChangePos(pos);

                // @FIXME: 这段逻辑给PlayerSelf、PlayerOppo分别实现更合适?
                var rect = WinPercent.GetComponent <RectTransform>();
                if (Uid == GameData.Shared.Uid)
                {
                    rect.localPosition = new Vector2(191, -286);
                }
                else if (pos == SeatPosition.Left)
                {
                    rect.localPosition = new Vector2(127, -36);
                }
                else
                {
                    rect.localPosition = new Vector2(-127, -36);
                }
            }).AddTo(this);

            player.PrChips.AsObservable().Subscribe((value) => {
                if (value == 0)
                {
                    return;
                }

                setPrChips(value);
            }).AddTo(this);

            player.Destroyed.AsObservable().Where((v) => v).Subscribe((_) => {
                myDelegate.Despawn();
            }).AddTo(this);

            player.PlayerStat.Subscribe((state) => {
                HandGo.SetActive(false);

                var stateGo = StateLabel.transform.parent.gameObject;
                stateGo.SetActive(false);

                switch (state)
                {
                case PlayerState.Hanging:
                    HandGo.SetActive(true);
                    break;

                case PlayerState.Reserve:
                    stateGo.SetActive(true);
                    break;

                default:
                    break;
                }
            }).AddTo(this);

            player.ActState.Subscribe((e) => {
                if (e == ActionState.None)
                {
                    return;
                }

                if (e == ActionState.Fold)
                {
                    SetFolded();
                    myDelegate.Fold();
                }
                else
                {
                    myDelegate.MoveOut();
                }

                dealAct(e);
                actCardsNumber = GameData.Shared.PublicCards.Count;
            }).AddTo(this);

            IDisposable reserveCd = null;

            player.ReservedCD.Subscribe((value) => {
                if (reserveCd != null)
                {
                    reserveCd.Dispose();
                }

                if (value > 0)
                {
                    setReserveCd(value);

                    reserveCd = Observable.Interval(TimeSpan.FromSeconds(1)).Subscribe((_) => {
                        value = Mathf.Max(value - 1, 1);
                        setReserveCd(value);
                    }).AddTo(this);
                }
            }).AddTo(this);

            RxSubjects.GainChip.Where((gainChip) => gainChip.Uid == Uid).Subscribe((gainChip) => {
                gainChip.Grp.ToParent(transform, () => {
                    if (!gameObject.activeInHierarchy)
                    {
                        return;
                    }

                    if (chipsParticle.isPlaying)
                    {
                        return;
                    }

                    if (player.OverData.Value.Gain() <= 0)
                    {
                        return;
                    }

                    playParticle(chipsParticle);
                });
            }).AddTo(this);

            player.Bankroll.Subscribe((value) => {
                setScoreText(value);
            }).AddTo(this);

            RxSubjects.MoveTurn.Subscribe((e) => {
                var uid = e.Data.String("uid");
                var dc  = e.Data.Int("deal_card");

                if (uid == Uid)
                {
                    myDelegate.TurnTo(e.Data, GameData.Shared.ThinkTime);
                    setAct(false, false);
                }
                else
                {
                    myDelegate.MoveOut();

                    // 刚发了牌
                    if (dc == 1 || GameData.Shared.PublicCards.Count != actCardsNumber)
                    {
                        setAct(false);
                    }
                }

                if (Uid == GameData.Shared.Uid)
                {
                    player.SetTrust(e.Data.Dict("trust"));
                }
            }).AddTo(this);

            // 思考延时
            RxSubjects.Moretime.Subscribe((e) => {
                var model = e.Data.ToObject <MoreTimeModel>();

                if (model.uid != Uid)
                {
                    return;
                }

                if (!model.IsRound())
                {
                    return;
                }

                myDelegate.ResetTime(model.total);
            }).AddTo(this);

            RxSubjects.GameOver.Subscribe((e) => {
                player.InGame = false;

                myDelegate.MoveOut();
                stopParticle(allinParticle);
                player.PrChips.Value = 0;
                player.WinPercent.OnNext(-1);                 // 隐藏胜率
                OP.Despawn();
            }).AddTo(this);

            player.Cards.AsObservable().Subscribe((cards) => {
                if (cards.Count < 2)
                {
                    return;
                }
                myDelegate.ShowCard(cards);
            }).AddTo(this);

            IDisposable winEndDisposable = null;

            player.OverData.AsObservable().Where((data) => data != null).Subscribe((data) => {
                var gain = data.Gain();
                if (gain > 0)
                {
                    playParticle(winParticle);
                }

                if (data.prize > 0)                   // 回收大于0
                {
                    var cvg   = WinCq.GetComponent <CanvasGroup>();
                    cvg.alpha = 0;
                    cvg.DOFade(1, 0.3f).SetId(AnimID);

                    var rect = WinCq.GetComponent <RectTransform>();
                    rect.anchoredPosition = new Vector2(0, -300);
                    rect.DOAnchorPos(new Vector2(0, -224), 0.3f).SetId(AnimID);

                    var image = WinCq.GetComponent <Image>();

                    if (gain >= 0)
                    {
                        image.enabled      = true;
                        WinNumber.fontSize = 36;
                        WinNumber.color    = _.HexColor("#FAD028FF");
                    }
                    else
                    {
                        image.enabled      = false;
                        WinNumber.fontSize = 42;
                        WinNumber.color    = MaterialColor.greenA200;
                    }

                    WinCq.SetActive(true);
                    WinNumber.text = _.Number2Text(gain);
                    ScoreParent.SetActive(false);
                }

                // 重新计算用户的bankroll
                player.Bankroll.Value = player.Bankroll.Value + data.prize;

                if (player.Uid == GameData.Shared.Uid)
                {
                    GameData.Shared.Bankroll.Value = player.Bankroll.Value;
                }

                myDelegate.HandOver(data);

                if (winEndDisposable != null)
                {
                    winEndDisposable.Dispose();
                }

                if (data.bury_card)
                {
                    player.ActState.OnNext(ActionState.BuryCard);
                }
                else
                {
                    PlayerAct.SetActive(false);
                }

                // 4s后隐藏动画
                winEndDisposable = Observable.Timer(TimeSpan.FromSeconds(4)).Subscribe((_) => {
                    hideWinAnim();
                    PlayerAct.SetActive(false);
                }).AddTo(this);
            }).AddTo(this);

            RxSubjects.MatchRank.Subscribe((_) => {
                if (winEndDisposable != null)
                {
                    winEndDisposable.Dispose();
                }

                hideWinAnim();
            }).AddTo(this);

            player.Rank.Where((rank) => rank > 0 && player.readyState == 0).Subscribe((rank) => {
                RankText.transform.parent.gameObject.SetActive(true);
                RankText.text = string.Format("第<size=42>{0}</size>名", rank);
            }).AddTo(this);


            player.WinPercent.Subscribe((num) =>
            {
                if (num == -1)
                {
                    WinPercent.SetActive(false);
                }
                else
                {
                    WinPercent.SetActive(true);
                    WinPercent.GetComponentInChildren <Text>().text = num + "%";

                    var img = WinPercent.GetComponent <ProceduralImage>();

                    if (num == Player.MaxWinPercent)
                    {
                        img.color = _.HexColor("#ff1744");
                    }
                    else
                    {
                        img.color = _.HexColor("#868d94");
                    }
                }
            }).AddTo(this);
        }