Exemplo n.º 1
0
    /// <summary>
    /// Start as server and if discovery not running, start broadcast.
    /// </summary>
    public void SetupServer()
    {
        if (!NetworkServer.active)
        {
            Debug.Log("SetupServer( )");
            ConnectionConfig config = new ConnectionConfig();
            config.AddChannel(QosType.ReliableSequenced);
            config.AddChannel(QosType.Unreliable);
            NetworkServer.Configure(config, 1000);
            NetworkServer.dontListen = false;

            NetworkServer.Listen(4444);
            // 注册回调绑定
            NetworkServer.RegisterHandler(MsgType.Connect, OnConnected);
            NetworkServer.RegisterHandler(MsgType.Disconnect, OnDisconnected);
            NetworkServer.RegisterHandler(MyMsgType.UID, OnUID);
            NetworkServer.RegisterHandler(MyMsgType.Custom, OnCustomMessage);
        }

        if (!discovery.running)
        {
            discovery.Initialize();
            discovery.StartAsServer();
        }
    }
Exemplo n.º 2
0
    private void OnGUI()
    {
        if (GUI.Button(new Rect(0, 0, 250, 20), "ホストとして起動"))
        {
            StartHost();
            m_NetworkDiscovery.Initialize();
            m_NetworkDiscovery.StartAsServer();
        }

        if (GUI.Button(new Rect(0, 30, 250, 20), "クライアントとして接続"))
        {
            m_NetworkDiscovery.Initialize();
            m_NetworkDiscovery.StartAsClient();
        }
    }
Exemplo n.º 3
0
    private void Awake()
    {
        Team = Team.None;
        if (Instance != null)
        {
            Debug.Log(Util.C($"Multiple NetworkControllers!!!", Color.red));
            throw new Exception();
        }

        Instance = this;

        discovery.Register(this);
        discovery.Initialize();
        Debug.Log("Discovery as client in awake");
        discovery.StartAsClient();
        manager.Register(this);
        inputListeners = new HashSet <InputListener>();
        broadcastTable = new Dictionary <string, Team>();
        InitHostHandlers();
        InitAndRegisterSpawnable();
        DontDestroyOnLoad(this);
        gameState = GameState.Lobby;
    }
Exemplo n.º 4
0
 private void Start()
 {
     _discovery = GetComponent <MyNetworkDiscovery>();
     //this require on network discovery
     _discovery.Initialize();
 }
Exemplo n.º 5
0
 private void Start()
 {
     lobbyPlayers = new List <LobbyPlayers>();
     netDiscover.Initialize();
     //servers.options = netDiscover.broadcastsReceived;
 }
Exemplo n.º 6
0
 public void StartReceiveLocalBroadcast()
 {
     localNetworkDiscovery = GetComponent <MyNetworkDiscovery>();
     localNetworkDiscovery.Initialize();
     localNetworkDiscovery.StartAsClient();
 }
Exemplo n.º 7
0
 public void StartLocalBroadcast()
 {
     localNetworkDiscovery = GetComponent <MyNetworkDiscovery>();
     localNetworkDiscovery.Initialize();
     localNetworkDiscovery.StartAsServer();
 }