public Texture2D LoadTexture(string path, CreateTextureOptions options) { Ensure.That(nameof(path)).IsNotNull(path); path = NormalizePath(path); var stream = assembly.GetManifestResourceStream(path); if (stream == null) { Debug.LogWarning("Failed to get assembly resource stream:\n" + path); return(null); } BinaryReader reader = null; try { reader = new BinaryReader(stream); var bytes = reader.ReadBytes((int)stream.Length); var texture = new Texture2D(0, 0, options.textureFormat, options.mipmaps, options.linear ?? LudiqGUIUtility.createLinearTextures); texture.alphaIsTransparency = options.alphaIsTransparency; texture.filterMode = options.filterMode; texture.hideFlags = options.hideFlags; texture.LoadImage(bytes); return(texture); } finally { reader?.Close(); } }
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 Texture2D LoadTexture(string path, CreateTextureOptions options) { return(LoadAsset <Texture2D>(path)); }
public static EditorTexture Load(IEnumerable <IResourceProvider> resourceProviders, string path, TextureResolution[] resolutions, CreateTextureOptions options, bool required) { foreach (var resources in resourceProviders) { var texture = Load(resources, path, resolutions, options, false); if (texture != null) { return(texture); } } if (required) { var message = new StringBuilder(); message.AppendLine("Missing editor texture: "); foreach (var resources in resourceProviders) { message.AppendLine($"{resources.GetType().HumanName()}: {resources.DebugPath(path)}"); } Debug.LogWarning(message.ToString()); } return(null); }
public EditorTexture LoadTexture(string path, TextureResolution[] resolutions, CreateTextureOptions options, bool required = true) { return(EditorTexture.Load(providers, path, resolutions, options, required)); }