public static void GetPlatformTextureFormatValuesAndStrings(TextureImporterType textureType, BuildTarget target, out int[] formatValues, out string[] formatStrings) { BuildValidFormats(); var key = new TextureTypeAndBuildTarget(textureType, target); formatValues = s_ValidTextureFormats[key].formatValues; formatStrings = s_ValidTextureFormats[key].formatStrings; }
private static void BuildValidFormats() { if (s_ValidTextureFormats != null) { return; } s_ValidTextureFormats = new Dictionary <TextureTypeAndBuildTarget, Value>(); s_ValidDefaultTextureFormats = new Dictionary <TextureImporterType, Value>(); foreach (var textureTypeName in Enum.GetNames(typeof(TextureImporterType))) { var textureTypeField = typeof(TextureImporterType).GetField(textureTypeName); if (textureTypeField.IsDefined(typeof(ObsoleteAttribute), false)) { continue; } var textureType = (TextureImporterType)Enum.Parse(typeof(TextureImporterType), textureTypeName); List <int> defaultFormats = null; foreach (var targetName in Enum.GetNames(typeof(BuildTarget))) { var targetField = typeof(BuildTarget).GetField(targetName); if (targetField.IsDefined(typeof(ObsoleteAttribute), false)) { continue; } var target = (BuildTarget)Enum.Parse(typeof(BuildTarget), targetName); var Key = new TextureTypeAndBuildTarget(textureType, target); var validFormats = Array.ConvertAll(TextureImporter.RecommendedFormatsFromTextureTypeAndPlatform(textureType, target), value => (int)value); s_ValidTextureFormats.Add(Key, new Value(validFormats, BuildTextureStrings(validFormats))); defaultFormats = defaultFormats?.Intersect(validFormats).ToList() ?? validFormats.ToList(); } // need "Auto" as the first entry for defaults defaultFormats.Insert(0, -1); var defaultFormatsArray = defaultFormats.ToArray(); s_ValidDefaultTextureFormats[textureType] = new Value(defaultFormatsArray, BuildTextureStrings(defaultFormatsArray)); } }