void RefreshScrollViewContentScan() { #pragma warning disable CS0162 if (isLogging) { Debug.Log(TAG + "RefreshScrollViewContentScan"); } #pragma warning restore CS0162 int scannedDevices = MovesenseDevice.Devices.Count; int scanElementsCount = ScanElements.Count; if (scanElementsCount < scannedDevices) { #pragma warning disable CS0162 if (isLogging) { Debug.Log(TAG + "RefreshScrollViewContentScan, add clones"); } #pragma warning restore CS0162 for (int i = scanElementsCount; i < scannedDevices; i++) { GameObject ScanElementClone = Instantiate(ScanElement, scrollViewContentScan) as GameObject; // Positioning RectTransform ScanElementRect = ScanElementClone.GetComponent <RectTransform>(); if (scanElementHeight == 0) { scanElementHeight = ScanElementRect.sizeDelta.y; } // change position ScanElementRect.anchoredPosition = new Vector2(0, -scanElementHeight / 2 - (i * scanElementHeight)); ScanElements.Add(ScanElementClone); } scrollViewContentScan.sizeDelta = new Vector2(0, scanElementHeight * scannedDevices); } else if (scanElementsCount > scannedDevices) { #pragma warning disable CS0162 if (isLogging) { Debug.Log(TAG + "RefreshScrollViewContentScan, destroy clones"); } #pragma warning restore CS0162 for (int i = scanElementsCount - 1; i > scannedDevices - 1; i--) { Destroy(ScanElements[i]); ScanElements.RemoveAt(i); } scrollViewContentScan.sizeDelta = new Vector2(0, scanElementHeight * scannedDevices); } // Debug.Log(TAG + "RefreshScrollViewContentScan, assign properties"); for (int i = 0; i < scannedDevices; i++) { MovesenseDevice device = null; try { device = MovesenseDevice.Devices[i]; } catch { Debug.LogWarning(TAG + "RefreshScrollViewContentScan, Device is currently not available"); continue; } // change texts string rssi; if (device.Rssi <= -500) { rssi = "~"; } else { rssi = device.Rssi.ToString(); } // define connectionColor Color32 fontColor; if (device.IsConnecting) { fontColor = Color.yellow; } else if (device.IsConnected) { fontColor = Color.green; } else { fontColor = Color.red; } TMP_Text[] scanElementTexts = ScanElements[i].GetComponentsInChildren <TMP_Text>(); foreach (var text in scanElementTexts) { if (isColorizedScan) { text.color = fontColor; } if (text.name == "Text Serial") { text.text = device.Serial; } else if (text.name == "Text MacID") { text.text = device.MacID; } else if (text.name == "Text Rssi") { text.text = rssi + "db"; } else if (text.name == "Text Status") { if (device.IsConnecting) { text.text = "connecting"; } else { text.text = device.IsConnected ? "Connected" : "Disconnected"; } } } // change OnClickButtonConnect-methodparameters Button scanElementButton = ScanElements[i].GetComponentInChildren <Button>(); scanElementButton.onClick.RemoveAllListeners(); System.Func <string, string, bool, bool, UnityEngine.Events.UnityAction> actionBuilder = (macID, serial, connecting, connected) => () => OnClickButtonConnect(macID, serial, connecting, connected); UnityEngine.Events.UnityAction action1 = actionBuilder(device.MacID, device.Serial, device.IsConnecting, device.IsConnected); scanElementButton.onClick.AddListener(action1); } if (MovesenseDevice.NumberOfConnectedDevices() > 0) { buttonSubscriptions.gameObject.SetActive(true); } }
void RefreshScrollViewContentConnectedDevices(bool isInit) { #pragma warning disable CS0162 if (isLogging) { Debug.Log(TAG + "RefreshScrollViewContentConnectedDevices"); } #pragma warning restore CS0162 int connectedDevices = MovesenseDevice.NumberOfConnectedDevices(); int connectedElementsCount = connectedElements.Count; if (connectedElementsCount < connectedDevices) { #pragma warning disable CS0162 if (isLogging) { Debug.Log(TAG + "RefreshScrollViewContentConnectedDevices, add clones"); } #pragma warning restore CS0162 for (int i = connectedElementsCount; i < connectedDevices; i++) { GameObject connectedElementClone = Instantiate(ConnectedElement, contentConnected) as GameObject; // Positioning RectTransform connectedElementRect = connectedElementClone.GetComponent <RectTransform>(); if (connectedElementHeight == 0) { connectedElementHeight = connectedElementRect.sizeDelta.y; } // change position connectedElementRect.anchoredPosition = new Vector2(0, -connectedElementHeight / 2 - (i * connectedElementHeight)); connectedElements.Add(connectedElementClone); } contentConnected.sizeDelta = new Vector2(0, connectedElementHeight * connectedDevices); if (isInit) { foreach (var item in connectedElements[0].GetComponentInChildren <Button>().GetComponentsInChildren <Image>()) { if (item.name == "Image Background") { item.color = colorHighlited; break; } } connectedElementHighlitedIndex = 0; } } else if (connectedElementsCount > connectedDevices) { #pragma warning disable CS0162 if (isLogging) { Debug.Log(TAG + "RefreshScrollViewContentConnectedDevices, destroy clones"); } #pragma warning restore CS0162 for (int i = connectedElementsCount - 1; i > connectedDevices - 1; i--) { Destroy(connectedElements[i]); connectedElements.RemoveAt(i); } contentConnected.sizeDelta = new Vector2(0, connectedElementHeight * connectedDevices); } for (int i = 0; i < connectedDevices; i++) { // change texts TMP_Text[] connectedElementTexts = connectedElements[i].GetComponentsInChildren <TMP_Text>(); foreach (var text in connectedElementTexts) { if (text.name == "Text Serial") { text.text = MovesenseDevice.Devices[i].Serial; } else if (text.name == "Text MacID") { text.text = MovesenseDevice.Devices[i].MacID; } } // Highlight Button btn = connectedElements[i].GetComponentInChildren <Button>(); btn.onClick.RemoveAllListeners(); System.Func <int, UnityEngine.Events.UnityAction> actionBuilder = (connectedElementIndex) => () => OnClickButtonConnectElement(connectedElementIndex); UnityEngine.Events.UnityAction action1 = actionBuilder(i); btn.onClick.AddListener(action1); } }