public void SetNewActiveItem(ListItem newItem, bool captureInput = true) { // null checking if (activeItem == null) { activeItem = new List <ListItem>(); } if (activeItem.Count > 0) { if (activeItem[0] != null) { if (activeItem[0] == newItem && activeItem.Count == 0) { return; } } } // Regular click; clear list then add the new item as active if (!shiftDown.value && !ctrlDown.value || activeItem.Count == 0 || captureInput == false) { activeItem.Clear(); activeItem.Add(newItem); cardCode.WriteInput(newItem.cardData.cardCode); // Dehighlight other items foreach (ListItem item in listItemInstances) { if (item != newItem) { item.Dehighlight(); } } } // Multi-select cLICK, for export else if (ctrlDown.value && !shiftDown.value) // CTRL input, add if not in list, remove if in list { activeItem[0].Highlight(); if (!activeItem.Contains(newItem)) { activeItem.Insert(0, newItem); newItem.Highlight(); cardCode.WriteInput(newItem.cardData.cardCode); } else if (activeItem.Count > 1) { // logic for to select last item if the removed item is the active item if (activeItem[0] == newItem) { ListItem lastActive = activeItem[activeItem.Count - 2]; foreach (ListItem li in activeItem) { if (li.listOrderIndex > lastActive.listOrderIndex && li != newItem) { lastActive = li; } } // add item activeItem.Remove(lastActive); activeItem.Insert(0, lastActive); cardCode.WriteInput(lastActive.cardData.cardCode); } // remove item newItem.Dehighlight(); activeItem.Remove(newItem); } } else if (shiftDown.value) // SHIFT input, gather all in between orderIndex { int startIndex = Mathf.Min(activeItem[0].listOrderIndex, newItem.listOrderIndex); int endIndex = Mathf.Max(activeItem[0].listOrderIndex, newItem.listOrderIndex); if (startIndex != endIndex) { activeItem[0].Highlight(); for (int i = startIndex; i < endIndex; i++) { ListItem n = listItemInstances[i]; if (!activeItem.Contains(n)) { activeItem.Insert(0, n); n.Highlight(); } } // Set new active activeItem.Remove(newItem); activeItem.Insert(0, newItem); newItem.Highlight(); cardCode.WriteInput(newItem.cardData.cardCode); } } // Check if there are multiple cards selected if (activeItem.Count > 1) { multiCardExportEvent.Invoke(); } else { nonMultiCardExportEvent.Invoke(); } }