private Sprite TryGetOrCreateSprite(string assetName) { //if we already cached from a previous operation Sprite item = _assets.GetSpriteByName(assetName); if (item != null) { return(item); } Sprite SpriteCreationAction() { LDtkTextureSpriteSlicer slicer = new LDtkTextureSpriteSlicer(_srcTex, _pixelsPerUnit); Sprite sprite = slicer.CreateSpriteSliceForPosition(_srcPos); if (sprite == null) { Debug.LogError("SpriteCreationAction error"); return(null); } sprite.name = assetName; return(sprite); } //otherwise make a new one return((Sprite)CreateAndAddAsset(SpriteCreationAction)); }
private Sprite GetSprite() { Rect rect = _level.BgPos.UnityCropRect; rect.position = LDtkToolOriginCoordConverter.LevelBackgroundImageSliceCoord(rect.position, _texture.height, rect.height); if (!LDtkTextureSpriteSlicer.IsLegalSpriteSlice(_texture, rect)) { Debug.LogError($"Illegal Sprite slice {rect} from texture ({_texture.width}, {_texture.height})"); return(null); } Sprite sprite = Sprite.Create(_texture, rect, Vector2.up, _importer.PixelsPerUnit); sprite.name = _texture.name; return(sprite); }