Exemplo n.º 1
0
        public static Mesh CreateMesh(GradationMaterial material, Vector2 drawSize, Color lightColor, Color darkColor)
        {
            var result = CreateMesh(material);

            if (material.keys.Any(x => x.color.a < 1.0f))
            {
                var cellSize    = new Vector2(32.0f / drawSize.x, 32.0f / drawSize.y);
                var checkerMesh = CreateCheckerMesh(new Rect(-1.0f, -1.0f, 2.0f, 2.0f), cellSize, Color.white, Color.gray);

                var vertices = new Vector3[result.vertices.Length + checkerMesh.vertices.Length];
                Array.Copy(checkerMesh.vertices, 0, vertices, 0, checkerMesh.vertices.Length);
                Array.Copy(result.vertices, 0, vertices, checkerMesh.vertices.Length, result.vertices.Length);

                var colors = new Color[result.colors.Length + checkerMesh.colors.Length];
                Array.Copy(checkerMesh.colors, 0, colors, 0, checkerMesh.colors.Length);
                Array.Copy(result.colors, 0, colors, checkerMesh.colors.Length, result.colors.Length);

                var indices = checkerMesh.GetIndices(0)
                              .Concat(result.GetIndices(0)
                                      .Select(x => x + checkerMesh.vertices.Length)
                                      )
                              .ToArray();

                result.Clear();
                result.vertices = vertices;
                result.colors   = colors;
                result.SetIndices(indices, MeshTopology.Triangles, 0);
            }
            return(result);
        }
Exemplo n.º 2
0
 private Grid()
 {
     m_Material    = null;
     m_XThresholds = null;
     m_YThresholds = null;
     m_Colors      = null;
 }
Exemplo n.º 3
0
        private const float k_SnapRange    = 6.0f;      //スナップ範囲

        public static GradationWindow Instantiate(GradationMaterial target)
        {
            var result = EditorWindow.GetWindow <GradationWindow>();

            result.target = target;
            result.Show();
            return(result);
        }
Exemplo n.º 4
0
 public Grid(GradationMaterial material)
 {
     this.material = material;
     xThresholds   = material.keys.Select(x => x.position.x)
                     .Concat(new[] { 0.0f, 1.0f })
                     .OrderBy(x => x)
                     .Distinct()
                     .ToArray();
     yThresholds = material.keys.Select(x => x.position.y)
                   .Concat(new[] { 0.0f, 1.0f })
                   .OrderBy(x => x)
                   .Distinct()
                   .ToArray();
     colors = GetColors();
 }
Exemplo n.º 5
0
        public static Texture2D CreatePreviewTexture2D(PreviewRenderUtility previewRender, GradationMaterial material, Vector2 textureSize, Vector2 drawSize, Color lightColor, Color darkColor)
        {
            previewRender.m_Camera.orthographic     = true;
            previewRender.m_Camera.orthographicSize = 1.0f;
            previewRender.m_Camera.nearClipPlane    = 0.0f;
            previewRender.m_Camera.farClipPlane     = 2.0f;
            var previewMaterial = new Material(Shader.Find("Sprites/Default"));

            Rect r = new Rect(Vector2.zero, textureSize);

            previewRender.BeginStaticPreview(r);

            var matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(previewRender.m_Camera.aspect, 1.0f, 1.0f));
            var mesh   = CreateMesh(material, drawSize, lightColor, darkColor);

            previewRender.DrawMesh(mesh, matrix, previewMaterial, 0);

            previewRender.m_Camera.Render();
            var result = previewRender.EndStaticPreview();

            return(result);
        }
Exemplo n.º 6
0
        public static Texture2D CreatePreviewTexture2D(GradationMaterial material, Vector2 textureSize, Vector2 drawSize, Color lightColor, Color darkColor)
        {
            var previewRender = new PreviewRenderUtility();

            return(CreatePreviewTexture2D(previewRender, material, textureSize, drawSize, lightColor, darkColor));
        }
Exemplo n.º 7
0
 public static Texture2D CreatePreviewTexture2D(GradationMaterial material, Vector2 size, Color lightColor, Color darkColor)
 {
     return(CreatePreviewTexture2D(material, size, size, lightColor, darkColor));
 }
Exemplo n.º 8
0
        public static Mesh CreateMesh(GradationMaterial material)
        {
            var result = new Mesh();

            var grid            = material.GetGrid();
            var mainVertexCount = grid.xThresholds.Length * grid.yThresholds.Length;
            var subVertexCount  = mainVertexCount - grid.xThresholds.Length - grid.yThresholds.Length + 1;
            var vertexCount     = mainVertexCount + subVertexCount;

            var vertices = new Vector3[vertexCount];

            for (int y = 0, yMax = grid.yThresholds.Length; y < yMax; ++y)
            {
                for (int x = 0, xMax = grid.xThresholds.Length; x < xMax; ++x)
                {
                    var index = x + y * xMax;
                    vertices[index] = new Vector3(grid.xThresholds[x] * 2.0f - 1.0f
                                                  , 1.0f - grid.yThresholds[y] * 2.0f
                                                  , 0.0f
                                                  );
                }
            }
            for (int y = 0, yMax = grid.yThresholds.Length - 1; y < yMax; ++y)
            {
                for (int x = 0, xMax = grid.xThresholds.Length - 1; x < xMax; ++x)
                {
                    var index = x + y * xMax + mainVertexCount;
                    vertices[index] = new Vector3((grid.xThresholds[x] + grid.xThresholds[x + 1]) - 1.0f
                                                  , 1.0f - (grid.yThresholds[y] + grid.yThresholds[y + 1])
                                                  , 0.0f
                                                  );
                }
            }
            result.vertices = vertices;

            var colors = new Color[vertexCount];

            Array.Copy(grid.colors, colors, grid.colors.Length);
            for (int y = 0, yMax = grid.yThresholds.Length - 1; y < yMax; ++y)
            {
                for (int x = 0, xMax = grid.xThresholds.Length - 1; x < xMax; ++x)
                {
                    var index = x + y * xMax + mainVertexCount;
                    colors[index] = (grid.GetColor(x, y) + grid.GetColor(x + 1, y) + grid.GetColor(x + 1, y + 1) + grid.GetColor(x, y + 1)) * 0.25f;
                }
            }
            result.colors = colors;

            var indices = new int[12 * (grid.yThresholds.Length - 1) * (grid.xThresholds.Length - 1)];

            for (int y = 0, yMax = grid.yThresholds.Length - 1; y < yMax; ++y)
            {
                for (int x = 0, xMax = grid.xThresholds.Length - 1; x < xMax; ++x)
                {
                    var index           = x + y * xMax;
                    var upperLeftIndex  = x + y * grid.xThresholds.Length;
                    var upperRightIndex = upperLeftIndex + 1;
                    var lowerLeftIndex  = upperLeftIndex + grid.xThresholds.Length;
                    var lowerRightIndex = lowerLeftIndex + 1;
                    var centerIndex     = index + mainVertexCount;
                    indices[index * 12 + 0]  = centerIndex;
                    indices[index * 12 + 1]  = upperLeftIndex;
                    indices[index * 12 + 2]  = upperRightIndex;
                    indices[index * 12 + 3]  = centerIndex;
                    indices[index * 12 + 4]  = upperRightIndex;
                    indices[index * 12 + 5]  = lowerRightIndex;
                    indices[index * 12 + 6]  = centerIndex;
                    indices[index * 12 + 7]  = lowerRightIndex;
                    indices[index * 12 + 8]  = lowerLeftIndex;
                    indices[index * 12 + 9]  = centerIndex;
                    indices[index * 12 + 10] = lowerLeftIndex;
                    indices[index * 12 + 11] = upperLeftIndex;
                }
            }
            result.SetIndices(indices, MeshTopology.Triangles, 0);

            return(result);
        }
 public static Mesh CreateMesh(GradationMaterial material)
 {
     return(material.GetMesh());
 }