I’ve created a little test script and it works fine. It’s something in my code…
using UnityEngine;
using System.Collections;
using UnityEngine.VR.WSA.Input;
using UnityEngine.Windows.Speech;
using System.Collections.Generic;
using System.Linq;
public class Fitbox : MonoBehaviour
{
[Tooltip("The collection of holograms to show when the Fitbox is dismissed.")]
public GameObject HologramCollection;
[Tooltip("Reposition the collection of holograms relative to where the Fitbox was dismissed.")]
public bool MoveCollectionOnDismiss = false;
[Tooltip("The material used to render the Fitbox border.")]
public Material FitboxMaterial;
// The offset from the Camera to the HologramCollection when
// the app starts up. This is used to place the Collection
// in the correct relative position after the Fitbox is
// dismissed.
private Vector3 collectionStartingOffsetFromCamera;
private float Distance = 1.6f;
private Interpolator interpolator;
private GestureRecognizer recognizer;
private bool isInitialized = false;
GameObject testObject;
public GameObject logo;
public GameObject TopDiamondRing;
public GameObject TopGoldBox;
public GameObject TopPlatinumBox;
public GameObject TopWhiteDiamond;
public GameObject TopPinkDiamond;
public GameObject Incubator;
public GameObject TopOrchid;
public GameObject TopTree;
public GameObject TopWoman;
public GameObject TopCouple;
public GameObject TopBloodDiamond;
KeywordRecognizer keywordRecognizer;
Dictionary<string, System.Action> keywords = new Dictionary<string, System.Action>();
AudioSource audioSource = null;
AudioClip tapSound = null;
AudioClip ringBoxSound = null;
AudioClip moveHoldSound = null;
AudioClip largerSound = null;
AudioClip smallerSound = null;
AudioClip pinkDiamond = null;
AudioClip incubator = null;
AudioClip treeSound = null;
AudioClip girlSound = null;
AudioClip incubatorNext = null;
AudioClip bigRing = null;
AudioClip bloodSound = null;
bool spinInc = false;
bool spinCouple = false;
bool spinBingRing = false;
bool spinGirl = false;
bool spinTree = false;
bool spinPink = false;
bool spinBlood = false;
private void Awake()
{
// Add an AudioSource component and set up some defaults
audioSource = gameObject.AddComponent<AudioSource>();
audioSource.playOnAwake = false;
audioSource.spatialize = false;
audioSource.spatialBlend = 1.0f;
audioSource.dopplerLevel = 0.0f;
audioSource.rolloffMode = AudioRolloffMode.Custom;
// Load the Sphere sounds from the Resources folder
tapSound = Resources.Load<AudioClip>("Select13");
ringBoxSound = Resources.Load<AudioClip>("SlotPrize2");
pinkDiamond = Resources.Load<AudioClip>("voice5a");
moveHoldSound = Resources.Load<AudioClip>("Select17");
smallerSound = Resources.Load<AudioClip>("Shrink2");
largerSound = Resources.Load<AudioClip>("Grow");
incubator = Resources.Load<AudioClip>("voice3a");
treeSound = Resources.Load<AudioClip>("voice7ab");
girlSound = Resources.Load<AudioClip>("IVONAa");
bigRing = Resources.Load<AudioClip>("IVONA2a");
incubatorNext = Resources.Load<AudioClip>("INC");
bloodSound = Resources.Load<AudioClip>("sociallyresponsible");
logo.SetActive(true);
TopDiamondRing.SetActive(false);
TopPlatinumBox.SetActive(false);
TopGoldBox.SetActive(false);
TopWhiteDiamond.SetActive(false);
//TopPinkDiamond.SetActive(false);
Incubator.SetActive(false);
TopOrchid.SetActive(false);
TopTree.SetActive(false);
TopWoman.SetActive(false);
TopCouple.SetActive(false);
TopBloodDiamond.SetActive(false);
// These are the holograms to show when the Fitbox is dismissed
if (HologramCollection)
{
collectionStartingOffsetFromCamera = HologramCollection.transform.localPosition;
HologramCollection.SetActive(false);
}
// Set up our GestureRecognizer to listen for the SelectEvent
recognizer = new GestureRecognizer();
recognizer.TappedEvent += (source, tapCount, ray) =>
{
StartIncubator();
};
recognizer.StartCapturingGestures();
}
////////////////////START//////////////////////
private void Start()
{
if (interpolator == null)
{
interpolator = gameObject.AddComponent<Interpolator>();
}
// Screen-lock the Fitbox to match the OOBE Fitbox experience
interpolator.PositionPerSecond = 0.0f;
GameObject.Find("gSpeechManager").GetComponent<SpeechManager>().enabled = false;
GameObject.Find("gGestureManager").GetComponent<GazeGestureManager>().enabled = false;
testObject = GameObject.FindGameObjectWithTag("TEST");
}
////////////////////UPDATE//////////////////////
void update()
{
if (spinInc)
{
}
//TopPinkDiamond.transform.Rotate(Vector3.up, Time.deltaTime * 50);
testObject.transform.Rotate(Vector3.up, Time.deltaTime * 50);
}
////////////////////INCUBATOR//////////////////////
private void StartIncubator()
{
//Dismiss logo
logo.SetActive(false);
//Turn on incubaotr
Incubator.SetActive(true);
spinInc = true;
//Create keywords for keyword recognizer
keywords.Add("Tell Me", () =>
{
if (spinInc)
{
audioSource.clip = incubator;
keywordRecognizer.Stop();
}
else if (spinBingRing)
{
audioSource.clip = bigRing;
spinBingRing = false;
keywordRecognizer.Stop();
}
else if (spinGirl)
{
audioSource.clip = girlSound;
spinGirl = false;
keywordRecognizer.Stop();
}
else if (spinTree)
{
audioSource.clip = treeSound;
spinTree = false;
keywordRecognizer.Stop();
}
else if (spinPink)
{
audioSource.clip = pinkDiamond;
spinPink = false;
keywordRecognizer.Stop();
}
else if (spinBlood)
{
audioSource.clip = bloodSound;
spinBlood = false;
keywordRecognizer.Stop();
}
audioSource.Play();
});
keywordRecognizer = new KeywordRecognizer(keywords.Keys.ToArray());
keywordRecognizer.OnPhraseRecognized += KeywordRecognizer_OnPhraseRecognized;
keywordRecognizer.Start();
// Set up our GestureRecognizer to listen for the SelectEvent
recognizer = new GestureRecognizer();
recognizer.TappedEvent += (source, tapCount, ray) =>
{
//Go to next
StartCouple();
};
recognizer.StartCapturingGestures();
}
////////////////////SPEECH CALLBACK//////////////////////
private void KeywordRecognizer_OnPhraseRecognized(PhraseRecognizedEventArgs args)
{
System.Action keywordAction;
// if the keyword recognized is in our dictionary, call that Action.
if (keywords.TryGetValue(args.text, out keywordAction))
{
keywordAction.Invoke();
}
}
////////////////////COUPLE//////////////////////
private void StartCouple()
{
TopCouple.SetActive(true);
spinInc = false;
// Set up our GestureRecognizer to listen for the SelectEvent
recognizer = new GestureRecognizer();
recognizer.TappedEvent += (source, tapCount, ray) =>
{
StartLargeRing();
};
recognizer.StartCapturingGestures();
}
////////////////////LARGE RING//////////////////////
private void StartLargeRing()
{
//Turn on/off
keywordRecognizer.Start();
TopDiamondRing.SetActive(true);
spinBingRing = true;
spinInc = false;
// Set up our GestureRecognizer to listen for the SelectEvent
recognizer = new GestureRecognizer();
recognizer.TappedEvent += (source, tapCount, ray) =>
{
//Go to next
StartGirl();
};
recognizer.StartCapturingGestures();
}
////////////////////GIRL//////////////////////
private void StartGirl()
{
//Turn on/off
keywordRecognizer.Start();
TopWoman.SetActive(true);
spinGirl = true;
spinBingRing = false;
spinInc = false;
// Set up our GestureRecognizer to listen for the SelectEvent
recognizer = new GestureRecognizer();
recognizer.TappedEvent += (source, tapCount, ray) =>
{
//Go to next
StartTree();
};
recognizer.StartCapturingGestures();
}
////////////////////TREE//////////////////////
private void StartTree()
{
//Turn on/off
keywordRecognizer.Start();
TopTree.SetActive(true);
spinTree = true;
spinGirl = false;
spinBingRing = false;
spinInc = false;
// Set up our GestureRecognizer to listen for the SelectEvent
recognizer = new GestureRecognizer();
recognizer.TappedEvent += (source, tapCount, ray) =>
{
//Go to next
StartPink();
};
recognizer.StartCapturingGestures();
}
////////////////////PINK DIAMOND//////////////////////
private void StartPink()
{
//Turn on/off
keywordRecognizer.Start();
TopPinkDiamond.SetActive(true);
TopWhiteDiamond.SetActive(true);
TopOrchid.SetActive(true);
spinPink = true;
spinTree = false;
spinGirl = false;
spinBingRing = false;
spinInc = false;
// Set up our GestureRecognizer to listen for the SelectEvent
recognizer = new GestureRecognizer();
recognizer.TappedEvent += (source, tapCount, ray) =>
{
//Go to next
StartBlood();
};
recognizer.StartCapturingGestures();
}
////////////////////BLOODY//////////////////////
private void StartBlood()
{
//Turn on/off
keywordRecognizer.Start();
TopBloodDiamond.SetActive(true);
spinBlood = true;
spinPink = false;
spinTree = false;
spinGirl = false;
spinBingRing = false;
spinInc = false;
// Set up our GestureRecognizer to listen for the SelectEvent
recognizer = new GestureRecognizer();
recognizer.TappedEvent += (source, tapCount, ray) =>
{
//Go to next
StartBoxes();
};
recognizer.StartCapturingGestures();
}
////////////////////RING BOXES//////////////////////
private void StartBoxes()
{
//Start
TopGoldBox.SetActive(true);
TopPlatinumBox.SetActive(true);
//Close and dispose
recognizer.CancelGestures();
recognizer.StopCapturingGestures();
recognizer.Dispose();
keywordRecognizer.Stop();
keywordRecognizer.Dispose();
//activate global speech and gesture
GameObject.Find("gSpeechManager").GetComponent<SpeechManager>().enabled = true;
GameObject.Find("gGestureManager").GetComponent<GazeGestureManager>().enabled = true;
}
private void InitializeComponents()
{
// Return early if we've already been initialized...
if (isInitialized || Camera.main == null)
{
return;
}
// Calculate Hologram Dimensions and Positions based on RedLine drawing
const int drawingPixelWidth = 1440;
const int drawingPixelHeight = 818;
const int drawingBoxLeftEdgeScreen = 240;
const int drawingBoxBottomEdgeScreen = 139;
const int drawingBoxWidthScreen = 960;
const int drawingBoxHeightScreen = 540;
const int drawingQuadWidthScreen = 8;
const int drawingQuadHeightScreen = 8;
// Calculate a ratio between the actual screen dimensions and those of the RedLine drawing
var xRatio = (float)Camera.main.pixelWidth / (float)drawingPixelWidth;
var yRatio = (float)Camera.main.pixelHeight / (float)drawingPixelHeight;
// Factor the real dimensions in screen space
var realBoxLeftEdgeScreen = drawingBoxLeftEdgeScreen * xRatio;
var realBoxBottomEdgeScreen = drawingBoxBottomEdgeScreen * yRatio;
var realBoxWidthScreen = drawingBoxWidthScreen * xRatio;
var realBoxHeightScreen = drawingBoxHeightScreen * yRatio;
var realQuadWidthScreen = drawingQuadWidthScreen * xRatio;
var realQuadHeightScreen = drawingQuadHeightScreen * yRatio;
// Calculate the real width of the top/bottom (horizontal) quads
var hQuadLeftEdgeScreen = new Vector3(realBoxLeftEdgeScreen, realBoxBottomEdgeScreen + (realQuadHeightScreen / 2.0f), Distance);
var hQuadLeftEdge = Camera.main.ScreenToWorldPoint(hQuadLeftEdgeScreen);
var hQuadRightEdgeScreen = new Vector3(realBoxLeftEdgeScreen + realBoxWidthScreen, hQuadLeftEdgeScreen.y, Distance);
var hQuadRightEdge = Camera.main.ScreenToWorldPoint(hQuadRightEdgeScreen);
var hQuadWid = Vector3.Distance(hQuadRightEdge, hQuadLeftEdge);
// Calculate the real height of the top/bottom (horizontal) quads
var hQuadBottomEdgeScreen = new Vector3(0, hQuadLeftEdge.y, Distance);
var hQuadBottomEdge = Camera.main.ScreenToWorldPoint(hQuadBottomEdgeScreen);
var hQuadTopEdgeScreen = new Vector3(0, hQuadBottomEdgeScreen.y + realQuadHeightScreen, Distance);
var hQuadTopEdge = Camera.main.ScreenToWorldPoint(hQuadTopEdgeScreen);
var hQuadHgt = Vector3.Distance(hQuadTopEdge, hQuadBottomEdge);
// Calculate the real height of the left/right (vertical) quads
var vQuadBottomEdgeScreen = new Vector3(realBoxLeftEdgeScreen + (realQuadWidthScreen / 2.0f), realBoxBottomEdgeScreen, Distance);
var vQuadBottomEdge = Camera.main.ScreenToWorldPoint(vQuadBottomEdgeScreen);
var vQuadTopEdgeScreen = new Vector3(vQuadBottomEdgeScreen.x, realBoxBottomEdgeScreen + realBoxHeightScreen, Distance);
var vQuadTopEdge = Camera.main.ScreenToWorldPoint(vQuadTopEdgeScreen);
var vQuadHgt = Vector3.Distance(vQuadTopEdge, vQuadBottomEdge);
// Calculate the real width of the left/right quads...
// ...just use the height of the horizontal quad for the width of the vertical quad
var vQuadWid = hQuadHgt;
// Create the Quads for our FitBox
/* leftQuad*/
//CreateFitboxQuad(transform, (-hQuadWid / 2.0f) + (vQuadWid / 2.0f), 0f, vQuadWid, vQuadHgt);
/* rightQuad*/
//CreateFitboxQuad(transform, (hQuadWid / 2.0f) - (vQuadWid / 2.0f), 0f, vQuadWid, vQuadHgt);
/*bottomQuad*/
//CreateFitboxQuad(transform, 0f, (vQuadHgt / 2.0f) - (hQuadHgt / 2.0f), hQuadWid, hQuadHgt);
/* topQuad*/
//CreateFitboxQuad(transform, 0f, (-vQuadHgt / 2.0f) + (hQuadHgt / 2.0f), hQuadWid, hQuadHgt);
isInitialized = true;
}
private void CreateFitboxQuad(Transform parent, float xPos, float yPos, float width, float height)
{
var quad = GameObject.CreatePrimitive(PrimitiveType.Quad);
quad.transform.parent = parent;
quad.transform.localPosition = new Vector3(xPos, yPos, 0);
quad.transform.localScale = new Vector3(width, height, quad.transform.localScale.z);
quad.transform.localRotation = Quaternion.Euler(0f, 180f, 0f);
quad.GetComponent<MeshRenderer>().material = FitboxMaterial;
}
int foo = 0;
private void LateUpdate()
{
foo++;
if (foo < 2) return;
InitializeComponents();
Transform cameraTransform = Camera.main.transform;
interpolator.SetTargetPosition(cameraTransform.position + (cameraTransform.forward * Distance));
interpolator.SetTargetRotation(Quaternion.LookRotation(-cameraTransform.forward, -cameraTransform.up));
}
}