c# - What is the correct Resource.Load path? -
i'm trying load texture2d
(.png) resource using resource.load
. i've tried following path patterns:
assets/casesensitivepath/texturename casesensitivepath/texturename assets/casesensitivepath/texturename.png casesensitivepath/texturename.png
every time, resource.load(path, typeof(texture2d))
returns null. code , error handling:
public class lazyresource<t> t : unityengine.object { //path read-only public string path { { return _path; } } private string _path = ""; //whether not found warning thrown //in case, further load attemts ommited , resource returns null... public bool failed = false; //constructor uses path first parameter public lazyresource(string path) { _path = path; } //cached resource private t cache = null; public t res { { //does not re-try if failed before if (cache == null && !failed) { //load proper type of resource cache = (t)resources.load(_path, typeof(t)); //throw warning (once) if (cache == null) { debug.logwarning("icon not found @ '" + _path + "'!"); failed = true; } } //can return null return cache; } } }
error:
icon not found @ 'textures/gui/build/egg'! unityengine.debug:logwarning(object) lazyresource`1:get_res() (at assets/worldobject/lazyresource.cs:28) actions.action:getmenuicon() (at assets/worldobject/action.cs:203) hud:drawactions(action[]) (at assets/player/hud/hud.cs:115) hud:drawordersbar() (at assets/player/hud/hud.cs:85) hud:ongui() (at assets/player/hud/hud.cs:63)
what correct path load texture in unity3d project?
you don't need path. can type
resources.load<texture2d>("texturename");
if texturename
in folder type:
resources.load<texture2d>("myfolder/texturename");
if want use resources.load
need put resource in resource folder. how looks in editor.
Comments
Post a Comment