/// <summary> /// 加载文件中的皮肤 /// </summary> /// <param name="path"></param> /// <param name="platform">当前平台</param> /// <param name="logger">提示用Logger</param> /// <returns></returns> public async Task <CardSkinData[]> loadSkins(string path, PlatformCompability platform = null, ILogger logger = null) { platform = platform ?? PlatformCompability.Current; DataSet dataset = platform.SupportExcelReading ? await getManager <ResourceManager>().loadExcelAsDataSet(path, platform) : await getManager <ResourceManager>().loadDataSet(path, platform); if (dataset.Tables.Count < 1) { throw new Exception("空数据集"); } var table = dataset.Tables[0]; List <CardSkinData> skins = new List <CardSkinData>(); for (int i = 1; i < table.Rows.Count; i++) { try { var datarow = table.Rows[i]; if (datarow.ReadCol("Ignore", false)) { continue; } var skin = new CardSkinData() { id = datarow.ReadCol <int>("ID"), name = datarow.ReadCol <string>("Name"), desc = datarow.ReadCol <string>("Desc", "") }; logger?.log("加载卡片资源: " + skin.name); string imagePath = datarow.ReadCol("Image", ""); try { Texture2D texture = await getManager <ResourceManager>().loadTexture(imagePath, Path.GetDirectoryName(path)); Sprite sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(.5f, .5f), 100); skin.image = sprite; } catch (Exception e) { Debug.LogWarning("加载贴图 " + imagePath + " 失败:" + e); skin.image = await getDefaultSprite(); } skins.Add(skin); } catch (Exception e) { Debug.LogWarning($"Error when loading {path} (row {i}): " + e); } } return(skins.ToArray()); }
public Task <DataSet> loadExcelAsDataSet(string path, PlatformCompability platform = null, string curDir = null) { if (string.IsNullOrEmpty(path)) { return(null); } platform = platform ?? PlatformCompability.Current; if (platform.RequireWebRequest) { return(loadExcelAsDataSetByWebRequest(path, curDir)); } return(loadExcelAsDataSetBySystemIO(path, curDir)); }
/// <summary> /// 加载文件中的卡片 /// </summary> /// <param name="path"></param> /// <returns></returns> public async Task <CardDefine[]> loadCards(string path, PlatformCompability platform = null) { platform = platform ?? PlatformCompability.Current; DataSet dataset = platform.SupportExcelReading ? await getManager <ResourceManager>().loadExcelAsDataSet(path, platform) : await getManager <ResourceManager>().loadDataSet(path, platform); if (dataset.Tables.Count < 1) { throw new Exception("空数据集"); } var table = dataset.Tables[0]; List <CardDefine> cards = new List <CardDefine>(); for (int i = 1; i < table.Rows.Count; i++) { try { var datarow = table.Rows[i]; if (datarow.ReadCol("Ignore", false)) { continue; } var card = new GeneratedCardDefine(); card.id = datarow.ReadCol <int>("ID"); card.type = datarow.ReadCol <string>("Type"); card.setProp(nameof(ServantCardDefine.cost), datarow.ReadCol("Cost", 0)); card.setProp(nameof(ServantCardDefine.attack), datarow.ReadCol("Attack", 0)); card.setProp(nameof(ServantCardDefine.life), datarow.ReadCol("Life", 0)); card.setProp(nameof(ServantCardDefine.tags), datarow.ReadCol("Tags", "").Split(',')); card.setProp(nameof(ServantCardDefine.keywords), datarow.ReadCol("Keywords", "").Split(',')); card.setProp(nameof(ServantCardDefine.isToken), datarow.ReadCol("IsToken", false)); card.setProp(nameof(ServantCardDefine.isActive), datarow.ReadCol("IsActive", false)); cards.Add(card); } catch (Exception e) { Debug.LogWarning($"Error when loading {path} (row {i}): " + e); } } return(cards.ToArray()); }
public Task <Texture2D> loadTexture(string path, string curDir, PlatformCompability platform = null) { if (string.IsNullOrEmpty(path)) { return(null); } if (path.StartsWith("res:")) { return(Task.FromResult(Resources.Load <Texture2D>(path.Replace("res:", "")))); } platform = platform ?? PlatformCompability.Current; if (platform.RequireWebRequest) { return(loadTextureByWebRequestWithFallback(path, curDir)); } return(loadTextureBySystemIOWithFallback(path, curDir)); }
public Task <DataSet> loadDataSet(string path, PlatformCompability platform = null, string curDir = null) { if (string.IsNullOrEmpty(path)) { return(null); } if (Path.GetExtension(path).ToLower() == ".xls" || Path.GetExtension(path).ToLower() == ".xlsx") { Debug.Log("尝试直接读取Excel文件,程序将读取对应的dataset文件"); path += ".dataset"; } platform = platform ?? PlatformCompability.Current; if (platform.RequireWebRequest) { return(loadDataSetByWebRequest(path, curDir)); } return(loadDataSetBySystemIO(path, curDir)); }