diff --git a/EdgeMultiplay.unitypackage b/EdgeMultiplay.unitypackage index f28e963..28f548d 100644 Binary files a/EdgeMultiplay.unitypackage and b/EdgeMultiplay.unitypackage differ diff --git a/EdgeMultiplay/Scripts/DataContracts.cs b/EdgeMultiplay/Scripts/DataContracts.cs index e72d730..8d3c141 100644 --- a/EdgeMultiplay/Scripts/DataContracts.cs +++ b/EdgeMultiplay/Scripts/DataContracts.cs @@ -691,7 +691,7 @@ public Dictionary playerTagsDict { if(playerTags != null) { - return Tag.HashtableToDictionary(playerTags); + return Util.HashtableToDictionary(playerTags); } else { diff --git a/EdgeMultiplay/Scripts/EdgeManager.cs b/EdgeMultiplay/Scripts/EdgeManager.cs index ad0df19..2aab67c 100644 --- a/EdgeMultiplay/Scripts/EdgeManager.cs +++ b/EdgeMultiplay/Scripts/EdgeManager.cs @@ -32,6 +32,7 @@ namespace EdgeMultiplay /// EdgeManager have many static variables, your app/game should have only one EdgeManager /// [RequireComponent(typeof(MobiledgeX.LocationService))] + [RequireComponent(typeof(EdgeEventsManager))] [AddComponentMenu("EdgeMultiplay/EdgeManager")] public class EdgeManager : MonoBehaviour { @@ -124,7 +125,22 @@ private void Awake() { Destroy(gameObject); } - integration = new MobiledgeXIntegration(); + integration = new MobiledgeXIntegration(FindObjectOfType()); + integration.matchingEngine.EnableEdgeEvents = true; + integration.NewFindCloudletHandler += HandleFindCloudlet; + } + + private void HandleFindCloudlet(EdgeEventsStatus edgeEventstatus, FindCloudletEvent fcEvent) + { + print("NewFindCloudlet triggered status is " + edgeEventstatus.status + ", Trigger" + fcEvent.trigger); + if (fcEvent.newCloudlet != null) + { + print("New Cloudlet FQDN: " + fcEvent.newCloudlet.Fqdn); + } + if (edgeEventstatus.status == Status.error) + { + print("Error received: " + edgeEventstatus.error_msg); + } } void Update() @@ -219,7 +235,7 @@ public async Task ConnectToServer(bool useAnyCarrierNetwork = true, bool useFall integration.useFallbackLocation = useFallBackLocation; wsClient = new MobiledgeXWebSocketClient(); await integration.RegisterAndFindCloudlet(); - integration.GetAppPort(LProto.L_PROTO_TCP); + integration.GetAppPort(LProto.Tcp); string url = integration.GetUrl("ws") + path; Uri uri = new Uri(url); if (wsClient.isOpen()) @@ -230,6 +246,11 @@ public async Task ConnectToServer(bool useAnyCarrierNetwork = true, bool useFall await wsClient.Connect(@uri); EdgeMultiplayCallbacks.connectedToEdge(); } + catch (AppPortException appPortException) + { + EdgeMultiplayCallbacks.failureToConnect(appPortException.Message); + Debug.LogError("EdgeMultiplay: Failed to connect to Edge, Error finding AppPort"); + } catch (Exception e) { EdgeMultiplayCallbacks.failureToConnect(e.Message); @@ -279,7 +300,7 @@ public static void JoinOrCreateRoom(string playerName, int playerAvatar, int max Hashtable playertagsHashtable; if (playerTags != null) { - playertagsHashtable = Tag.DictionaryToHashtable(playerTags); + playertagsHashtable = Util.DictionaryToHashtable(playerTags); } else { @@ -336,7 +357,7 @@ public static void CreateRoom(string playerName, int playerAvatar, int maxPlayer Hashtable playertagsHashtable; if (playerTags != null) { - playertagsHashtable = Tag.DictionaryToHashtable(playerTags); + playertagsHashtable = Util.DictionaryToHashtable(playerTags); } else { @@ -367,7 +388,7 @@ public static void JoinRoom(string roomId, string playerName, int playerAvatar, Hashtable playertagsHashtable; if (playerTags != null) { - playertagsHashtable = Tag.DictionaryToHashtable(playerTags); + playertagsHashtable = Util.DictionaryToHashtable(playerTags); } else { @@ -527,7 +548,7 @@ void HandleWebSocketMessage(string message) } else { - udpClient = new MobiledgeXUDPClient(integration.GetHost(), integration.GetAppPort(LProto.L_PROTO_UDP).public_port); + udpClient = new MobiledgeXUDPClient(integration.GetHost(), integration.GetAppPort(LProto.Udp).PublicPort); } SendUDPMessage(new GamePlayEvent(){eventName = "Start"}); break; diff --git a/EdgeMultiplay/Scripts/Util.cs b/EdgeMultiplay/Scripts/Util.cs index 398245a..83553c1 100644 --- a/EdgeMultiplay/Scripts/Util.cs +++ b/EdgeMultiplay/Scripts/Util.cs @@ -16,6 +16,8 @@ */ using System; +using System.Collections; +using System.Collections.Generic; using UnityEngine; namespace EdgeMultiplay @@ -162,5 +164,54 @@ public static Quaternion ConvertFloatArrayToQuaternion(float[] floatArray, int s throw new Exception("floatArray starting from the start index doesn't qualify to create a Vector3"); } } + + /// + /// Converts a Hashtable to Dictionary + /// + /// Hashtable + /// Dictionary + public static Dictionary HashtableToDictionary(Hashtable htable) + { + Dictionary dict = new Dictionary(); + if (htable == null) + { + return null; + } + foreach (var key in htable.Keys) + { + if (htable[key] == null) + { + continue; + } + dict[key.ToString()] = htable[key].ToString(); + Debug.Log("Key: " + key + ", Value: " + dict[key.ToString()]); + } + return dict; + } + + /// + /// Converts a Dictionary to Hashtable + /// + /// Dictionary + /// Hashtable + public static Hashtable DictionaryToHashtable(Dictionary dict) + { + Hashtable htable = new Hashtable(); + if (dict == null) + { + return null; + } + foreach (KeyValuePair entry in dict) + { + if (entry.Value == null) + { + continue; + } + htable.Add(entry.Key, entry.Value); + Debug.Log("Key: " + entry.Key + ", Value: " + htable[entry.Key]); + } + return htable; + } + } } diff --git a/EdgeMultiplay/link.xml b/EdgeMultiplay/link.xml new file mode 100644 index 0000000..71d1d02 --- /dev/null +++ b/EdgeMultiplay/link.xml @@ -0,0 +1,4 @@ + + + + diff --git a/EdgeMultiplay/link.xml.meta b/EdgeMultiplay/link.xml.meta new file mode 100644 index 0000000..6899983 --- /dev/null +++ b/EdgeMultiplay/link.xml.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: d919df62656c649b2842c3ee3c34275e +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: