AddUIVertexStream() public method

public AddUIVertexStream ( List verts, List indices ) : void
verts List
indices List
return void
Example #1
0
        void GeneratePolygonSprite(VertexHelper vh, bool preserveAspect)
        {
            Vector4 v = GetDrawingDimensions(preserveAspect);
            var color32 = color;

            int len = sprite.vertices.Length;
            var vertices = new List<UIVertex>(len);
            Vector2 center = sprite.bounds.center;
            Vector2 invExtend = new Vector2(1 / sprite.bounds.size.x, 1 / sprite.bounds.size.y);
            for (int i = 0; i < len; i++)
            {
                // range [-0.5, 0.5] + 0.5 = [0, 1]
                float x = (sprite.vertices[i].x - center.x) * invExtend.x + 0.5f;
                float y = (sprite.vertices[i].y - center.y) * invExtend.y + 0.5f;
                
                UIVertex vertice = new UIVertex();
                vertice.color = color32;
                vertice.uv0 = sprite.uv[i];
                vertice.position = CalPosition(v, x, y);
                
                vertices.Add(vertice);
            }

            len = sprite.triangles.Length;
            
            var triangles = new List<int>(len);
            for (int i = 0; i < len; i++)
            {
                triangles.Add(sprite.triangles[i]);
            }
            vh.Clear();
            vh.AddUIVertexStream(vertices, triangles);
        }
Example #2
0
 static public int AddUIVertexStream(IntPtr l)
 {
     try {
                     #if DEBUG
         var    method     = System.Reflection.MethodBase.GetCurrentMethod();
         string methodName = GetMethodName(method);
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.BeginSample(methodName);
                     #else
         Profiler.BeginSample(methodName);
                     #endif
                     #endif
         UnityEngine.UI.VertexHelper self = (UnityEngine.UI.VertexHelper)checkSelf(l);
         System.Collections.Generic.List <UnityEngine.UIVertex> a1;
         checkType(l, 2, out a1);
         System.Collections.Generic.List <System.Int32> a2;
         checkType(l, 3, out a2);
         self.AddUIVertexStream(a1, a2);
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
             #if DEBUG
     finally {
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.EndSample();
                     #else
         Profiler.EndSample();
                     #endif
     }
             #endif
 }
Example #3
0
        public override void ModifyMesh(VertexHelper vh)
        {
            if (!isActiveAndEnabled)
            {
                return;
            }
            if (rectTransform == null)
            {
                rectTransform = GetComponent <RectTransform>();
            }
            if (image == null)
            {
                image = GetComponent <Image>();
            }
            if (image.type != Image.Type.Simple)
            {
                return;
            }
            Sprite sprite = image.overrideSprite;

            if (sprite == null || sprite.triangles.Length == 6)
            {
                // only 2 triangles
                return;
            }
            // at first I copy codes from Image.GetDrawingDimensions
            // to calculate Image's dimensions. But now for easy to read, I just take usage of corners.
            if (vh.currentVertCount != 4)
            {
                return;
            }
            rectTransform.GetLocalCorners(fourCorners);
            // recalculate vertices from Sprite!
            int     len       = sprite.vertices.Length;
            var     vertices  = new List <UIVertex>(len);
            Vector2 Center    = sprite.bounds.center;
            Vector2 invExtend = new Vector2(1 / sprite.bounds.size.x, 1 / sprite.bounds.size.y);

            for (int i = 0; i < len; i++)
            {
                // normalize
                float x = (sprite.vertices[i].x - Center.x) * invExtend.x + 0.5f;
                float y = (sprite.vertices[i].y - Center.y) * invExtend.y + 0.5f;
                // lerp to position
                vertice.position = new Vector2(Mathf.Lerp(fourCorners[0].x, fourCorners[2].x, x), Mathf.Lerp(fourCorners[0].y, fourCorners[2].y, y));
                vertice.color    = image.color;
                vertice.uv0      = sprite.uv[i];
                vertices.Add(vertice);
            }
            len = sprite.triangles.Length;
            var triangles = new List <int>(len);

            for (int i = 0; i < len; i++)
            {
                triangles.Add(sprite.triangles[i]);
            }
            vh.Clear();
            vh.AddUIVertexStream(vertices, triangles);
        }
Example #4
0
        protected override void OnPopulateMesh(VertexHelper vh)
        {
            base.OnPopulateMesh(vh);
            if (type != Type.Simple)
            {
                return;
            }
            if (overrideSprite == null || overrideSprite.triangles.Length == 6)
            {
                return;
            }
            if (vh.currentVertCount != 4)
            {
                return;
            }
            var vertice = new UIVertex();

            vh.PopulateUIVertex(ref vertice, 0);
            Vector2 lb = vertice.position;

            vh.PopulateUIVertex(ref vertice, 2);
            Vector2 rt = vertice.position;


            var     len       = sprite.vertices.Length;
            var     vertices  = new List <UIVertex>(len);
            Vector2 Center    = sprite.bounds.center;
            var     invExtend = new Vector2(1 / sprite.bounds.size.x, 1 / sprite.bounds.size.y);

            for (var i = 0; i < len; i++)
            {
                vertice = new UIVertex();
                // normalize
                var x = (sprite.vertices[i].x - Center.x) * invExtend.x + 0.5f;
                var y = (sprite.vertices[i].y - Center.y) * invExtend.y + 0.5f;
                // lerp to position
                vertice.position = new Vector2(Mathf.Lerp(lb.x, rt.x, x), Mathf.Lerp(lb.y, rt.y, y));
                vertice.color    = color;
                vertice.uv0      = sprite.uv[i];
                vertices.Add(vertice);
            }


            len = sprite.triangles.Length;
            var triangles = new List <int>(len);

            for (var i = 0; i < len; i++)
            {
                triangles.Add(sprite.triangles[i]);
            }
            vh.Clear();
            vh.AddUIVertexStream(vertices, triangles);
        }
 static public int AddUIVertexStream(IntPtr l)
 {
     try {
         UnityEngine.UI.VertexHelper self = (UnityEngine.UI.VertexHelper)checkSelf(l);
         System.Collections.Generic.List <UnityEngine.UIVertex> a1;
         checkType(l, 2, out a1);
         System.Collections.Generic.List <System.Int32> a2;
         checkType(l, 3, out a2);
         self.AddUIVertexStream(a1, a2);
         return(0);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Example #6
0
        protected override void OnPopulateMesh(VertexHelper vh)
        {
            if (overrideSprite == null)
            {
                base.OnPopulateMesh(vh);
                return;
            }

            List <UIVertex> vbo = null;
            List <int>      ibo = null;

            if (type != Type.Filled)
            {
                vbo = new List <UIVertex>();
                ibo = new List <int>();
                vh.Clear();
                vh.GetUIVertexStream(vbo);
            }

            switch (type)
            {
            case Type.Simple:
                GenerateSimpleSpriteNew(vbo, ibo, this.preserveAspect);
                break;

            case Type.Sliced:
                GenerateSlicedSpriteNew(vbo, ibo);
                break;

            case Type.Tiled:
                GenerateTiledSpriteNew(vbo, ibo);
                break;

            case Type.Filled:
                //				GenerateFilledSprite(vbo, this.preserveAspect);
                base.OnPopulateMesh(vh);
                return;
            }

            if (type != Type.Filled)
            {
                vh.Clear();
                vh.AddUIVertexStream(vbo, ibo);
            }
        }
        public override void ModifyMesh(VertexHelper vh)
        {
            if (!isActiveAndEnabled)
            {
                return;
            }

            if (rectTransform == null)
            {
                rectTransform = GetComponent <RectTransform> ();
            }
            if (image == null)
            {
                image = GetComponent <Image> ();
            }
            if (image.type != Image.Type.Simple)
            {
                return;
            }
            if (vh.currentVertCount != 4)
            {
                return;
            }

            rectTransform.GetLocalCorners(fourCorners);
            var vertices = new List <UIVertex> (3);

            for (int i = 0; i < 3; i++)
            {
                vertice.position = fourCorners[i];
                vertice.color    = image.color;
                vertice.uv0      = GetUV(i);
                vertices.Add(vertice);
            }

            var triangles = new List <int> (3);

            for (int i = 0; i < 3; i++)
            {
                triangles.Add(i);
            }

            vh.Clear();
            vh.AddUIVertexStream(vertices, triangles);
        }
	/// <summary>
	/// Update all renderer data.
	/// </summary>
#if UNITY_5 && !UNITY_5_0 && !UNITY_5_1
	protected override void OnPopulateMesh(VertexHelper vh)
	{
		vh.Clear();

		List<UIVertex> aVerts = new List<UIVertex>();
		_OnFillVBO(aVerts);

		List<int> aIndicies = new List<int>(new int[] { 0, 1, 2, 2, 3, 0 });
		vh.AddUIVertexStream(aVerts, aIndicies);
	}
Example #9
0
        public override void ModifyMesh(VertexHelper vh)
        {
            Image image = GetComponent <Image>();

            if (image.type != Image.Type.Simple)
            {
                return;
            }

            Sprite sprite = image.overrideSprite;

            if (sprite == null || sprite.triangles.Length == 6)
            {
                return;
            }

            // Kanglai: at first I copy codes from Image.GetDrawingDimensions
            // to calculate Image's dimensions. But now for easy to read, I just take usage of corners.

            if (vh.currentVertCount != 4)
            {
                return;
            }
            UIVertex vertice = new UIVertex();

            vh.PopulateUIVertex(ref vertice, 0);
            Vector2 lb = vertice.position;

            vh.PopulateUIVertex(ref vertice, 2);
            Vector2 rt = vertice.position;

            // Kanglai: recalculate vertices from Sprite!
            int     len       = sprite.vertices.Length;
            var     vertices  = new List <UIVertex>(len);
            Vector2 Center    = sprite.bounds.center;
            Vector2 invExtend = new Vector2(1 / sprite.bounds.size.x, 1 / sprite.bounds.size.y);

            for (int i = 0; i < len; i++)
            {
                vertice = new UIVertex();
                // normalize
                float x = (sprite.vertices[i].x - Center.x) * invExtend.x + 0.5f;
                float y = (sprite.vertices[i].y - Center.y) * invExtend.y + 0.5f;
                // lerp to position
                vertice.position = new Vector2(Mathf.Lerp(lb.x, rt.x, x), Mathf.Lerp(lb.y, rt.y, y));
                vertice.color    = image.color;
                vertice.uv0      = sprite.uv[i];
                vertices.Add(vertice);
            }

            len = sprite.triangles.Length;

            var triangles = new List <int>(len);

            for (int i = 0; i < len; i++)
            {
                triangles.Add(sprite.triangles[i]);
            }

            vh.Clear();
            vh.AddUIVertexStream(vertices, triangles);
        }
Example #10
0
        public override void ModifyMesh(VertexHelper vh)
        {
            if (!isActiveAndEnabled)
            {
                return;
            }

            if (!recTransform)
            {
                recTransform = GetComponent <RectTransform>();
            }

            if (!image)
            {
                image = GetComponent <Image>();
            }

            //目前仅支持优化普通模式的image
            if (image.type != Image.Type.Simple)
            {
                return;
            }

            //注意此处是overrideSprite
            Sprite sprite = image.overrideSprite;

            //只有两个三角形,不用进行优化
            if (sprite == null || sprite.triangles.Length == 6)
            {
                return;
            }

            if (vh.currentVertCount != 4)
            {
                return;
            }

            recTransform.GetLocalCorners(fourCorners);

            //重新计算sprite的顶点数据
            int     len       = sprite.vertices.Length;
            var     vertices  = new List <UIVertex>(len);
            Vector2 Center    = sprite.bounds.center;
            Vector2 invExtend = new Vector2(1 / sprite.bounds.size.x, 1 / sprite.bounds.size.y);

            for (int i = 0; i < len; i++)
            {
                // normalize
                float x = (sprite.vertices[i].x - Center.x) * invExtend.x + 0.5f;
                float y = (sprite.vertices[i].y - Center.y) * invExtend.y + 0.5f;
                // lerp to position
                vertice.position = new Vector2(Mathf.Lerp(fourCorners[0].x, fourCorners[2].x, x), Mathf.Lerp(fourCorners[0].y, fourCorners[2].y, y));
                vertice.color    = image.color;
                vertice.uv0      = sprite.uv[i];
                vertices.Add(vertice);
            }
            len = sprite.triangles.Length;
            var triangles = new List <int>(len);

            for (int i = 0; i < len; i++)
            {
                //根据sprite的顶点进行三角形的绘制
                triangles.Add(sprite.triangles[i]);
            }

            vh.Clear();
            vh.AddUIVertexStream(vertices, triangles);
        }
Example #11
0
        public override void ModifyMesh(VertexHelper vh)
        {
            Image image = GetComponent <Image>();

            if (image.type != Image.Type.Simple)
            {
                return;
            }
            Sprite sprite = image.overrideSprite;

            if (sprite == null || sprite.triangles.Length == 6)
            {
                // only 2 triangles
                return;
            }

            if (vh.currentVertCount != 4)
            {
                return;
            }
            UIVertex vertice = new UIVertex();

            vh.PopulateUIVertex(ref vertice, 0);
            Vector2 lb = vertice.position;

            vh.PopulateUIVertex(ref vertice, 2);
            Vector2 rt = vertice.position;

            int len      = sprite.vertices.Length;
            var vertices = new List <UIVertex>(len);

            float minX = float.MaxValue;
            float maxX = float.MinValue;
            float minY = float.MaxValue;
            float maxY = float.MinValue;

            for (int i = 0; i < len; i++)
            {
                minX = Mathf.Min(minX, sprite.vertices[i].x);
                maxX = Mathf.Max(maxX, sprite.vertices[i].x);
                minY = Mathf.Min(minY, sprite.vertices[i].y);
                maxY = Mathf.Max(maxY, sprite.vertices[i].y);
            }

            Vector2 invExtend = new Vector2(1.0f / (maxX - minX), 1.0f / (maxY - minY));

            for (int i = 0; i < len; i++)
            {
                vertice = new UIVertex();

                float x = (sprite.vertices[i].x - minX) * invExtend.x;
                float y = (sprite.vertices[i].y - minY) * invExtend.y;

                vertice.position = new Vector2(Mathf.Lerp(lb.x, rt.x, x), Mathf.Lerp(lb.y, rt.y, y));
                vertice.color    = image.color;
                vertice.uv0      = sprite.uv[i];
                vertices.Add(vertice);
            }

            len = sprite.triangles.Length;

            var triangles = new List <int>(len);

            for (int i = 0; i < len; i++)
            {
                triangles.Add(sprite.triangles[i]);
            }

            vh.Clear();
            vh.AddUIVertexStream(vertices, triangles);
        }