Created
September 10, 2023 14:20
-
-
Save acoppes/854168b60d4450d9b5b856aa096fc495 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RandomAnimalNameGeneratorService : MonoBehaviour | |
{ | |
[FormerlySerializedAs("colorsTextAsset")] | |
public TextAsset firstNameTextAsset; | |
[FormerlySerializedAs("adjectivesTextAsset")] | |
public TextAsset secondNameTextAsset; | |
[FormerlySerializedAs("namesTextAsset")] | |
public TextAsset thirdNameTextAsset; | |
private List<string> firstNameOptions = new List<string>(); | |
private List<string> secondNameOptions = new List<string>(); | |
private List<string> thirdNameOptions = new List<string>(); | |
private string Capitalize(string text) | |
{ | |
return text[..1].ToUpper() + text[1..]; | |
} | |
public string Generate() | |
{ | |
if (thirdNameOptions.Count == 0) | |
{ | |
thirdNameOptions = JsonConvert.DeserializeObject<List<string>>(thirdNameTextAsset.text); | |
} | |
if (secondNameOptions.Count == 0) | |
{ | |
secondNameOptions = JsonConvert.DeserializeObject<List<string>>(secondNameTextAsset.text); | |
} | |
if (firstNameOptions.Count == 0) | |
{ | |
firstNameOptions = JsonConvert.DeserializeObject<List<string>>(firstNameTextAsset.text); | |
} | |
return $"{Capitalize(firstNameOptions.Random())}{Capitalize(secondNameOptions.Random())}{Capitalize(thirdNameOptions.Random())}"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment