/// <summary> /// Loads all material textures using a coroutine. /// </summary> public IEnumerator LoadTextures() { foreach (IntermediateMaterial im in Materials) { string path = FileFinder.Instance.Find(im.MainTexture.FileName); if (path != string.Empty) { // Have we already loaded this texture? if (_Textures.ContainsKey(path)) { // Dont need to load it. break; } string ext = Path.GetExtension(path); if (ext == ".rgb" || ext == ".rgba" || ext == ".bw" || ext == ".int" || ext == ".inta" || ext == ".sgi") { TextureSGI sgi = new TextureSGI(path); Texture2D tex = sgi.Texture; if (tex != null) { _Textures[path] = tex; tex.name = Path.GetFileNameWithoutExtension(path); yield return(tex); } } else { WWW www = new WWW("file://" + path); yield return(www); if (www.error == null && www.texture != null) { _Textures[path] = www.texture; // DuckbearLab: FIX! //_Textures[path].hideFlags = HideFlags.DontSave; www.texture.name = Path.GetFileNameWithoutExtension(path); yield return(www.texture); } else { Debug.LogError(www.error); } } } } }
/// <summary> /// Finds the texture if it has already been loaded else loads /// the new texture and records it for future re-use. /// </summary> Texture will be loaded in the same thread. /// <returns> /// Found texture or null if it can not be found/loaded. /// </returns> /// <param name='tp'>Tp.</param> public Texture2D FindOrCreateTexture(TexturePalette tp) { // Find the texture // TODO: Make the path absolute? string path = FileFinder.Instance.Find(tp.FileName); if (path != string.Empty) { // Have we already loaded this texture? Texture2D tex = null; // TODO: Maybe hash the paths for faster lookup? if (_Textures.TryGetValue(path, out tex)) { // We found it! return(tex); } string ext = Path.GetExtension(path); if (ext == ".rgb" || ext == ".rgba" || ext == ".bw" || ext == ".int" || ext == ".inta" || ext == ".sgi") { TextureSGI sgi = new TextureSGI(path); tex = sgi.Texture; if (tex != null) { // DuckbearLab: FIX! //_Textures[path].hideFlags = HideFlags.DontSave; // DuckbearLab: FIX! //tex.name = Path.GetFileNameWithoutExtension(path); tex.name = Path.GetFullPath(path); _Textures[path] = tex; return(tex); } } else { WWW www = new WWW("file://" + path); while (!www.isDone) { } if (string.IsNullOrEmpty(www.error) && www.texture != null) { // DuckbearLab: FIX! //www.texture.hideFlags = HideFlags.DontSave; // DuckbearLab: FIX! //www.texture.name = Path.GetFileNameWithoutExtension(path); //www.texture.name = Path.GetFullPath(path); var resultTexture = www.texture; resultTexture.name = Path.GetFullPath(path); _Textures[path] = resultTexture; // TODO: You are here!!!! /*FieldInfo fi = www.texture.GetType().GetField("m_Name", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.IgnoreCase); * if (fi != null) Debug.Log("FOund it ");*/ //myFieldInfo.SetValue( www.texture, "TEST" ); //Debug.Log( myFieldInfo.GetValue( www.texture ) ); return(resultTexture); } else { Debug.LogError(www.error); } } } return(null); }