using UnityEngine; using System.Collections.Generic; using UnityEngine.Windows.Speech; using Academy.HoloToolkit.Unity; using Academy.HoloToolkit.Sharing; public class HologramPlacement : Singleton { /// /// Tracks if we have been sent a transform for the anchor model. /// The anchor model is rendered relative to the actual anchor. /// public bool GotTransform { get; private set; } private bool animationPlayed = false; void Start() { // We care about getting updates for the anchor transform. CustomMessages.Instance.MessageHandlers[CustomMessages.TestMessageID.StageTransform] = this.OnStageTransfrom; // And when a new user join we will send the anchor transform we have. SharingSessionTracker.Instance.SessionJoined += Instance_SessionJoined; } /// /// When a new user joins we want to send them the relative transform for the anchor if we have it. /// /// /// private void Instance_SessionJoined(object sender, SharingSessionTracker.SessionJoinedEventArgs e) { if (GotTransform) { CustomMessages.Instance.SendStageTransform(transform.localPosition, transform.localRotation); } } void Update() { if (GotTransform) { if (ImportExportAnchorManager.Instance.AnchorEstablished && animationPlayed == false) { // This triggers the animation sequence for the anchor model and // puts the cool materials on the model. GetComponent().SendMessage("OnSelect"); animationPlayed = true; } } else { transform.position = Vector3.Lerp(transform.position, ProposeTransformPosition(), 0.2f); } } Vector3 ProposeTransformPosition() { // Put the anchor 2m in front of the user. Vector3 retval = Camera.main.transform.position + Camera.main.transform.forward * 2; return retval; } public void OnSelect() { // Note that we have a transform. GotTransform = true; // And send it to our friends. CustomMessages.Instance.SendStageTransform(transform.localPosition, transform.localRotation); } /// /// When a remote system has a transform for us, we'll get it here. /// /// void OnStageTransfrom(NetworkInMessage msg) { // We read the user ID but we don't use it here. msg.ReadInt64(); transform.localPosition = CustomMessages.Instance.ReadVector3(msg); transform.localRotation = CustomMessages.Instance.ReadQuaternion(msg); // The first time, we'll want to send the message to the anchor to do its animation and // swap its materials. if (GotTransform == false) { GetComponent().SendMessage("OnSelect"); } GotTransform = true; } public void ResetStage() { // We'll use this later. } }