Exemplo n.º 1
0
        // It is the responsibility of the new peer (the one joining the room) to begin the process of creating a peer connection,
        // and existing peers to accept that connection.
        // This is because we need to know that the remote peer is established, before beginning the exchange of messages.
        private void OnJoinedRoom(IRoom room)
        {
            UpdateIceServerCollection(room);

            foreach (var peer in client.Peers)
            {
                if (peer.UUID == client.Me.UUID)
                {
                    continue; // Don't connect to ones self!
                }

                if (peerUuidToConnection.ContainsKey(peer.UUID))
                {
                    continue; // This peer existed in the previous room and we already have a connection to it
                }

                var pcid = NetworkScene.GenerateUniqueId(); //A single audio channel exists between two peers. Each audio channel has its own Id.

                logger.Log("CreatePeerConnectionForPeer", pcid, peer.NetworkObjectId);

                var pc = CreatePeerConnection(pcid, peer.UUID, polite: true);

                Message m;
                m.type     = "RequestPeerConnection";
                m.objectid = pcid;           // the shared Id is set by this peer, but it must be chosen so as not to conflict with any other shared id on the network
                m.uuid     = client.Me.UUID; // this is so the other end can identify us if we are removed from the room
                Send(peer.NetworkObjectId, m);
                logger.Log("RequestPeerConnection", pcid, peer.NetworkObjectId);
            }
        }
Exemplo n.º 2
0
        public GameObject Spawn(GameObject gameObject)
        {
            var i         = ResolveIndex(gameObject);
            var networkId = NetworkScene.GenerateUniqueId();

            context.SendJson(new Message()
            {
                catalogueIndex = i, networkId = networkId
            });
            return(Instantiate(i, networkId, true));
        }
Exemplo n.º 3
0
        public void SpawnBasketball()
        {
            var ball = Instantiate(Prefab, transform).GetComponent <SimpleBasketball>();

            ball.Id.Set(NetworkScene.GenerateUniqueId());
            ball.owner = true;
            context.SendJson(new Message()
            {
                newNetworkObjectId = ball.Id
            });
        }
Exemplo n.º 4
0
        public GameObject SpawnPersistent(GameObject gameObject)
        {
            var i         = ResolveIndex(gameObject);
            var networkId = NetworkScene.GenerateUniqueId();
            var key       = $"SpawnedObject{ networkId }";
            var spawned   = Instantiate(i, networkId, true);

            roomClient.room[key] = JsonUtility.ToJson(new Message()
            {
                catalogueIndex = i, networkId = networkId
            });
            return(spawned);
        }
Exemplo n.º 5
0
        private void Start()
        {
            client.OnPeer.AddListener(OnPeer);
            client.OnPeerRemoved.AddListener(OnPeerRemoved);
            client.OnJoinedRoom.AddListener(OnJoinedRoom);

            localAvatarArgs.objectId   = NetworkScene.GenerateUniqueId();
            localAvatarArgs.prefabUuid = localPrefabUuid;

            if (localAvatarArgs.prefabUuid.Length > 0)
            {
                UpdateAvatar(localAvatarArgs, true);
                UpdatePeer(LocalAvatar);
            }
        }
Exemplo n.º 6
0
        private void Start()
        {
            //todo: invert this so params come from avatar object?
            myBoidsParams.sharedId = NetworkScene.GenerateUniqueId();

            if (localBoids != null)
            {
                boids.Add(myBoidsParams.sharedId, localBoids);
            }

            client.OnPeerAdded.AddListener(OnPeer);
            client.Me["boids-params"] = JsonUtility.ToJson(myBoidsParams);

            MakeUpdateBoids(myBoidsParams, true);
        }
Exemplo n.º 7
0
        private void Start()
        {
            localAvatarId = NetworkScene.GenerateUniqueId();

            RoomClient.OnPeerAdded.AddListener(UpdateAvatar);
            RoomClient.OnPeerUpdated.AddListener(UpdateAvatar);
            RoomClient.OnPeerRemoved.AddListener(OnPeerRemoved);

            RoomClient.Me["ubiq.avatar.networkid"] = localAvatarId.ToString();

            // The default prefab for the player has been defined; create the avatar with this prefab
            if (LocalPrefabUuid.Length > 0)
            {
                RoomClient.Me["ubiq.avatar.prefab"] = LocalPrefabUuid;
            }

            UpdateAvatar(RoomClient.Me);
        }
Exemplo n.º 8
0
        // It is the responsibility of the new peer (the one joining the room) to begin the process of creating a peer connection,
        // and existing peers to accept that connection.
        // This is because we need to know that the remote peer is established, before beginning the exchange of messages.

        public void OnJoinedRoom()
        {
            foreach (var peer in client.Peers)
            {
                if (peer.UUID == client.Me.UUID)
                {
                    continue; // don't connect to ones self!
                }

                var pcid = NetworkScene.GenerateUniqueId(); //A single audio channel exists between two peers. Each audio channel has its own Id.
                var pc   = CreatePeerConnection(pcid, peer.UUID);
                pc.MakePolite();
                pc.AddLocalAudioSource();
                pc.stats.peer = peer.UUID;
                Message m;
                m.type     = "RequestPeerConnection";
                m.objectid = pcid;           // the shared Id is set by this peer, but it must be chosen so as not to conflict with any other shared id on the network
                m.uuid     = client.Me.UUID; // this is so the other end can identify us if we are removed from the room
                Send(peer.NetworkObjectId, m);
            }
        }