- Home /
Can i load my binary with Resources.Load()?
Hello. How can i make Resources.Load() to recognize and load my custom extension binary files?
Comment
Answer by eppz · Sep 09, 2016 at 08:23 PM
Rename 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)
{ ... }
Your answer
Follow this Question
Related Questions
Reading binary file from Resources folder 2 Answers
Yet another binary file loading question 1 Answer
Load binary files from Resources 1 Answer
Components for 2D Animation System 0 Answers
Calling Instantiate from a function within a class 2 Answers