Ejemplo n.º 1
0
 // Use this for initialization
 void Start()
 {
     client = new NetworkClient();
     client.RegisterHandler(889, ClientReceiveLocation);
     discovery = GetComponent <ClientNetworkDiscovery>();
     discovery.StartAsClient();
 }
Ejemplo n.º 2
0
    public void OnClick()
    {
        GameObject             client = GameObject.Find("ClientObject");
        ClientNetworkDiscovery listen = client.GetComponent <ClientNetworkDiscovery>();

        GameObject.Find("ConnectText").GetComponent <Text>().text = "Conectar";
        listen.InitializeListening();
    }
Ejemplo n.º 3
0
 private void GetServerIP()  // 非阻塞
 {
     ClientDiscovery = gameObject.AddComponent <ClientNetworkDiscovery>();
     ClientDiscovery.Initialize();
     ClientDiscovery.broadcastPort = portBroadCastUDP;
     ClientDiscovery.showGUI       = false;
     ClientDiscovery.StartAsClient();    // 非阻塞
 }
Ejemplo n.º 4
0
    protected virtual void Start()
    {
        try
        {
            //LogFilter.currentLogLevel = LogFilter.Debug;

            // get reference to the multi-ar manager
            marManager = MultiARManager.Instance;

            // setup network manager component
            netManager = GetComponent <ClientNetworkManager>();
            if (netManager == null)
            {
                netManager = gameObject.AddComponent <ClientNetworkManager>();
            }

            if (netManager != null)
            {
                netManager.arClient = this;

                if (playerPrefab != null)
                {
                    netManager.playerPrefab = playerPrefab;
                }

                if (spawnPrefabs != null && spawnPrefabs.Count > 0)
                {
                    netManager.spawnPrefabs.AddRange(spawnPrefabs);
                }
            }

            if (serverHost != "0.0.0.0" && !string.IsNullOrEmpty(serverHost))
            {
                // connect to the server
                ConnectToServer();
            }
            else
            {
                // start network discovery
                netDiscovery = gameObject.GetComponent <ClientNetworkDiscovery>();
                if (netDiscovery == null)
                {
                    netDiscovery = gameObject.AddComponent <ClientNetworkDiscovery>();
                }

                if (netDiscovery != null)
                {
                    netDiscovery.arClient = this;
                    //netDiscovery.broadcastPort = broadcastPort;
                    //netDiscovery.broadcastKey = serverPort;
                    //netDiscovery.broadcastData = gameName;
                    netDiscovery.showGUI = false;

                    netDiscovery.Initialize();
                    netDiscovery.StartAsClient();
                }
            }
        }
        catch (System.Exception ex)
        {
            Debug.LogError(ex.Message + "\n" + ex.StackTrace);

            if (statusText)
            {
                statusText.text = ex.Message;
            }
        }
    }