Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.39 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using System.IO.Ports;
  6.  
  7. public class ColourModifier : MonoBehaviour
  8. {
  9. public float red;
  10. public float green;
  11. public float blue;
  12.  
  13. public int LightEffect;
  14. public int LightMode;
  15.  
  16. public float Speed;
  17.  
  18. public float Brightness;
  19.  
  20. private int input;
  21.  
  22. public float redAnimation;
  23. public float greenAnimation;
  24. public float blueAnimation;
  25.  
  26. public int TriNumber = 1;
  27.  
  28. public int PlayDesign;
  29.  
  30. //Switching (Scenes)
  31. public GameObject Design;
  32. public GameObject Gallery;
  33. public GameObject PreMadeEffects;
  34. public GameObject DesignOptionsTab;
  35.  
  36. public Image[] TriangePreviews;
  37.  
  38. //Animations
  39. public GameObject PreMadeEffectsOptions;
  40.  
  41. public int OnOrOff;
  42.  
  43. public static SerialPort sp = new SerialPort("COM7", 9600);
  44.  
  45. public void Start()
  46. {
  47. OpenConnection();
  48. PreMadeEffects.SetActive(true);
  49. Gallery.SetActive(false);
  50. Design.SetActive(false);
  51. DesignOptionsTab.SetActive(false);
  52. PreMadeEffectsOptions.SetActive(false);
  53. }
  54.  
  55. public void Update()
  56. {
  57.  
  58. }
  59.  
  60. public void Increment()
  61. {
  62. TriNumber++;
  63. if (TriNumber == 10)
  64. {
  65. TriNumber = 1;
  66. }
  67. }
  68.  
  69. public void Decrease()
  70. {
  71. TriNumber--;
  72. if (TriNumber == 0)
  73. {
  74. TriNumber = 9;
  75. }
  76. }
  77.  
  78. //Effects
  79. public void Effect(int Effect)
  80. {
  81. LightEffect = Effect;
  82. PreMadeEffectsOptions.SetActive(true);
  83. Debug.Log(LightEffect);
  84. }
  85.  
  86. public void Mode(int Mode)
  87. {
  88. LightMode = Mode;
  89. }
  90.  
  91. public void PlayPreMadeEffect()
  92. {
  93. sp.Write("1" + LightEffect.ToString());
  94. Debug.Log("Sent To Arduino: " + "1" + LightEffect.ToString());
  95. }
  96.  
  97. public void Red(float RedValue)
  98. {
  99. red = RedValue;
  100. }
  101.  
  102. public void Green(float GreenValue)
  103. {
  104. green = GreenValue;
  105. }
  106.  
  107. public void Blue(float BlueValue)
  108. {
  109. blue = BlueValue;
  110. //TriangePreviews[TriNumber] = new Color32((byte)red, (byte)green, (byte)blue, 255);
  111. }
  112.  
  113. public void SwitchToDesign()
  114. {
  115. PreMadeEffects.SetActive(false);
  116. Gallery.SetActive(false);
  117. Design.SetActive(true);
  118. DesignOptionsTab.SetActive(false);
  119. PreMadeEffectsOptions.SetActive(false);
  120. }
  121.  
  122. public void OnOrOffButton()
  123. {
  124. if(OnOrOff == 0)
  125. {
  126. sp.Write("01");
  127. }
  128. if (OnOrOff == 1)
  129. {
  130. sp.Write("02");
  131. }
  132. OnOrOff++;
  133. if(OnOrOff == 2)
  134. {
  135. OnOrOff == 0;
  136. }
  137. }
  138.  
  139.  
  140. public void OpenConnection()
  141. {
  142. if (sp != null)
  143. {
  144. if (sp.IsOpen)
  145. {
  146. sp.Close();
  147. Debug.Log("Closing, As It Was Already Open");
  148. }
  149. else
  150. {
  151. sp.Open();
  152. Debug.Log("Port Has Been Opened");
  153. }
  154. }
  155. else
  156. {
  157. if (sp.IsOpen)
  158. {
  159. Debug.Log("Port Is Already Open");
  160. }
  161. else
  162. {
  163. Debug.Log("Port == null");
  164. }
  165. }
  166. }
  167. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement