public void LoadLocalTextures() { LocalTextures = new TextureResourceInfo(); LocalTextures.m_name = LocalizationManager.instance.current["local_tex"]; foreach (string file in Directory.GetFiles(ProceduralObjectsMod.TextureConfigPath, "*.png", SearchOption.AllDirectories)) { if (!File.Exists(file)) { continue; } try { var tex = TextureUtils.LoadPNG(file); // textures.Add(tex); int pos = file.LastIndexOf(ProceduralObjectsMod.IsLinux ? "/" : @"\") + 1; tex.name = "LOCALFOLDER/" + file.Substring(pos, file.Length - pos).Replace(".png", ""); LocalTextures.m_textures.Add(TextureUtils.CreateSelectorThumbnail(tex), tex); TotalTexturesCount += 1; LocalTexturesCount += 1; } catch { Debug.LogError("[ProceduralObjects] Texture Loading Error : Failed to load a texture at " + file + " !"); LocalTextures.m_failedToLoadTextures += 1; } } // LocalTexturesCount = textures.Count; TextureResources.Add(LocalTextures); Debug.Log("[ProceduralObjects] Texture Loading : Successfully loaded " + LocalTexturesCount + @" texture(s) from ProceduralObjects\Textures"); }
public void LoadTextures() { Debug.Log("[ProceduralObjects] Texture Loading : Started local texture loading."); // textures = new List<Texture2D>(); TextureResources = new List <TextureResourceInfo>(); LocalTexturesCount = 0; TotalTexturesCount = 0; // local textures loading LocalTextures = new TextureResourceInfo(); if (!Directory.Exists(ProceduralObjectsMod.TextureConfigPath)) { if (Directory.Exists(ProceduralObjectsMod.OldTextureConfigPath)) { try { Directory.Move(ProceduralObjectsMod.OldTextureConfigPath, ProceduralObjectsMod.TextureConfigPath); Debug.Log("[ProceduralObjects] Found old textures externals directory, moving to the new."); LoadLocalTextures(); } catch (Exception e) { Debug.LogError("[ProceduralObjects] Failed to move the old textures directory to the new one : " + e); Directory.CreateDirectory(ProceduralObjectsMod.TextureConfigPath); } } else { Directory.CreateDirectory(ProceduralObjectsMod.TextureConfigPath); Debug.Log("[ProceduralObjects] Local Texture Loading : directory doesn't exist ! Creating it and skipping texture loading."); } } else { LoadLocalTextures(); } // workshop textures loading Debug.Log("[ProceduralObjects] Texture Loading : Starting Workshop textures loading."); foreach (string path in ProceduralObjectsMod.WorkshopOrLocalFolders) { var infoFiles = Directory.GetFiles(path, "*ProceduralObjectsTextures.cfg", SearchOption.AllDirectories); foreach (string infoPath in infoFiles) { if (!File.Exists(infoPath)) { continue; } var texResource = new TextureResourceInfo(); texResource.m_fullPath = path; string[] files = File.ReadAllLines(infoPath); for (int i = 0; i < files.Count(); i++) { if (files[i].Contains("name = ")) { texResource.m_name = files[i].Replace("name = ", ""); } else { string pngPath = Path.GetDirectoryName(infoPath) + (ProceduralObjectsMod.IsLinux ? "/" : @"\") + files[i] + ".png"; if (File.Exists(pngPath)) { var tex = TextureUtils.LoadPNG(pngPath); // textures.Add(tex); tex.name = texResource.m_name + "/" + files[i]; texResource.m_textures.Add(TextureUtils.CreateSelectorThumbnail(tex), tex); TotalTexturesCount += 1; } else { Debug.LogError("[ProceduralObjects] Workshop texture : a file marked as a PO texture was not found at " + pngPath); texResource.m_failedToLoadTextures += 1; } } } TextureResources.Add(texResource); } } Debug.Log("[ProceduralObjects] Texture Loading : Successfully ended. " + TextureResources.Count + " workshop texture-containing folders loaded."); // return textures; }
public static List <Texture2D> LoadModConfigTextures(this List <Texture2D> textures) { Debug.Log("[ProceduralObjects] Texture Loading : Started local texture loading."); textures = new List <Texture2D>(); // local textures loading if (!Directory.Exists(ProceduralObjectsMod.TextureConfigPath)) { Directory.CreateDirectory(ProceduralObjectsMod.TextureConfigPath); Debug.Log("[ProceduralObjects] Local Texture Loading : ModConfig directory doesn't exist ! Creating it and skipping texture loading."); } else { foreach (string file in Directory.GetFiles(ProceduralObjectsMod.TextureConfigPath, "*.png", SearchOption.AllDirectories)) { if (!File.Exists(file)) { continue; } try { textures.Add(LoadPNG(file)); } catch { Debug.LogError("[ProceduralObjects] Texture Loading Error : Failed to load a texture at " + file + " !"); } } LocalTexturesCount = textures.Count; Debug.Log("[ProceduralObjects] Texture Loading : Successfully loaded " + LocalTexturesCount + @" texture(s) from ModConfig\ProceduralObjects"); } // workshop textures loading Debug.Log("[ProceduralObjects] Texture Loading : Starting Workshop textures loading."); TextureResources = new List <TextureResourceInfo>(); foreach (PublishedFileId fileId in PlatformService.workshop.GetSubscribedItems()) { string path = PlatformService.workshop.GetSubscribedItemPath(fileId); string infoPath = ProceduralObjectsMod.IsLinux ? path + @"/ProceduralObjectsTextures.cfg" : path + @"\ProceduralObjectsTextures.cfg"; if (File.Exists(infoPath)) { var texResource = new TextureResourceInfo(); texResource.m_fullPath = path; string[] files = File.ReadAllLines(infoPath); for (int i = 0; i < files.Count(); i++) { if (files[i].Contains("name = ")) { texResource.m_name = files[i].Replace("name = ", ""); } else { if (File.Exists(path + (ProceduralObjectsMod.IsLinux ? "/" : @"\") + files[i] + ".png")) { var tex = LoadPNG(path + (ProceduralObjectsMod.IsLinux ? "/" : @"\") + files[i] + ".png"); textures.Add(tex); texResource.m_textures.Add(tex); } else { Debug.LogError("[ProceduralObjects] Workshop texture : a file marked as a PO texture was not found at " + path + (ProceduralObjectsMod.IsLinux ? "/" : @"\") + files[i] + ".png"); texResource.m_failedToLoadTextures += 1; } } } TextureResources.Add(texResource); } } Debug.Log("[ProceduralObjects] Texture Loading : Successfully ended. " + TextureResources.Count + " workshop texture-containing folders loaded."); return(textures); }