public static async ETVoid EnterMapAsync()
        {
            try
            {
                Session hotfixSession = Game.Scene.GetComponent <SessionComponent>().Session;
                ResourcesAsyncComponent resourcesAsync = ETModel.Game.Scene.GetComponent <ResourcesAsyncComponent>();
                PlayerInfoComponent     playerInfo     = Game.Scene.GetComponent <PlayerInfoComponent>();

                if (hotfixSession == null)
                {
                    Log.Error("获取hotfixSession失败");
                }

                G2C_RequestEnterMap g2CRequestEnterMap = (G2C_RequestEnterMap)await hotfixSession.Call(new C2G_RequestEnterMap()
                {
                    Account = playerInfo.account
                });

                // 加载场景资源
                SceneAssetRequest sceneAssetAsyncRequest = Assets.LoadSceneAsync("Arena.unity3d");
                await resourcesAsync.LoadSceneAsync(sceneAssetAsyncRequest);

                // 切换到map场景
                using (SceneChangeComponent sceneChangeComponent = ETModel.Game.Scene.AddComponent <SceneChangeComponent>())
                {
                    await sceneChangeComponent.ChangeSceneAsync(SceneType.Arena);
                }

                PlayerCube playerCube = await PlayerCubeFactory.Create(new Vector3(g2CRequestEnterMap.PositionX, g2CRequestEnterMap.PositionY, g2CRequestEnterMap.PositionZ));

                //获取其它在地图里的玩家
                hotfixSession.Send(new C2G_GetOtherPlayer()
                {
                    Account = playerInfo.account
                });

                //添加网络同步脚本
                playerCube.AddComponent <PlayerCubeNetComponent, int>(playerInfo.account);

                nowPlayerCube = playerCube;

                Game.EventSystem.Run(EventIdType.EnterMapFinish);
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
        protected override async ETTask Run(ETModel.Session session, G2C_OtherPlayerPosition message)
        {
            if (otherCubeManagerComponent == null)
            {
                otherCubeManagerComponent = Game.Scene.GetComponent <OtherCubeManagerComponent>();
            }

            if (message.ServerTime > serverTime)
            {
                serverTime = message.ServerTime;

                int[]   DirAccount = message.DirAccount.array;
                float[] PositionX  = message.PositionX.array;
                float[] PositionY  = message.PositionY.array;
                float[] PositionZ  = message.PositionZ.array;

                float[] RotationX = message.RotationX.array;
                float[] RotationY = message.RotationY.array;
                float[] RotationZ = message.RotationZ.array;
                float[] RotationW = message.RotationW.array;

                float[] VelocityX = message.VelocityX.array;
                float[] VelocityY = message.VelocityY.array;
                float[] VelocityZ = message.VelocityZ.array;

                bool[] Fire = message.Fire.array;

                for (int i = 0; i < DirAccount.Length; i++)
                {
                    OtherCubeNetSyncComponent otherCubeNetSyncComponent = otherCubeManagerComponent.GetNetSyncComponentByOtherCubeAccount(DirAccount[i]);
                    if (otherCubeNetSyncComponent != null)
                    {
                        otherCubeNetSyncComponent.NetWorkAsyncPosition(new Vector3(PositionX[i], PositionY[i], PositionZ[i]), new Quaternion(RotationX[i], RotationY[i], RotationZ[i], RotationW[i]), new Vector3(VelocityX[i], VelocityY[i], VelocityZ[i]));
                        //Log.Info("同步一次位置:" + DirAccount[i]);

                        otherCubeNetSyncComponent.NetWorkAsyncFire(Fire[i]);
                    }
                }

                PlayerInfoComponent playerInfoComponent = Game.Scene.GetComponent <PlayerInfoComponent>();


                //if (message.Bullets.array.Length != 0)
                //{
                //    Debug.LogError("子弹数量:" + message.Bullets.count);
                //}

                //同步子弹数量
                int count = message.Bullets.count;
                for (int i = 0; i < count; i++)
                {
                    //不是自己的子弹才需要创建同步
                    if (message.Bullets[i].Account != playerInfoComponent.account)
                    {
                        CubeBullet cubeBullet = CubeBulletFactory.CreateCubeBullet();
                        cubeBullet.SyncBullet(new Vector3(message.Bullets[i].PositionX, message.Bullets[i].PositionY, message.Bullets[i].PositionZ),
                                              new Quaternion(message.Bullets[i].RotationX, message.Bullets[i].RotationY, message.Bullets[i].RotationZ, message.Bullets[i].RotationW),
                                              new Vector3(message.Bullets[i].VelocityX, message.Bullets[i].VelocityY, message.Bullets[i].VelocityZ));

                        //Debug.LogError("创建一颗子弹");
                    }
                }
            }
            else
            {
                Debug.LogError("丢包了: " + message.ServerTime + " || " + serverTime);
            }


            await ETTask.CompletedTask;
        }
        public async void Awake()
        {
            ReferenceCollector rc = GetParent <UI>().GameObject.GetComponent <ReferenceCollector>();

            nameTxt        = rc.Get <GameObject>("NameTxt").GetComponent <Text>();
            uIDTxt         = rc.Get <GameObject>("UIDTxt").GetComponent <Text>();
            realNameTxt    = rc.Get <GameObject>("RealNameTxt").GetComponent <Text>();
            noBindPhoneTxt = rc.Get <GameObject>("NoBindPhoneTxt").GetComponent <Text>();
            HuafeiNumTxt   = rc.Get <GameObject>("HuafeiNumTxt").GetComponent <Text>();
            AlPlayTxt      = rc.Get <GameObject>("AlPlayTxt").GetComponent <Text>();
            WinGameTxt     = rc.Get <GameObject>("WinGameTxt").GetComponent <Text>();
            SuccessRateTxt = rc.Get <GameObject>("SuccessRateTxt").GetComponent <Text>();
            MaxSuccessTxt  = rc.Get <GameObject>("MaxSuccessTxt").GetComponent <Text>();
            VipTimeTxt     = rc.Get <GameObject>("VipTimeTxt").GetComponent <Text>();

            returnBtn        = rc.Get <GameObject>("ReturnBtn").GetComponent <Button>();
            playerIcon       = rc.Get <GameObject>("PlayerIcon").GetComponent <Button>();
            changeNameBtn    = rc.Get <GameObject>("ChangeNameBtn").GetComponent <Button>();
            realNameBtn      = rc.Get <GameObject>("RealNameBtn").GetComponent <Button>();
            bindPhoneBtn     = rc.Get <GameObject>("BindPhoneBtn").GetComponent <Button>();
            ChangeAccountBtn = rc.Get <GameObject>("ChangeAccountBtn").GetComponent <Button>();
            DuihuanBtn       = rc.Get <GameObject>("DuihuanBtn").GetComponent <Button>();

            De         = rc.Get <GameObject>("De").GetComponent <Button>();
            GoldNumTxt = rc.Get <GameObject>("GoldNumTxt").GetComponent <Text>();
            WingNumTxt = rc.Get <GameObject>("WingNumTxt").GetComponent <Text>();
            AddBtn     = rc.Get <GameObject>("AddBtn").GetComponent <Button>();
            DuihuanBtn.onClick.Add(() =>
            {
                Game.Scene.GetComponent <UIComponent>().Create(UIType.UIUseHuaFei);
            });

            AddBtn.onClick.Add(() =>
            {
                Game.Scene.GetComponent <UIComponent>().Remove(UIType.UIPlayerInfo);
                Game.Scene.GetComponent <UIComponent>().Create(UIType.UIShop);
            });

            PlayerFrame = rc.Get <GameObject>("PlayerFrame");

            bindPhoneBtn.onClick.Add(() =>
            {
                Game.Scene.GetComponent <UIComponent>().Create(UIType.UIBindPhone);
            });

            realNameBtn.onClick.Add(() =>
            {
                Game.Scene.GetComponent <UIComponent>().Create(UIType.UIRealName);
            });

            returnBtn.onClick.Add(() =>
            {
                Game.Scene.GetComponent <UIComponent>().Get(UIType.UIMain).GetComponent <UIMainComponent>().SetUIHideOrOpen(true);
                Game.Scene.GetComponent <UIComponent>().Remove(UIType.UIPlayerInfo);
                if (Game.Scene.GetComponent <UIComponent>().Get(UIType.UIVIP) != null)
                {
                    if (Game.Scene.GetComponent <UIComponent>().Get(UIType.UIVIP).GameObject.activeInHierarchy)
                    {
                        Game.Scene.GetComponent <UIComponent>().Remove(UIType.UIVIP);
                    }
                }
            });

            changeNameBtn.onClick.Add(() =>
            {
                Game.Scene.GetComponent <UIComponent>().Create(UIType.UIChangeName);
            });

            ChangeAccountBtn.onClick.Add(() =>
            {
                onClickChangeAccount();
            });

            De.onClick.Add(() =>
            {
                Game.Scene.GetComponent <UIComponent>().Create(UIType.UIVIP);
            });

            PlayerInfoComponent pc         = Game.Scene.GetComponent <PlayerInfoComponent>();
            PlayerInfo          playerInfo = pc.GetPlayerInfo();

            nameTxt.text   = playerInfo.Name;
            uIDTxt.text    = pc.uid.ToString();
            AlPlayTxt.text = $"已玩牌局:{ playerInfo.TotalGameCount}";
            string winRate = GameUtil.GetWinRate(playerInfo.TotalGameCount, playerInfo.WinGameCount).ToString();

            if (winRate.Equals(0))
            {
                SuccessRateTxt.text = $"胜       率:{0}%";
            }
            else
            {
                SuccessRateTxt.text = $"胜       率:{winRate}%";
            }
            MaxSuccessTxt.text = $"最大赢取:{playerInfo.MaxHua}";
            WinGameTxt.text    = $"获胜局数:{ playerInfo.WinGameCount}";

            if (playerInfo.IsRealName)
            {
                realNameTxt.text = "已实名";
            }
            if (!string.IsNullOrEmpty(playerInfo.Phone))
            {
                noBindPhoneTxt.text = "已绑定";
            }

            // 设置头像
            {
                HeadManager.setHeadSprite(playerIcon.GetComponent <Image>(), PlayerInfoComponent.Instance.GetPlayerInfo().Icon);
            }

            playerIcon.onClick.Add(() =>
            {
                CommonUtil.ShowUI(UIType.UIIcon);
            });

            Init();
        }
Beispiel #4
0
        public void Awake()
        {
            #region get
            ReferenceCollector  rc            = GetParent <UI>().GameObject.GetComponent <ReferenceCollector>();
            PlayerInfoComponent playerInfoCom = Game.Scene.GetComponent <PlayerInfoComponent>();
            wingBtn = rc.Get <GameObject>("WingToggle").GetComponent <Button>();
            goldBtn = rc.Get <GameObject>("GoldToggle").GetComponent <Button>();
            proBtn  = rc.Get <GameObject>("ProToggle").GetComponent <Button>();
            vipBtn  = rc.Get <GameObject>("VipToggle").GetComponent <Button>();

            Wing = rc.Get <GameObject>("Wing");
            Gold = rc.Get <GameObject>("Gold");
            Prop = rc.Get <GameObject>("Prop");
            Vip  = rc.Get <GameObject>("Vip");

            returnBtn = rc.Get <GameObject>("ReturnBtn").GetComponent <Button>();
            wingGrid  = rc.Get <GameObject>("WingGrid");
            goldGrid  = rc.Get <GameObject>("GoldGrid");
            propGrid  = rc.Get <GameObject>("PropGrid");
            vipGrid   = rc.Get <GameObject>("VipGrid");
            buyTip    = rc.Get <GameObject>("BuyTip");
            sureBtn   = rc.Get <GameObject>("SureBtn").GetComponent <Button>();
            cancelBtn = rc.Get <GameObject>("CancelBtn").GetComponent <Button>();
            maskClick = rc.Get <GameObject>("maskClick").GetComponent <Button>();
            buyTxt    = rc.Get <GameObject>("BuyTxt").GetComponent <Text>();
            BuyTipS   = rc.Get <GameObject>("BuyTipS");

            WeipayBtn    = rc.Get <GameObject>("WeipayBtn").GetComponent <Button>();
            AlipayBtn    = rc.Get <GameObject>("AlipayBtn").GetComponent <Button>();
            PaySelectTip = rc.Get <GameObject>("PaySelectTip");

            shopInfoList = playerInfoCom.GetShopInfoList();
            #endregion

            CommonUtil.SetTextFont(this.GetParent <UI>().GameObject);

            #region AddButton
            buttonDic.Add(ShopType.Wing, Wing);
            buttonDic.Add(ShopType.Gold, Gold);
            buttonDic.Add(ShopType.Vip, Vip);
            buttonDic.Add(ShopType.Prop, Prop);
            #endregion

            AddShopInfoByType();

            #region buttonClickEvt
            //元宝商城
            wingBtn.onClick.Add(() =>
            {
                ButtonClick(ShopType.Wing, UIType.UIWingItem, wingGrid.transform);
            });

            //金币商城
            goldBtn.onClick.Add(() =>
            {
                ButtonClick(ShopType.Gold, UIType.UIGoldItem, goldGrid.transform);
            });

            //道具商城
            proBtn.onClick.Add(() =>
            {
                ButtonClick(ShopType.Prop, UIType.UIPropItem, propGrid.transform);
            });

            //VIP商城
            vipBtn.onClick.Add(() =>
            {
                ButtonClick(ShopType.Vip, UIType.UIVipItem, vipGrid.transform);
            });

            //返回
            returnBtn.onClick.Add(() =>
            {
                Game.Scene.GetComponent <UIComponent>().Remove(UIType.UIShop);
            });

            //确定购买
            sureBtn.onClick.Add(() =>
            {
                if (isCanBuy)
                {
                    if (shopInfo == null)
                    {
                        return;
                    }
                    BuyItem();
                }
                else
                {
                    buyTip.SetActive(false);
                    ButtonClick(ShopType.Wing, UIType.UIWingItem, wingGrid.transform);
                }
            });

            //取消购买
            cancelBtn.onClick.Add(() =>
            {
                buyTip.SetActive(false);
            });

            //支付宝支付
            AlipayBtn.onClick.Add(() =>
            {
                Recharge(1);
            });

            //微信支付
            WeipayBtn.onClick.Add(() =>
            {
                Recharge(2);
            });

            //关闭支付界面
            maskClick.onClick.Add(() =>
            {
                PaySelectTip.SetActive(false);
            });

            ButtonClick(ShopType.Wing, UIType.UIWingItem, wingGrid.transform);
            #endregion
        }
Beispiel #5
0
 public void Awake()
 {
     Instance = this;
 }