Example #1
0
        Data.Player AddPlayer(int deskId, int uid)
        {
            Data.Player     player = new Data.Player();
            Data.PlayerInfo info   = new Data.PlayerInfo();
            info.id = uid;

            player.Info   = info;
            player.DeskId = deskId;
            player.Index  = player.DeskId - Data.Game.DeskId;
            if (player.Index < 0)
            {
                player.Index = 10 + player.Index;
            }

            player.PlayerUi = ui.GetChild("player" + (player.Index + 1)).asCom;
            player.PlayerUi.sortingOrder = 2000;
            if (!Data.Game.Players.ContainsKey(uid))
            {
                Data.Game.Players.Add(uid, player);

                // 自己坐下,不用播放声音
                if (uid != Data.User.Id)
                {
                    roomAudio.clip = Resources.Load <AudioClip>("Game/audio/game_sit");
                    roomAudio.Play();
                }
            }

            return(player);
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="deskId"></param>
        /// <param name="cards"></param>
        /// <param name="action">是否执行发牌动画</param>
        void PutCard(int deskId, string cards, bool action = false)
        {
            Data.Player player = null;
            foreach (var p in Data.Game.Players.Values)
            {
                if (p.DeskId == deskId)
                {
                    player = p;
                }
            }
            if (player == null)
            {
                return;
            }

            List <GImage> cardImgs = new List <GImage>();
            var           cp       = cardPlaces[player.Index];
            var           cpos     = cp.position;
            var           tpos     = cpos; // 记录牌动画的目的点

            foreach (var v in cards.Split('|'))
            {
                if (v == "-")
                {
                    cpos.x += player.DeskId == Data.Game.DeskId ? 40 : 15;
                    continue;
                }

                var    n        = int.Parse(v);
                string cardName = getName(n);
                GImage card     = UIPackage.CreateObject("qipai", cardName).asImage;

                card.position = cpos;
                tpos          = cpos;
                var scale = 1.0f;
                if (player.DeskId == Data.Game.DeskId)
                {
                    cpos.x += 50;
                }
                else
                {
                    cpos.x += 23;
                    scale   = 0.6f;
                }

                if (action)
                {
                    card.position = cardCenterPlace.position;
                    card.TweenMove(new Vector2(tpos.x, tpos.y), 0.3f);
                    card.TweenScale(new Vector2(scale, scale), 0.3f);
                }
                else
                {
                    card.SetScale(scale, scale);
                }


                card.AddRelation(cp, RelationType.Middle_Middle);
                card.AddRelation(cp, RelationType.Center_Center);
                ui.AddChild(card);
                cardImgs.Add(card);
            }

            if (cardsUi.ContainsKey(deskId))
            {
                foreach (var img in cardsUi[deskId])
                {
                    ui.RemoveChild(img);
                }
                cardsUi.Remove(deskId);
            }

            cardsUi.Add(deskId, cardImgs);
        }