- Home /
Write physically files from resource folder into harddrive
Hello,
Besides txt filetypes I have some png-files in the levels folder of the resources folder that should be created as physically .png files in the datapath of the standalone:
foreach(TextAsset example in (TextAsset[])Resources.LoadAll("Levels"))
File.WriteAllText(Application.dataPath+"/Resources/Levels/"+example.name+".png",
example.text);
But I get an error: Cannot cast from source type to destination type.
Answer by revolute · Mar 25, 2016 at 02:57 AM
Resources.LoadAll returns object[] and that is not exactly meant to be cast to TextAsset[].
From what i see, your code should be
foreach(var item in Resoureces.LoadAll("levels"))
{
TextAsset asset = (TextAsset)item;
....
}
Answer by seth_slax · Mar 25, 2016 at 03:01 AM
I don't think you can cast a TextAsset as an image. It needs to be in byte[] format. Take a look at these two links:
http://docs.unity3d.com/ScriptReference/Texture2D.LoadImage.html http://docs.unity3d.com/ScriptReference/Texture2D.EncodeToPNG.html
Your answer
Follow this Question
Related Questions
What is better for text reading and writing? 1 Answer
Gain access to directory 1 Answer
Load JSON Resource as TextAsset 3 Answers