Assuming unity has access to these calls. You can just use File.ReadAllines
and then convert it to a HashSet
, use Contains
to do a fast lookup.
var hashSet = File
.ReadAllLines("SomeFileName")
.ToHashSet();
// if you want case insensitivity
//.ToHashSet(StringComparer.OrdinalIgnoreCase);
if (hashSet .Contains(SomeUserInputedString))
Debug.Log("You Won");
If unity doesn't have ToHashSet
, you can just use its constructor
var hashSet = new HashSet(File.ReadAllLines("SomeFileName")) ;
Additional Resources
File.ReadAllLines Method
Opens a text file, reads all lines of the file into a string array,
and then closes the file.
Enumerable.ToHashSet Method
Creates a HashSet<T>
from an IEnumerable<T>
using the comparer to
compare keys.
HashSet.Contains(T) Method
Determines whether a HashSet object contains the specified element.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…