Skip to content

bkudiess/Unity-MultipeerConnectivity

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Unity-MultipeerConnectivity

Using the MultipeerConnectivity framework to share data between nearby devices. Works with iOS and tvOS.

Usage

  1. From Source
    • Clone or download and copy Assets/UnityMultipeerConnectivity, Assets/UnitySwift and Assets/Plugin directories to your own project.
  2. Check Examples
    • see exemple scene in Assets/Scenes and the scripts used in Assets/Scripts.

Example code

Send Data

public class MultipeerSender : MonoBehaviour
{
    public void SendData(string data)
    {
        UnityMCSessionNativeInterface.GetMcSessionNativeInterface()
            .SendToAllPeers(SystemInfo.deviceName + "," + data);
    }
}

Receive Data

public class MultipeerReceiver : MonoBehaviour
{
    public Text text;
    void Start()
    {
        UnityMCSessionNativeInterface.GetMcSessionNativeInterface()
            .DataReceivedAsObservable()
            .Subscribe(Received)
            .AddTo(this);
    }

    void Received(byte[] bytes)
    {
        string dataReceived = System.Text.Encoding.UTF8.GetString(bytes);
        string[] tokens = dataReceived.Split(',');
        text.text += "\n"+ "Received " + tokens[1] + " from " + tokens[0];
    }

}

And more

See Example Sene.

Based on noir-neo/UnityARKitMultipeerConnectivity.

Requirements

  • Unity 2018.3+
  • iOS 12.0+
  • Xcode 10.0+

About

Example of Multipeer Connectivity Experience with Unity

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages