- Home /
editor script - load texture from disk (not assets folder)
i am working on small wizard which will do very simple thing - duplicates template folder with scene and material, copies them to another folder, and rename them by string provided by gamedesginer - this part works well
i want to add one more function to the wizard - gamedesigner picks image anywhere on the disk, that image will show in that window and if gamedesigner clicks create, the image will be copied to the same folder, renamed and attached as texture to the material
any ideas?
Answer by pafla · Mar 10, 2014 at 12:56 PM
You can open, edit and create files anywhere on the pc with ordinary .NET Code: http://msdn.microsoft.com/en-us/library/System.IO(v=vs.110).aspx
Also, for copying or moving files, unity offers this class: http://docs.unity3d.com/Documentation/ScriptReference/FileUtil.html
EDIT: This might also help: http://answers.unity3d.com/questions/30147/loading-images-textures-resourcesload-vs-wwwtextur.html
Answer by Paulius-Liekis · Jul 03, 2014 at 12:10 PM
At the moment Unity allows to create texture from bytes in memory, so reading a texture (jpg/png) anywhere from disk is easy:
Texture2D tex = new Texture2D(4, 4);
tex.LoadImage(File.ReadAllBytes(path));
Answer by RickyAh · Mar 10, 2014 at 12:50 PM
Can't be done as far as I know. To be able to load a Texture, or any Asset, and be used in the project, I must be located inside that project's Assets folder. That's because `AssetDatabase.LoadAssetAtPath()` requires a relative path. Using a full path won't work,
The only partial solution I can think of is
Copy the template folder to a new folder inside Assets
Modify the copy
Move the copy to the destination folder outside the projects assets folder,
But doing so the new folder won't be accesible in the Unity project (i.e: it won't be shown in the Unity Project window)
Your answer
Follow this Question
Related Questions
How do I change the default application used to open logs from the Unity editor? (on Mac) 1 Answer
3ds max chariter texture and animation problem 1 Answer
Generate a gradient texture from editor script 0 Answers
How to make changes to a copied object 1 Answer
Are textured/z-clipped gizmos possible? 0 Answers