/// <summary> /// 装备1001003 /// </summary> private void OnClickLoadEquip3() { AtlasVo atlasItem = OnLoadUIAtlasAsset <AtlasVo>("equip"); // 参数填写asset资源名 Sprite sprite = atlasItem.OnGetSprite("1001003"); equipPos_3.GetComponent <Image>().sprite = sprite; }
/// <summary> /// 生成UI图集序列化资源 /// </summary> private static void CreateUIAtlasAsset(string path_) { // asset文件夹 string assetPath = "Assets/Resassets/Data/AssetUIAtlas"; DirectoryInfo directInfo = new DirectoryInfo(path_); FileSystemInfo[] infos = directInfo.GetFileSystemInfos(); List <Sprite> spriteList = new List <Sprite>(); for (int i = 0; i < infos.Length; ++i) { FileSystemInfo info = infos[i]; if (Directory.Exists(info.FullName)) { CreateUIAtlasAsset(info.FullName); } else { if (info.Extension == ".png" || info.Extension == ".jpg") { string repPath = info.FullName.Replace("//", "/").Substring(info.FullName.IndexOf("Assets")); Sprite sprite = AssetDatabase.LoadAssetAtPath <Sprite>(repPath); spriteList.Add(sprite); } } } if (spriteList.Count > 0) { AtlasVo atlasVo = new AtlasVo(); atlasVo.OnConfDataFill(spriteList); string filePath = assetPath + "/" + directInfo.Name + ".asset"; AssetDatabase.DeleteAsset(filePath); AssetDatabase.CreateAsset(atlasVo, filePath); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); } }