public static EditorTexture Load(IResourceProvider resources, string path, TextureResolution[] resolutions, CreateTextureOptions options, bool required) { using (ProfilingUtility.SampleBlock("Load Editor Texture")) { Ensure.That(nameof(resources)).IsNotNull(resources); Ensure.That(nameof(path)).IsNotNull(path); Ensure.That(nameof(resolutions)).HasItems(resolutions); var set = new EditorTexture(); // Try with explicit resolutions first foreach (var resolution in resolutions) { var width = resolution.width; // var height = resolution.height; var personalPath = String.Empty; var professionalPath = String.Empty; personalPath = resources.GetPersonalPath(path, width); professionalPath = resources.GetProfessionalPath(path, width); if (resources.FileExists(personalPath)) { var tex = resources.LoadTexture(personalPath, options); set.personal.Add(width, tex); } if (resources.FileExists(professionalPath)) { var tex = resources.LoadTexture(professionalPath, options); set.professional.Add(width, tex); } } if (set.personal.Count == 0) { if (required) { Debug.LogWarning($"Missing editor texture: {path}\n{resources.DebugPath(path)}"); } // Never return an empty set; the codebase assumes this guarantee return(null); } set.textureName = path; return(set); } }
public static EditorTexture Load(IResourceProvider resources, string path, CreateTextureOptions options, bool required) { using (ProfilingUtility.SampleBlock("Load Editor Texture")) { Ensure.That(nameof(resources)).IsNotNull(resources); Ensure.That(nameof(path)).IsNotNull(path); var set = new EditorTexture(); var name = Path.GetFileNameWithoutExtension(path).PartBefore('@'); var extension = Path.GetExtension(path); var directory = Path.GetDirectoryName(path); var personalPath = Path.Combine(directory, $"{name}{extension}"); var professionalPath = Path.Combine(directory, $"{name}@Pro{extension}"); if (resources.FileExists(personalPath)) { var personalTexture = resources.LoadTexture(personalPath, options); if (personalTexture != null) { set.personal.Add(personalTexture.width, personalTexture); } } if (resources.FileExists(professionalPath)) { var professionalTexture = resources.LoadTexture(professionalPath, options); if (professionalTexture != null) { set.professional.Add(professionalTexture.width, professionalTexture); } } if (set.personal.Count == 0) { if (required) { Debug.LogWarning($"Missing editor texture: {name}\n{resources.DebugPath(path)}"); } // Never return an empty set; the codebase assumes this guarantee return(null); } return(set); } }
public static EditorTexture Load(IResourceProvider resources, string path, TextureResolution[] resolutions, CreateTextureOptions options, bool required) { using (ProfilingUtility.SampleBlock("Load Editor Texture")) { Ensure.That(nameof(resources)).IsNotNull(resources); Ensure.That(nameof(path)).IsNotNull(path); Ensure.That(nameof(resolutions)).HasItems(resolutions); var set = new EditorTexture(); var name = Path.GetFileNameWithoutExtension(path).PartBefore('@'); var extension = Path.GetExtension(path); var directory = Path.GetDirectoryName(path); // Try with explicit resolutions first foreach (var resolution in resolutions) { var width = resolution.width; // var height = resolution.height; var personalPath = Path.Combine(directory, $"{name}@{width}x{extension}"); var professionalPath = Path.Combine(directory, $"{name}_Pro@{width}x{extension}"); if (resources.FileExists(personalPath)) { set.personal.Add(width, resources.LoadTexture(personalPath, options)); } if (resources.FileExists(professionalPath)) { set.professional.Add(width, resources.LoadTexture(professionalPath, options)); } } if (set.personal.Count == 0) { if (required) { Debug.LogWarning($"Missing editor texture: {name}\n{resources.DebugPath(path)}"); } // Never return an empty set; the codebase assumes this guarantee return(null); } return(set); } }