Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class CalculateController : MonoBehaviour {
- public static void CalculateControl()
- {
- //Creates an instance of Particle for values to be stored in
- Particle values = new Particle();
- //Gets the number of dimentions selected by the user
- int dimentions = System.Convert.ToInt16(UiController.instances.DropBoxDimention.value);
- //No dimention selected
- if (dimentions == 0)
- {
- Debug.Log("No dimention selected");
- return;
- }
- GetInput_Suvat_x(UiController.instances, ref values);
- Debug.Log("x dimention got");
- if (dimentions >= 2)
- {
- GetInput_Suvat_y(UiController.instances, ref values);
- Debug.Log("y dimention got");
- }
- if (dimentions >= 3)
- {
- GetInput_Suvat_z(UiController.instances, ref values);
- Debug.Log("z dimention got");
- }
- GetInput_Misc(UiController.instances, ref values);
- Debug.Log("misc inputs got");
- //Checking if atleast 3 values have been added in all dimentions.
- if (CheckInputs(ref values, dimentions) == true)
- {
- print("Dimentions true");
- values = SuvatSolvers.FindEquation(values);
- if (values.inValidInput == true)
- {
- //Updates the UI elements on screen
- UiController.instances.UpdateUI(values);
- Debug.Log("updating ui");
- }
- else
- {
- string msg = "Input is impossible!";
- Debug.Log(msg);
- }
- }
- else
- {
- print("Dimentions false");
- string msg = "Please enter atleast 3 quantities per dimention";
- Debug.Log(msg);
- }
- }
- public static void GetInput_Suvat_x(UiController Ui, ref Particle values)
- {
- print("Get input");
- //Taking the input from the user and storing it in the corresponding variable inside the list
- if (Ui.InputField_s_x.text == "")
- {
- values.Key[0] = "0";
- }
- else
- {
- values.Displacement[0] = float.Parse(Ui.InputField_s_x.text);
- values.Key[0] = "1";
- }
- if (Ui.InputField_u_x.text == "")
- {
- values.Key[0] += "0";
- }
- else
- {
- values.InitialVelociy[0] = float.Parse(Ui.InputField_u_x.text);
- values.Key[0] += "1";
- }
- if (Ui.InputField_v_x.text == "")
- {
- values.Key[0] += "0";
- }
- else
- {
- values.FinalVelocity[0] = float.Parse(Ui.InputField_v_x.text);
- values.Key[0] += "1";
- }
- if (Ui.InputField_a_x.text == "")
- {
- values.Key[0] += "0";
- }
- else
- {
- values.Acceleration[0] = float.Parse(Ui.InputField_a_x.text);
- values.Key[0] += "1";
- }
- if (Ui.InputField_Time.text == "")
- {
- values.Key[0] += "0";
- }
- else
- {
- values.Time = float.Parse(Ui.InputField_Time.text);
- values.Key[0] += "1";
- }
- if (Ui.InputField_r_x.text != "")
- {
- values.Position[0] = float.Parse(Ui.InputField_r_x.text);
- }
- else
- {
- values.Position[0] = 0;
- }
- print("Input got");
- }
- public static void GetInput_Suvat_y(UiController Ui, ref Particle values)
- {
- print("Get input");
- //Taking the input from the user and storing it in the corresponding variable inside the list
- if (Ui.InputField_s_y.text == "")
- {
- values.Key[1] = "0";
- }
- else
- {
- values.Displacement[1] = float.Parse(Ui.InputField_s_y.text);
- values.Key[1] = "1";
- }
- if (Ui.InputField_u_y.text == "")
- {
- values.Key[1] += "0";
- }
- else
- {
- values.InitialVelociy[1] = float.Parse(Ui.InputField_u_y.text);
- values.Key[1] += "1";
- }
- if (Ui.InputField_v_y.text == "")
- {
- values.Key[1] += "0";
- }
- else
- {
- values.FinalVelocity[1] = float.Parse(Ui.InputField_v_y.text);
- values.Key[1] += "1";
- }
- if (Ui.InputField_a_y.text == "")
- {
- values.Key[1] += "0";
- }
- else
- {
- values.Acceleration[1] = float.Parse(Ui.InputField_a_y.text);
- values.Key[1] += "1";
- }
- if (Ui.InputField_Time.text == "")
- {
- values.Key[1] += "0";
- }
- else
- {
- values.Time = float.Parse(Ui.InputField_Time.text);
- values.Key[1] += "1";
- }
- if (Ui.InputField_r_y.text != "")
- {
- values.Position[1] = float.Parse(Ui.InputField_r_y.text);
- }
- else
- {
- values.Position[1] = 0;
- }
- print("Input got");
- }
- public static void GetInput_Suvat_z(UiController Ui, ref Particle values)
- {
- //Taking the input from the user and storing it in the corresponding variable inside the list
- if (Ui.InputField_s_z.text == "")
- {
- values.Key[2] = "0";
- }
- else
- {
- values.Displacement[0] = float.Parse(Ui.InputField_s_z.text);
- values.Key[2] = "1";
- }
- if (Ui.InputField_u_z.text == "")
- {
- values.Key[2] += "0";
- }
- else
- {
- values.InitialVelociy[0] = float.Parse(Ui.InputField_u_z.text);
- values.Key[2] += "1";
- }
- if (Ui.InputField_v_z.text == "")
- {
- values.Key[2] += "0";
- }
- else
- {
- values.FinalVelocity[0] = float.Parse(Ui.InputField_v_z.text);
- values.Key[2] += "1";
- }
- if (Ui.InputField_a_z.text == "")
- {
- values.Key[2] += "0";
- }
- else
- {
- values.Acceleration[0] = float.Parse(Ui.InputField_a_z.text);
- values.Key[2] += "1";
- }
- if (Ui.InputField_Time.text == "")
- {
- values.Key[2] += "0";
- }
- else
- {
- values.Time = float.Parse(Ui.InputField_Time.text);
- values.Key[2] += "1";
- }
- values.Position[2] = float.Parse(Ui.InputField_r_z.text);
- }
- public static void GetInput_Misc(UiController Ui, ref Particle values)
- {
- if (Ui.InputField_Mass.text != "")
- {
- values.Mass = float.Parse(Ui.InputField_Mass.text);
- }
- else
- {
- values.Mass = 0;
- }
- values.Restitution = Ui.SliderRestitution.value;
- if (Ui.InputField_Radius.text != "")
- {
- values.Radius = float.Parse(Ui.InputField_Radius.text);
- }
- else
- {
- values.Radius = 1;
- }
- }
- public static bool CheckInputs(ref Particle values, int dimentions)
- {
- bool flag = false;
- for (int i = 0; i < dimentions; i++)
- {
- if (values.GetNumberOfInputs()[i] >= 3)
- {
- flag = true;
- }
- }
- return flag;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment