Наследование: IDisposable
Пример #1
0
        public Tilemap(string csvFile, string textureName)
        {
            string mapBody = File.ReadAllText(csvFile).TrimEnd(new char[] { '\n' });
            string[] rows = mapBody.Split('\n');
            int index = 0;
            height = rows.Length;
            foreach (string row in rows)
            {
                string[] cols = row.Split(',');
                width = cols.Length;
                if (this.map == null)
                {
                    this.map = new int[cols.Length * rows.Length];
                }
                foreach (string col in cols)
                {
                    this.map[index] = int.Parse(col);
                    index++;
                }
            }

            this.mapMesh = new Mesh();
            List<float> vertices = new List<float>();
            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    vertices.Add(x * 70);
                    vertices.Add(y * 70);

                    vertices.Add(x * 70);
                    vertices.Add((y + 1) * 70);

                    vertices.Add((x + 1) * 70);
                    vertices.Add(y * 70);

                    vertices.Add((x + 1) * 70);
                    vertices.Add(y * 70);

                    vertices.Add((x + 1) * 70);
                    vertices.Add((y + 1) * 70);

                    vertices.Add(x * 70);
                    vertices.Add((y + 1) * 70);
                }
            }

            this.mapMesh.v = vertices.ToArray();
            this.mapMesh.uv = new float[this.mapMesh.v.Length];
            this.mapMesh.Update();
            this.tileSheet = new Texture(textureName);
            // use nearest mode for sampling
            this.tileSheet.SetNearest();
        }
Пример #2
0
        public PostProcessingEffect(string fragmentShader, string fragmentShaderObsolete = null)
        {
            string[] attribs = null;
            if (fragmentShaderObsolete != null)
            {
                attribs = new string[] { "screen_vertex", "screen_uv" };
            }
            screenMesh = new Mesh(new Shader(vertexShader, fragmentShader, vertexShaderObsolete, fragmentShaderObsolete, attribs));
            screenMesh.hasVertexColors = false;

            screenMesh.v = new float[]
            {
                    -1, 1,
                    1, 1,
                    1, -1,

                    1,-1,
                    -1, -1,
                    -1, 1
            };

            screenMesh.uv = new float[]
            {
                    0, 1,
                    1, 1,
                    1, 0,

                    1, 0,
                    0, 0,
                    0, 1
            };

            // upload both vertices and uvs
            screenMesh.Update();
            screenMesh.noMatrix = true;

            // enabled by default
            this.enabled = true;
        }