Example #1
0
 public void RefreshScope()
 {
     for (int i = 0; i < Network.connections.Length; i++)
     {
         if (connectedUser == Network.connections[i])
         {
             sender.SetScope(Network.connections[i], true);
         }
         else
         {
             sender.SetScope(Network.connections[i], false);
         }
     }
 }
Example #2
0
        public void InitializeConnection(NetworkPlayer player)
        {
            //this runs on server side
            Debug.Log("New client connected. Initializing ...");
            ConnectionId playerid = NextConnectionId();

            mPlayerToConnectionId[player] = playerid;


            GameObject go = new GameObject("UnityPlayerConnection" + player);

            go.transform.parent = this.gameObject.transform;
            SingleEndpointConnection connection = go.AddComponent <SingleEndpointConnection>();

            connection.Parent        = this;
            connection.ConnectedUser = player;


            NetworkView sender = connection.gameObject.AddComponent <NetworkView>();

            sender.viewID = Network.AllocateViewID();
            //sender.observed = this;
            sender.stateSynchronization = NetworkStateSynchronization.Unreliable;

            //immediately turn off the sender on server side as it would spam to every client by default.
            //it will be turned on for the correct state after the client confirmed the createn of the counterpart
            for (int i = 0; i < Network.connections.Length; i++)
            {
                sender.SetScope(Network.connections[i], false);
            }

            connection.Sender       = sender;
            mKnownPlayers[playerid] = connection;
            this.glNetworkView.RPC("AddClientSide", player, sender.viewID);
        }