3
Resource.Load
을 사용하여 Texture2D
(.png) 리소스를로드하려고합니다. 나는 경로 패턴 다음 시도했다 :올바른 Resource.Load 경로는 무엇입니까?
Assets/CaseSensitivePath/TextureName
CaseSensitivePath/TextureName
Assets/CaseSensitivePath/TextureName.png
CaseSensitivePath/TextureName.png
때마다, Resource.Load(path, typeof(Texture2D))
는 null를 돌려줍니다. 이것은 내 코드 및 오류 처리입니다 :
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/Build/egg.png'에 있습니다. 문제는 내가 [Resources 폴더] (http://answers.unity3d.com/questions/14748/c-resourcesload-problem.html)를 사용해야한다는 것을 몰랐다는 것입니다. 내가 원하는대로 파일을 정리하고 싶습니다. –
'Resources.Load'를 사용하려면 자원을 ** Resource 폴더 **에 넣어야합니다. – FunctionR
다른 것을 사용하겠습니다. –