Ejemplo n.º 1
0
        void ShowHeaders()
        {
            for (int i = 0; i < mappings.Count; i++)
            {
                InputMapping mapping = mappings[i];

                if (headers.Count > i)
                {
                    //Fill old header
                    headers[i].Fill(mapping.displayName, i);
                }
                else
                {
                    //New Header

                    //Spawn
                    KeyBindingHeader header = Instantiate(headerPrefab.gameObject).GetComponent <KeyBindingHeader>();
                    header.transform.SetParent(headerPrefab.transform.parent);
                    header.transform.localScale = Vector3.one;

                    //Listener
                    header.onClick.AddListener(OnHeaderClick);

                    //List
                    headers.Add(header);

                    //Fill with data
                    header.Fill(mapping.displayName, i);
                }
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Adds the mapping to the list of dirtied mappings (if it's not already there)
 /// </summary>
 void Dirty(InputMapping mapping)
 {
     foreach (InputMapping dirtied in dirtiedMappings)
     {
         if (dirtied == mapping)
         {
             return;
         }
     }
     dirtiedMappings.Add(mapping);
 }
Ejemplo n.º 3
0
        public void Rebind(KeyCombination combination, InputMapping mapping, UnityAction <KeyCombination, KeyCombination> onComplete = null)
        {
            this.onComplete    = onComplete;
            currentMapping     = mapping;
            currentCombination = combination;

            conflictGroup.alpha          = 0;
            conflictGroup.blocksRaycasts = false;

            gameObject.SetActive(true);
            box.rectTransform.sizeDelta = normalSize;

            normalText.text = "Waiting for input...";

            StartCoroutine(InputGetter());
        }
Ejemplo n.º 4
0
        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);
            }
        }