private void UpdateSprite(int currentScreenWidth, int currentScreenHeight) { if (this.Atlas != null && this.SpriteReference != null) { SpriteRenderer renderer = this.gameObject.GetComponent <SpriteRenderer>(); if (renderer != null) { float scale; if (this.Atlas.UpdateRuntimeSprites(currentScreenWidth, currentScreenHeight, out scale)) { SVGRuntimeSprite newSprite = this.Atlas.GetRuntimeSprite(this.SpriteReference); if (newSprite != null) { renderer.sprite = newSprite.Sprite; // fix for the first time the sprite is regenerated at runtime if (this.m_RuntimeScale == 0) { this.m_RuntimeScale = this.Atlas.EditorGenerationScale; } // update local position this.FixLocalPosition(newSprite.GenerationScale / this.m_RuntimeScale); this.m_RuntimeScale = newSprite.GenerationScale; } } } } }
private void DisposeCards() { if (this.Camera != null) { int[] cardsIndexes; int slotsPerRow, slotsPerColumn; SVGRuntimeSprite data = this.Atlas.GetSpriteByName(GameCardBehaviour.AnimalSpriteName(GameCardType.BackSide)); float cardWidth = data.Sprite.bounds.size.x; float cardHeight = data.Sprite.bounds.size.y; float worldWidth = this.Camera.WorldWidth; float worldHeight = this.Camera.WorldHeight; if (worldWidth <= worldHeight) { // number of card slots in each dimension slotsPerRow = 3; slotsPerColumn = 4; cardsIndexes = CARDS_INDEXES_PORTRAIT; } else { // number of card slots in each dimension slotsPerRow = 4; slotsPerColumn = 3; cardsIndexes = CARDS_INDEXES_LANDSCAPE; } // 5% border float ofsX = worldWidth * 0.05f; float ofsY = worldHeight * 0.05f; float horizSeparator = ((worldWidth - (slotsPerRow * cardWidth) - (2.0f * ofsX)) / (slotsPerRow - 1)); float vertSeparator = ((worldHeight - (slotsPerColumn * cardHeight) - (2.0f * ofsY)) / (slotsPerColumn - 1)); int cardIdx = 0; for (int y = 0; y < slotsPerColumn; ++y) { for (int x = 0; x < slotsPerRow; ++x) { float posX = ofsX + (x * (cardWidth + horizSeparator)) - (worldWidth * 0.5f) + (cardWidth * 0.5f); float posY = ofsY + (y * (cardHeight + vertSeparator)) - (worldHeight * 0.5f) + (cardHeight * 0.5f); this.Cards[cardsIndexes[cardIdx]].transform.position = new Vector3(posX, posY); cardIdx++; } } } }
private void UpdateSprite(float canvasScaleFactor) { if ((this.UIAtlas != null) && (this.SpriteReference != null)) { Image uiImage = this.gameObject.GetComponent <Image>(); if (uiImage != null) { if (this.UIAtlas.UpdateRuntimeSprites(canvasScaleFactor)) { SVGRuntimeSprite newSprite = this.UIAtlas.GetRuntimeSprite(this.SpriteReference); if (newSprite != null) { // NB: we change sprite only, anchors and position will be updated by the canvas uiImage.sprite = newSprite.Sprite; } } } } }
public Sprite UpdateCardSprite(GameCardBehaviour card) { if (this.Atlas != null) { GameCardType cardType = card.BackSide ? GameCardType.BackSide : card.AnimalType; SVGRuntimeSprite data = this.Atlas.GetSpriteByName(GameCardBehaviour.AnimalSpriteName(cardType)); // get the sprite, given its name if (data != null) { card.gameObject.GetComponent <SpriteRenderer>().sprite = data.Sprite; // keep updated the SVGSpriteLoaderBehaviour component too SVGSpriteLoaderBehaviour loader = card.gameObject.GetComponent <SVGSpriteLoaderBehaviour>(); if (loader != null) { loader.SpriteReference = data.SpriteReference; } return(data.Sprite); } } return(null); }