- Home /
Custom Editor Textures for Asset Store
I'm currently working on a toolkit for the Asset Store, and have reached a point where I require textures to be used.
My problem is, although there are methods to gain access to textures at a particular file location, currently there doesn't seem to be any way to always access a texture, regardless of where the user puts my toolkits folder.
Is there any way Unity has provided for such loading? Or am I going to have to work it through System code?
Answer by Randomman159 · May 02, 2014 at 11:13 PM
My solution in the end was to do a search for a uniquely named folder that all assets are in. Once this folder is found, it's trivial to load in all the images.
string[] assetDir = Directory.GetDirectories(Application.dataPath, "FancyTextureFoundExample.*", SearchOption.AllDirectories);
string graphicFile = assetDir[0] + "/SubFolder/Graphic.png";
graphicFile = graphicFile .Substring(Application.dataPath.Length + 1);
icon = AssetDatabase.LoadAssetAtPath("Assets/" + graphicFile, typeof(Texture2D)) as Texture2D;
This solution works great as long as only one folder has been named that which your provide (in my example, a folder named FancyTextureFoundExample should only be found once). Hence why I do a search for one of the lower folders in the hierarchy, as it uses the name of the pack in it, a unique name which other developers (almost positively) won't use.
Searching for something generic like "Graphics" or "Icons" or whatever is just going to end in disaster, there's no way you can really assure that yours will be picked first.
Your answer
Follow this Question
Related Questions
Expanding a custom property drawer of a list item forces further items in the list to disappear. 2 Answers
Custom editor not editing? 1 Answer
Custom Editor Similar to Animatior 1 Answer
How to create bitmask flags per scene that are available in the editor? 0 Answers
Custom editor tags not saving 1 Answer