Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
TextureAtlas.cs
浏览该文件的文档.
1using System.Globalization;
2using Engine;
4
5namespace Game {
6 public class TextureAtlas {
8
9 public Dictionary<string, Rectangle> m_rectangles = [];
10
12
13 public TextureAtlas(Texture2D texture, string atlasDefinition, string prefix) {
14 m_texture = texture;
15 string[] array = atlasDefinition.Split(['\n', '\r'], StringSplitOptions.RemoveEmptyEntries);
16 int num = 0;
17 while (true) {
18 if (num < array.Length) {
19 string[] array2 = array[num].Split([' '], StringSplitOptions.RemoveEmptyEntries);
20 if (array2.Length < 5) {
21 break;
22 }
23 string key = prefix + array2[0];
24 Rectangle value = new() {
25 Left = int.Parse(array2[1], CultureInfo.InvariantCulture),
26 Top = int.Parse(array2[2], CultureInfo.InvariantCulture),
27 Width = int.Parse(array2[3], CultureInfo.InvariantCulture),
28 Height = int.Parse(array2[4], CultureInfo.InvariantCulture)
29 };
30 m_rectangles.Add(key, value);
31 num++;
32 continue;
33 }
34 return;
35 }
36 throw new InvalidOperationException("Invalid texture atlas definition.");
37 }
38
39 public bool ContainsTexture(string textureName) => m_rectangles.ContainsKey(textureName);
40
41 public Vector4? GetTextureCoordinates(string textureName) {
42 if (m_rectangles.TryGetValue(textureName, out Rectangle value)) {
43 Vector4 value2 = default;
44 value2.X = value.Left / (float)m_texture.Width;
45 value2.Y = value.Top / (float)m_texture.Height;
46 value2.Z = value.Right / (float)m_texture.Width;
47 value2.W = value.Bottom / (float)m_texture.Height;
48 return value2;
49 }
50 return null;
51 }
52 }
53}
TextureAtlas(Texture2D texture, string atlasDefinition, string prefix)
Dictionary< string, Rectangle > m_rectangles
bool ContainsTexture(string textureName)
Vector4? GetTextureCoordinates(string textureName)