/// <summary> /// Return a random string from _list /// </summary> /// <param name="_list"></param> /// <returns>Random string</returns> public string GetRandomPseudo(PseudoPool _list, int _minCharacterCount = 1, int _maxCharacterCount = -1) { if (_list == null || _list._strings.Count == 0) { return(""); } return(_list.GetRandomString(_minCharacterCount, _maxCharacterCount)); }
/// <summary> /// Return a list of random strings from the _list. /// </summary> /// <param name="_list">The list of initial strings</param> /// <param name="_numberRequired">The number of random element needed</param> /// <param name="_duplicateAllowed">If true, duplicate are allowed, automatically true if the _list can't return enough strings</param> /// <returns></returns> public List <string> GetRandomPseudos(PseudoPool _list, int _numberRequired, bool _duplicateAllowed = false, int _minCharacterCount = 1, int _maxCharacterCount = -1) { // The list to return List <string> randomStrings = new List <string>(); // For non duplicate elements List <string> stringAvailables = new List <string>(); // Verify if there is name in the list, and the number of element is positive without 0 if (_list == null || _list._strings.Count == 0 || _numberRequired <= 0) { return(randomStrings); } // If no duplicate, verify there is at least as many names availables as number required if (_list._strings.Count < _numberRequired && _duplicateAllowed == false) { Debug.Log("Not enough element in " + _list.name + " to have no duplicate"); _duplicateAllowed = true; } // If still duplicated, create a sub list for the random pick strategy if (_duplicateAllowed == false) { stringAvailables = new List <string>(_list._strings); } // Get as many name as required for (int i = 0; i < _numberRequired; i++) { if (_duplicateAllowed) { // Just add a random one randomStrings.Add(GetRandomPseudo(_list)); } else { // Get a random on in the available list and remove it after int _index = Random.Range(0, stringAvailables.Count); randomStrings.Add(stringAvailables[_index]); stringAvailables.RemoveAt(_index); } } return(randomStrings); }
void ImportCSV() { // Get the File string file = File.ReadAllText(sourcePath); // Split by lines string[] lines = Regex.Split(file, @"\r\n|\n\r|\n|\r"); // Scriptable scriptableObject = CreateInstance(typeof(PseudoPool)) as PseudoPool; scriptableObject._strings = new List <string>(); for (int i = 0; i < lines.Length; i++) { // Get the _header string[] header = Regex.Split(lines[i], ","); for (int y = 0; y < header.Length; y++) { scriptableObject._strings.Add(header[y]); } } if (!Directory.Exists(dataPath)) { //if it doesn't, create it Directory.CreateDirectory(dataPath); } // Create the asset in the project AssetDatabase.CreateAsset(scriptableObject, dataPath + "/" + "NewLocalizationFile" + ".asset"); AssetDatabase.Refresh(); CSVToPseudoPool window = (CSVToPseudoPool)EditorWindow.GetWindow(typeof(CSVToPseudoPool)); window.Close(); }