Exemplo n.º 1
0
        // 3: 选中某个服务器列表项
        private void OnSelectedServer(GameEvent e)
        {
            ServerListConfig config = (ServerListConfig)e.data;

            if (config.GsID != string.Empty)
            {
                ServerListConfig nServerList = ConfigsManager.Inst.GetServerList(config.GsID);
                if (nServerList != null)
                {
                    string[] _str = nServerList.ServerName.Split('#');
                    if (_str.Length >= 2)
                    {
                        serverName.text = "  " + _str[0] + "   " + _str[1];
                        if (config.ServerStatus != 4)
                        {
                            serverStatus.sprite = UIResourceMgr.LoadSprite(common.defaultPath + "img_TY_0208");
                        }
                        else
                        {
                            serverStatus.sprite = UIResourceMgr.LoadSprite(common.defaultPath + "img_TY_0209");
                        }
                    }
                }
            }
            isEmptyServer = false;
        }
Exemplo n.º 2
0
        // ===================== 按钮回调 =================
        // 1: 登陆按钮
        private void OnClickLoginBtn()
        {
            // 第一次登陆没有选择过登陆服务器,强制让用户选择一个
            if (isEmptyServer)
            {
                OnClickServerBtn();
                return;
            }

            string ServerID = ConfigsManager.Inst.GetClientConfig(ClientConfigs.ServerID);

            if (ServerID != string.Empty)
            {
                ServerListConfig serverconfig = ConfigsManager.Inst.GetServerList(ServerID);
                if (serverconfig != null)
                {
                    curServerName = serverconfig.ServerName;

                    IOControler.Connect(serverconfig.ServerIP, (ushort)serverconfig.ServerPort);

                    GameUtils.SetBtnSpriteGrayState(LoginBtn, true);
                    LoginBtn.interactable = false;
                }
                else
                {
                    // 加代码
                    UI_LoginControler.Inst.AddUI(UI_ServerList.UI_ResPath);
                }
            }
            else
            {
                GameEventDispatcher.Inst.dispatchEvent(GameEventID.U_GameTips, GameUtils.getString("error #100052"));//serverid 错误
            }
        }
Exemplo n.º 3
0
        // ===================== 回调 =================
        // 选中某个服务器列表项
        private void OnSelectedServer(GameEvent e)
        {
            ServerListConfig config = (ServerListConfig)e.data;

            ConfigsManager.Inst.SetClientConfig(ClientConfigs.ServerID, config.GsID.ToString());
            UpdateSelectState();
            UIState = UIStateEnum.ReadyForClose;
        }
Exemplo n.º 4
0
        // 2:初始化UI显示内容
        public override void InitUIView()
        {
            base.InitUIView();


            string ServerID = ConfigsManager.Inst.GetClientConfig(ClientConfigs.ServerID);

            if (ServerID != string.Empty)
            {
                ServerListConfig nServerList = ConfigsManager.Inst.GetServerList(ServerID);
                if (nServerList != null)
                {
                    string[] _str = nServerList.ServerName.Split('#');
                    if (_str.Length >= 2)
                    {
                        serverName.text = "  " + _str[0] + "   " + _str[1];
                        foreach (var listData in serverListData)
                        {
                            if (byte.Parse(ServerID) == byte.Parse(listData.Value.GsID))
                            {
                                if (listData.Value.ServerStatus != 4)
                                {
                                    serverStatus.sprite = UIResourceMgr.LoadSprite(common.defaultPath + "img_TY_0208");
                                }
                                else
                                {
                                    serverStatus.sprite = UIResourceMgr.LoadSprite(common.defaultPath + "img_TY_0209");
                                }
                            }
                        }
                    }
                    isEmptyServer = false;
                }
            }
            else
            {
                serverName.text = GameUtils.getString("login_content1");//"请选择服务器"
                isEmptyServer   = true;
            }

            _comps = transform.GetComponentsInChildren <Component>();
            //全透明 [6/19/2015 Zmy]
            foreach (Component item in _comps)
            {
                if (item is Graphic)
                {
                    Graphic _aphic = item as Graphic;
                    if (_aphic != null)
                    {
                        _aphic.color = new Color(_aphic.color.r, _aphic.color.g, _aphic.color.b, 0f);
                    }
                }
            }

            //ShowAnnounceUI();
        }
Exemplo n.º 5
0
        // 2:初始化UI显示内容
        public override void InitUIView()
        {
            base.InitUIView();

            string ServerID = ConfigsManager.Inst.GetClientConfig(ClientConfigs.ServerID);

            if (ServerID != string.Empty)
            {
                ServerListConfig nServerList = ConfigsManager.Inst.GetServerList(ServerID);
                if (nServerList != null)
                {
                    string[] _str = nServerList.ServerName.Split('#');
                    if (_str.Length >= 2)
                    {
                        BeforServerTxt.text = "  " + _str[0] + "   " + _str[1];
                        NewServerTxt.text   = BeforServerTxt.text;
                    }
                }
            }
            else
            {
                NewServerTxt.text = BeforServerTxt.text = GameUtils.getString("create_role_tip8"); //"无"
            }
        }
Exemplo n.º 6
0
    public bool Init(string[] args)
    {
        m_StateMachine = new StateMachine <ClientState>();
        m_StateMachine.Add(ClientState.Browsing, EnterBrowsingState, UpdateBrowsingState, LeaveBrowsingState);
        m_StateMachine.Add(ClientState.Connecting, EnterConnectingState, UpdateConnectingState, null);
        m_StateMachine.Add(ClientState.Loading, EnterLoadingState, UpdateLoadingState, null);
        m_StateMachine.Add(ClientState.Playing, EnterPlayingState, UpdatePlayingState, LeavePlayingState);

#if UNITY_EDITOR
        Game.game.levelManager.UnloadLevel();
        World.DisposeAllWorlds();
#endif
        m_GameWorld = new GameWorld("ClientWorld");

#if USE_UNET
        m_NetworkTransport = new UNETTransport();
        if (!m_NetworkTransport.Init())
        {
            return(false);
        }
        m_NetworkClient = new NetworkClient(m_NetworkTransport);
#else
        m_NetworkTransport = new SocketTransport();
        m_NetworkClient    = new NetworkClient(m_NetworkTransport);
#endif

        if (Application.isEditor || Game.game.buildId == "AutoBuild")
        {
            NetworkClient.clientVerifyProtocol.Value = "0";
        }

        m_NetworkClient.UpdateClientConfig();
        m_NetworkStatistics = new NetworkStatisticsClient(m_NetworkClient);
        m_ChatSystem        = new ChatSystemClient(m_NetworkClient);

#if USE_UNET
        //m_BroadcastListener = new UNETBroadcastListener();
        //m_BroadcastListener.config = new UNETBroadcastConfig();
        //m_BroadcastListener.Init();
        m_ServerListClient = new ServerListClient(ServerListConfig.BasicConfig("da76f801-609f-47c8-b711-a54234e2b7be"));
#endif
        GameDebug.Log("Network client initialized");

        m_requestedPlayerSettings.playerName = clientPlayerName.Value;
        m_requestedPlayerSettings.teamId     = -1;

        Console.AddCommand("disconnect", CmdDisconnect, "Disconnect from server if connected", this.GetHashCode());
        Console.AddCommand("prediction", CmdTogglePrediction, "Toggle prediction", this.GetHashCode());
        Console.AddCommand("runatserver", CmdRunAtServer, "Run command at server", this.GetHashCode());
        Console.AddCommand("respawn", CmdRespawn, "Force a respawn", this.GetHashCode());
        Console.AddCommand("nextchar", CmdNextChar, "Select next character", this.GetHashCode());
        Console.AddCommand("nextteam", CmdNextTeam, "Select next character", this.GetHashCode());
        Console.AddCommand("spectator", CmdSpectator, "Select spectator cam", this.GetHashCode());
        Console.AddCommand("matchmake", CmdMatchmake, "matchmake <ip:port>: Find and join a server", this.GetHashCode());

        if (args.Length > 0)
        {
            targetServer = args[0];
            m_StateMachine.SwitchTo(ClientState.Connecting);
        }
        else
        {
            m_StateMachine.SwitchTo(ClientState.Browsing);
        }

        GameDebug.Log("Client initialized");

        return(true);
    }
Exemplo n.º 7
0
 private void Start()
 {
     instance    = this;
     this.config = base.GetComponent <GameConfig>();
 }
Exemplo n.º 8
0
 // ==================== 公共对外接口 =================
 // 1: 设置服务器选项数据
 public void SetServerDate(ServerListConfig data, bool isSelected)
 {
     serverData   = data;
     m_isSelected = isSelected;
 }
Exemplo n.º 9
0
 public ServerListClient(ServerListConfig config)
 {
     this.Config       = config;
     this.KnownServers = new List <ServerInfo>();
     this.nextUpdate   = Time.time;
 }
Exemplo n.º 10
0
        // ===================== 按钮回调 =================
        private void OnClickYesBtn()
        {
            if (type == TipsType.GameTips)
            {
                if (!SceneManager.Inst.CurScene.Equals(SceneEntry.Login.ToString()))
                {
                    GameObject.Destroy(MainGameControler.Inst.gameObject.GetComponent <ObjectSelf>());
                    SceneManager.Inst.StartChangeScene(SceneEntry.Login.ToString());
                }
                else
                {
                    HideUI();
                    GameEventDispatcher.Inst.dispatchEvent(GameEventID.U_ReActive);
                }

                SocketManager.GetInstance().Uninit();

                return;
            }

            if (type == TipsType.SocketTips)
            {
                string ServerID = ConfigsManager.Inst.GetClientConfig(ClientConfigs.ServerID);
                if (ServerID != string.Empty)
                {
                    ServerListConfig serverconfig = ConfigsManager.Inst.GetServerList(ServerID);
                    if (serverconfig != null)
                    {
                        IOControler.Connect(serverconfig.ServerIP, (ushort)serverconfig.ServerPort);
                    }
                }
                else
                {
                    GameEventDispatcher.Inst.dispatchEvent(GameEventID.U_GameTips, GameUtils.getString("error #100053"));//serverid 错误
                }
            }

            if (type == TipsType.Recruit)
            {
                //招募界面
                UI_HomeControler.Inst.AddUI(UI_Recruit.UI_ResPath);
            }

            if (type == TipsType.GoPlatform || type == TipsType.CancelOrGoPlatform)
            {
                //Debug.Log("GoPlatform");
                Application.OpenURL("www.baidu.com");
            }

            if (type == TipsType.StartLoadUpdataAsset)
            {
                AssetManager.Inst.StartLoadAsset();
                GameEventDispatcher.Inst.dispatchEvent(GameEventID.U_OpenUI, UI_AssetsLoading.UI_ResPath);
            }

            if (type == TipsType.ResourceDownloadUnOk)
            {
                Debug.Log("Quit");
                Application.Quit();
            }

            if (UI_HomeControler.Inst != null)
            {
                UI_HomeControler.Inst.ReMoveUI(gameObject);
            }
            else if (UI_LoginControler.Inst != null)
            {
                UI_LoginControler.Inst.ReMoveUI(gameObject);
            }
            else if (UI_FightControler.Inst != null)
            {
                UI_FightControler.Inst.ReMoveUI(gameObject);
            }
            else if (UI_LodingControler.Inst != null)
            {
                UI_LodingControler.Inst.ReMoveUI(gameObject);
            }
            else
            {
                Debug.LogError("destory game tips error");
            }
        }