void OnEntryClicked(KeyBindingEntry entry) { KeyCombination combination = null; if (entry.pressedKey == 0) { combination = entry.key.Value.primary; } else if (entry.pressedKey == 1) { combination = entry.key.Value.secondary; } binder.Rebind(combination, mappings[entry.mappingIndex], OnFinishRebind); }
public void ShowMapping(int index) { //Highlight header if (currentMappingIndex >= 0) { headers[currentMappingIndex].Highlight(false); } currentMappingIndex = index; headers[currentMappingIndex].Highlight(true); List <string> categorieNames = new List <string>() { "Other" }; List <List <Transform> > categoryItems = new List <List <Transform> >() { new List <Transform>() }; //Display all entries InputMapping mapping = mappings[index]; int i = 0; foreach (KeyValuePair <string, InputKey> key in mapping.keys) { if (entries.Count > i) { entries[i].gameObject.SetActive(true); entries[i].Fill(key, currentMappingIndex); } else { KeyBindingEntry entry = Instantiate(entryPrefab.gameObject).GetComponent <KeyBindingEntry>(); entry.transform.SetParent(entryPrefab.transform.parent); entry.transform.localScale = Vector3.one; //Listener entry.onClick.AddListener(OnEntryClicked); //List entries.Add(entry); //Fill with data entry.Fill(key, currentMappingIndex); } if (!string.IsNullOrEmpty(key.Value.displayCategory)) { int ind = -1; if (!categorieNames.Contains(key.Value.displayCategory)) { ind = categorieNames.Count; categorieNames.Add(key.Value.displayCategory); categoryItems.Add(new List <Transform>()); } else { ind = categorieNames.IndexOf(key.Value.displayCategory); } categoryItems[ind].Add(entries[i].transform); } else { categoryItems[0].Add(entries[i].transform); } i++; } //Deactivate the rest for (int u = i; u < entries.Count; u++) { entries[u].gameObject.SetActive(false); } int y = 0; if (categorieNames.Count > 1) { //Category: other if (categoryItems[0].Count > 0) { for (int f = categoryItems[0].Count - 1; f >= 0; f--) { categoryItems[0][f].SetAsFirstSibling(); } categories[0].transform.SetAsFirstSibling(); categories[0].GetComponentInChildren <Text>().text = categorieNames[0]; categories[0].SetActive(true); y++; } //All categories for (int v = categorieNames.Count - 1; v > 0; v--) { for (int f = categoryItems[v].Count - 1; f >= 0; f--) { categoryItems[v][f].SetAsFirstSibling(); } if (categories.Count > y) { categories[y].transform.SetAsFirstSibling(); categories[y].GetComponentInChildren <Text>().text = categorieNames[v]; categories[y].SetActive(true); } else { GameObject categoryObj = Instantiate(categoryPrefab); categoryObj.transform.SetParent(categoryPrefab.transform.parent); categoryObj.transform.localScale = Vector3.one; categoryObj.transform.SetAsFirstSibling(); //List categories.Add(categoryObj); //Fill categoryObj.GetComponentInChildren <Text>().text = categorieNames[v]; } y++; } } //Deactivate the rest for (int u = y; u < categories.Count; u++) { categories[u].gameObject.SetActive(false); } }