Skip to content

Instantly share code, notes, and snippets.

@acoppes
Created September 10, 2023 14:20
Show Gist options
  • Save acoppes/854168b60d4450d9b5b856aa096fc495 to your computer and use it in GitHub Desktop.
Save acoppes/854168b60d4450d9b5b856aa096fc495 to your computer and use it in GitHub Desktop.
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