// Called when the HueBridgeManager has gathered all light info and created a list of SmartLights public static void InitLightUI() { foreach (SmartLight sl in SmartLightManager.lights) { lightUIs.Add(new LightUI(sl.ID, false, ColorService.GetColorByHue(sl.State.Hue), sl.State.Bri, sl.Name)); } }
public void initColors(List <SmartLight> sls) { foreach (SmartLight sl in sls) { lightUIs.Add(new LightUI(sl.ID, false, ColorService.GetColorByHue(sl.State.Hue), sl.State.Bri, sl.Name)); updateLightUI(sl.ID, sl.State); } }
private void UpdateSmartLightUI(SmartLight sl) { if (sl.Name == gameObject.name) { Renderer rend = gameObject.GetComponent <Renderer>(); Vector4 ledColor = ColorService.GetColorByHue(sl.State.Hue); rend.material.color = ledColor; } }
// creates smart light game objects and sets color of prefab void InstantiateLights() { lightPrefab = (GameObject)Resources.Load("Prefabs/SmartBulb"); holoLightContPrefab = (GameObject)Resources.Load("Prefabs/HoloLightContainer"); // Vector3 camPos = Camera.main.transform.position; // where to spawn unassigned SmartBulb GameObjects in relation to the user's current position Vector3 pos = new Vector3(-1, 0, 2); // Quaternion rotation = Quaternion.FromToRotation(Vector3.forward, camPos); foreach (SmartLight light in lights) { var lightObject = Instantiate(lightPrefab, pos, Quaternion.identity); lightObject.name = light.Name; // gets newly instantiated GameObject and sets to child of Parent GameObject GameObject currentLight = GameObject.Find(light.Name); currentLight.transform.parent = gameObject.transform; Vector3 lightContainerPos = new Vector3(pos.x, lightContainerOffset * currentLight.transform.localScale.y, pos.z); var lightContObject = Instantiate(holoLightContPrefab, lightContainerPos, Quaternion.identity); // assigns light ID to tag for easier interating downstream. var lightIDOffset = light.ID - 1; currentLight.tag = lightIDOffset.ToString(); lightContObject.tag = lightIDOffset.ToString(); lightContObject.transform.parent = currentLight.transform; // sets color of light prefab based on current light hue state Renderer rend = currentLight.GetComponent <Renderer>(); Vector4 ledColor = ColorService.GetColorByHue(light.State.Hue); rend.material.color = ledColor; if (!StateManager.Instance.Configuring && !StateManager.Instance.SetupMode) { rend.enabled = false; } // increments x value to space out spawned prefabs that have no Anchor Store entry. pos += new Vector3(0.5f, 0, 0); // TODO see if this call is needed. Real lights should already be these values //hueAPI.UpdateLight(light); } EventManager.TriggerEvent("SmartLightManagerReady"); if (StateManager.Instance.SetupMode) { configureLights(); } else { StateManager.Instance.CurrentState = StateManager.HueAppState.Ready; } }
void Start() { foreach (SmartLight sl in SmartLightManager.lights) { // gets each light's current color for use on indicator arrow var currentColor = ColorService.GetColorByHue(sl.State.Hue); directionIndicatorColor = currentColor; // set the arrow to the current light color updateArrowColor(sl.ID, currentColor); } }
void OnEnable() { rend = GetComponent <Renderer>(); LightUIManager.colorChanged += updateMaterial; parentTag = transform.parent.tag; if (parentTag != "Untagged") { int tagId = int.Parse(parentTag); int currentHue = SmartLightManager.lights[tagId].State.Hue; updateMaterial(tagId, ColorService.GetColorByHue(currentHue)); } }
void OnEnable() { VoiceManager.voiceChangedColor += PerformRotation; // perform rotation any time this orb is selected and the UI is opened grandparentTag = gameObject.transform.parent.transform.parent.tag; if (grandparentTag != "Untagged") { int tagId = int.Parse(grandparentTag); int currentHue = SmartLightManager.lights[tagId].State.Hue; Color currentColor = ColorService.GetColorByHue(currentHue); bypassTransition = true; PerformRotation(tagId + 1, currentColor); } }
// sets color of light prefab based on current light hue state public void UpdateOrbColor(int id, State state) { foreach (Transform child in transform) { if (child.tag != "Untagged") { var idTag = child.tag; // Ignores objects that do not have a valid id assigned to tag if (int.TryParse(idTag, out arrayId)) { // adjusted arrayId to compensate for Hue starting index at 1 if ((arrayId + 1) == id) { Renderer rend = child.GetComponent <Renderer>(); Vector4 ledColor = ColorService.GetColorByHue(state.Hue); rend.material.color = ledColor; } } } } }
void updateMaterial(int id, Color color) { if (rend != null) { currentColor = rend.material.color; // if transition is already active, we discard the previous transition before we start a new one if (transitionInProgress) { StopCoroutine(coroutine); } transitionInProgress = true; coroutine = StartCoroutine(LerpColor(color, transitionTime)); } else { if (transform.parent.tag != "Untagged") { var idTag = transform.parent.tag; // Ignores objects that do not have a valid id assigned to tag if (int.TryParse(idTag, out arrayId)) { // adjusted arrayId to compensate for Hue starting index at 1 if ((arrayId + 1) == id) { var currentHue = SmartLightManager.lights[arrayId].State.Hue; currentColor = ColorService.GetColorByHue(currentHue); } } } else { Debug.Log("No tag containing arrayId was found on parent."); } } }
private void updateLightUI(int id, State state) { // ajustment needed to compensate for difference in light.ID and array index int adjustedId = id - 1; LightUI currentUI = lightUIs[adjustedId]; if (currentUI.OrbColor.Equals(ColorService.GetColorByHue(state.Hue))) { Debug.Log("The orb color has not changed"); } else { currentUI.OrbColor = ColorService.GetColorByHue(state.Hue); if (colorChanged != null) { colorChanged(currentUI.LightID, currentUI.OrbColor); } UpdateOrbColor(id, state); } if (currentUI.Brightness == state.Bri) { } else { currentUI.Brightness = state.Bri; if (brightnessChanged != null) { brightnessChanged(currentUI.LightID, currentUI.Brightness); } } if (state.Alert == "lselect") { MakeOrbBlink(id); } }
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."); } } }