Hello. How can i make Resources.Load() to recognize and load my custom extension binary files?
1 Answer
1Rename binary files to use bytes extension, then something like:
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName);
TextAsset textAsset = Resources.Load(fileNameWithoutExtension) as TextAsset;
Stream stream = new MemoryStream(textAsset.bytes);
BinaryFormatter formatter = new BinaryFormatter();
MyClass myInstance = formatter.Deserialize(stream) as MyClass;
Then simply may wrap it all into a factory method, like:
public static MyClass LoadFromResources(string fileName)
{ ... }
This was perfect for me, thank you.
– unity_bTkJGG31azdikQ