// Converts hex string with Uuid format "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" to Byte array Uuid public static byte[] StringToUuid(string str) { byte[] uuid = new byte[16]; str = str.Replace("-", ""); if (str.Length != 32) { AnchorSession.Log("StringToUuid failed because string was incorrect length: " + str.Length); return(uuid); } for (int i = 0; i < 16; ++i) { uuid[i] = (byte)(GetHexVal(str[2 * i]) * 16 + GetHexVal(str[(2 * i) + 1])); } return(uuid); }
// Converts Byte array to string with Uuid format "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" public static string UuidToString(byte[] encodedMessage) { if (encodedMessage.Length != 16) { AnchorSession.Log("UuidToString failed because uuid byte array was incorrect length: " + encodedMessage.Length); return(""); } StringBuilder message = new StringBuilder("", 36); var messageWithNoDashes = BitConverter.ToString(encodedMessage).ToLower().Replace('-'.ToString(), String.Empty); for (int iter = 0; iter < 32; iter++) { if (iter == 8 || iter == 12 || iter == 16 || iter == 20) { message.Append("-"); } message.Append(messageWithNoDashes[iter]); } return(message.ToString()); }
private static int GetHexVal(char hex) { int val = (int)hex; if (val >= '0' && val <= '9') { return(val - 48); } else if (val >= 'a' && val <= 'f') { return(val - 87); } else if (val >= 'A' && val <= 'F') { return(val - 55); } else { AnchorSession.Log("GetHexVal failed because of invalid hex character: " + hex); return(0); } }
/// <summary> /// Spawns an anchor and parents it under the given transform /// </summary> /// <param name="transform"></param> public void PlaceAnchorAtTransform(Transform transform) { AnchorSession.Log("Placing anchor at pose: " + transform.ToOVRPose().ToPosef().ToString()); var anchorHandle = AnchorSession.Instance.CreateSpatialAnchor(transform); if (anchorHandle == AnchorSession.kInvalidHandle) { AnchorSession.Log("Failed to create spatial anchor"); return; } GameObject anchorObject = Instantiate(anchorPrefab_); Anchor anchor = anchorObject.GetComponent <Anchor>(); if (anchor == null) { anchor = anchorObject.AddComponent <Anchor>(); } anchor.SetAnchorHandle(anchorHandle); AnchorSession.Instance.handleToAnchor.Add(anchorHandle, anchor); }