public BasicRenderInformation GetFromLocalAtlases(string atlasName, string spriteName, bool fallbackOnInvalid = false) { if (spriteName.IsNullOrWhiteSpace()) { return(GetFromLocalAtlases(null, "K45_WTS FrameParamsInvalidImage")); } if (LocalAtlasesCache.TryGetValue(atlasName ?? string.Empty, out Dictionary <string, BasicRenderInformation> resultDicCache) && resultDicCache.TryGetValue(spriteName ?? "", out BasicRenderInformation cachedInfo)) { return(cachedInfo); } if (!LocalAtlases.TryGetValue(atlasName ?? string.Empty, out UITextureAtlas atlas) || !atlas.spriteNames.Contains(spriteName)) { return(fallbackOnInvalid ? GetFromLocalAtlases(null, "K45_WTS FrameParamsInvalidImage") : null); } if (resultDicCache == null) { LocalAtlasesCache[atlasName ?? string.Empty] = new Dictionary <string, BasicRenderInformation>(); } LocalAtlasesCache[atlasName ?? string.Empty][spriteName] = null; StartCoroutine(CreateItemAtlasCoroutine(LocalAtlases, LocalRenderMaterial, LocalAtlasesCache, atlasName ?? string.Empty, spriteName)); return(null); }
public void LoadImagesFromLocalFolders() { LocalAtlases.Clear(); var errors = new List <string>(); var folders = new string[] { WTSController.ExtraSpritesFolder }.Concat(Directory.GetDirectories(WTSController.ExtraSpritesFolder)); foreach (var dir in folders) { bool isRoot = dir == WTSController.ExtraSpritesFolder; var spritesToAdd = new List <SpriteInfo>(); WTSAtlasLoadingUtils.LoadAllImagesFromFolderRef(dir, ref spritesToAdd, ref errors, isRoot); if (isRoot || spritesToAdd.Count > 0) { var atlasName = isRoot ? string.Empty : Path.GetFileNameWithoutExtension(dir); LocalAtlases[atlasName] = new UITextureAtlas { material = new Material(UIView.GetAView().defaultAtlas.material.shader) }; if (isRoot) { spritesToAdd.AddRange(UIView.GetAView().defaultAtlas.sprites.Select(x => CloneSpriteInfo(x)).ToList()); TextureAtlasUtils.LoadImagesFromResources("commons.UI.Images", ref spritesToAdd); TextureAtlasUtils.LoadImagesFromResources("UI.Images", ref spritesToAdd); } TextureAtlasUtils.RegenerateTextureAtlas(LocalAtlases[atlasName], spritesToAdd); } } LocalAtlasesCache.Clear(); LocalRenderMaterial.Clear(); if (errors.Count > 0) { K45DialogControl.ShowModal(new K45DialogControl.BindProperties { message = $"{Locale.Get("K45_WTS_CUSTOMSPRITE_ERRORHEADER")}:\n\t{string.Join("\n\t", errors.ToArray())}" }, (x) => true); } }