System.Collections.Generic.List.Add(uInput)

Here are the examples of the csharp api System.Collections.Generic.List.Add(uInput) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

1 Examples 7

19 View Source File : unicaveInput.cs
License : MIT License
Project Creator : widVE

[ContextMenu("Sync Inputs")]
    private void syncInputs()
    {
        bool changeFile = true;
        inputs = new List<uInput>();
        Debug.Log("Syncing Inputs...");
        if (inputs == null)
        {
            inputs = new List<uInput>();
        } else
        {
            inputs.Clear();
        }
            
        char[] UNICAVE = { 'u', 'n', 'i', 'c', 'a', 'v', 'e'};
        char[] instanceChar = { 'I', 'n', 's', 't', 'a', 'n', 'c', 'e', '(', ')', '.'};
        DirectoryInfo dir = new DirectoryInfo("replacedets"); //directory to start search in
        List<FileInfo> filepaths = new List<FileInfo>(); //make list to put all cs files in
        syncInputs(filepaths, dir);
        List<int> indices = new List<int>();
        foreach (FileInfo file in filepaths)
        {
            changeFile = true;
            if (/* file.Name != "unicaveInput.cs" */ file.Name == "PlayerShooting.cs")
            {
                //parse each file looking for 'Input.getButtonDown' and replace with 'unicaveInput.getButtonDown'
                StreamReader sr = file.OpenText();
                string s = sr.ReadToEnd();
                sr.Close();
                List<char> chars = new List<char>((char[])s.ToCharArray());
                for (int i = 0; i < chars.Count; i++)
                {
                    if (chars[i] == 'I' && chars[i + 1] == 'n' && chars[i + 2] == 'p' && chars[i + 3] == 'u' && chars[i + 4] == 't' && chars[i + 5] == '.')
                    {
                        if (chars[i - 1] == 'e') {
                            //continue;
                            changeFile = false;
                            //break;
                        }
                        indices.Add(i);
                        if (changeFile)
                        {
                            //insert 'unicave' before 'Input.' and 'Instance(). after it
                            for (int j = 0; j < 7; j++)
                            {
                                chars.Insert(i + j, UNICAVE[j]);
                            }
                            i += 13;
                            for (int j = 0; j < 11; j++)
                            {
                                chars.Insert(i + j, instanceChar[j]);
                            }
                        }
                        i += 11;
                        //check if 'getButtonDown' is being called
                        if (chars[i + 6] == 'G' && chars[i + 9] == 'B' && chars[i + 19] == '(')
                        {
                            List<char> inputName = new List<char>();
                            int count = 21;
                            while (chars[i + count] != '\"')
                            {
                                inputName.Add(chars[i + count]);
                                count++;
                            }
                            string inputNameString = new string(inputName.ToArray());
                            uInput newInput = (uInput)ScriptableObject.CreateInstance(typeof(uInput));
                            newInput.inputName = inputNameString;
                            newInput.isPressed = false;
                            newInput.name = inputNameString;
                            bool shouldAdd = true;
                            for (int j = 0; j < inputs.Count; j++)
                            {
                                if (inputs[j].inputName.Equals(newInput.inputName))
                                {
                                    shouldAdd = false;
                                    break;
                                }
                            }
                            if (shouldAdd)
                            {
                                inputs.Add(newInput);
                                Debug.Log("Input: \"" + newInput.inputName + "\" added.");
                            }

                        }
                        //check if 'getButton' is being called
                        if (chars[i + 6] == 'G' && chars[i + 9] == 'B' && chars[i + 15] == '(')
                        {
                            List<char> inputName = new List<char>();
                            int count = 17;
                            while (chars[i + count] != '\"')
                            {
                                inputName.Add(chars[i + count]);
                                count++;
                            }
                            string inputNameString = new string(inputName.ToArray());
                            uInput newInput = (uInput)ScriptableObject.CreateInstance(typeof(uInput));
                            newInput.inputName = inputNameString;
                            newInput.isPressed = false;
                            newInput.name = inputNameString;
                            bool shouldAdd = true;
                            for (int j = 0; j < inputs.Count; j++)
                            {
                                if (inputs[j].inputName.Equals(newInput.inputName))
                                {
                                    shouldAdd = false;
                                    break;
                                }
                            }
                            if (shouldAdd)
                            {
                                inputs.Add(newInput);
                                Debug.Log("Input: \"" + newInput.inputName + "\" added.");
                            }

                        }

                    } 
                }
                if (indices.Count == 0)
                {
                    Debug.Log("Nothing found.");
                }
                //Debug.Log(new string(chars.ToArray()));

            //overwrite file with new contents
                StreamWriter writer = File.CreateText(file.FullName);
                writer.Write(new string(chars.ToArray()));
                writer.Close();
            }
        }
        Debug.Log("Inputs Synced.");
    }