public void toggleCurtainsOf(CurtainController controller) { if (areCurtainsOpenOf(controller)) { controller.CloseCurtains(false); } else { controller.OpenCurtains(false); } }
public void SwitchCurtainOnRoom(CurtainController curController) { // switch all the curtains connected to the curtain controller foreach (CurtainController curtainController in curtainControllers) { if (curtainController == curController) { if (!CheckIfCurtainsAreOpen(curtainController)) { curtainController.OpenCurtains(false); } else { curtainController.CloseCurtains(false); } } } }
public bool CheckIfCurtainsAreOpen(CurtainController curtainController) { //if more than 50 % of the curtains are open this will return true float totalCurtains = 0.0f; float totalEnabled = 0.0f; foreach (GameObject curtain in curtainController.curtains) { totalCurtains += 1.0f; if (curtain.GetComponent <CurtainInteractable>().isActive()) { totalEnabled += 1.0f; } } if (totalEnabled >= Mathf.Ceil(totalCurtains / 2.0f)) { return(true); } else { return(false); } }
private void CreateButtons(System.Type type) { // position of starting button float x = 47.65f; float a = 30.64f; if (type == typeof(string)) { // Create buttons in the main menu panel with domotica List <string> tempDomotica = domoticaController.GetListDomotica(); for (int i = 0; i < tempDomotica.Count; i++) { int z = i; GameObject butn = Instantiate(buttonPrefab) as GameObject; butn.transform.SetParent(mainMenuPanel.transform, false); butn.transform.localPosition = new Vector3(0, (x - (a * z)), 0); butn.GetComponentInChildren <Text>().text = tempDomotica[i]; butn.GetComponent <Button>().onClick.AddListener(() => SwitchPanel(tempDomotica[z])); buttonListMainMenu.Add(butn); } } if (type == typeof(LightController)) { // Create buttons of all lightcontrollers with the check "show controller in mobile" lightControllers = new LightController[domoticaController.GetListLights().Length]; lightControllers = domoticaController.GetListLights(); int z = 0; for (int i = 0; i < lightControllers.Length; i++) { int p = i; if (lightControllers[i].ShowControllerInMobile == true) { GameObject butn = Instantiate(toggleButtonPrefab) as GameObject; butn.transform.SetParent(lightMenuPanel.transform, false); butn.transform.localPosition = new Vector3(0, (x - (a * z)), 0); butn.GetComponentInChildren <Text>().text = lightControllers[i].controllerName; if (butn != null) { on = butn.transform.Find("Toggle/ON"); off = butn.transform.Find("Toggle/OFF"); } on.GetComponent <Text>().text = "Aan"; off.GetComponent <Text>().text = "Uit"; ButtonOnOff = butn.transform.Find("Toggle/Button"); ButtonOnOff.GetComponent <Button>().onClick.AddListener(() => SwitchLights(lightControllers[p])); buttonDictLightsMenu.Add(butn, lightControllers[p]); z += 1; } } } if (type == typeof(CurtainController)) { // Create buttons of all curtaincontrollers with the check "show controller in mobile" CurtainController[] curtainControllers = new CurtainController[domoticaController.GetListCurtains().Length]; curtainControllers = domoticaController.GetListCurtains(); for (int i = 0; i < curtainControllers.Length; i++) { int z = i; GameObject butn = Instantiate(toggleButtonPrefab) as GameObject; butn.transform.SetParent(curtainMenuPanel.transform, false); butn.transform.localPosition = new Vector3(0, (x - (a * i)), 0); butn.GetComponentInChildren <Text>().text = curtainControllers[i].controllerName; if (butn != null) { on = butn.transform.Find("Toggle/ON"); off = butn.transform.Find("Toggle/OFF"); } on.GetComponent <Text>().text = "Open"; off.GetComponent <Text>().text = "Dicht"; ButtonOnOff = butn.transform.Find("Toggle/Button"); ButtonOnOff.GetComponent <Button>().onClick.AddListener(() => SwitchCurtains(curtainControllers[z])); buttonDictCurtainMenu.Add(butn, curtainControllers[z]); } } if (type == typeof(InfraredController)) { // Create buttons of all infraredcontrollers with the check "show controller in mobile" InfraredController[] infraredControllers = new InfraredController[domoticaController.GetListInfrared().Length]; infraredControllers = domoticaController.GetListInfrared(); for (int i = 0; i < infraredControllers.Length; i++) { int z = i; GameObject butn = Instantiate(toggleButtonPrefab) as GameObject; butn.transform.SetParent(infraredMenuPanel.transform, false); butn.transform.localPosition = new Vector3(0, (x - (a * i)), 0); butn.GetComponentInChildren <Text>().text = infraredControllers[i].controllerName; if (butn != null) { on = butn.transform.Find("Toggle/ON"); off = butn.transform.Find("Toggle/OFF"); } on.GetComponent <Text>().text = "Aan"; off.GetComponent <Text>().text = "Uit"; ButtonOnOff = butn.transform.Find("Toggle/Button"); ButtonOnOff.GetComponent <Button>().onClick.AddListener(() => SwitchInfrared(infraredControllers[z])); buttonDictInfraredMenu.Add(butn, infraredControllers[z]); } } }
private void SwitchCurtains(CurtainController curtainController) { domoticaController.toggleCurtainsOf(curtainController); }
private void SwitchCurtains(CurtainController curtainController) { domoticaController.GetComponent <DomoticaController>().SwitchCurtainOnRoom(curtainController); }