Example #1
0
    Mesh CreateContentMesh(Size size, ContentBorderType contentType, ContentBorderAlignment alignment = ContentBorderAlignment.Default, IndexWindingOrder windingOrder = IndexWindingOrder.Clockwise)
    {
        var mesh = new Mesh();

        var vertices = new Vector3[4];
        var uv       = new Vector2[4];
        var indices  = new int[vertices.Length + 2];

        if (contentType == ContentBorderType.Triangle)
        {
            vertices = new Vector3[3];
            uv       = new Vector2[3];
            if (alignment == ContentBorderAlignment.Left)
            {
                SetVertices(ref vertices,
                            new Vector3(0, 0, 0),
                            new Vector3(0, size.Height, 0),
                            new Vector3(size.Width, size.Height, 0));

                SetUVs(ref uv, new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0));

                SetIndices(ref indices, 0, 1, 2);
            }
            else
            {
                SetVertices(ref vertices,
                            new Vector3(0, 0, 0),
                            new Vector3(size.Width, size.Height, 0),
                            new Vector3(size.Width, 0, 0));

                SetUVs(ref uv, new Vector2(0, 1), new Vector2(1, 0), new Vector2(1, 1));

                SetIndices(ref indices, 0, 1, 2);
            }
        }
        else if (contentType == ContentBorderType.Rectangle || contentType == ContentBorderType.Square)
        {
            SetVertices(ref vertices,
                        new Vector3(0, 0, 0),
                        new Vector3(0, size.Height, 0),
                        new Vector3(size.Width, size.Height, 0),
                        new Vector3(size.Width, 0, 0));

            SetUVs(ref uv, new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1));

            SetIndices(ref indices, 0, 1, 2, 0, 2, 3);
        }
        if (windingOrder == IndexWindingOrder.CounterClockWise)
        {
            indices = Reverse(indices);
        }

        mesh.vertices = vertices;
        mesh.uv       = (uv);
        mesh.SetIndices(indices, MeshTopology.Triangles, 0);
        mesh.RecalculateNormals();
        return(mesh);
    }
Example #2
0
    GameObject CreateContentDisplay(ContentBorderType type, ContentBorderAlignment align, int frameIndex, int contentIndex)
    {
        var contentDisplay = new GameObject("ContentDisplay_" + frameIndex + "_" + contentIndex, typeof(MeshRenderer), typeof(MeshFilter));

        var size = new Size(1, 1);

        if (type == ContentBorderType.Triangle)
        {
            size = new Size(2, 1);
        }
        else if (type == ContentBorderType.Rectangle)
        {
            size = new Size(2 + (ContentDistance * 2f), 1);
        }

        contentDisplay.GetComponent <MeshFilter>().mesh = CreateContentMesh(size, type, align);

        // Set texture
        var tex = (Texture)Resources.Load("ContentTexture_" + ((frameIndex * 2) + contentIndex));

        contentDisplay.renderer.material.mainTexture = tex;

        // Set shader for this sprite; unlit supporting transparency
        // If we dont do this the sprite seems 'dark' when drawn.
        var shader = Shader.Find("Diffuse");

        contentDisplay.renderer.material.shader = shader;

        contentDisplay.transform.renderer.material.mainTextureOffset = new Vector2(0, 1);         // +0.1x
        contentDisplay.transform.renderer.material.mainTextureScale  = new Vector2(1, -1);

        // contentDisplay.transform.rotation = new Quaternion(0, 0, 180, 0);

        // contentDisplay.AddComponent<Material>()

        return(contentDisplay);
    }