logancberrypie

CalculateController

Sep 1st, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.52 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class CalculateController : MonoBehaviour {
  6.  
  7.     public static void CalculateControl()
  8.     {
  9.         //Creates an instance of Particle for values to be stored in
  10.         Particle values = new Particle();
  11.         //Gets the number of dimentions selected by the user
  12.         int dimentions = System.Convert.ToInt16(UiController.instances.DropBoxDimention.value);
  13.         //No dimention selected
  14.         if (dimentions == 0)
  15.         {
  16.             Debug.Log("No dimention selected");
  17.             return;
  18.         }
  19.         GetInput_Suvat_x(UiController.instances, ref values);
  20.         Debug.Log("x dimention got");
  21.         if (dimentions >= 2)
  22.         {
  23.             GetInput_Suvat_y(UiController.instances, ref values);
  24.             Debug.Log("y dimention got");
  25.         }
  26.         if (dimentions >= 3)
  27.         {
  28.             GetInput_Suvat_z(UiController.instances, ref values);
  29.             Debug.Log("z dimention got");
  30.         }
  31.         GetInput_Misc(UiController.instances, ref values);
  32.         Debug.Log("misc inputs got");
  33.  
  34.         //Checking if atleast 3 values have been added in all dimentions.
  35.         if (CheckInputs(ref values, dimentions) == true)
  36.         {
  37.             print("Dimentions true");
  38.             values = SuvatSolvers.FindEquation(values);
  39.             if (values.inValidInput == true)
  40.             {
  41.                 //Updates the UI elements on screen
  42.                 UiController.instances.UpdateUI(values);
  43.                 Debug.Log("updating ui");
  44.             }
  45.             else
  46.             {
  47.                 string msg = "Input is impossible!";
  48.                 Debug.Log(msg);
  49.             }
  50.         }
  51.         else
  52.         {
  53.             print("Dimentions false");
  54.             string msg = "Please enter atleast 3 quantities per dimention";
  55.             Debug.Log(msg);
  56.         }
  57.     }
  58.  
  59.  
  60.      public static void GetInput_Suvat_x(UiController Ui, ref Particle values)
  61.     {
  62.         print("Get input");
  63.         //Taking the input from the user and storing it in the corresponding variable inside the list
  64.         if (Ui.InputField_s_x.text == "")
  65.         {
  66.             values.Key[0] = "0";
  67.         }
  68.         else
  69.         {
  70.             values.Displacement[0] = float.Parse(Ui.InputField_s_x.text);
  71.             values.Key[0] = "1";
  72.         }
  73.         if (Ui.InputField_u_x.text == "")
  74.         {
  75.             values.Key[0] += "0";
  76.         }
  77.         else
  78.         {
  79.             values.InitialVelociy[0] = float.Parse(Ui.InputField_u_x.text);
  80.             values.Key[0] += "1";
  81.         }
  82.  
  83.         if (Ui.InputField_v_x.text == "")
  84.         {
  85.             values.Key[0] += "0";
  86.         }
  87.         else
  88.         {
  89.             values.FinalVelocity[0] = float.Parse(Ui.InputField_v_x.text);
  90.             values.Key[0] += "1";
  91.         }
  92.  
  93.         if (Ui.InputField_a_x.text == "")
  94.         {
  95.             values.Key[0] += "0";
  96.         }
  97.         else
  98.         {
  99.             values.Acceleration[0] = float.Parse(Ui.InputField_a_x.text);
  100.             values.Key[0] += "1";
  101.         }
  102.         if (Ui.InputField_Time.text == "")
  103.         {
  104.             values.Key[0] += "0";
  105.         }
  106.         else
  107.         {
  108.             values.Time = float.Parse(Ui.InputField_Time.text);
  109.             values.Key[0] += "1";
  110.         }
  111.         if (Ui.InputField_r_x.text != "")
  112.         {
  113.             values.Position[0] = float.Parse(Ui.InputField_r_x.text);
  114.         }
  115.         else
  116.         {
  117.             values.Position[0] = 0;
  118.         }
  119.         print("Input got");
  120.     }
  121.  
  122.     public static void GetInput_Suvat_y(UiController Ui, ref Particle values)
  123.     {
  124.         print("Get input");
  125.         //Taking the input from the user and storing it in the corresponding variable inside the list
  126.         if (Ui.InputField_s_y.text == "")
  127.         {
  128.             values.Key[1] = "0";
  129.         }
  130.         else
  131.         {
  132.             values.Displacement[1] = float.Parse(Ui.InputField_s_y.text);
  133.             values.Key[1] = "1";
  134.         }
  135.         if (Ui.InputField_u_y.text == "")
  136.         {
  137.             values.Key[1] += "0";
  138.         }
  139.         else
  140.         {
  141.             values.InitialVelociy[1] = float.Parse(Ui.InputField_u_y.text);
  142.             values.Key[1] += "1";
  143.         }
  144.  
  145.         if (Ui.InputField_v_y.text == "")
  146.         {
  147.             values.Key[1] += "0";
  148.         }
  149.         else
  150.         {
  151.             values.FinalVelocity[1] = float.Parse(Ui.InputField_v_y.text);
  152.             values.Key[1] += "1";
  153.         }
  154.  
  155.         if (Ui.InputField_a_y.text == "")
  156.         {
  157.             values.Key[1] += "0";
  158.         }
  159.         else
  160.         {
  161.             values.Acceleration[1] = float.Parse(Ui.InputField_a_y.text);
  162.             values.Key[1] += "1";
  163.         }
  164.         if (Ui.InputField_Time.text == "")
  165.         {
  166.             values.Key[1] += "0";
  167.         }
  168.         else
  169.         {
  170.             values.Time = float.Parse(Ui.InputField_Time.text);
  171.             values.Key[1] += "1";
  172.         }
  173.         if (Ui.InputField_r_y.text != "")
  174.         {
  175.             values.Position[1] = float.Parse(Ui.InputField_r_y.text);
  176.         }
  177.         else
  178.         {
  179.             values.Position[1] = 0;
  180.         }
  181.         print("Input got");
  182.     }
  183.  
  184.     public static void GetInput_Suvat_z(UiController Ui, ref Particle values)
  185.     {
  186.         //Taking the input from the user and storing it in the corresponding variable inside the list
  187.         if (Ui.InputField_s_z.text == "")
  188.         {
  189.             values.Key[2] = "0";
  190.         }
  191.         else
  192.         {
  193.             values.Displacement[0] = float.Parse(Ui.InputField_s_z.text);
  194.             values.Key[2] = "1";
  195.         }
  196.  
  197.         if (Ui.InputField_u_z.text == "")
  198.         {
  199.             values.Key[2] += "0";
  200.         }
  201.         else
  202.         {
  203.             values.InitialVelociy[0] = float.Parse(Ui.InputField_u_z.text);
  204.             values.Key[2] += "1";
  205.         }
  206.  
  207.         if (Ui.InputField_v_z.text == "")
  208.         {
  209.             values.Key[2] += "0";
  210.         }
  211.         else
  212.         {
  213.             values.FinalVelocity[0] = float.Parse(Ui.InputField_v_z.text);
  214.             values.Key[2] += "1";
  215.         }
  216.  
  217.         if (Ui.InputField_a_z.text == "")
  218.         {
  219.             values.Key[2] += "0";
  220.         }
  221.         else
  222.         {
  223.             values.Acceleration[0] = float.Parse(Ui.InputField_a_z.text);
  224.             values.Key[2] += "1";
  225.         }
  226.         if (Ui.InputField_Time.text == "")
  227.         {
  228.             values.Key[2] += "0";
  229.         }
  230.         else
  231.         {
  232.             values.Time = float.Parse(Ui.InputField_Time.text);
  233.             values.Key[2] += "1";
  234.         }
  235.  
  236.         values.Position[2] = float.Parse(Ui.InputField_r_z.text);
  237.     }
  238.  
  239.     public static void GetInput_Misc(UiController Ui, ref Particle values)
  240.     {
  241.         if (Ui.InputField_Mass.text != "")
  242.         {
  243.             values.Mass = float.Parse(Ui.InputField_Mass.text);
  244.         }
  245.         else
  246.         {
  247.             values.Mass = 0;
  248.         }
  249.         values.Restitution = Ui.SliderRestitution.value;
  250.         if (Ui.InputField_Radius.text != "")
  251.         {
  252.             values.Radius = float.Parse(Ui.InputField_Radius.text);
  253.         }
  254.         else
  255.         {
  256.             values.Radius = 1;
  257.         }
  258.     }
  259.  
  260.     public static bool CheckInputs(ref Particle values, int dimentions)
  261.     {
  262.         bool flag = false;
  263.         for (int i = 0; i < dimentions; i++)
  264.         {
  265.             if (values.GetNumberOfInputs()[i] >= 3)
  266.             {
  267.                 flag = true;
  268.             }
  269.         }
  270.         return flag;
  271.     }
  272.  
  273. }
Advertisement
Add Comment
Please, Sign In to add comment