using System; using System.Collections.Generic; using UnityEngine; public class ConfigManager : MonoBehaviour { private static string jsonConfig = @"{ ""mesh"": [ { ""revertSeam"": 0, ""vertices"": [ 0, 0, 0, 1, 1, 0, 1, 0, 0 ], ""indices"": [ 0, 1, 2 ] }, { ""revertSeam"": 0, ""vertices"": [ 0, 0, 0, 0, 1, 0, 1, 1, 0 ], ""indices"": [ 0, 1, 2 ] } ], ""instances"": [ { ""meshidx"": 0, ""uniforms"" : { ""vTransform"" : [0, 0, 0], ""vLocalTransform"": [0.25, 0.25], ""vSeamOffset"": [0, 0], ""vTextureSize"": [1, 1] }, ""texture"": 0 }, { ""meshidx"": 1, ""uniforms"" : { ""vTransform"" : [0, 0, 0], ""vLocalTransform"": [0.75, 0.25], ""vSeamOffset"": [0, 0], ""vTextureSize"": [1, 1] }, ""texture"": 1 }, { ""meshidx"": 0, ""uniforms"" : { ""vTransform"" : [0, 0, 0], ""vLocalTransform"": [0.25, 0.75], ""vSeamOffset"": [0, 0], ""vTextureSize"": [1, 1] }, ""texture"": 2 }, { ""meshidx"": 1, ""uniforms"" : { ""vTransform"" : [0.5, 0, 0], ""vLocalTransform"": [0.75, 0.75], ""vSeamOffset"": [0, 0], ""vTextureSize"": [1, 1] }, ""texture"": 3 } ], ""size"": [1206, 1206] }"; // 测试贴图数组 纯色: 红 绿 蓝 黄 private static List textures; private static List textureSizes = new List { new Vector2(600, 600), new Vector2(600, 600), new Vector2(600, 600), new Vector2(600, 600), new Vector2(600, 600), new Vector2(600, 600), new Vector2(600, 600), new Vector2(600, 600) }; public class TexturesConfig { public List textures; public List textureSizes; } public static JsonConfigParser.TileConfig getTestTileConfig(string configStr) { JsonConfigParser.TileConfig config = JsonConfigParser.ParseJsonConfig(configStr); return config; } public static TexturesConfig getTestTextures() { return new TexturesConfig { // 初始化四个纯色图片,颜色分别为 红色 绿色 蓝色 白色,宽高为1000 textures = new List { CreateTexture(Color.red), CreateTexture(Color.green), CreateTexture(Color.blue), CreateTexture(Color.white), CreateTexture(Color.yellow), CreateTexture(Color.cyan), CreateTexture(Color.gray), CreateTexture(Color.magenta) }, textureSizes = textureSizes }; } private static Texture2D CreateTexture(Color color) { // 创建一个 1000x1000 的纹理 Texture2D texture = new Texture2D(600, 600, TextureFormat.RGBA32, false); // 填充纹理为指定颜色 Color[] pixels = new Color[600 * 600]; for (int i = 0; i < pixels.Length; i++) { pixels[i] = color; } texture.SetPixels(pixels); texture.Apply(); // 应用更改 return texture; } }