예제 #1
0
  internal void OnRoomFound(NearbyRoom room, bool available)
  {
      if (available)

      {
          myEndpointId = UnityEngine.Random.Range(1000, 10000).ToString();
          myName       = UnityEngine.Random.Range(1000, 10000).ToString();
          NearbyPlayer nearbyPlayer = new NearbyPlayer(SystemInfo.deviceUniqueIdentifier, myEndpointId, myName);

          room.JoinRoom(nearbyPlayer, Encoding.ASCII.GetBytes("asdasd"), OnRoomJoined);

          // GameObject obj = Instantiate() as GameObject;
      }
  }
예제 #2
0
  internal void OnRoomJoined(ConnectionResponse response)
  {
      Debug.Log("OnRoomJoined Called status: " + response.ResponseStatus);
      if (response.ResponseStatus == ConnectionResponse.Status.Accepted)
      {
          // if we are connected, stop looking for rooms.
          NearbyRoom.StopRoomDiscovery();

          // the first payload is sent with the response so we can initialize
          // the game scene.
          OnMessageReceived(room.Address, response.Payload);
          textObject.text = room.Address + " :  " + response.Payload.ToString() + response.RemoteEndpointId;
          connected       = true;
      }
  }
예제 #3
0
  public void onCreateRoom()
  {
      myEndpointId = UnityEngine.Random.Range(1000, 10000).ToString();
      myName       = UnityEngine.Random.Range(1000, 10000).ToString();

      NearbyPlayer nearbyPlayer = new NearbyPlayer(SystemInfo.deviceUniqueIdentifier, myEndpointId, myName);

      globalNearbyPlayer = nearbyPlayer;
      NearbyRoom.StopAll();
      PlayGamesPlatform.InitializeNearby((client) =>
        {
            Debug.Log("Nearby connections initialized");
        });

      NearbyRoom nearbyRoom = new NearbyRoom("Most Popular Room!!");

      nearbyRoom.AutoJoin   = true;
      nearbyRoom.AlwaysOpen = true;
      isClient = false;
      nearbyRoom.OpenRoom();



      //List<string> appIdentifiers = new List<string>();
      //appIdentifiers.Add(PlayGamesPlatform.Nearby.GetAppBundleId());
      //PlayGamesPlatform.Nearby.StartAdvertising(
      //          "Awesome Game Host",  // User-friendly name
      //            appIdentifiers,  // App bundle Id for this game
      //           TimeSpan.FromSeconds(0),// 0 = advertise forever
      //           (AdvertisingResult result) =>
      //           {

      //               Debug.Log("OnAdvertisingResult: " + result);
      //           },
      //              (ConnectionRequest request) =>
      //              {

      //                  Debug.Log("Received connection request: " +
      //                   request.RemoteEndpoint.ServiceId + " " +
      //                   request.RemoteEndpoint.EndpointId + " " +
      //                   request.RemoteEndpoint.Name);

      //              }
      //           );
  }
예제 #4
0
  internal void onStartDiscovery()
  {
      NearbyRoom.StopAll();

      myEndpointId = UnityEngine.Random.Range(1000, 10000).ToString();
      myName       = UnityEngine.Random.Range(1000, 10000).ToString();
      NearbyPlayer nearbyPlayer = new NearbyPlayer(SystemInfo.deviceUniqueIdentifier, myEndpointId, myName);

      globalNearbyPlayer = nearbyPlayer;
      NearbyRoom.FindRooms(OnRoomFound);

      //PlayGamesPlatform.InitializeNearby((client) =>
      //{
      //    Debug.Log("Nearby connections initialized");
      //});
      //Debug.Log("onStartDiscovery called");
      //PlayGamesPlatform.Nearby.StartDiscovery(
      //                PlayGamesPlatform.Nearby.GetServiceId(),
      //                TimeSpan.FromSeconds(0),
      //                listener);
  }