Exemple #1
0
        static void Reset(CustomRawImage image)
        {
            var vert = image.uIVertices;

            vert.Clear();
            var      size   = image.rectTransform.sizeDelta;
            float    x1     = size.x * 0.5f;
            float    x0     = -x1;
            float    y1     = size.y * 0.5f;
            float    y0     = -y1;
            UIVertex vertex = new UIVertex();

            vertex.position = new Vector3(x0, y0, 0);
            vertex.uv0      = Vector2.zero;
            vert.Add(vertex);
            vertex          = new UIVertex();
            vertex.position = new Vector3(x0, y1, 0);
            vertex.uv0      = new Vector2(0, 1);
            vert.Add(vertex);
            vertex          = new UIVertex();
            vertex.position = new Vector3(x1, y1, 0);
            vertex.uv0      = new Vector2(1, 1);
            vert.Add(vertex);
            vertex          = new UIVertex();
            vertex.position = new Vector3(x1, y0, 0);
            vertex.uv0      = new Vector2(1, 0);
            vert.Add(vertex);

            image.triangle.Clear();
            image.triangle.AddRange(tri_rect);
        }
Exemple #2
0
        static void SetSpriteNativeSize(CustomRawImage image)
        {
            var sprite = image.m_sprite;

            if (sprite == null)
            {
                return;
            }
            var w = sprite.rect.width;
            var h = sprite.rect.height;

            image.rectTransform.sizeDelta = new Vector2(w, h);
            Vector2 piovt = sprite.pivot;
            float   x     = sprite.rect.x;
            float   y     = sprite.rect.y;
            float   x0    = 0 - piovt.x;
            float   x1    = x0 + w;
            float   y0    = 0 - piovt.y;
            float   y1    = y0 + h;

            float u0 = x;
            float v0 = y;
            float u1 = w + u0;
            float v1 = h + v0;

            w   = image.texture.width;
            h   = image.texture.height;
            u0 /= w;
            u1 /= w;
            v0 /= h;
            v1 /= h;
            var vert = image.uIVertices;

            vert.Clear();
            UIVertex vertex = new UIVertex();

            vertex.position = new Vector3(x0, y0, 0);
            vertex.uv0      = new Vector2(u0, v0);
            vert.Add(vertex);
            vertex          = new UIVertex();
            vertex.position = new Vector3(x0, y1, 0);
            vertex.uv0      = new Vector2(u0, v1);
            vert.Add(vertex);
            vertex          = new UIVertex();
            vertex.position = new Vector3(x1, y1, 0);
            vertex.uv0      = new Vector2(u1, v1);
            vert.Add(vertex);
            vertex          = new UIVertex();
            vertex.position = new Vector3(x1, y0, 0);
            vertex.uv0      = new Vector2(u1, v0);
            vert.Add(vertex);
        }
Exemple #3
0
 public void Apply(CustomRawImage image)
 {
     if (image == null)
     {
         return;
     }
     image.texture = texture;
     image.uIVertices.Clear();
     image.uIVertices.AddRange(vert);
     image.triangle.Clear();
     image.triangle.AddRange(tri);
     image.Refresh();
 }