4 using System.Collections.Generic;
8 #if UNITY_WSA || UNITY_STANDALONE_WIN 14 [RequireComponent(typeof(RemoteMeshTarget))]
17 [Tooltip(
"Key to press in editor to enable spatial mapping over the network.")]
18 public KeyCode RemoteMappingKey = KeyCode.N;
20 [Tooltip(
"Keyword for sending meshes from HoloLens to Unity over the network.")]
21 public string SendMeshesKeyword =
"send meshes";
23 #if UNITY_EDITOR || UNITY_STANDALONE 30 #if UNITY_WSA || UNITY_STANDALONE_WIN 31 private KeywordRecognizer keywordRecognizer;
39 private Dictionary<string,
System.Action> keywordCollection;
45 #if UNITY_WSA || UNITY_STANDALONE_WIN 47 keywordCollection =
new Dictionary<string,
System.Action> { { SendMeshesKeyword, SendMeshes } };
50 keywordRecognizer =
new KeywordRecognizer(keywordCollection.Keys.ToArray());
52 keywordRecognizer.OnPhraseRecognized += KeywordRecognizer_OnPhraseRecognized;
53 keywordRecognizer.Start();
56 #if UNITY_EDITOR || UNITY_STANDALONE 57 remoteMeshTarget = GetComponent<RemoteMeshTarget>();
70 #if UNITY_EDITOR || UNITY_STANDALONE 72 if (Input.GetKeyUp(RemoteMappingKey))
79 #if UNITY_WSA || UNITY_STANDALONE_WIN 80 private void KeywordRecognizer_OnPhraseRecognized(PhraseRecognizedEventArgs args)
86 System.Action keywordAction;
88 if (keywordCollection.TryGetValue(args.text, out keywordAction))
90 keywordAction.Invoke();
98 private void SendMeshes()
100 #if !UNITY_EDITOR && UNITY_WSA 102 for (
int index = 0; index < MeshFilters.Count; index++)
104 List<Mesh> meshesToSend =
new List<Mesh>();
105 MeshFilter filter = MeshFilters[index];
106 Mesh source = filter.sharedMesh;
107 Mesh clone =
new Mesh();
108 List<Vector3> verts =
new List<Vector3>();
109 verts.AddRange(source.vertices);
111 for(
int vertIndex=0; vertIndex < verts.Count; vertIndex++)
113 verts[vertIndex] = filter.transform.TransformPoint(verts[vertIndex]);
116 clone.SetVertices(verts);
117 clone.SetTriangles(source.triangles, 0);
118 meshesToSend.Add(clone);