-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upgrade to v1.10. Supporting visionOS.
- Loading branch information
Showing
14 changed files
with
211 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
// SPDX-FileCopyrightText: Copyright 2023 Reality Design Lab <[email protected]> | ||
// SPDX-FileCopyrightText: Copyright 2024 Reality Design Lab <[email protected]> | ||
// SPDX-FileContributor: Yuchen Zhang <[email protected]> | ||
// SPDX-FileContributor: Botao Amber Hu <[email protected]> | ||
// SPDX-License-Identifier: MIT | ||
|
||
using System.IO; | ||
using UnityEditor; | ||
using UnityEditor.Callbacks; | ||
|
||
#if UNITY_IOS && UNITY_EDITOR | ||
#if (UNITY_IOS || UNITY_VISIONOS) && UNITY_EDITOR | ||
using UnityEditor.iOS.Xcode; | ||
|
||
namespace Netcode.Transports.MultipeerConnectivity.Editor | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
// SPDX-FileCopyrightText: Copyright 2023 Reality Design Lab <[email protected]> | ||
// SPDX-FileCopyrightText: Copyright 2024 Reality Design Lab <[email protected]> | ||
// SPDX-FileContributor: Yuchen Zhang <[email protected]> | ||
// SPDX-FileContributor: Botao Amber Hu <[email protected]> | ||
// SPDX-License-Identifier: MIT | ||
|
||
using System; | ||
|
@@ -12,6 +13,12 @@ namespace Netcode.Transports.MultipeerConnectivity | |
{ | ||
public class MultipeerConnectivityTransport : NetworkTransport | ||
{ | ||
#if (UNITY_IOS || UNITY_VISIONOS) && !UNITY_EDITOR | ||
public const string IMPORT_LIBRARY = "__Internal"; | ||
#else | ||
public const string IMPORT_LIBRARY = "MultipeerConnectivityTransportForNetcodeForGameObjectsNativePlugin"; | ||
#endif | ||
|
||
/// <summary> | ||
/// This class is a singleton so it's easy to be referenced anywhere. | ||
/// </summary> | ||
|
@@ -79,11 +86,6 @@ public class MultipeerConnectivityTransport : NetworkTransport | |
/// </summary> | ||
private readonly Dictionary<int, string> _pendingConnectionRequestDict = new(); | ||
|
||
/// <summary> | ||
/// Check if we are currently running on an iOS device. | ||
/// </summary> | ||
public static bool IsRuntime => Application.platform == RuntimePlatform.IPhonePlayer; | ||
|
||
/// <summary> | ||
/// Initialize the MPCSession and register native callbacks. | ||
/// </summary> | ||
|
@@ -96,7 +98,7 @@ public class MultipeerConnectivityTransport : NetworkTransport | |
/// <param name="onConnectedWithPeer">Invoked when connected with a peer</param> | ||
/// <param name="onDisconnectedWithPeer">Invoked when disconnected with a peer</param> | ||
/// <param name="onReceivedData">Invoked when receives data message from a peer</param> | ||
[DllImport("__Internal")] | ||
[DllImport(IMPORT_LIBRARY)] | ||
private static extern void MPC_Initialize(string nickname, | ||
Action<int, string> onBrowserFoundPeer, | ||
Action<int, string> onBrowserLostPeer, | ||
|
@@ -112,33 +114,33 @@ private static extern void MPC_Initialize(string nickname, | |
/// </summary> | ||
/// <param name="sessionId">The unique id of the network session</param> | ||
/// <param name="autoApproveConnectionRequest">Setting to true to approve all incoming connection requests</param> | ||
[DllImport("__Internal")] | ||
[DllImport(IMPORT_LIBRARY)] | ||
private static extern void MPC_StartAdvertising(string sessionId, bool autoApproveConnectionRequest); | ||
|
||
/// <summary> | ||
/// Start browsing for nearny advertising peers. | ||
/// </summary> | ||
/// <param name="sessionId">The unique id of the network session</param> | ||
/// <param name="autoSendConnectionRequest">Setting to true to automatically send connection request to the first browsed peer</param> | ||
[DllImport("__Internal")] | ||
[DllImport(IMPORT_LIBRARY)] | ||
private static extern void MPC_StartBrowsing(string sessionId, bool autoSendConnectionRequest); | ||
|
||
/// <summary> | ||
/// Stop advertising. | ||
/// </summary> | ||
[DllImport("__Internal")] | ||
[DllImport(IMPORT_LIBRARY)] | ||
private static extern void MPC_StopAdvertising(); | ||
|
||
/// <summary> | ||
/// Stop browsing. | ||
/// </summary> | ||
[DllImport("__Internal")] | ||
[DllImport(IMPORT_LIBRARY)] | ||
private static extern void MPC_StopBrowsing(); | ||
|
||
/// <summary> | ||
/// Shutdown and deinitialize the MPCSession. | ||
/// </summary> | ||
[DllImport("__Internal")] | ||
[DllImport(IMPORT_LIBRARY)] | ||
private static extern void MPC_Shutdown(); | ||
|
||
/// <summary> | ||
|
@@ -148,21 +150,21 @@ private static extern void MPC_Initialize(string nickname, | |
/// <param name="data">The raw data</param> | ||
/// <param name="length">The length of the data</param> | ||
/// <param name="reliable">Whether to use realiable way to send the data</param> | ||
[DllImport("__Internal")] | ||
[DllImport(IMPORT_LIBRARY)] | ||
private static extern void MPC_SendData(int transportID, byte[] data, int length, bool reliable); | ||
|
||
/// <summary> | ||
/// Send connection request to a specific browsed host. | ||
/// </summary> | ||
/// <param name="nearbyHostKey">The key of the host in the dict</param> | ||
[DllImport("__Internal")] | ||
[DllImport(IMPORT_LIBRARY)] | ||
private static extern void MPC_SendConnectionRequest(int nearbyHostKey); | ||
|
||
/// <summary> | ||
/// Approve the connection request sent by a specific client. | ||
/// </summary> | ||
/// <param name="connectionRequestKey">The key of the connection request in the dict</param> | ||
[DllImport("__Internal")] | ||
[DllImport(IMPORT_LIBRARY)] | ||
private static extern void MPC_ApproveConnectionRequest(int connectionRequestKey); | ||
|
||
/// <summary> | ||
|
@@ -409,25 +411,23 @@ public override void DisconnectRemoteClient(ulong transportId) | |
|
||
public override void Shutdown() | ||
{ | ||
if (IsRuntime) | ||
{ | ||
MPC_Shutdown(); | ||
// Reset variables | ||
_pendingConnectionRequestDict.Clear(); | ||
_nearbyHostDict.Clear(); | ||
_isAdvertising = false; | ||
_isBrowsing = false; | ||
} | ||
MPC_Shutdown(); | ||
// Reset variables | ||
_pendingConnectionRequestDict.Clear(); | ||
_nearbyHostDict.Clear(); | ||
_isAdvertising = false; | ||
_isBrowsing = false; | ||
} | ||
|
||
/// <summary> | ||
/// Start advertising. | ||
/// </summary> | ||
public void StartAdvertising() | ||
{ | ||
if (IsRuntime && !_isAdvertising) | ||
if (!_isAdvertising) | ||
{ | ||
_pendingConnectionRequestDict.Clear(); | ||
Debug.Log("Start advertising"); | ||
MPC_StartAdvertising(SessionId, AutoApproveConnectionRequest); | ||
_isAdvertising = true; | ||
} | ||
|
@@ -438,7 +438,7 @@ public void StartAdvertising() | |
/// </summary> | ||
public void StopAdvertising() | ||
{ | ||
if (IsRuntime && _isAdvertising) | ||
if (_isAdvertising) | ||
{ | ||
MPC_StopAdvertising(); | ||
_isAdvertising = false; | ||
|
@@ -451,7 +451,7 @@ public void StopAdvertising() | |
/// </summary> | ||
public void StartBrowsing() | ||
{ | ||
if (IsRuntime && !_isBrowsing) | ||
if (!_isBrowsing) | ||
{ | ||
_nearbyHostDict.Clear(); | ||
MPC_StartBrowsing(SessionId, AutoSendConnectionRequest); | ||
|
@@ -464,7 +464,7 @@ public void StartBrowsing() | |
/// </summary> | ||
public void StopBrowsing() | ||
{ | ||
if (IsRuntime && _isBrowsing) | ||
if (_isBrowsing) | ||
{ | ||
MPC_StopBrowsing(); | ||
_isBrowsing = false; | ||
|
@@ -474,18 +474,12 @@ public void StopBrowsing() | |
|
||
public void SendConnectionRequest(int nearbyHostKey) | ||
{ | ||
if (IsRuntime) | ||
{ | ||
MPC_SendConnectionRequest(nearbyHostKey); | ||
} | ||
MPC_SendConnectionRequest(nearbyHostKey); | ||
} | ||
|
||
public void ApproveConnectionRequest(int connectionRequestKey) | ||
{ | ||
if (IsRuntime) | ||
{ | ||
MPC_ApproveConnectionRequest(connectionRequestKey); | ||
} | ||
MPC_ApproveConnectionRequest(connectionRequestKey); | ||
} | ||
} | ||
} |
Binary file modified
BIN
-192 Bytes
(100%)
Runtime/Plugins/iOS/libMultipeerConnectivityTransportForNetcodeForGameObjectsNativePlugin.a
Binary file not shown.
12 changes: 11 additions & 1 deletion
12
.../Plugins/iOS/libMultipeerConnectivityTransportForNetcodeForGameObjectsNativePlugin.a.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file modified
BIN
-48 KB
(73%)
...e/Plugins/macOS/MultipeerConnectivityTransportForNetcodeForGameObjectsNativePlugin.bundle
Binary file not shown.
10 changes: 10 additions & 0 deletions
10
...gins/macOS/MultipeerConnectivityTransportForNetcodeForGameObjectsNativePlugin.bundle.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file added
BIN
+140 KB
.../Plugins/visionOS/libMultipeerConnectivityTransportForNetcodeForGameObjectsNativePlugin.a
Binary file not shown.
Oops, something went wrong.