Я пытаюсь загрузить Texture2D
(.png) ресурс, используя Resource.Load
. Я попытался следующие шаблоны пути:Каков правильный путь Resource.Load?
Assets/CaseSensitivePath/TextureName
CaseSensitivePath/TextureName
Assets/CaseSensitivePath/TextureName.png
CaseSensitivePath/TextureName.png
Каждый раз, Resource.Load(path, typeof(Texture2D))
возвращает нуль. Это мой код и обработка ошибок:
public class LazyResource<T> where T : UnityEngine.Object
{
//Path is read-only
public string path { get { return _path; } }
private string _path = "";
//Whether NOT FOUND warning was thrown
//in that case, further load attemts are ommited and the resource returns always null...
public bool failed = false;
//Constructor uses the path as first parameter
public LazyResource(string path) {
_path = path;
}
//Cached resource
private T cache = null;
public T res
{
get
{
//Does not re-try if it failed before
if (cache == null && !failed)
{
//Load the proper type of resource
cache = (T)Resources.Load(_path, typeof(T));
//Throw warning (once)
if (cache == null)
{
Debug.LogWarning("Icon not found at '" + _path + "'!");
failed = true;
}
}
//Can return null
return cache;
}
}
}
Ошибка:
Icon not found at '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)
Что такое правильный путь, чтобы загрузить текстуру в проекте Unity3D?
Это в 'Assets/GUI/сборки/egg.png'. Проблема в том, что я не знал, что вы должны использовать папку [Ресурсы] (http://answers.unity3d.com/questions/14748/c-resourcesload-problem.html) ... Это отстой. Я хочу организовать свои файлы так, как я. –
Если вы хотите использовать 'Resources.Load', вам необходимо поместить ресурс в папку ** Resource **. – FunctionR
Я буду использовать что-то другое. –