void performRayCast() { var rayDirection = gameObject; RaycastHit hitInfo; if (Physics.Raycast(transform.position, transform.forward, out hitInfo, 0.1f, layerMask)) { // Only call update if the color has changed if (previousHitTag != hitInfo.collider.tag) { previousHitTag = hitInfo.collider.tag; //Debug.Log("hit info: " + hitInfo.collider.tag); int hue = ColorService.GetHueByColor(hitInfo.collider.tag); if (currentLight != null) { currentLight.State.Hue = hue; SmartLightManager.UpdateLightState(arrayId); } } } }
void performRayCast() { RaycastHit hitInfo; if (Physics.Raycast(transform.position, transform.forward, out hitInfo, 0.1f, layerMask)) { // Only call update if the color has changed if (previousHitTag != hitInfo.collider.tag && !isInitialColor && hitInfo.collider.tag != initialHue) { previousHitTag = hitInfo.collider.tag; //Debug.Log("hit info: " + hitInfo.collider.tag); int hue = ColorService.GetHueByColor(hitInfo.collider.tag); if (currentLight != null) { // auto sets saturation to full to show vibrant colors. Will replace when Saturation UI is added in another version currentLight.State.Sat = 254; currentLight.State.Hue = hue; SmartLightManager.UpdateLightState(arrayId); } initialHue = ""; } else if (isInitialColor) { initialHue = hitInfo.collider.tag; isInitialColor = false; } } }
// Assign actions to slider value changes public void OnSlider(Vector3 scaledLocalPositionDelta) { if (SliderX) { } if (SliderY) { float adjustedDelta = Mathf.Clamp((scaledLocalPositionDelta.y * sliderSensitivity), minHeight, maxHeight); float percentOfMaxHeight = (adjustedDelta - minHeight) / (heightRange); float scaleSize = (percentOfMaxHeight * sizeRange) + minSize; gameObject.transform.localPosition = new Vector3(gameObject.transform.localPosition.x, adjustedDelta, gameObject.transform.localPosition.z); gameObject.transform.localScale = new Vector3(scaleSize, scaleSize, scaleSize); int brightness = (int)((percentOfMaxHeight * brightnessRange) + minBrightness); if (currentLight != null && currentLight.State.Bri != brightness) { currentLight.State.Bri = brightness; SmartLightManager.UpdateLightState(arrayId); } } if (SliderZ) { } }
void Awake() { smartLights = new List <SmartLight>(); if (GameObject.Find("HologramCollection") != null) { hologramCollection = GameObject.Find("HologramCollection"); slm = hologramCollection.GetComponent <SmartLightManager>(); } else { Debug.LogError("No GameObject name HologramCollection can be found. This object should contain all holograms and the SmartLightManager"); } }
void TestChangeLightV2() { State testState = smartLights[0].State; testState.On = true; testState.Hue = 57100; string request = "http://" + bridgeip + "/api/" + username + "/lights/1/state"; string json = JsonUtility.ToJson(testState); JsonUtility.FromJson <State>(json); UnityWebRequest setLight = UnityWebRequest.Put(request, json); Debug.Log("Send triggered to " + request); setLight.Send(); SmartLightManager.UpdateLightState(1); }
void Update() { if (Input.GetKeyDown("q")) { SmartLightManager.lights[0].State.Bri = 200; SmartLightManager.UpdateLightState(0); Notification notification = new Notification("error", "There was an error with the app startup state."); NotificationManager.DisplayNotification(notification); } if (Input.GetKeyDown("w")) { SmartLightManager.lights[0].State.Bri = 155; SmartLightManager.UpdateLightState(0); Notification notification = new Notification("alert", "Please press the link button on your Bridge and try again."); NotificationManager.DisplayNotification(notification); } }
void buildUpdateCall(string param, int value) { var focusedObject = GestureManager.Instance.FocusedObject; //Debug.Log("here is focused object: " + focusObject); //if (focusObject != null) //{ // slm.UpdateLightState(focusObject.name, param, value); // //SmartLightManager.light //} if (focusedObject != null) { // retrieves array index (arrayId) from the tag assigned in SmartLightManager if (focusedObject.tag != "Untagged") { var idTag = focusedObject.tag; //// Ignores focusedObject if it does not have a valid id assigned to tag if (int.TryParse(idTag, out arrayId)) { currentLight = SmartLightManager.lights[arrayId]; if (param == "On") { currentLight.State.On = true; } else if (param == "Off") { currentLight.State.On = false; } else if (param == "hue") { // auto sets saturation to full to show vibrant colors. Will replace when Saturation UI is added in another version currentLight.State.Sat = 254; currentLight.State.Hue = value; if (voiceChangedColor != null) { // arrayID is adjusted to compensate for diff in Hue id voiceChangedColor(arrayId + 1, ColorService.GetColorByHue(value)); } } else if (param == "bri") { currentLight.State.Bri = value; } else if (param == "alert") { if (value == 0) { currentLight.State.Alert = "none"; } else { currentLight.State.Alert = "lselect"; } } // hueAPI.UpdateLight(currentLight); SmartLightManager.UpdateLightState(arrayId); currentLight.State.Alert = "none"; } else { Debug.Log("a tag with a valid array index (arrayId) could not be found on focusedObject"); } } else { Debug.Log("No tag containing arrayId was found on this focusedObject."); } } }
public void RegisterPhrases() { // called outside of Start() to ensure the SmartLightManager has been loaded first slm = hologramCollection.GetComponent <SmartLightManager>(); keywords = new Dictionary <string, System.Action>(); /// <summary> /// Global systemwide voice commands /// </summary> /// // shows and hides the Voice Command Board with keyPhrases and associated actions keywords.Add("Show Voice Commands", () => { SendMessage("OpenVCBoard", SendMessageOptions.DontRequireReceiver); }); keywords.Add("Show The Voice Commands", () => { SendMessage("OpenVCBoard", SendMessageOptions.DontRequireReceiver); }); keywords.Add("Show Voice Command Menu", () => { SendMessage("OpenVCBoard", SendMessageOptions.DontRequireReceiver); }); keywords.Add("Show Voice Menu", () => { SendMessage("OpenVCBoard", SendMessageOptions.DontRequireReceiver); }); // Hides Voice Command Board keywords.Add("Hide Voice Commands", () => { SendMessage("CloseVCBoard", SendMessageOptions.DontRequireReceiver); }); keywords.Add("Hide The Voice Commands", () => { SendMessage("CloseVCBoard", SendMessageOptions.DontRequireReceiver); }); keywords.Add("Hide Voice Command Menu", () => { SendMessage("CloseVCBoard", SendMessageOptions.DontRequireReceiver); }); keywords.Add("Hide Voice Menu", () => { SendMessage("CloseVCBoard", SendMessageOptions.DontRequireReceiver); }); // Repositions the Voice Command Board in front of user keywords.Add("Reposition Voice Commands", () => { SendMessage("ResetVCBoardPosition", SendMessageOptions.DontRequireReceiver); }); // reset app back to starting state keywords.Add("Reset And Search For Bridge", () => { SendMessage("RetrySetup", SendMessageOptions.DontRequireReceiver); }); keywords.Add("Reset And Search For A Bridge", () => { SendMessage("RetrySetup", SendMessageOptions.DontRequireReceiver); }); keywords.Add("Try Searching Again", () => { SendMessage("RetrySetup", SendMessageOptions.DontRequireReceiver); }); // opens the main menu of the app keywords.Add("Show Main Menu", () => { SendMessage("InitMainMenu", SendMessageOptions.DontRequireReceiver); }); keywords.Add("Show The Main Menu", () => { SendMessage("InitMainMenu", SendMessageOptions.DontRequireReceiver); }); // closes the main menu of the app keywords.Add("Hide Main Menu", () => { NotificationManager.Instance.DismissAction();; }); keywords.Add("Hide The Main Menu", () => { NotificationManager.Instance.DismissAction(); }); keywords.Add("Dismiss Menu", () => { NotificationManager.Instance.DismissAction(); }); // runs a search function to discover Hue Bridges on the same network. keywords.Add("Check For A Bridge", () => { SendMessage("RecheckOrGetBridgeIP", SendMessageOptions.DontRequireReceiver); }); // runs a search for existing usernames associated with the Bridge ip. If none are found, creates one. keywords.Add("Link To Bridge", () => { SendMessage("RecheckOrCreateBridgeUser", SendMessageOptions.DontRequireReceiver); }); // Changes current state of app. The Configuration state displays all found lights and their position keywords.Add("Configure Room", () => { StateManager.Instance.CurrentState = StateManager.HueAppState.Configuring; }); keywords.Add("Configure The Room", () => { StateManager.Instance.CurrentState = StateManager.HueAppState.Configuring; }); keywords.Add("Setup The Room", () => { StateManager.Instance.CurrentState = StateManager.HueAppState.Configuring; }); keywords.Add("Show All Lights", () => { StateManager.Instance.CurrentState = StateManager.HueAppState.Configuring; }); // Changes current state of app. Saves configuration and switches back into main mode - Ready keywords.Add("Save The Room", () => { StateManager.Instance.CurrentState = StateManager.HueAppState.Ready; }); keywords.Add("Save Room", () => { StateManager.Instance.CurrentState = StateManager.HueAppState.Ready; }); keywords.Add("Hide All Lights", () => { StateManager.Instance.CurrentState = StateManager.HueAppState.Ready; }); /// <summary> /// Collection of lights voice commands /// </summary> /// // resets all lights back to default hue, full saturation, and full brightness. keywords.Add("Normal Lights", () => { SmartLightManager.Instance.SetLightsToDefault(); }); keywords.Add("Normal Lighting", () => { SmartLightManager.Instance.SetLightsToDefault(); }); keywords.Add("Reset Lights", () => { SmartLightManager.Instance.SetLightsToDefault(); }); keywords.Add("Reset Lighting", () => { SmartLightManager.Instance.SetLightsToDefault(); }); keywords.Add("Regular Lights", () => { SmartLightManager.Instance.SetLightsToDefault(); }); keywords.Add("Regular Lighting", () => { SmartLightManager.Instance.SetLightsToDefault(); }); keywords.Add("Natural Lights", () => { SmartLightManager.Instance.SetLightsToDefault(); }); keywords.Add("Natural Lighting", () => { SmartLightManager.Instance.SetLightsToDefault(); }); // turns off all available lights keywords.Add("Turn Off All Light", () => { SmartLightManager.Instance.TurnOffAllLights(); }); keywords.Add("Turn Off The Lights", () => { SmartLightManager.Instance.TurnOffAllLights(); }); // turns on all available lights keywords.Add("Turn On All Light", () => { SmartLightManager.Instance.TurnOnAllLights(); }); keywords.Add("Turn On The Lights", () => { SmartLightManager.Instance.TurnOnAllLights(); }); // sets all available lights' brightness to dim value keywords.Add("Dim All Lights", () => { SmartLightManager.Instance.DimAllLights(); }); keywords.Add("Dim All The Lights", () => { SmartLightManager.Instance.DimAllLights(); }); // sets all available lights' brightness to full value keywords.Add("Undim All Lights", () => { SmartLightManager.Instance.UndimAllLights(); }); keywords.Add("Undim All The Lights", () => { SmartLightManager.Instance.UndimAllLights(); }); foreach (string color in colorList) { string colorCommand = "Turn All Lights " + color; keywords.Add(colorCommand, () => { int hue; hue = ColorService.GetHueByColor(color); SmartLightManager.Instance.TurnAllLightsToColor(hue); }); } /// <summary> /// Individual light voice commands /// </summary> /// // On/Off commands keywords.Add("Light On", () => { buildUpdateCall("On", 0); }); keywords.Add("Turn On", () => { buildUpdateCall("On", 0); }); keywords.Add("Light Off", () => { buildUpdateCall("Off", 0); }); keywords.Add("Turn Off", () => { buildUpdateCall("Off", 0); }); // color change commands foreach (string color in colorList) { string colorCommand = "Turn Light " + color; keywords.Add(colorCommand, () => { int hue; hue = ColorService.GetHueByColor(color); buildUpdateCall("hue", hue); }); } foreach (string color in colorList) { string colorCommand = "Set To " + color; keywords.Add(colorCommand, () => { int hue; hue = ColorService.GetHueByColor(color); buildUpdateCall("hue", hue); }); } // Brightness adjustment commands keywords.Add("Dim Light", () => { buildUpdateCall("bri", dimValue); }); keywords.Add("Dim The Light", () => { buildUpdateCall("bri", dimValue); }); keywords.Add("Dim Light More", () => { buildUpdateCall("bri", dimMoreValue); }); keywords.Add("Full Brightness", () => { buildUpdateCall("bri", 254); }); keywords.Add("Undim the light", () => { buildUpdateCall("bri", 254); }); // flashes the corresponding light of the currently focused gameObject keywords.Add("Identify Light", () => { buildUpdateCall("alert", 1); }); keywords.Add("What Light Am I", () => { buildUpdateCall("alert", 1); }); // stops flashing of light prior to 15 second default time keywords.Add("OK That's Enough", () => { buildUpdateCall("alert", 0); }); keywords.Add("That's Enough", () => { buildUpdateCall("alert", 0); }); keywords.Add("Stop Blinking", () => { buildUpdateCall("alert", 0); }); /// <summary> /// Hotspots Commands /// </summary> /// keywords.Add("Easter Egg", () => { HotspotManager.Instance.EnableHotspots(); }); // Deactivates hotspots and removes all hotspot gameObjects keywords.Add("Destroy Easter Egg", () => { HotspotManager.Instance.DisableHotspots(); }); // Shows all hotspots by enabling their mesh keywords.Add("Show All Hot Spots", () => { HotspotManager.Instance.ShowAllHotspots(); }); // Hides all hotspots by disabling their mesh keywords.Add("Hide All Hot Spots", () => { HotspotManager.Instance.HideAllHotspots(); }); /// <summary> /// "Gaze it say it" commands /// </summary> /// keywords.Add("Tutorial", () => { // TODO make a more robust and less brittle solution if (MenuStateManager.Instance.CurrentState == mainMenuRef) { bool hitMenuWrapper; hitMenuWrapper = raycastHitMenuWrapper(); if (hitMenuWrapper) { NotificationManager.Instance.TutorialAction(); } } }); keywords.Add("Next", () => { // TODO make a more robust and less brittle solution if (MenuStateManager.Instance.CurrentState == linkSuccessRef || MenuStateManager.Instance.CurrentState == identifyRef || MenuStateManager.Instance.CurrentState == tt_interactionsRef || MenuStateManager.Instance.CurrentState == tt_voiceRef || MenuStateManager.Instance.CurrentState == tt_gestureRef) { bool hitMenuWrapper; hitMenuWrapper = raycastHitMenuWrapper(); if (hitMenuWrapper) { NotificationManager.Instance.NextAction(); } } }); keywords.Add("Back", () => { // TODO make a more robust and less brittle solution if (MenuStateManager.Instance.CurrentState == identifyRef || MenuStateManager.Instance.CurrentState == repeatRef || MenuStateManager.Instance.CurrentState == tt_voiceRef || MenuStateManager.Instance.CurrentState == tt_gestureRef || MenuStateManager.Instance.CurrentState == tt_hotspotRef) { bool hitMenuWrapper; hitMenuWrapper = raycastHitMenuWrapper(); if (hitMenuWrapper) { NotificationManager.Instance.BackAction(); } } }); keywords.Add("Finish Tutorial", () => { // TODO make a more robust and less brittle solution if (MenuStateManager.Instance.CurrentState == tt_hotspotRef) { bool hitMenuWrapper; hitMenuWrapper = raycastHitMenuWrapper(); if (hitMenuWrapper) { NotificationManager.Instance.FinishAction(); } } }); keywords.Add("Setup", () => { // TODO make a more robust and less brittle solution if (MenuStateManager.Instance.CurrentState == mainMenuRef) { bool hitMenuWrapper; hitMenuWrapper = raycastHitMenuWrapper(); if (hitMenuWrapper) { NotificationManager.Instance.SetupAction(); } } }); keywords.Add("Save Configuration", () => { // TODO make a more robust and less brittle solution if (MenuStateManager.Instance.CurrentState == repeatRef) { bool hitMenuWrapper; hitMenuWrapper = raycastHitMenuWrapper(); if (hitMenuWrapper) { NotificationManager.Instance.SaveAction(); } } }); /// <summary> /// Hidden color commands /// </summary> /// // Easter Egg color themes by keyPhrase keywords.Add("Set To Disco", () => { string[] themeColors = new string[5]; themeColors[0] = "Blue"; themeColors[1] = "Pink"; themeColors[2] = "Red"; themeColors[3] = "Yellow"; themeColors[4] = "Orange"; SmartLightManager.Instance.ColorTheme(themeColors, true); }); // Tell the KeywordRecognizer about our keywords. keywordRecognizer = new KeywordRecognizer(keywords.Keys.ToArray()); // Register a callback for the KeywordRecognizer and start recognizing! keywordRecognizer.OnPhraseRecognized += KeywordRecognizer_OnPhraseRecognized; keywordRecognizer.Start(); }
public void RegisterPhrases() { // called outside of Start() to ensure the SmartLightManager has been loaded first slm = hologramCollection.GetComponent <SmartLightManager>(); keywords = new Dictionary <string, System.Action>(); // Global light commands keywords.Add("Normal Lights", () => { slm.SetLightsToDefault(); }); // On/Off commands keywords.Add("Light On", () => { buildUpdateCall("On", 0); }); keywords.Add("Light Off", () => { buildUpdateCall("Off", 0); }); // color change commands keywords.Add("Set To Red", () => { int hue; hue = ColorService.GetHueByColor("Red"); buildUpdateCall("hue", hue); }); keywords.Add("Set To Orange", () => { int hue; hue = ColorService.GetHueByColor("Orange"); buildUpdateCall("hue", hue); }); keywords.Add("Set To Yellow", () => { int hue; hue = ColorService.GetHueByColor("Yellow"); buildUpdateCall("hue", hue); }); keywords.Add("Set To Green", () => { int hue; hue = ColorService.GetHueByColor("Green"); buildUpdateCall("hue", hue); }); keywords.Add("Set To White", () => { int hue; hue = ColorService.GetHueByColor("White"); buildUpdateCall("hue", hue); }); keywords.Add("Set To Blue", () => { int hue; hue = ColorService.GetHueByColor("Blue"); buildUpdateCall("hue", hue); }); keywords.Add("Set To Purple", () => { int hue; hue = ColorService.GetHueByColor("Purple"); buildUpdateCall("hue", hue); }); keywords.Add("Set To Pink", () => { int hue; hue = ColorService.GetHueByColor("Pink"); buildUpdateCall("hue", hue); }); // Brightness adjustment commands keywords.Add("Dim Light", () => { buildUpdateCall("bri", dimValue); }); keywords.Add("Dim Light More", () => { buildUpdateCall("bri", dimMoreValue); }); keywords.Add("Full Brightness", () => { buildUpdateCall("bri", 254); }); // flashes the corresponding light of the currently focused gameObject keywords.Add("Identify Light", () => { buildUpdateCall("alert", 1); }); // stops flashing of light prior to 15 second default time keywords.Add("OK That's Enough", () => { buildUpdateCall("alert", 0); }); // system voice commands keywords.Add("Show Voice Menu", () => { //showVCMenu(true); }); keywords.Add("Hide Voice Menu", () => { //showVCMenu(false); }); // Tell the KeywordRecognizer about our keywords. keywordRecognizer = new KeywordRecognizer(keywords.Keys.ToArray()); // Register a callback for the KeywordRecognizer and start recognizing! keywordRecognizer.OnPhraseRecognized += KeywordRecognizer_OnPhraseRecognized; keywordRecognizer.Start(); // populates voice control help menu with available commands //buildMenu(keywords); }
void buildUpdateCall(string param, int value) { var focusedObject = GestureManager.Instance.FocusedObject; //Debug.Log("here is focused object: " + focusObject); //if (focusObject != null) //{ // slm.UpdateLightState(focusObject.name, param, value); // //SmartLightManager.light //} if (focusedObject != null) { // retrieves array index (arrayId) from the tag assigned in SmartLightManager if (focusedObject.tag != "Untagged") { var idTag = focusedObject.tag; //// Ignores focusedObject if it does not have a valid id assigned to tag if (int.TryParse(idTag, out arrayId)) { currentLight = SmartLightManager.lights[arrayId]; if (param == "On") { currentLight.State.On = true; } else if (param == "Off") { currentLight.State.On = false; } else if (param == "hue") { currentLight.State.Hue = value; currentLight.State.Sat = 254; } else if (param == "bri") { currentLight.State.Bri = value; } else if (param == "alert") { if (value == 0) { currentLight.State.Alert = "none"; } else { currentLight.State.Alert = "lselect"; } } // hueAPI.UpdateLight(currentLight); SmartLightManager.UpdateLightState(arrayId); currentLight.State.Alert = "none"; } else { Debug.Log("a tag with a valid array index (arrayId) could not be found on focusedObject"); } } else { Debug.Log("No tag containing arrayId was found on this focusedObject."); } } }