Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic Sprite Sizes #19

Open
wants to merge 3 commits into
base: v2-pipeline-patch2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@ public class SpritesAsset
public const int AtlasTexture_Width = 512;
public const int AtlasTexture_Height = 512;

private static Vector2Int[] s_SpritesAssetSizesRef = new Vector2Int[] {
new Vector2Int(1, 1),
new Vector2Int(1, 2),
new Vector2Int(2, 1),
new Vector2Int(2, 2)
};

private uint _firstSpriteId = 0;
private uint _lastSpriteId = 0;
private uint _spriteType = 0;
Expand All @@ -33,12 +26,19 @@ public SpritesAsset(uint firstSpriteId, uint lastSpriteId, uint spriteType, stri
_fileName = filename;
}

private static Vector2Int GetSpriteSize(uint spriteType) {
var width = spriteType / 100;
var height = spriteType % 100;

return new Vector2Int((int) width, (int) height);
}

public Rendering.CachedSpriteInformation GetCachedSpriteInformation(uint spriteId, AssetBundle assetBundle) {
Texture2D tex2D = assetBundle.LoadAsset<Texture2D>(_fileName);
if (!tex2D)
return null;

var realSpriteSize = s_SpritesAssetSizesRef[_spriteType - 1] * Constants.FieldSize;
var realSpriteSize = GetSpriteSize(_spriteType) * Constants.FieldSize;
uint realId = spriteId - _firstSpriteId;
int texPerRow = AtlasTexture_Width / realSpriteSize.x;
int x = (int)((realId % texPerRow) * realSpriteSize.x);
Expand Down
15 changes: 8 additions & 7 deletions OpenTibia/Assets/Scripts/Core/Appearances/SpriteProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,17 @@ public void GenerateChannelsMaterialProps(MaterialPropertyBlock props) {
}

public sealed class SpritesProvider {
private static Vector2[] SpriteTypeSizeRefs = new Vector2[] {
new Vector2(1.0f, 1.0f),
new Vector2(1.0f, 2.0f),
new Vector2(2.0f, 1.0f),
new Vector2(2.0f, 2.0f)
};

List<SpriteTypeImpl> _spriteSheet;
List<CachedSprite> _cachedSprites = new List<CachedSprite>();

private static Vector2 GetSpriteSize(uint spriteType) {
var width = spriteType / 100;
var height = spriteType % 100;

return new Vector2(width, height);
}

public IEnumerator Parse(System.IO.Stream stream) {
using (var reader = new System.IO.BinaryReader(stream)) {
uint total = reader.ReadUInt32();
Expand Down Expand Up @@ -109,7 +110,7 @@ private SpriteLoadingStatus GetSpriteInfo(uint spriteId, out Vector4 uv, out Vec
return loadingStatus;
}

size = SpriteTypeSizeRefs[match.SpriteType - 1] * Constants.FieldSize;
size = GetSpriteSize(match.SpriteType) * Constants.FieldSize;
uint realId = spriteId - match.FirstSpriteId;
int texPerRow = (int)(texture.width / size.x);

Expand Down
2 changes: 1 addition & 1 deletion OpenTibia/Packages/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"com.unity.collab-proxy": "1.2.16",
"com.unity.ide.rider": "1.1.4",
"com.unity.ide.vscode": "1.1.4",
"com.unity.test-framework": "1.1.9",
"com.unity.test-framework": "1.1.13",
"com.unity.textmeshpro": "2.0.1",
"com.unity.ugui": "1.0.0",
"com.unity.modules.androidjni": "1.0.0",
Expand Down
4 changes: 2 additions & 2 deletions OpenTibia/ProjectSettings/ProjectVersion.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
m_EditorVersion: 2019.3.0f6
m_EditorVersionWithRevision: 2019.3.0f6 (27ab2135bccf)
m_EditorVersion: 2019.3.8f1
m_EditorVersionWithRevision: 2019.3.8f1 (4ba98e9386ed)