public static void SetPlatformIcon(BuildTargetGroup platform, PlatformIconKind kind, string folderPath, int layer = 0) { var iconNames = new List <string>(); var icons = PlayerSettings.GetPlatformIcons(platform, kind); var iconSizes = icons.Select(x => Tuple.Create(x.width, x.height)).ToArray(); foreach (var iconSize in iconSizes) { var fileName = string.Format("{0}x{1}.png", iconSize.Item1, iconSize.Item2); iconNames.Add(fileName); } var iconTextures = LoadIconTextures(folderPath, iconNames); foreach (var icon in icons) { var iconTexture = iconTextures.FirstOrDefault(x => x.width == icon.width && x.height == icon.height); if (iconTexture != null) { icon.SetTexture(iconTexture, layer); } } PlayerSettings.SetPlatformIcons(platform, kind, icons); }
private static Texture2D[] GetIconsFromAsset(BuildTargetGroup target, PlatformIconKind kind, PlatformIcon[] icons) { Texture2D[] texArray = new Texture2D[icons.Length]; //因为Android设置会带有" API (xx)"等附加信息,为了文件夹不出现空格,只取空格前单词 string folder = kind.ToString().Split(' ')[0]; string filename; for (int i = 0; i < texArray.Length; ++i) { //不需要再通过GetIconSizesForTargetGroup了来获得Icon尺寸数组, //直接由对应的PlatformIcon.width来获取Icon大小 int iconSize = icons[i].width; Debug.Log("iconSize:" + iconSize); filename = string.Format(Icon_Path, target, folder, iconSize); if (!File.Exists(filename)) { Debug.LogErrorFormat("图片文件不存在, 1路径为:{0}", filename); continue; } Texture2D tex2D = AssetDatabase.LoadAssetAtPath(filename, typeof(Texture2D)) as Texture2D; texArray[i] = tex2D; } return(texArray); }
static void SetIcons(BuildTargetGroup group, PlatformIconKind kind, params Texture2D[] icons) { var platIcons = PlayerSettings.GetPlatformIcons(group, kind); for (var i = 0; i < platIcons.Length; i++) //Assign textures to each available icon slot. { platIcons[i].SetTextures(icons); } PlayerSettings.SetPlatformIcons(group, kind, platIcons); }
public void AddPlatformIcons(PlatformIcon[] icons, PlatformIconKind kind) { m_PlatformIconsByKind[kind] = icons; IconFieldGroupInfo kindKey = new IconFieldGroupInfo(); kindKey.m_Kind = kind; kindKey.m_Label = kind.ToString(); kindKey.m_KindDescription = kind.description; Dictionary <IconFieldGroupInfo, PlatformIconField[]> kindDictionary; if (!m_IconsFields.ContainsKey(kindKey)) { kindKey.m_State = false; kindDictionary = new Dictionary <IconFieldGroupInfo, PlatformIconField[]>(); } else { kindDictionary = m_IconsFields[kindKey]; } var groupedBySubKind = icons.GroupBy(i => i.iconSubKind); foreach (var subKindGroup in groupedBySubKind) { var subKindIcons = subKindGroup.ToArray().Select(i => CreatePlatformIconField(i)).ToArray(); IconFieldGroupInfo subKindKey = new IconFieldGroupInfo(); subKindKey.m_Kind = null; subKindKey.m_Label = subKindGroup.Key; subKindKey.m_IconSlotCount = subKindIcons.Length; subKindKey.m_SetIconSlots = PlayerSettings.GetNonEmptyPlatformIconCount(subKindGroup.ToArray()); if (!kindDictionary.ContainsKey(subKindKey)) { subKindKey.m_State = false; } kindKey.m_IconSlotCount += subKindKey.m_IconSlotCount; kindKey.m_SetIconSlots += subKindKey.m_SetIconSlots; kindDictionary[subKindKey] = subKindIcons; } m_IconsFields[kindKey] = kindDictionary; }
private static void SetIcons(BuildTargetGroup platform, PlatformIconKind kind) { //获得当前平台和当前Icon类型的PlatformIcon数组 PlatformIcon[] icons = PlayerSettings.GetPlatformIcons(platform, kind); //将Asset转为Texture2D Texture2D[] iconSources = GetIconsFromAsset(platform, kind, icons); for (int i = 0, length = icons.Length; i < length; ++i) { icons[i].SetTexture(iconSources[i]); } PlayerSettings.SetPlatformIcons(platform, kind, icons); AssetDatabase.SaveAssets(); Debug.LogFormat("Set {0}/{1} Icon Complete", platform, kind); }
public void AddPlatformIcons(PlatformIcon[] icons, PlatformIconKind kind) { this.m_PlatformIconsByKind[kind] = icons; PlatformIconFieldGroup.IconFieldGroupInfo iconFieldGroupInfo = new PlatformIconFieldGroup.IconFieldGroupInfo(); iconFieldGroupInfo.m_Kind = kind; iconFieldGroupInfo.m_Label = kind.ToString(); Dictionary <PlatformIconFieldGroup.IconFieldGroupInfo, PlatformIconField[]> dictionary; if (!this.m_IconsFields.ContainsKey(iconFieldGroupInfo)) { iconFieldGroupInfo.m_State = false; dictionary = new Dictionary <PlatformIconFieldGroup.IconFieldGroupInfo, PlatformIconField[]>(); } else { dictionary = this.m_IconsFields[iconFieldGroupInfo]; } IEnumerable <IGrouping <string, PlatformIcon> > enumerable = from i in icons group i by i.iconSubKind; foreach (IGrouping <string, PlatformIcon> current in enumerable) { PlatformIconField[] array = (from i in current.ToArray <PlatformIcon>() select this.CreatePlatformIconField(i)).ToArray <PlatformIconField>(); PlatformIconFieldGroup.IconFieldGroupInfo iconFieldGroupInfo2 = new PlatformIconFieldGroup.IconFieldGroupInfo(); iconFieldGroupInfo2.m_Kind = null; iconFieldGroupInfo2.m_Label = current.Key; iconFieldGroupInfo2.m_IconSlotCount = array.Length; iconFieldGroupInfo2.m_SetIconSlots = PlayerSettings.GetNonEmptyPlatformIconCount(current.ToArray <PlatformIcon>()); if (!dictionary.ContainsKey(iconFieldGroupInfo2)) { iconFieldGroupInfo2.m_State = false; } iconFieldGroupInfo.m_IconSlotCount += iconFieldGroupInfo2.m_IconSlotCount; iconFieldGroupInfo.m_SetIconSlots += iconFieldGroupInfo2.m_SetIconSlots; dictionary[iconFieldGroupInfo2] = array; } this.m_IconsFields[iconFieldGroupInfo] = dictionary; }