예제 #1
0
        public static PlayerInfo AddPendingPlayer(NearbyPlayer player, int charIndex)
        {
            PlayerInfo info;

            if (allPlayers.ContainsKey(player.DeviceId))
            {
                info = allPlayers[player.DeviceId];
            }
            else
            {
                info = null;
            }

            if (info == null)
            {
                info = ScriptableObject.CreateInstance <PlayerInfo>();
                allPlayers.Add(player.DeviceId, info);
            }
            else
            {
                DestroyObject(info.scorePanel);
                info.scorePanel = null;
            }

            info.player                = player;
            info.dataState             = new PlayerData();
            info.dataState.avatarIndex = charIndex;
            info.dataState.deviceId    = player.DeviceId;
            info.dataState.Name        = player.Name;
            return(info);
        }
예제 #2
0
        /// <summary>
        /// New player is connecting to the game
        /// </summary>
        /// <param name="player">Player.</param>
        /// <param name="data">Data.</param>
        internal void OnPlayerConnecting(NearbyPlayer player, byte[] data)
        {
            PlayerInfo p   = PlayerInfo.AddPendingPlayer(player, data);
            GameObject obj = owner.LevelManager.CreatePlayer(
                p.AvatarIndex,
                p.DeviceId);

            PlayerController ctl = obj.GetComponent <PlayerController>();

            if (ctl != null)
            {
                ctl.Player            = p;
                ctl.BroadcastMovement = true;

                // force the  movement message so the remote player moves to the
                // assigned, random position.
                ItemState state = new ItemState();
                state.Enabled     = obj.activeSelf;
                state.Name        = obj.name;
                state.Position    = obj.transform.position;
                state.PrefabIndex = p.AvatarIndex;
                state.Rotation    = obj.transform.rotation;
                state.TileSetName = ItemState.PlayerTileSet;
                owner.LevelData.Add(state);
            }

            owner.CreatePlayerScorePanel(p);
        }
예제 #3
0
 /// <summary>
 /// Accepts the request.
 /// </summary>
 /// <param name="player">Player to accept the request from.</param>
 public void AcceptRequest(NearbyPlayer player)
 {
     PlayGamesPlatform.Nearby.AcceptConnectionRequest(
         player.EndpointId,
         ConnectionData(),
         this);
     playerHandler(player, true);
 }
예제 #4
0
 /// <summary>
 /// Raises the player changed event.
 /// </summary>
 /// <param name="player">Player.</param>
 /// <param name="present">If set to <c>true</c> present.</param>
 internal void OnPlayerChanged(NearbyPlayer player, bool present)
 {
     Debug.Log("Player " + player.Name + " " + (string)(present ? "Arrived" : "Left"));
     if (player.DeviceId == Room.Address.DeviceId)
     {
         connected = false;
     }
 }
예제 #5
0
        /// <summary>
        /// Accepts the request.
        /// </summary>
        /// <param name="player">Player to accept the request from.</param>
        public void AcceptRequest(string endpointId)
        {
            NearbyPlayer player = NearbyPlayer.FindByEndpointId(endpointId);

            PlayGamesPlatform.Nearby.AcceptConnectionRequest(
                player.EndpointId,
                ConnectionData(),
                this);
            playerHandler(player, true);
        }
예제 #6
0
        /// <summary>
        /// Called when a player is requesting to join a room.
        /// </summary>
        /// <param name="player">Player.</param>
        /// <param name="data">Data.</param>
        internal void OnPlayerFound(NearbyPlayer player, byte[] data)
        {
            GameObject obj = Instantiate(itemChoicePrefab) as GameObject;

            obj.transform.SetParent(lobbyListArea.transform, false);
            obj.GetComponentInChildren <Text>().text = player.Name;
            Toggle t = obj.GetComponentInChildren <Toggle>();

            t.gameObject.name = player.DeviceId;
            t.isOn            = true;
            PlayerInfo.AddPendingPlayer(player, data);
        }
예제 #7
0
 /// <summary>
 /// Joins the room.  This is called by a remote player to
 /// join a room.  This sends the nearby connection request message
 /// to the remote room.
 /// </summary>
 /// <param name="localPlayer">the Local player.</param>
 /// <param name="playerData">the serialized Player data to include in the request.</param>
 /// <param name="callback">Callback from the remote room accepting or rejecting the request.</param>
 public void JoinRoom(
     NearbyPlayer localPlayer,
     byte[] playerData,
     Action <ConnectionResponse> callback)
 {
     PlayGamesPlatform.Nearby.SendConnectionRequest(
         localPlayer.Name,
         address.EndpointId,
         playerData,
         callback,
         this);
 }
예제 #8
0
        /// <summary>
        /// Raises the message received event.
        /// </summary>
        /// <param name="remoteEndpointId">Remote endpoint identifier.</param>
        /// <param name="data">Data payload of the message.</param>
        /// <param name="isReliableMessage">If set to <c>true</c> is reliable message.</param>
        public void OnMessageReceived(string remoteEndpointId, byte[] data, bool isReliableMessage)
        {
            Debug.Log("RECEIVED Message from " + remoteEndpointId);
            NearbyPlayer sender = NearbyPlayer.FindByEndpointId(remoteEndpointId);

            if (messageHandler != null)
            {
                messageHandler(sender, data);
            }
            else
            {
                Debug.Log("Messagehandler not set, ignoring!");
            }
        }
예제 #9
0
        /// <summary>
        /// Raises the connection request event.
        /// </summary>
        /// <param name="request">Request sent to join the room.</param>
        internal void OnConnectionRequest(ConnectionRequest request)
        {
            NearbyPlayer player = new NearbyPlayer(
                request.RemoteEndpoint.DeviceId,
                request.RemoteEndpoint.EndpointId,
                request.RemoteEndpoint.Name);

            if (playerFoundCallback != null)
            {
                playerFoundCallback.Invoke(player, request.Payload);
            }

            if (AutoJoin)
            {
                Debug.Log("Automatically connecting to " + request.RemoteEndpoint);
                AcceptRequest(player);
            }
        }
예제 #10
0
        public static PlayerInfo AddPendingPlayer(string endpointId, NearbyPlayer player, byte[] data)
        {
            PlayerInfo info;

            if (player != null && player.DeviceId != null && allPlayers.ContainsKey(player.DeviceId))
            {
                info = allPlayers[player.DeviceId];
            }
            else
            {
                info = null;
            }

            if (info == null)
            {
                info = ScriptableObject.CreateInstance <PlayerInfo>();
            }
            else
            {
                DestroyObject(info.scorePanel);
            }

            info.SetDataState(data);
            NearbyPlayer newPlayer = NearbyPlayer.FindByDeviceId(info.dataState.DeviceId);

            if (newPlayer == null)
            {
                newPlayer = new NearbyPlayer(info.dataState.DeviceId, endpointId, info.DataState.Name);
            }

            info.player         = newPlayer;
            info.dataState.Name = newPlayer.Name;

            allPlayers.Add(newPlayer.DeviceId, info);

            return(info);
        }
        /// <summary>
        /// New player is connecting to the game
        /// </summary>
        /// <param name="player">Player.</param>
        /// <param name="data">Data.</param>
        internal void OnPlayerConnecting(NearbyPlayer player, byte[] data)
        {
            PlayerInfo p = PlayerInfo.AddPendingPlayer(player, data);
            GameObject obj = owner.LevelManager.CreatePlayer(
                                 p.AvatarIndex, 
                                 p.DeviceId);

            PlayerController ctl = obj.GetComponent<PlayerController>();
            if (ctl != null)
            {
                ctl.Player = p;
                ctl.BroadcastMovement = true;

                // force the  movement message so the remote player moves to the 
                // assigned, random position.
                ItemState state = new ItemState();
                state.Enabled = obj.activeSelf;
                state.Name = obj.name;
                state.Position = obj.transform.position;
                state.PrefabIndex = p.AvatarIndex;
                state.Rotation = obj.transform.rotation;
                state.TileSetName = ItemState.PlayerTileSet;
                owner.LevelData.Add(state);
            }

            owner.CreatePlayerScorePanel(p);
        }
 /// <summary>
 /// Called when a player is requesting to join a room.
 /// </summary>
 /// <param name="player">Player.</param>
 /// <param name="data">Data.</param>
 internal void OnPlayerFound(NearbyPlayer player, byte[] data)
 {
     GameObject obj = Instantiate(itemChoicePrefab) as GameObject;
     obj.transform.SetParent(lobbyListArea.transform, false);
     obj.GetComponentInChildren<Text>().text = player.Name;
     Toggle t = obj.GetComponentInChildren<Toggle>();
     t.gameObject.name = player.DeviceId;
     t.isOn = true;
     PlayerInfo.AddPendingPlayer(player, data);
 }
 /// <summary>
 /// Raises the message received event.
 /// </summary>
 /// <param name="sender">Sender.</param>
 /// <param name="data">Data.</param>
 internal void OnMessageReceived(NearbyPlayer sender, byte[] data)
 {
     UpdateGameStateFromData(data);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="NearbyDroids.NearbyRoom"/> class.
 /// This is a local room.
 /// </summary>
 /// <param name="name">Name - the local room name</param>
 internal NearbyRoom(string name)
 {
     this.address = new NearbyPlayer(name);
     local = true;
     knownRooms[address.EndpointId] = this;
 }
        /// <summary>
        /// Raises the connection request event.
        /// </summary>
        /// <param name="request">Request sent to join the room.</param>
        internal void OnConnectionRequest(ConnectionRequest request)
        {
            NearbyPlayer player = new NearbyPlayer(
                                      request.RemoteEndpoint.DeviceId,
                                      request.RemoteEndpoint.EndpointId,
                                      request.RemoteEndpoint.Name);
        
            if (playerFoundCallback != null)
            {
                playerFoundCallback.Invoke(player, request.Payload);
            }

            if (AutoJoin)
            {
                Debug.Log("Automatically connecting to " + request.RemoteEndpoint);
                AcceptRequest(player);
            }
        }
 /// <summary>
 /// Raises the player changed event.
 /// </summary>
 /// <param name="player">Player.</param>
 /// <param name="present">If set to <c>true</c> present.</param>
 internal void OnPlayerChanged(NearbyPlayer player, bool present)
 {
     Debug.Log("Player " + player.Name + " " + (string)(present ? "Arrived" : "Left"));
     if (player.DeviceId == Room.Address.DeviceId)
     {
         connected = false;
     }
 }
예제 #17
0
 /// <summary>
 /// Raises the message received event.
 /// </summary>
 /// <param name="sender">Sender.</param>
 /// <param name="data">Data.</param>
 internal void OnMessageReceived(NearbyPlayer sender, byte[] data)
 {
     UpdateGameStateFromData(data);
 }
예제 #18
0
        /// <summary>
        /// Raises the remote endpoint disconnected event.
        /// </summary>
        /// <param name="remoteEndpointId">Remote endpoint identifier.</param>
        public void OnRemoteEndpointDisconnected(string remoteEndpointId)
        {
            NearbyPlayer player = NearbyPlayer.FindByEndpointId(remoteEndpointId);

            playerHandler(player, false);
        }
 /// <summary>
 /// Joins the room.  This is called by a remote player to
 /// join a room.  This sends the nearby connection request message
 /// to the remote room.
 /// </summary>
 /// <param name="localPlayer">the Local player.</param>
 /// <param name="playerData">the serialized Player data to include in the request.</param>
 /// <param name="callback">Callback from the remote room accepting or rejecting the request.</param>
 public void JoinRoom(
     NearbyPlayer localPlayer,
     byte[] playerData,
     Action<ConnectionResponse> callback)
 {
     PlayGamesPlatform.Nearby.SendConnectionRequest(
         localPlayer.Name,
         address.EndpointId,
         playerData,
         callback,
         this);
 }
예제 #20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NearbyDroids.NearbyRoom"/> class.
 /// This is a local room.
 /// </summary>
 /// <param name="name">Name - the local room name</param>
 internal NearbyRoom(string name)
 {
     this.address = new NearbyPlayer(name);
     local        = true;
     knownRooms[address.EndpointId] = this;
 }
 /// <summary>
 /// Accepts the request.
 /// </summary>
 /// <param name="player">Player to accept the request from.</param>
 public void AcceptRequest(NearbyPlayer player)
 {
     PlayGamesPlatform.Nearby.AcceptConnectionRequest(
         player.EndpointId,
         ConnectionData(),
         this);
     playerHandler(player, true);
 }
예제 #22
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NearbyDroids.NearbyRoom"/> class.
 /// This is a remote room.
 /// </summary>
 /// <param name="deviceId">Device identifier of the remote room</param>
 /// <param name="endpointId">Endpoint identifier of the remote room</param>
 /// <param name="name">Name of the remote room</param>
 internal NearbyRoom(string deviceId, string endpointId, string name)
 {
     this.address           = new NearbyPlayer(deviceId, endpointId, name);
     local                  = false;
     knownRooms[endpointId] = this;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="NearbyDroids.NearbyRoom"/> class.
 /// This is a remote room.
 /// </summary>
 /// <param name="deviceId">Device identifier of the remote room</param>
 /// <param name="endpointId">Endpoint identifier of the remote room</param>
 /// <param name="name">Name of the remote room</param>
 internal NearbyRoom(string deviceId, string endpointId, string name)
 {
     this.address = new NearbyPlayer(deviceId, endpointId, name);
     local = false;
     knownRooms[endpointId] = this;
 }
        public static PlayerInfo AddPendingPlayer(NearbyPlayer player, int charIndex)
        {
            PlayerInfo info;
            if (allPlayers.ContainsKey(player.DeviceId))
            {
                info = allPlayers[player.DeviceId];
            }
            else
            {
                info = null;
            }

            if (info == null)
            {
                info = ScriptableObject.CreateInstance<PlayerInfo>();
                allPlayers.Add(player.DeviceId, info);
            }
            else
            {
                DestroyObject(info.scorePanel);
                info.scorePanel = null;
            }

            info.player = player;
            info.dataState = new PlayerData();
            info.dataState.avatarIndex = charIndex;
            info.dataState.deviceId = player.DeviceId;
            info.dataState.Name = player.Name;
            return info;
        }