private void Update() { if (Input.GetMouseButtonDown(0)) { float surfaceValue = 0f; SetSunOnClick(); sunCoordinates = ConsoleInputs.BuildingData.sunCoordinates; numOfBuildings = ConsoleInputs.BuildingData.numOfBuildings; buildingData = ConsoleInputs.BuildingData.buildingData; ConsoleInputs.SetSun(sunCoordinates); bisectionPoint = Bisection(); print("bisectionPoint" + bisectionPoint); leftPart = bisectionPoint == 0 ? false : true; rightPart = bisectionPoint == numOfBuildings - 1 ? false : true; GameObject[] OldLines1 = GameObject.FindGameObjectsWithTag("LinesOnGround"); for (int i = 0; i < OldLines1.Length; i++) { Destroy(OldLines1[i]); } GameObject[] OldLines = GameObject.FindGameObjectsWithTag("Lines"); for (int i = 0; i < OldLines.Length; i++) { Destroy(OldLines[i]); } surfaceValue = CalculateSurface(); OutputText.text = "Length of surface exposed to sunlight " + Convert.ToString(surfaceValue); } }
public void SetInputsFromList(List <InputData> inputList) { ConsoleInputs.Clear(); for (int i = 0; i < inputList.Count; i++) { InputData inputData = inputList[i]; ConsoleInputs[inputData.Name] = inputData; } UpdateInputRegex(); }
/// <summary> /// Tells if a given button value exists and returns it if so. /// </summary> /// <param name="buttonName">The name of the button to get the value for.</param> /// <param name="inputButton">The returned InputButton if found.</param> /// <returns>true if an enabled button with the given name exists, otherwise false.</returns> public bool GetButtonValue(string buttonName, out InputButton inputButton) { if (ConsoleInputs.TryGetValue(buttonName, out InputData inputData) == false || inputData.Enabled == 0 || EnumUtility.HasEnumVal((long)inputData.InputType, (long)InputTypes.Button) == false) { inputButton = default; return(false); } inputButton = new InputButton((uint)inputData.ButtonValue); return(true); }
/// <summary> /// Tells if a given axis value exists and returns it if so. /// </summary> /// <param name="axisName">The name of the axis to get the value for.</param> /// <param name="inputAxis">The returned InputAxis if found.</param> /// <returns>true if an enabled axis with the given name exists, otherwise false.</returns> public bool GetAxisValue(string axisName, out InputAxis inputAxis) { if (ConsoleInputs.TryGetValue(axisName, out InputData inputData) == false || inputData.Enabled == 0 || EnumUtility.HasEnumVal((long)inputData.InputType, (long)InputTypes.Axis) == false) { inputAxis = default; return(false); } inputAxis = new InputAxis(inputData.AxisValue, inputData.MinAxisVal, inputData.MaxAxisVal, inputData.MaxAxisPercent); return(true); }
/// <summary> /// Removes an input from the console. /// This updates the input regex if removed. /// </summary> /// <param name="inputName">The name of the input to remove.</param> /// <returns>true if the input was removed, otherwise false.</returns> public bool RemoveInput(string inputName) { bool removed = ConsoleInputs.Remove(inputName); if (removed == true) { int index = InputList.FindIndex((inpData) => inpData.Name == inputName); InputList.RemoveAt(index); UpdateInputRegex(); } return(removed); }
/// <summary> /// Adds an input to the console. If the input already exists, it will be updated with the new value. /// This updates the input regex if the input did not previously exist. /// </summary> /// <param name="inputName">The name of the input to add.</param> /// <param name="inputData">The data corresponding to the input.</param> /// <returns>true if the input was added, otherwise false.</returns> public bool AddInput(string inputName, InputData inputData) { bool existed = ConsoleInputs.ContainsKey(inputName); ConsoleInputs[inputName] = inputData; if (existed == false) { InputList.Add(inputData); UpdateInputRegex(); } else { int index = InputList.FindIndex((inpData) => inpData.Name == inputName); InputList.RemoveAt(index); InputList.Add(inputData); } return(true); }
/// <summary> /// Tells if a given input exists and is enabled for this console. /// </summary> /// <param name="inputName">The name of the input.</param> /// <returns>true if the input name is a valid input and the input is enabled, otherwise false.</returns> public bool IsInputEnabled(string inputName) { ConsoleInputs.TryGetValue(inputName, out InputData inputData); return(inputData != null && inputData.Enabled != 0); }
/// <summary> /// Tells if a given input exists for this console. /// </summary> /// <param name="inputName">The name of the input.</param> /// <returns>true if the input name is a valid input, otherwise false.</returns> public bool DoesInputExist(string inputName) { return(ConsoleInputs.ContainsKey(inputName)); }
public static void DrawPolygon() { PointStatic.transform.position = PolygonData.pointCoordinates; ConsoleInputs.PolygonData.polygonData = new Vector2[PolygonData.numOfVertices]; ConsoleInputs.PolygonCoordinates(); }
public static void DrawBuilding() { SunStatic.transform.position = BuildingData.sunCoordinates; ConsoleInputs.BuildingData.buildingData = new Vector2[BuildingData.numOfBuildings, 4]; ConsoleInputs.BuildingCoordinates(); }
public void RetrieveCmd() { List <string> cmd = new List <string>(); string temp = inputField.text.ToString(); inputField.text = ""; cmd.Add(temp); //Debug.Log(cmd[0]); switch (ConsoleInputs.option) { case (1): int numOfVertices; switch (it) { case (0): temp = temp.Replace("], [", " ").Replace("],", " ").Replace("[", "").Replace("]", "").Trim(); temp = Regex.Replace(temp, @"\s+", " "); string[] coordinates = temp.Split(' '); numOfVertices = coordinates.Length; ConsoleInputs.PolygonData.numOfVertices = numOfVertices; if (numOfVertices >= 3) { currText.text = "Enter the coordinates of the point ( X and Y separated by a comma)"; ConsoleInputs.PolygonData.polygonDataRaw = temp.Split(' '); defaultOptions1.SetActive(false); } else { currText.text = "Error: Wrong number of coordinates ( enter atleast three coordinates ) or wrong format, try again ( Tip: Use the format given in default options )"; it--; } break; case (1): string[] coord; float coordX, coordY; if (temp != "") { temp = temp.Replace("[", "").Replace("]", ""); coord = temp.Split(','); coordX = Convert.ToSingle(coord[0]); coordY = Convert.ToSingle(coord[1]); ConsoleInputs.PolygonData.pointCoordinates = new Vector2(coordX, coordY); //Debug.Log(ConsoleInputs.PolygonData.pointCoordinates); } else if (temp == "") { ConsoleInputs.PolygonData.pointCoordinates = new Vector2(1, 1); } SimulationMode.SetActive(true); IO.SetActive(false); resetButton.SetActive(true); ConsoleInputs.DrawPolygon(); break; } break; case (2): int numOfBuildings; switch (it) { case (0): if (temp != "") { temp = temp.Replace("]], [[", " ").Replace("]],", " ").Replace("],[", " ").Replace("[", "").Replace("]", "").Trim(); temp = Regex.Replace(temp, @"\s+", " "); string[] coordinates = temp.Split(' '); if (coordinates.Length % 4 == 0 && coordinates.Length >= 4) { defaultOptions2.SetActive(false); numOfBuildings = coordinates.Length / 4; ConsoleInputs.BuildingData.numOfBuildings = numOfBuildings; ConsoleInputs.BuildingData.buildingDataRaw = coordinates; currText.text = "Enter the coordinates of the light source ( X and Y separated by a comma) ( Default [1,1] )"; } else { currText.text = "Wrong number of coordinates or wrong format, please try again. ( Tip: Use the format given in default options )"; it--; } } else { currText.text = "Wrong number of coordinates or wrong format, please try again. ( Tip: Use the format given in default options )"; it--; } break; case (1): string[] coord; float coordX, coordY; if (temp != "") { temp = temp.Replace("[", "").Replace("]", ""); coord = temp.Split(','); coordX = Convert.ToSingle(coord[0]); coordY = Convert.ToSingle(coord[1]); ConsoleInputs.BuildingData.sunCoordinates = new Vector2(coordX, coordY); } else { ConsoleInputs.BuildingData.sunCoordinates = new Vector2(1, 1); } SimulationMode.SetActive(true); // Debug.Log(ConsoleInputs.BuildingData.sunCoordinates); IO.SetActive(false); resetButton.SetActive(true); ConsoleInputs.DrawBuilding(); break; //case(3): } break; case (3): temp = temp.Replace("], [", " ").Replace("],", " ").Replace("[", "").Replace("]", "").Trim(); temp = Regex.Replace(temp, @"\s+", " "); string[] CircleDataRaw = temp.Split(','); float X, Y; X = Convert.ToSingle(CircleDataRaw[0]); Y = Convert.ToSingle(CircleDataRaw[1]); InstantiateCircle.circlePos = new Vector2(X, Y); InstantiateCircle.radius = Convert.ToSingle(CircleDataRaw[2]); InstantiateCircle.angle = Convert.ToSingle(CircleDataRaw[3]); InstantiateCircle.clearance = Convert.ToSingle(CircleDataRaw[4]); InstantiateCircle.lineLength = Convert.ToDouble(CircleDataRaw[5]); if (CircleDataRaw.Length == 6) { it++; input[0].text = X + ", " + Y; input[1].text = CircleDataRaw[2]; input[2].text = CircleDataRaw[3]; input[3].text = CircleDataRaw[4]; input[4].text = CircleDataRaw[5]; SimulationMode.SetActive(true); IO.SetActive(false); OutputLeft.SetActive(false); resetButton.SetActive(true); circleChords.SetActive(true); circleChordsCanvas.SetActive(true); } else { currText.text = "Error: Wrong format, use the format from the given in the default option"; it--; } break; } it++; }
public void RetrieveCmd() { List <string> cmd = new List <string>(); string temp = inputField.text.ToString(); inputField.text = ""; cmd.Add(temp); //Debug.Log(cmd[0]); switch (ConsoleInputs.option) { case (1): int numOfVertices; switch (it) { case (0): temp = temp.Replace("], [", " ").Replace("[", "").Replace("]", ""); string[] coordinates = temp.Split(' '); numOfVertices = coordinates.Length; ConsoleInputs.PolygonData.numOfVertices = numOfVertices; if (numOfVertices >= 3) { currText.text = "Enter the coordinates of the point ( X and Y separated by a comma)"; ConsoleInputs.PolygonData.polygonDataRaw = temp.Split(' '); defaultOptions1.SetActive(false); } else { currText.text = "Error: Wrong number of coordinates ( enter atleast three coordinates ) or wrong format, try again ( Tip: Use the format given in default options )"; it--; } //else if (temp == "") //{ // if (7 == numOfVertices) // { // { // string defaultOption = "3.36,6.79 3.49,4.70 1.03,3.44 2.18,1.19 3.72,3.78 6.00,1.78 6.86,3.89"; // print(defaultOption); // ConsoleInputs.PolygonData.polygonDataRaw = defaultOption.Split(' '); // defaultOptions1.SetActive(false); // } // } // else // { // currText.text = "Error: Wrong number of coordinates or wrong format, enter coordinates of " + numOfVertices + " Vertices"; // it--; // } //} // Debug.Log(ConsoleInputs.PolygonData.polygonDataRaw); break; case (1): string[] coord; float coordX, coordY; if (temp != "") { temp = temp.Replace("[", "").Replace("]", ""); coord = temp.Split(','); coordX = Convert.ToSingle(coord[0]); coordY = Convert.ToSingle(coord[1]); ConsoleInputs.PolygonData.pointCoordinates = new Vector2(coordX, coordY); //Debug.Log(ConsoleInputs.PolygonData.pointCoordinates); } else if (temp == "") { ConsoleInputs.PolygonData.pointCoordinates = new Vector2(1, 1); } SimulationMode.SetActive(true); IO.SetActive(false); resetButton.SetActive(true); ConsoleInputs.DrawPolygon(); break; } break; case (2): int numOfBuildings; switch (it) { case (0): if (temp != "") { temp = temp.Replace("]], [[", " ").Replace("],[", " ").Replace("[", "").Replace("]", ""); string[] coordinates = temp.Split(' '); if (coordinates.Length % 4 == 0 && coordinates.Length >= 4) { defaultOptions2.SetActive(false); numOfBuildings = coordinates.Length / 4; ConsoleInputs.BuildingData.numOfBuildings = numOfBuildings; ConsoleInputs.BuildingData.buildingDataRaw = coordinates; currText.text = "Enter the coordinates of the light source ( X and Y separated by a comma) ( Default [1,1] )"; } else { currText.text = "Wrong number of coordinates or wrong format, please try again. ( Tip: Use the format given in default options )"; it--; } } else { currText.text = "Wrong number of coordinates or wrong format, please try again. ( Tip: Use the format given in default options )"; it--; } break; case (1): string[] coord; float coordX, coordY; if (temp != "") { temp = temp.Replace("[", "").Replace("]", ""); coord = temp.Split(','); coordX = Convert.ToSingle(coord[0]); coordY = Convert.ToSingle(coord[1]); ConsoleInputs.BuildingData.sunCoordinates = new Vector2(coordX, coordY); } else { ConsoleInputs.BuildingData.sunCoordinates = new Vector2(1, 1); } SimulationMode.SetActive(true); // Debug.Log(ConsoleInputs.BuildingData.sunCoordinates); IO.SetActive(false); resetButton.SetActive(true); ConsoleInputs.DrawBuilding(); break; //case(3): } break; } it++; }