// Update is called once per frame void Update() { // Prevent blocking if no message is available as we are not doing anything else // Alternative solutions : set a timeout, read messages in another thread, coroutines, futures... if (_serial.BytesToRead <= 0) { return; } var message = _serial.ReadLine(); // Arduino sends "\r\n" with println, '\n' is removed by ReadLine() message = message.Trim('\r'); string[] tokens = message.Split(':'); switch (tokens[0]) { case "bt": switch (tokens[1]) { case "on": Debug.Log("Arduinon button on"); SetLedInternal(true); break; case "off": Debug.Log("Arduinon button off"); SetLedInternal(false); break; } break; case "sw": switch (tokens[1]) { case "l": //Debug.Log("Arduinon Swap Left"); Swap?.Invoke(false); break; case "r": //Debug.Log("Arduinon Swap Right"); Swap?.Invoke(true); break; } break; case "tp": SeasonManager.Instance.TempSet(float.Parse(tokens[1], CultureInfo.InvariantCulture)); break; case "po": int val; if (int.TryParse(tokens[1], out val)) { ValuePotentiometre = val; } break; } }
private void OnSwap() { GameObject firstContent = selectedSlots.First().Content; selectedSlots.First().Content = selectedSlots.Last().Content; selectedSlots.Last().Content = firstContent; Swap?.Invoke(this, new SwapEventArgs(selectedSlots.First(), selectedSlots.Last())); }
public static void BubbleSort <T>(T[] array, Swap <T> swap, Compare <T> compare) { var len = array.Length; for (var i = 1; i < len; i++) { for (var j = 0; j < len - i; j++) { if (compare.Invoke(array[j], array[j + 1])) { swap.Invoke(ref array[j], ref array[j + 1]); } } } }
public void Sort <T>(T[] array) where T : IComparable <T> { for (int i = 0; i < array.Length - 1; i++) { for (int j = array.Length - 1; j > i; j--) { if (array[j - 1].CompareTo(array[j]) > 0) { T temp = array[j - 1]; array[j - 1] = array[j]; array[j] = temp; Swap?.Invoke(this, new SwapEventArgs(array[j], array[j - 1])); } } } }