forked from microsoft/MixedRealityCompanionKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLocalPlayerManager.cs
More file actions
109 lines (91 loc) · 3.2 KB
/
Copy pathLocalPlayerManager.cs
File metadata and controls
109 lines (91 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
#if UNITY_WSA
using UnityEngine.XR.WSA.Input;
using UnityEngine.Windows.Speech;
#endif
namespace SimpleSharing
{
public class LocalPlayerManager : MonoBehaviour
{
public AudioClip placeSound;
#if WINDOWS_UWP
GestureRecognizer gr;
// Simple example showing how to respond to remote user's interaction.
// See RemotePlayerManager.
GameObject placedObject = null;
KeywordRecognizer kr;
AudioSource placeSource;
void Start()
{
// Send pose data less frequently than Update frequency.
// Sending data too frequently will saturate the socket and force a disconnect.
InvokeRepeating("SendTransform", 0, 0.1f);
gr = new GestureRecognizer();
gr.SetRecognizableGestures(GestureSettings.Tap);
gr.Tapped += Tapped;
gr.StartCapturingGestures();
kr = new KeywordRecognizer(new string[] {"Reset Anchor."});
kr.OnPhraseRecognized += OnPhraseRecognized;
kr.Start();
placeSource = GetComponent<AudioSource>();
if (placeSource == null)
{
placeSource = gameObject.AddComponent<AudioSource>();
}
}
private void OnPhraseRecognized(PhraseRecognizedEventArgs args)
{
if (AnchorManager.Instance != null)
{
Debug.Log("Reset anchors.");
AnchorManager.Instance.ResetAnchor();
}
}
private void Tapped(TappedEventArgs e)
{
if (SharingManager.Instance != null)
{
Vector3 position = Camera.main.transform.position;
Vector3 direction = Camera.main.transform.forward;
RaycastHit hitInfo;
Vector3 hitPoint = Vector3.zero;
if (Physics.Raycast(position, direction, out hitInfo))
{
hitPoint = hitInfo.point;
}
else
{
hitPoint = position + direction * 2;
}
SharingManager.Instance.SendAirTap(position, direction, hitPoint);
if (placedObject == null)
{
placedObject = GameObject.CreatePrimitive(PrimitiveType.Sphere);
placedObject.transform.localScale = Vector3.one * 0.2f;
}
placedObject.transform.position = hitPoint;
if (placeSound != null && !placeSource.isPlaying)
{
placeSource.PlayOneShot(placeSound);
}
}
}
private void OnDestroy()
{
CancelInvoke("SendTransform");
gr.StopCapturingGestures();
}
private void SendTransform()
{
if (SharingManager.Instance != null)
{
SharingManager.Instance.SendPose();
}
}
#endif
}
}