FillMesh() public méthode

Fill the given mesh with the stream data.

public FillMesh ( Mesh mesh ) : void
mesh UnityEngine.Mesh
Résultat void
Exemple #1
0
        private void DoMeshGeneration()
        {
            if (rectTransform != null && rectTransform.rect.width >= 0 && rectTransform.rect.height >= 0)
            {
                OnPopulateMesh(s_VertexHelper);//确定(填充)每一个UI元素Mesh的信息,包括顶点数据、三角形数据、UV数据、顶点色数据
            }
            else
            {
                s_VertexHelper.Clear(); // clear the vertex helper so invalid graphics dont draw.
            }
            var components = ListPool <Component> .Get();

            //获取当前对象是否有IMeshModifier接口
            //Text的描边和阴影都是通过IMeshModifier的ModeifyMesh()实现出来的
            GetComponents(typeof(IMeshModifier), components);

            for (var i = 0; i < components.Count; i++)
            {
                ((IMeshModifier)components[i]).ModifyMesh(s_VertexHelper);
            }

            ListPool <Component> .Release(components);

            s_VertexHelper.FillMesh(workerMesh);
            canvasRenderer.SetMesh(workerMesh);//提交网格信息,开始合并网格
            //SetMesh()方法最终在C++中实现,毕竟由于UI的元素很多,同时参与合并顶点的信息也会很多,在C++中实现效率会更好。
            //UGUI效率会比NGUI要高一些,因为NGUI的“网格Mesh合并”都是在C#中完成的,而UGUI“网格Mesh合并”都是在C++中底层中完成的。
        }
Exemple #2
0
        /// <summary>
        /// 重新生成mesh
        /// </summary>
        private void DoMeshGeneration()
        {
            if (rectTransform != null && rectTransform.rect.width >= 0 && rectTransform.rect.height >= 0)
            {
                //这里会调用具体子类override的方法
                OnPopulateMesh(s_VertexHelper);
            }
            else
            {
                s_VertexHelper.Clear(); // clear the vertex helper so invalid graphics dont draw.
            }
            //将顶点列表传入实现了IMeshModifier脚本的组件中去,以便修改mesh
            //实现了IMeshModifier的组件可以修改Mesh
            var components = ListPool <Component> .Get();

            GetComponents(typeof(IMeshModifier), components);

            for (var i = 0; i < components.Count; i++)
            {
                ((IMeshModifier)components[i]).ModifyMesh(s_VertexHelper);
            }

            ListPool <Component> .Release(components);

            s_VertexHelper.FillMesh(workerMesh);
            canvasRenderer.SetMesh(workerMesh);
        }
Exemple #3
0
        /// <summary>
        /// 网格生成
        /// </summary>
        private void DoMeshGeneration()
        {
            //填充网格顶点
            if (rectTransform != null && rectTransform.rect.width >= 0 && rectTransform.rect.height >= 0)
            {
                OnPopulateMesh(s_VertexHelper);
            }
            else
            {
                s_VertexHelper.Clear(); // clear the vertex helper so invalid graphics dont draw.
            }
            //修改网格顶点
            var components = ListPool <Component> .Get();

            GetComponents(typeof(IMeshModifier), components);

            for (var i = 0; i < components.Count; i++)
            {
                ((IMeshModifier)components[i]).ModifyMesh(s_VertexHelper);
            }

            ListPool <Component> .Release(components);

            //填充网格
            s_VertexHelper.FillMesh(workerMesh);
            //设置网格
            canvasRenderer.SetMesh(workerMesh);
        }
Exemple #4
0
        private void DoMeshGeneration()
        {
            Debug.Log("Graphic.DoMeshGeneration threadId " + Thread.CurrentThread.ManagedThreadId);
            if (rectTransform != null && rectTransform.rect.width >= 0 && rectTransform.rect.height >= 0)
            {
                OnPopulateMesh(s_VertexHelper);
            }
            else
            {
                s_VertexHelper.Clear(); // clear the vertex helper so invalid graphics dont draw.
            }
            var components = ListPool <Component> .Get();

            GetComponents(typeof(IMeshModifier), components);

            for (var i = 0; i < components.Count; i++)
            {
                ((IMeshModifier)components[i]).ModifyMesh(s_VertexHelper);
            }

            ListPool <Component> .Release(components);

            s_VertexHelper.FillMesh(workerMesh);
            canvasRenderer.SetMesh(workerMesh);
        }
Exemple #5
0
 public override void ModifyMesh(Mesh mesh)
 {
     if (this.IsActive())
     {
         List <UIVertex> stream = new List <UIVertex>();
         using (VertexHelper helper = new VertexHelper(mesh))
         {
             helper.GetUIVertexStream(stream);
         }
         int num = stream.Count * 5;
         if (stream.Capacity < num)
         {
             stream.Capacity = num;
         }
         int start = 0;
         int count = stream.Count;
         base.ApplyShadowZeroAlloc(stream, base.effectColor, start, stream.Count, base.effectDistance.x, base.effectDistance.y);
         start = count;
         count = stream.Count;
         base.ApplyShadowZeroAlloc(stream, base.effectColor, start, stream.Count, base.effectDistance.x, -base.effectDistance.y);
         start = count;
         count = stream.Count;
         base.ApplyShadowZeroAlloc(stream, base.effectColor, start, stream.Count, -base.effectDistance.x, base.effectDistance.y);
         start = count;
         count = stream.Count;
         base.ApplyShadowZeroAlloc(stream, base.effectColor, start, stream.Count, -base.effectDistance.x, -base.effectDistance.y);
         using (VertexHelper helper2 = new VertexHelper())
         {
             helper2.AddUIVertexTriangleStream(stream);
             helper2.FillMesh(mesh);
         }
     }
 }
Exemple #6
0
 public override void ModifyMesh(Mesh mesh)
 {
     if (this.IsActive())
     {
         List<UIVertex> stream = new List<UIVertex>();
         using (VertexHelper helper = new VertexHelper(mesh))
         {
             helper.GetUIVertexStream(stream);
         }
         int num = stream.Count * 5;
         if (stream.Capacity < num)
         {
             stream.Capacity = num;
         }
         int start = 0;
         int count = stream.Count;
         base.ApplyShadowZeroAlloc(stream, base.effectColor, start, stream.Count, base.effectDistance.x, base.effectDistance.y);
         start = count;
         count = stream.Count;
         base.ApplyShadowZeroAlloc(stream, base.effectColor, start, stream.Count, base.effectDistance.x, -base.effectDistance.y);
         start = count;
         count = stream.Count;
         base.ApplyShadowZeroAlloc(stream, base.effectColor, start, stream.Count, -base.effectDistance.x, base.effectDistance.y);
         start = count;
         count = stream.Count;
         base.ApplyShadowZeroAlloc(stream, base.effectColor, start, stream.Count, -base.effectDistance.x, -base.effectDistance.y);
         using (VertexHelper helper2 = new VertexHelper())
         {
             helper2.AddUIVertexTriangleStream(stream);
             helper2.FillMesh(mesh);
         }
     }
 }
Exemple #7
0
 protected override void OnPopulateMesh(Mesh toFill)
 {
     Texture mainTexture = this.mainTexture;
     if (mainTexture != null)
     {
         Vector4 zero = Vector4.zero;
         int num = Mathf.RoundToInt(mainTexture.width * this.uvRect.width);
         int num2 = Mathf.RoundToInt(mainTexture.height * this.uvRect.height);
         float num3 = ((num & 1) != 0) ? ((float) (num + 1)) : ((float) num);
         float num4 = ((num2 & 1) != 0) ? ((float) (num2 + 1)) : ((float) num2);
         zero.x = 0f;
         zero.y = 0f;
         zero.z = ((float) num) / num3;
         zero.w = ((float) num2) / num4;
         zero.x -= base.rectTransform.pivot.x;
         zero.y -= base.rectTransform.pivot.y;
         zero.z -= base.rectTransform.pivot.x;
         zero.w -= base.rectTransform.pivot.y;
         zero.x *= base.rectTransform.rect.width;
         zero.y *= base.rectTransform.rect.height;
         zero.z *= base.rectTransform.rect.width;
         zero.w *= base.rectTransform.rect.height;
         using (VertexHelper helper = new VertexHelper())
         {
             Color color = base.color;
             helper.AddVert(new Vector3(zero.x, zero.y), color, new Vector2(this.m_UVRect.xMin, this.m_UVRect.yMin));
             helper.AddVert(new Vector3(zero.x, zero.w), color, new Vector2(this.m_UVRect.xMin, this.m_UVRect.yMax));
             helper.AddVert(new Vector3(zero.z, zero.w), color, new Vector2(this.m_UVRect.xMax, this.m_UVRect.yMax));
             helper.AddVert(new Vector3(zero.z, zero.y), color, new Vector2(this.m_UVRect.xMax, this.m_UVRect.yMin));
             helper.AddTriangle(0, 1, 2);
             helper.AddTriangle(2, 3, 0);
             helper.FillMesh(toFill);
         }
     }
 }
Exemple #8
0
        private void DoMeshGeneration3D()
        {
            if (rectTransform != null && rectTransform.rect.width >= 0 && rectTransform.rect.height >= 0)
            {
                OnPopulateMesh(s_VertexHelper);
            }
            else
            {
                s_VertexHelper.Clear(); // clear the vertex helper so invalid graphics dont draw.
            }

            var components = ListPool <Component> .Get();

            GetComponents(typeof(IMeshModifier), components);

            for (var i = 0; i < components.Count; i++)
            {
                ((IMeshModifier)components[i]).ModifyMesh(s_VertexHelper);
            }

            ListPool <Component> .Release(components);

            s_VertexHelper.FillMesh(m_mesh);

            if (m_meshFilter)
            {
                m_meshFilter.sharedMesh = m_mesh;
            }
        }
Exemple #9
0
 static public int FillMesh(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);
         UnityEngine.Mesh            a1;
         checkType(l, 2, out a1);
         self.FillMesh(a1);
         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
 }
		public override void ModifyMesh(Mesh mesh) {

			if (this.IsActive() == false) {

				return;

			}
			
			var list = new List<UIVertex>();
			using (var vertexHelper = new VertexHelper(mesh)) {

				vertexHelper.GetUIVertexStream(list);

			}
			
			this.ModifyVertices(list);  // calls the old ModifyVertices which was used on pre 5.2
			
			using (var vertexHelper = new VertexHelper()) {

				vertexHelper.AddUIVertexTriangleStream(list);
				vertexHelper.FillMesh(mesh);

			}

		}
Exemple #11
0
        public override void ModifyMesh(Mesh mesh)
#endif
        {
            if (!IsActive())
            {
                return;
            }

            List <UIVertex> list = new List <UIVertex>();

#if UNITY_5_2_2 || UNITY_5_3_OR_NEWER
            vh.GetUIVertexStream(list);
#elif UNITY_5_2
            using (VertexHelper vertexHelper = new VertexHelper(mesh))
            {
                vertexHelper.GetUIVertexStream(list);
            }
#endif

            ModifyVertices(list);                // calls the old ModifyVertices which was used on pre 5.2

#if UNITY_5_2_2 || UNITY_5_3_OR_NEWER
            vh.Clear();
            vh.AddUIVertexTriangleStream(list);
#else
            using (VertexHelper vertexHelper2 = new VertexHelper())
            {
                vertexHelper2.AddUIVertexTriangleStream(list);
                vertexHelper2.FillMesh(mesh);
            }
#endif
        }
 /// <summary>
 /// Function that is called when the Graphic is populating the mesh.
 /// </summary>
 /// <param name="mesh">The generated mesh of the Graphic element that needs modification.</param>
 public virtual void ModifyMesh(Mesh mesh)
 {
     using (var vh = new VertexHelper(mesh))
     {
         ModifyMesh(vh);
         vh.FillMesh(mesh);
     }
 }
 /// <summary>
 /// <para>See:IMeshModifier.</para>
 /// </summary>
 /// <param name="mesh"></param>
 public virtual void ModifyMesh(Mesh mesh)
 {
     using (VertexHelper helper = new VertexHelper(mesh))
     {
         this.ModifyMesh(helper);
         helper.FillMesh(mesh);
     }
 }
 /// <summary>
 /// 
 /// <para>
 /// See:IMeshModifier.
 /// </para>
 /// 
 /// </summary>
 /// <param name="mesh"/>
 public virtual void ModifyMesh(Mesh mesh)
 {
   using (VertexHelper vh = new VertexHelper(mesh))
   {
     this.ModifyMesh(vh);
     vh.FillMesh(mesh);
   }
 }
Exemple #15
0
 public void ModifyMesh(Mesh mesh)
 {
     using (var vh = new VertexHelper(mesh))
     {
         EditMesh(vh);
         vh.FillMesh(mesh);
     }
 }
 public virtual void ModifyMesh(Mesh mesh)
 {
     using (VertexHelper vertexHelper = new VertexHelper(mesh))
     {
         this.ModifyMesh(vertexHelper);
         vertexHelper.FillMesh(mesh);
     }
 }
    public override void ModifyMesh(Mesh mesh)
    {
        if (!this.IsActive())
            return;

        using (var vh = new VertexHelper(mesh))
        {
            ModifyMesh(vh);
            vh.FillMesh(mesh);
        }
    }
Exemple #18
0
 protected override void OnPopulateMesh(Mesh toFill)
 {
     if (this.font != null)
     {
         this.m_DisableFontTextureRebuiltCallback = true;
         Vector2 size = base.rectTransform.rect.size;
         TextGenerationSettings generationSettings = this.GetGenerationSettings(size);
         this.cachedTextGenerator.Populate(this.text, generationSettings);
         Rect    rect            = base.rectTransform.rect;
         Vector2 textAnchorPivot = GetTextAnchorPivot(this.m_FontData.alignment);
         Vector2 zero            = Vector2.zero;
         zero.x = (textAnchorPivot.x != 1f) ? rect.xMin : rect.xMax;
         zero.y = (textAnchorPivot.y != 0f) ? rect.yMax : rect.yMin;
         Vector2          vector4 = base.PixelAdjustPoint(zero) - zero;
         IList <UIVertex> verts   = this.cachedTextGenerator.verts;
         float            num     = 1f / this.pixelsPerUnit;
         int num2 = verts.Count - 4;
         using (VertexHelper helper = new VertexHelper())
         {
             if (vector4 != Vector2.zero)
             {
                 for (int i = 0; i < num2; i++)
                 {
                     int index = i & 3;
                     this.m_TempVerts[index]             = verts[i];
                     this.m_TempVerts[index].position    = (Vector3)(this.m_TempVerts[index].position * num);
                     this.m_TempVerts[index].position.x += vector4.x;
                     this.m_TempVerts[index].position.y += vector4.y;
                     if (index == 3)
                     {
                         helper.AddUIVertexQuad(this.m_TempVerts);
                     }
                 }
             }
             else
             {
                 for (int j = 0; j < num2; j++)
                 {
                     int num6 = j & 3;
                     this.m_TempVerts[num6]          = verts[j];
                     this.m_TempVerts[num6].position = (Vector3)(this.m_TempVerts[num6].position * num);
                     if (num6 == 3)
                     {
                         helper.AddUIVertexQuad(this.m_TempVerts);
                     }
                 }
             }
             helper.FillMesh(toFill);
         }
         this.m_DisableFontTextureRebuiltCallback = false;
     }
 }
 static public int FillMesh(IntPtr l)
 {
     try {
         UnityEngine.UI.VertexHelper self = (UnityEngine.UI.VertexHelper)checkSelf(l);
         UnityEngine.Mesh            a1;
         checkType(l, 2, out a1);
         self.FillMesh(a1);
         return(0);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemple #20
0
        private void DoMeshGeneration()
        {
            if (rectTransform != null && rectTransform.rect.width >= 0f && rectTransform.rect.height >= 0f)
            {
                OnPopulateMesh(s_VertexHelper);
            }
            else
            {
                s_VertexHelper.Clear();
            }
            List <Component> list = ListPool <Component> .Get();

            GetComponents(typeof(IMeshModifier), list);
            for (int i = 0; i < list.Count; i++)
            {
                ((IMeshModifier)list[i]).ModifyMesh(s_VertexHelper);
            }
            ListPool <Component> .Release(list);

            s_VertexHelper.FillMesh(workerMesh);
            canvasRenderer.SetMesh(workerMesh);
        }
    protected override void OnPopulateMesh(Mesh m)
    {
        Vector2 corner1 = new Vector2(0f, 0f);
        Vector2 corner2 = new Vector2(1f, 1f);

        corner1.x -= rectTransform.pivot.x;
        corner1.y -= rectTransform.pivot.y;
        corner2.x -= rectTransform.pivot.x;
        corner2.y -= rectTransform.pivot.y;

        corner1.x *= rectTransform.rect.width;
        corner1.y *= rectTransform.rect.height;
        corner2.x *= rectTransform.rect.width;
        corner2.y *= rectTransform.rect.height;

        Vector2 dc=corner2-corner1;
        Vector4 uv = sprite == null ? Vector4.zero : DataUtility.GetOuterUV(sprite);
        Vector2 uvz=new Vector2(uv.x, uv.y);
        Vector2 duv=new Vector2(uv.z, uv.w)-uvz;
        using (var vh = new VertexHelper())
        {
            float dx=1.0f/(float)(numdef);
            int numer=0;
            for(int yy=0;yy<numdef;yy++)
            for(int xx=0;xx<numdef;xx++)
            {
                Vector2 c1 = corner1+new Vector2(xx*dc.x*dx, yy*dc.y*dx);
                Vector2 c2 = corner1+new Vector2((xx+1)*dc.x,(yy+1)*dc.y)*dx;

                float rx1=dx*xx;
                float rx2=dx*(xx+1);
                float ry1=dx*yy;
                float ry2=dx*(yy+1);
                rx1*=rx1;
                rx2*=rx2;
                ry1=Mathf.Sqrt(ry1);
                ry2=Mathf.Sqrt(ry2);
                Vector2 uv0 =uvz+new Vector2(rx1*duv.x,ry1*duv.y);
                Vector2 uv1 =uvz+new Vector2(rx2*duv.x,ry2*duv.y);
            vh.AddVert(new Vector3(c1.x, c1.y), color, uv0);
            vh.AddVert(new Vector3(c1.x, c2.y), color, new Vector2(uv0.x, uv1.y));
            vh.AddVert(new Vector3(c2.x, c2.y), color, uv1);
            vh.AddVert(new Vector3(c2.x, c1.y), color, new Vector2(uv1.x, uv0.y));
                vh.AddTriangle(0+numer*4, 1+numer*4, 2+numer*4);
                vh.AddTriangle(2+numer*4, 3+numer*4, 0+numer*4);
                numer++;
            }

            vh.FillMesh(m);
        }
    }
Exemple #22
0
        private void DoMeshGeneration()
        {
            if (rectTransform != null && rectTransform.rect.width >= 0 && rectTransform.rect.height >= 0)
            {
                OnPopulateMesh(s_VertexHelper);//在继承类中实现具体的元素信息
            }
            else
            {
                s_VertexHelper.Clear(); // clear the vertex helper so invalid graphics dont draw.
            }
            var components = ListPool <Component> .Get();

            GetComponents(typeof(IMeshModifier), components);
            //Text的描边和阴影都是通过IMeshModifier的ModifyMesh()实现出来的
            for (var i = 0; i < components.Count; i++)
            {
                ((IMeshModifier)components[i]).ModifyMesh(s_VertexHelper);
            }

            ListPool <Component> .Release(components);

            s_VertexHelper.FillMesh(workerMesh);
            canvasRenderer.SetMesh(workerMesh);//提交网格信息,开始合并网格
        }
Exemple #23
0
 public override void ModifyMesh(Mesh mesh)
 {
     if (this.IsActive())
     {
         List<UIVertex> stream = new List<UIVertex>();
         using (VertexHelper helper = new VertexHelper(mesh))
         {
             helper.GetUIVertexStream(stream);
         }
         this.ApplyShadow(stream, this.effectColor, 0, stream.Count, this.effectDistance.x, this.effectDistance.y);
         using (VertexHelper helper2 = new VertexHelper())
         {
             helper2.AddUIVertexTriangleStream(stream);
             helper2.FillMesh(mesh);
         }
     }
 }
Exemple #24
0
 public override void ModifyMesh(Mesh mesh)
 {
     if (this.IsActive())
     {
         List <UIVertex> stream = new List <UIVertex>();
         using (VertexHelper helper = new VertexHelper(mesh))
         {
             helper.GetUIVertexStream(stream);
         }
         this.ApplyShadow(stream, this.effectColor, 0, stream.Count, this.effectDistance.x, this.effectDistance.y);
         using (VertexHelper helper2 = new VertexHelper())
         {
             helper2.AddUIVertexTriangleStream(stream);
             helper2.FillMesh(mesh);
         }
     }
 }
    public override void ModifyMesh(Mesh mesh)
    {
        if (!this.IsActive())
            return;

        List<UIVertex> list = new List<UIVertex>();
        using (VertexHelper vertexHelper = new VertexHelper(mesh)) {
            vertexHelper.GetUIVertexStream(list);
        }

        ModifyVertices(list);

        using (VertexHelper vertexHelper2 = new VertexHelper()) {
            vertexHelper2.AddUIVertexTriangleStream(list);
            vertexHelper2.FillMesh(mesh);
        }
    }
Exemple #26
0
        protected virtual void OnPopulateMesh(Mesh m)
        {
            Rect    pixelAdjustedRect = this.GetPixelAdjustedRect();
            Vector4 vector            = new Vector4(pixelAdjustedRect.x, pixelAdjustedRect.y, pixelAdjustedRect.x + pixelAdjustedRect.width, pixelAdjustedRect.y + pixelAdjustedRect.height);
            Color32 color             = this.color;

            using (VertexHelper helper = new VertexHelper())
            {
                helper.AddVert(new Vector3(vector.x, vector.y), color, new Vector2(0f, 0f));
                helper.AddVert(new Vector3(vector.x, vector.w), color, new Vector2(0f, 1f));
                helper.AddVert(new Vector3(vector.z, vector.w), color, new Vector2(1f, 1f));
                helper.AddVert(new Vector3(vector.z, vector.y), color, new Vector2(1f, 0f));
                helper.AddTriangle(0, 1, 2);
                helper.AddTriangle(2, 3, 0);
                helper.FillMesh(m);
            }
        }
Exemple #27
0
        private void GenerateSimpleSprite(Mesh toFill, bool lPreserveAspect)
        {
            Vector4 drawingDimensions = this.GetDrawingDimensions(lPreserveAspect);
            Vector4 vector2           = (this.overrideSprite == null) ? Vector4.zero : DataUtility.GetOuterUV(this.overrideSprite);
            Color   color             = base.color;

            using (VertexHelper helper = new VertexHelper())
            {
                helper.AddVert(new Vector3(drawingDimensions.x, drawingDimensions.y), color, new Vector2(vector2.x, vector2.y));
                helper.AddVert(new Vector3(drawingDimensions.x, drawingDimensions.w), color, new Vector2(vector2.x, vector2.w));
                helper.AddVert(new Vector3(drawingDimensions.z, drawingDimensions.w), color, new Vector2(vector2.z, vector2.w));
                helper.AddVert(new Vector3(drawingDimensions.z, drawingDimensions.y), color, new Vector2(vector2.z, vector2.y));
                helper.AddTriangle(0, 1, 2);
                helper.AddTriangle(2, 3, 0);
                helper.FillMesh(toFill);
            }
        }
        public override void ModifyMesh(Mesh mesh)
        {
            if (!this.IsActive())
                return;
 
            List<UIVertex> list = new List<UIVertex>();
            using (VertexHelper vertexHelper = new VertexHelper(mesh))
            {
                vertexHelper.GetUIVertexStream(list);
            }
 
            ModifyVertices(list);  // calls the old ModifyVertices which was used on pre 5.2
 
            using (VertexHelper vertexHelper2 = new VertexHelper())
            {
                vertexHelper2.AddUIVertexTriangleStream(list);
                vertexHelper2.FillMesh(mesh);
            }
        }
        public void ModifyMesh(Mesh mesh)
        {
            if (!this.enabled)
                return;

            List<UIVertex> list = new List<UIVertex>();
            using (VertexHelper vertexHelper = new VertexHelper(mesh))
            {
                vertexHelper.GetUIVertexStream(list);
            }

            ModifyVertices(list);  // calls the old ModifyVertices which was used on pre 5.2

            using (VertexHelper vertexHelper2 = new VertexHelper())
            {
                vertexHelper2.AddUIVertexTriangleStream(list);
                vertexHelper2.FillMesh(mesh);
            }
        }
Exemple #30
0
        public override void ModifyMesh(Mesh mesh)
        {
            if (!IsActive())
            {
                return;
            }

            if (mesh.vertexCount != lastCount || mesh.vertices[0] != lastVector)
            {
                verts.Clear();
                using (var helper = new VertexHelper(mesh))
                    helper.GetUIVertexStream(verts);


                var neededCpacity = verts.Count * 5;
                if (verts.Capacity < neededCpacity)
                {
                    verts.Capacity = neededCpacity;
                }

                var start = 0;
                var end   = verts.Count;
                ApplyShadowZeroAlloc(verts, effectColor, start, verts.Count, effectDistance.x, effectDistance.y);

                start = end;
                end   = verts.Count;
                ApplyShadowZeroAlloc(verts, effectColor, start, verts.Count, effectDistance.x, -effectDistance.y);

                start = end;
                end   = verts.Count;
                ApplyShadowZeroAlloc(verts, effectColor, start, verts.Count, -effectDistance.x, effectDistance.y);

                start = end;
                end   = verts.Count;
                ApplyShadowZeroAlloc(verts, effectColor, start, verts.Count, -effectDistance.x, -effectDistance.y);
            }
            using (var helper = new VertexHelper())
            {
                helper.AddUIVertexTriangleStream(verts);
                helper.FillMesh(mesh);
            }
        }
Exemple #31
0
        protected override void OnPopulateMesh(Mesh toFill)
        {
            Texture mainTexture = this.mainTexture;

            if (mainTexture != null)
            {
                Vector4 zero = Vector4.zero;
                int     num  = Mathf.RoundToInt(mainTexture.width * this.uvRect.width);
                int     num2 = Mathf.RoundToInt(mainTexture.height * this.uvRect.height);
                float   num3 = ((num & 1) != 0) ? ((float)(num + 1)) : ((float)num);
                float   num4 = ((num2 & 1) != 0) ? ((float)(num2 + 1)) : ((float)num2);
                zero.x  = 0f;
                zero.y  = 0f;
                zero.z  = ((float)num) / num3;
                zero.w  = ((float)num2) / num4;
                zero.x -= base.rectTransform.pivot.x;
                zero.y -= base.rectTransform.pivot.y;
                zero.z -= base.rectTransform.pivot.x;
                zero.w -= base.rectTransform.pivot.y;
                zero.x *= base.rectTransform.rect.width;
                zero.y *= base.rectTransform.rect.height;
                zero.z *= base.rectTransform.rect.width;
                zero.w *= base.rectTransform.rect.height;
                using (VertexHelper helper = new VertexHelper())
                {
                    Color color = base.color;
                    helper.AddVert(new Vector3(zero.x, zero.y), color, new Vector2(this.m_UVRect.xMin, this.m_UVRect.yMin));
                    helper.AddVert(new Vector3(zero.x, zero.w), color, new Vector2(this.m_UVRect.xMin, this.m_UVRect.yMax));
                    helper.AddVert(new Vector3(zero.z, zero.w), color, new Vector2(this.m_UVRect.xMax, this.m_UVRect.yMax));
                    helper.AddVert(new Vector3(zero.z, zero.y), color, new Vector2(this.m_UVRect.xMax, this.m_UVRect.yMin));
                    helper.AddTriangle(0, 1, 2);
                    helper.AddTriangle(2, 3, 0);
                    helper.FillMesh(toFill);
                }
            }
        }
Exemple #32
0
        public override void ModifyMesh(VertexHelper vh)
        {
            if (!IsActive())
            {
                return;
            }

            if (mesh == null)
            {
                mesh = new Mesh()
                {
                    name = "QShadow_Cached_Mesh"
                };
            }

            vh.FillMesh(mesh);
            Vector3[] vertices = mesh.vertices;
            Color[]   colors   = mesh.colors;
            Vector2[] uv0s     = mesh.uv;
            Vector2[] uv1s     = mesh.uv2;
            Vector2[] uv2s     = mesh.uv3;
            Vector2[] uv3s     = mesh.uv4;
            Vector3[] normals  = mesh.normals;
            Vector4[] tangents = mesh.tangents;
            Int32[]   triangls = mesh.triangles;

            if (!IsNumsEqual(vertices.Length, colors.Length, uv0s.Length, uv1s.Length, uv2s.Length, uv3s.Length, normals.Length, tangents.Length))
            {
                // Debug.LogWarning("It's a little odd that these length are not equal");
                return;
            }

            vh.Clear();

            Vector3[] newVertices = GetArrayCopies(vertices, 2);
            Color[]   newColors   = GetArrayCopies(colors, 2);
            Vector2[] newUv0s     = GetArrayCopies(uv0s, 2);
            Vector2[] newUv1s     = GetArrayCopies(uv1s, 2);
            Vector2[] newUv2s     = GetArrayCopies(uv2s, 2);
            Vector2[] newUv3s     = GetArrayCopies(uv3s, 2);
            Vector3[] newNormals  = GetArrayCopies(normals, 2);
            Vector4[] newTangents = GetArrayCopies(tangents, 2);

            for (int i = 0; i < vertices.Length; i++)
            {
                newVertices[i] = vertices[i] + new Vector3(effectDistance.x, effectDistance.y);
                newColors[i]   = effectColor;
                if (useGraphicAlpha)
                {
                    newColors[i].a = effectColor.a * colors[i].a;
                }
            }

            int[] newTriangles = new int[triangls.Length * 2];
            for (var i = 0; i < triangls.Length; i++)
            {
                newTriangles[i] = triangls[i];
                newTriangles[i + triangls.Length] = triangls[i] + vertices.Length;
            }

            for (var i = 0; i < newVertices.Length; i++)
            {
                vh.AddVert(newVertices[i], newColors[i], newUv0s[i], newUv1s[i], newUv2s[i], newUv3s[i], newNormals[i], newTangents[i]);
            }

            for (var i = 0; i < newTriangles.Length / 3; i++)
            {
                vh.AddTriangle(newTriangles[i * 3], newTriangles[i * 3 + 1], newTriangles[i * 3 + 2]);
            }
        }
Exemple #33
0
        protected override void OnPopulateMesh(Mesh toFill)
        {
            Texture tex = mainTexture;

            if (tex != null)
            {
                Vector4 v = Vector4.zero;
                Rect uvRect = new Rect(Vector2.zero, rectTransform.rect.size);
                uvRect.width = Mathf.Ceil(uvRect.width);
                uvRect.height = Mathf.Ceil(uvRect.height);

                int w = Mathf.RoundToInt(tex.width * uvRect.width);
                int h = Mathf.RoundToInt(tex.height * uvRect.height);

                float paddedW = ((w & 1) == 0) ? w : w + 1;
                float paddedH = ((h & 1) == 0) ? h : h + 1;

                v.x = 0f;
                v.y = 0f;
                v.z = w / paddedW;
                v.w = h / paddedH;

                v.x -= rectTransform.pivot.x;
                v.y -= rectTransform.pivot.y;
                v.z -= rectTransform.pivot.x;
                v.w -= rectTransform.pivot.y;

                v.x *= rectTransform.rect.width;
                v.y *= rectTransform.rect.height;
                v.z *= rectTransform.rect.width;
                v.w *= rectTransform.rect.height;

                using (var vh = new VertexHelper())
                {
                    Vector2 radius = new Vector2((v.z - v.x), (v.w - v.y)) * 0.5f;
                    Vector3 center = new Vector3(v.x + radius.x, v.y + radius.y);

                    // Place center vertices
                    float distance = 0;
                    for (int sideIndex = 0; sideIndex < slider.Corners; sideIndex++)
                    {
                        float angle = ((float)sideIndex / slider.Corners);
                        angle = (angle + ((float)(sideIndex + 1) / slider.Corners)) / 2f; // get center
                        vh.AddVert(center, GetColor(angle, distance), new Vector2(0.25f, 0.25f));
                    }

                    int previousCorner = 0;
                    int currentCorner = slider.Corners;
                    for (int depthIndex = 1; depthIndex < GetMinimum(ValueType2); depthIndex++)
                    {
                        // Place Top vert (Triangle: 3, 7, 14, etc)
                        Vector2 rad = (radius / (GetMinimum(ValueType2) - 1)) * depthIndex;
                        distance = (float)depthIndex / (GetMinimum(ValueType2) - 1);
                        Vector3 t = new Vector3(0, 1, 0);
                        vh.AddVert(center + new Vector3(t.x * rad.x, t.y * rad.y), GetColor(0, distance), new Vector2(0.25f, 0.25f));

                        for (int sideIndex = 1; sideIndex <= slider.Corners; sideIndex++)
                        {
                            float prevAngle = ((float)(sideIndex - 1) / slider.Corners);
                            float angle = ((float)sideIndex / slider.Corners);
                            Vector3 t2 = (Quaternion.AngleAxis(prevAngle * 360f, Vector3.forward) * new Vector3(0, 1, 0));
                            Vector3 temp = (Quaternion.AngleAxis(angle * 360f, Vector3.forward) * new Vector3(0, 1, 0));
                            Vector3 prevVert = center + new Vector3(t2.x * rad.x, t2.y * rad.y);
                            Vector3 nextVert = center + new Vector3(temp.x * rad.x, temp.y * rad.y);

                            for (int vertIndex = 1; vertIndex < depthIndex; vertIndex++)
                            {
                                // Places one vert and 2 trianlges
                                float a = Mathf.Lerp(prevAngle, angle, (float)vertIndex / depthIndex);
                                vh.AddVert(Vector3.Lerp(prevVert, nextVert, (float)vertIndex / depthIndex), GetColor(a, distance), new Vector2(0.25f, 0.25f));

                                vh.AddTriangle(currentCorner + (depthIndex * (sideIndex - 1)) + (vertIndex - 1),
                                    currentCorner + (depthIndex * (sideIndex - 1)) + vertIndex,
                                    previousCorner + ((depthIndex - 1) * (sideIndex - 1)) + vertIndex - 1);
                                vh.AddTriangle(currentCorner + (depthIndex * (sideIndex - 1)) + vertIndex,
                                    previousCorner + ((depthIndex - 1) * (sideIndex - 1)) + vertIndex,
                                    previousCorner + ((depthIndex - 1) * (sideIndex - 1)) + vertIndex - 1);
                            }

                            // Place corner vert
                            vh.AddVert(nextVert, GetColor(angle, distance), new Vector2(0.25f, 0.25f));
                            vh.AddTriangle(currentCorner + (depthIndex * sideIndex) - 1, currentCorner + (depthIndex * sideIndex), previousCorner + ((depthIndex - 1) * sideIndex));
                            if (previousCorner < slider.Corners)
                                previousCorner++;
                        }
                        previousCorner = currentCorner;
                        currentCorner += (slider.Corners * depthIndex) + 1;
                    }
                    vh.FillMesh(toFill);
                }
            }
        }
Exemple #34
0
        protected override void OnPopulateMesh(Mesh toFill)
        {
            Texture tex = mainTexture;

            if (tex != null)
            {
                Vector4 v = Vector4.zero;
                Rect uvRect = new Rect(Vector2.zero, rectTransform.rect.size);
                uvRect.width = Mathf.Ceil(uvRect.width);
                uvRect.height = Mathf.Ceil(uvRect.height);

                int w = Mathf.RoundToInt(tex.width * uvRect.width);
                int h = Mathf.RoundToInt(tex.height * uvRect.height);

                float paddedW = ((w & 1) == 0) ? w : w + 1;
                float paddedH = ((h & 1) == 0) ? h : h + 1;

                v.x = 0f;
                v.y = 0f;
                v.z = w / paddedW;
                v.w = h / paddedH;

                v.x -= rectTransform.pivot.x;
                v.y -= rectTransform.pivot.y;
                v.z -= rectTransform.pivot.x;
                v.w -= rectTransform.pivot.y;

                v.x *= rectTransform.rect.width;
                v.y *= rectTransform.rect.height;
                v.z *= rectTransform.rect.width;
                v.w *= rectTransform.rect.height;

                using (var vh = new VertexHelper())
                {
                    Vector2 whiteUV = Vector2.zero;

                    Vector3 lb = new Vector3(v.x, v.y);
                    Vector3 lt = new Vector3(v.x, v.w);
                    Vector3 rt = new Vector3(v.z, v.w);
                    Vector3 rb = new Vector3(v.z, v.y);

                    int vert = 0;

                    vh.AddVert(lb, color, whiteUV);
                    vh.AddVert(lt, color, whiteUV);
                    vh.AddVert(rt, color, whiteUV);
                    vh.AddVert(rb, color, whiteUV);

                    vh.AddTriangle(0, 1, 2);
                    vh.AddTriangle(2, 3, 0);
                    vert += 4;

                    float width = rb.x - lb.x;
                    float height = lt.y - lb.y;

                    Vector3 center = Vector3.Lerp(lb, rt, 0.5f);
                    Rect rect = new Rect(lb, new Vector2(width, height));
                    bool sizeIsCorrect = pixelsToDisplay.Length == (1 + (Mathf.CeilToInt(horizontalPixels) * 2)) * (1 + (Mathf.CeilToInt(verticalPixels) * 2));

                    UIVertex[] vertices = new UIVertex[4];
                    vertices[0].uv0 = whiteUV;
                    vertices[1].uv0 = whiteUV;
                    vertices[2].uv0 = whiteUV;
                    vertices[3].uv0 = whiteUV;

                    if (ExpectedVertices >= 65000)
                    {
                        Debug.LogWarning("to many vertices, currently " + ExpectedVertices + "/64999. make sure the ColorEyedropperPreview displays less pixels. You can achiee this by either editing it's settings in the inspector or resizing the component", this);
                    }
                    else
                    {
                        for (int radius = 1; radius <= Mathf.Ceil(horizontalPixels) || radius <= Mathf.Ceil(verticalPixels); radius++)
                        {
                            float offset = radius * (pixelSize + borderSize);

                            // Top side
                            for (int top = 0; top < radius * 2; top++)
                            {
                                float extraOffset = top * (pixelSize + borderSize);
                                Vector3 pos = center + new Vector3(-offset, offset) + new Vector3(extraOffset, 0);

                                if (SetQuadPositions(vertices, pos, rect))
                                {
                                    Color32 c;
                                    if (sizeIsCorrect && activated)
                                        c = pixelsToDisplay[(pixelsToDisplay.Length / 2) + (((Mathf.CeilToInt(horizontalPixels) * 2) + 1) * radius) - (radius - top)];
                                    else
                                        c = InactiveColor;
                                    SetQuadColors(vertices, c);
                                    vh.AddUIVertexQuad(vertices);
                                }
                            }

                            // Right side
                            for (int right = 0; right < radius * 2; right++)
                            {
                                float extraOffset = right * (pixelSize + borderSize);
                                Vector3 pos = center + new Vector3(offset, offset) + new Vector3(0, -extraOffset);

                                if (SetQuadPositions(vertices, pos, rect))
                                {
                                    Color32 c;
                                    if (sizeIsCorrect && activated)
                                        c = pixelsToDisplay[(pixelsToDisplay.Length / 2) + radius + (((Mathf.CeilToInt(horizontalPixels) * 2) + 1) * (radius - right))];
                                    else
                                        c = InactiveColor;
                                    SetQuadColors(vertices, c);
                                    vh.AddUIVertexQuad(vertices);
                                }
                            }

                            // Bot side
                            for (int bot = 0; bot < radius * 2; bot++)
                            {
                                float extraOffset = bot * (pixelSize + borderSize);
                                Vector3 pos = center + new Vector3(offset, -offset) + new Vector3(-extraOffset, 0);

                                if (SetQuadPositions(vertices, pos, rect))
                                {
                                    Color32 c;
                                    if (sizeIsCorrect && activated)
                                        c = pixelsToDisplay[(pixelsToDisplay.Length / 2) - (((Mathf.CeilToInt(horizontalPixels) * 2) + 1) * radius) + (radius - bot)];
                                    else
                                        c = InactiveColor;
                                    SetQuadColors(vertices, c);
                                    vh.AddUIVertexQuad(vertices);
                                }
                            }

                            // Left side
                            for (int left = 0; left < radius * 2; left++)
                            {
                                float extraOffset = left * (pixelSize + borderSize);
                                Vector3 pos = center + new Vector3(-offset, -offset) + new Vector3(0, extraOffset);

                                if (SetQuadPositions(vertices, pos, rect))
                                {
                                    Color32 c;
                                    if (sizeIsCorrect && activated)
                                        c = pixelsToDisplay[(pixelsToDisplay.Length / 2) - radius - (((Mathf.CeilToInt(horizontalPixels) * 2) + 1) * (radius - left))];
                                    else
                                        c = InactiveColor;
                                    SetQuadColors(vertices, c);
                                    vh.AddUIVertexQuad(vertices);
                                }
                            }
                        }
                    }

                    // Selectionbox
                    if (SetQuadPositions(vertices, center, rect, borderSize + 1f))
                    {
                        SetQuadColors(vertices, selectionBoxColor);
                        vh.AddUIVertexQuad(vertices);
                    }

                    // Center piece
                    if (SetQuadPositions(vertices, center, rect))
                    {
                        Color32 co;
                        if (sizeIsCorrect && activated)
                            co = pixelsToDisplay[pixelsToDisplay.Length / 2];
                        else
                            co = InactiveColor;
                        SetQuadColors(vertices, co);
                        vh.AddUIVertexQuad(vertices);
                    }
                    vh.FillMesh(toFill);
                }
            }
        }
        protected override void OnPopulateMesh(VertexHelper vh)
        {
            if (sharedMesh == null) { base.OnPopulateMesh(vh); return; }
            vh.Clear();

            Mesh mesh = sharedMesh;
            tempVBOLength = mesh.vertexCount;    

            vertices = mesh.vertices;
            triangles = mesh.triangles;
            uv = mesh.uv;
            uv2 = mesh.uv2;
            colors = mesh.colors32;
            normals = mesh.normals;
            tangents = mesh.tangents;            
                                    
#endif
            if(vertexStream == null || vertexStream.Length != tempVBOLength) vertexStream = new UIVertex[tempVBOLength];

            Bounds bounds = sharedMesh.bounds;
            if(m_UsePivot)
            {
                bounds.center += new Vector3((-0.5f + _vectorGraphics.pivotPoint.x) * bounds.size.x, (0.5f - _vectorGraphics.pivotPoint.y) * bounds.size.y, 0f);
            }

            if(m_Type == Type.Simple)
            {
                Vector4 v = GetDrawingDimensions(preserveAspect);
                
                for(int i = 0; i < tempVBOLength; i++)
                {
                    vertexStream[i].position.x = v.x + InverseLerp(bounds.min.x, bounds.max.x, vertices[i].x) * v.z;
                    vertexStream[i].position.y = v.y + InverseLerp(bounds.min.y, bounds.max.y, vertices[i].y) * v.w;
                    vertexStream[i].color = colors[i] * color;                    
                }
            } else {
                Vector4 v = GetDrawingDimensions(false);
                
                // LEFT = X, BOTTOM = Y, RIGHT = Z, TOP = W
                Vector4 border = _vectorGraphics.border;                
                Vector4 borderCalc = new Vector4(border.x + epsilon, border.y + epsilon, 1f - border.z - epsilon, 1f - border.w - epsilon);
                
                Vector2 normalizedPosition;
                
                float rectSize = canvas.referencePixelsPerUnit * vectorGraphics.scale * 100f;
                Vector2 size = new Vector2(bounds.size.x * rectSize, bounds.size.y * rectSize);
                Vector4 transformRect = new Vector4(v.x, v.y, v.x + v.z, v.y + v.w);
                Vector4 borderRect = new Vector4(size.x * border.x,
                                                 size.y * border.y,
                                                 size.x * border.z,
                                                 size.y * border.w);
                
                Vector2 scale = new Vector2(SafeDivide(1f, (1f - (border.x + border.z))) * (v.z - (borderRect.x + borderRect.z)),
                                            SafeDivide(1f, (1f - (border.y + border.w))) * (v.w - (borderRect.w + borderRect.y)));
                
                float minWidth = borderRect.x + borderRect.z;
                if(minWidth != 0f)
                {
                    minWidth = Mathf.Clamp01(v.z / minWidth);
                    if(minWidth != 1f)
                    {
                        scale.x = 0f;
                        size.x *= minWidth;
                        borderRect.x *= minWidth;
                        borderRect.z *= minWidth;
                    }
                }
                
                float minHeight = borderRect.w + borderRect.y;
                if(minHeight != 0f)
                {
                    minHeight = Mathf.Clamp01(v.w / minHeight);
                    if(minHeight != 1f)
                    {
                        scale.y = 0f;
                        size.y *= minHeight;
                        borderRect.w *= minHeight;
                        borderRect.y *= minHeight;
                    }
                    
                }
                
                float borderTop = transformRect.w - borderRect.w;
                float borderLeft = transformRect.x + borderRect.x;
                
                for(int i = 0; i < tempVBOLength; i++)
                {
                    vertexStream[i].color = colors[i] * color;
                    
                    normalizedPosition.x = InverseLerp(bounds.min.x, bounds.max.x, vertices[i].x);
                    normalizedPosition.y = InverseLerp(bounds.min.y, bounds.max.y, vertices[i].y);
                    
                    if(border.x != 0f && normalizedPosition.x <= borderCalc.x)
                    {
                        vertexStream[i].position.x = transformRect.x + normalizedPosition.x * size.x;
                    } else if(border.z != 0f && normalizedPosition.x >= borderCalc.z)
                    {
                        vertexStream[i].position.x = transformRect.z - (1f - normalizedPosition.x) * size.x;
                    } else {
                        vertexStream[i].position.x = borderLeft + (normalizedPosition.x - border.x) * scale.x;
                    }
                    
                    if(border.w != 0f && normalizedPosition.y >= borderCalc.w)
                    {
                        vertexStream[i].position.y = transformRect.w - (1f - normalizedPosition.y) * size.y;
                    } else if(border.y != 0f && normalizedPosition.y <= borderCalc.y)
                    {
                        vertexStream[i].position.y = transformRect.y + normalizedPosition.y * size.y;
                    } else {
                        vertexStream[i].position.y = borderTop - (((1f - normalizedPosition.y) - border.w) * scale.y);
                    }                    
                }
            }
            
            if(_vectorGraphics.hasGradients)
            {
                for(int i = 0; i < tempVBOLength; i++)
                {
                    vertexStream[i].uv0 = uv[i];
                    vertexStream[i].uv1 = uv2[i];
                }
            }
            
            if(normals != null && normals.Length == tempVBOLength)
            {
                for(int i = 0; i < tempVBOLength; i++)
                {
                    vertexStream[i].normal = normals[i];
                }
            }
            
            if(tangents != null && tangents.Length == tempVBOLength)
            {
                for(int i = 0; i < tempVBOLength; i++)
                {
                    vertexStream[i].tangent = tangents[i];
                }
            }

#if UNITY_4_6 || UNITY_4_7 || UNITY_4_8 || UNITY_4_9 || UNITY_4_6 || UNITY_5_0 || UNITY_5_1
            vbo.AddRange(vertexStream);
#elif UNITY_5_2_0 || UNITY_5_2_1



                vh.FillMesh(toFill);
            }
 protected override void OnPopulateMesh(Mesh toFill)
 {
     float outer = -rectTransform.pivot.x * rectTransform.rect.width;
     float inner = -rectTransform.pivot.x * rectTransform.rect.width + thickness;
     toFill.Clear();
     var vbo = new VertexHelper(toFill);
     Vector2 prevX = Vector2.zero;
     Vector2 prevY = Vector2.zero;
     Vector2 uv0 = new Vector2(0, 0);
     Vector2 uv1 = new Vector2(0, 1);
     Vector2 uv2 = new Vector2(1, 1);
     Vector2 uv3 = new Vector2(1, 0);
     Vector2 pos0;
     Vector2 pos1;
     Vector2 pos2;
     Vector2 pos3;
     float f = (fillPercent / 100f);
     float degrees = 360f / segments;
     int fa = (int)((segments + 1) * f);
     for (int i = -1 - (fa / 2); i < fa / 2 + 1; i++)
     {
         float rad = Mathf.Deg2Rad * (i * degrees);
         float c = Mathf.Cos(rad);
         float s = Mathf.Sin(rad);
         uv0 = new Vector2(0, 1);
         uv1 = new Vector2(1, 1);
         uv2 = new Vector2(1, 0);
         uv3 = new Vector2(0, 0);
         pos0 = prevX;
         pos1 = new Vector2(outer * c, outer * s);
         if (fill)
         {
             pos2 = Vector2.zero;
             pos3 = Vector2.zero;
         }
         else
         {
             pos2 = new Vector2(inner * c, inner * s);
             pos3 = prevY;
         }
         prevX = pos1;
         prevY = pos2;
         vbo.AddUIVertexQuad(SetVbo(new[] { pos0, pos1, pos2, pos3 }, new[] { uv0, uv1, uv2, uv3 }));
     }
     if (vbo.currentVertCount > 3)
     {
         vbo.FillMesh(toFill);
     }
 }
        protected override void OnPopulateMesh(VertexHelper vh)
        {
            if (sharedMesh == null) { base.OnPopulateMesh(vh); return; }
            vh.Clear();
        #endif

            Bounds bounds = sharedMesh.bounds;
            if(m_UsePivot)
            {             
                bounds.center += new Vector3((-0.5f + _vectorGraphics.pivotPoint.x) * bounds.size.x, (0.5f - _vectorGraphics.pivotPoint.y) * bounds.size.y, 0f);
            }

            Mesh mesh = sharedMesh;
            Vector3[] vertices = mesh.vertices;
            int[] triangles = mesh.triangles;
            Vector2[] uv = mesh.uv;
            Vector2[] uv2 = mesh.uv2;
            Color32[] colors = mesh.colors32;
            Vector3[] normals = mesh.normals;
            Vector4[] tangents = mesh.tangents;

            int tempVBOLength = mesh.vertexCount;
            UIVertex vertex = new UIVertex();

            if(m_Type == Type.Simple)
            {
                Vector4 v = GetDrawingDimensions(preserveAspect);

                for(int i = 0; i < tempVBOLength; i++)
                {
                    vertex.position.x = v.x + InverseLerp(bounds.min.x, bounds.max.x, vertices[i].x) * v.z;
                    vertex.position.y = v.y + InverseLerp(bounds.min.y, bounds.max.y, vertices[i].y) * v.w;
                    vertex.color = colors[i] * color;
                    if(uv != null && i < uv.Length) { vertex.uv0 = uv[i]; }
                    if(uv2 != null && i < uv2.Length) { vertex.uv1 = uv2[i]; }
                    if(normals != null && i < normals.Length) { vertex.normal = normals[i]; }
                    if(tangents != null && i < tangents.Length) { vertex.tangent = tangents[i]; }

                    vh.AddVert(vertex);
                }
            } else {
                
                Vector4 v = GetDrawingDimensions(false);
                Vector2 normalizedPosition;
                
                // LEFT, BOTTOM, RIGHT, TOP
                Vector4 border = _vectorGraphics.border;
                
                Vector4 borderCalc = new Vector4(border.x + epsilon, border.y + epsilon, 1f - border.z - epsilon, 1f - border.w - epsilon);
                
                float left = v.x;
                float top = v.y;
                float right = v.x + v.z;
                float bottom = v.y + v.w;
                float size = canvas.referencePixelsPerUnit * vectorGraphics.scale * 100f;
                
                float minWidth = (border.x + border.z) * size;
                float minHeight = (border.y + border.w) * size;
                float scaleX = 0f; if(minWidth != 0f) scaleX = Mathf.Clamp01(v.z / minWidth);
                float scaleY = 0f; if(minHeight != 0f) scaleY = Mathf.Clamp01(v.w / minHeight);
                
                for(int i = 0; i < tempVBOLength; i++)
                {
                    normalizedPosition.x = InverseLerp(bounds.min.x, bounds.max.x, vertices[i].x);
                    normalizedPosition.y = InverseLerp(bounds.min.y, bounds.max.y, vertices[i].y);
                    
                    if(normalizedPosition.x <= borderCalc.x && border.x != 0f)
                    {
                        vertex.position.x = left + normalizedPosition.x * size * scaleX;
                    } else if(normalizedPosition.x >= borderCalc.z && border.z != 0f)
                    {
                        vertex.position.x = right - (1f - normalizedPosition.x) * size * scaleX;
                    } else {
                        vertex.position.x = v.x + normalizedPosition.x * v.z;
                    }
                    
                    if(normalizedPosition.y >= borderCalc.w && border.w != 0f)
                    {
                        vertex.position.y = bottom - (1f - normalizedPosition.y) * size * scaleY;
                    } else if(normalizedPosition.y <= borderCalc.y && border.y != 0f)
                    {
                        vertex.position.y = top + normalizedPosition.y * size * scaleY;
                    } else {
                        vertex.position.y = v.y + normalizedPosition.y * v.w;
                    }

                    vertex.color = colors[i] * color;
                    if(uv != null && i < uv.Length) { vertex.uv0 = uv[i]; }
                    if(uv2 != null && i < uv2.Length) { vertex.uv1 = uv2[i]; }
                    if(normals != null && i < normals.Length) { vertex.normal = normals[i]; }
                    if(tangents != null && i < tangents.Length) { vertex.tangent = tangents[i]; }

                    vh.AddVert(vertex);
                }
            }

            int triangleLength = triangles.Length;
            for(int i = 0; i < triangleLength; i +=3 )
            {
                vh.AddTriangle(triangles[i], triangles[i + 1], triangles[i + 2]);
            }

            #if UNITY_5_2_0 || UNITY_5_2_1
                vh.FillMesh(toFill);
            }
Exemple #38
0
        private void GenerateTiledSprite(Mesh toFill)
        {
            Vector4 outerUV;
            Vector4 innerUV;
            Vector4 adjustedBorders;
            Vector2 size;

            if (this.overrideSprite != null)
            {
                outerUV         = DataUtility.GetOuterUV(this.overrideSprite);
                innerUV         = DataUtility.GetInnerUV(this.overrideSprite);
                adjustedBorders = this.overrideSprite.border;
                size            = this.overrideSprite.rect.size;
            }
            else
            {
                outerUV         = Vector4.zero;
                innerUV         = Vector4.zero;
                adjustedBorders = Vector4.zero;
                size            = (Vector2)(Vector2.one * 100f);
            }
            Rect  pixelAdjustedRect = base.GetPixelAdjustedRect();
            float num  = ((size.x - adjustedBorders.x) - adjustedBorders.z) / this.pixelsPerUnit;
            float num2 = ((size.y - adjustedBorders.y) - adjustedBorders.w) / this.pixelsPerUnit;

            adjustedBorders = this.GetAdjustedBorders((Vector4)(adjustedBorders / this.pixelsPerUnit), pixelAdjustedRect);
            Vector2 uvMin   = new Vector2(innerUV.x, innerUV.y);
            Vector2 vector6 = new Vector2(innerUV.z, innerUV.w);

            UIVertex.simpleVert.color = base.color;
            float x    = adjustedBorders.x;
            float num4 = pixelAdjustedRect.width - adjustedBorders.z;
            float y    = adjustedBorders.y;
            float num6 = pixelAdjustedRect.height - adjustedBorders.w;

            if (((num4 - x) > (num * 100f)) || ((num6 - y) > (num2 * 100f)))
            {
                num  = (num4 - x) / 100f;
                num2 = (num6 - y) / 100f;
            }
            using (VertexHelper helper = new VertexHelper())
            {
                Vector2 uvMax = vector6;
                if (this.m_FillCenter)
                {
                    for (float i = y; i < num6; i += num2)
                    {
                        float num8 = i + num2;
                        if (num8 > num6)
                        {
                            uvMax.y = uvMin.y + (((vector6.y - uvMin.y) * (num6 - i)) / (num8 - i));
                            num8    = num6;
                        }
                        uvMax.x = vector6.x;
                        for (float j = x; j < num4; j += num)
                        {
                            float num10 = j + num;
                            if (num10 > num4)
                            {
                                uvMax.x = uvMin.x + (((vector6.x - uvMin.x) * (num4 - j)) / (num10 - j));
                                num10   = num4;
                            }
                            AddQuad(helper, new Vector2(j, i) + pixelAdjustedRect.position, new Vector2(num10, num8) + pixelAdjustedRect.position, base.color, uvMin, uvMax);
                        }
                    }
                }
                if (this.hasBorder)
                {
                    uvMax = vector6;
                    for (float k = y; k < num6; k += num2)
                    {
                        float num12 = k + num2;
                        if (num12 > num6)
                        {
                            uvMax.y = uvMin.y + (((vector6.y - uvMin.y) * (num6 - k)) / (num12 - k));
                            num12   = num6;
                        }
                        AddQuad(helper, new Vector2(0f, k) + pixelAdjustedRect.position, new Vector2(x, num12) + pixelAdjustedRect.position, base.color, new Vector2(outerUV.x, uvMin.y), new Vector2(uvMin.x, uvMax.y));
                        AddQuad(helper, new Vector2(num4, k) + pixelAdjustedRect.position, new Vector2(pixelAdjustedRect.width, num12) + pixelAdjustedRect.position, base.color, new Vector2(vector6.x, uvMin.y), new Vector2(outerUV.z, uvMax.y));
                    }
                    uvMax = vector6;
                    for (float m = x; m < num4; m += num)
                    {
                        float num14 = m + num;
                        if (num14 > num4)
                        {
                            uvMax.x = uvMin.x + (((vector6.x - uvMin.x) * (num4 - m)) / (num14 - m));
                            num14   = num4;
                        }
                        AddQuad(helper, new Vector2(m, 0f) + pixelAdjustedRect.position, new Vector2(num14, y) + pixelAdjustedRect.position, base.color, new Vector2(uvMin.x, outerUV.y), new Vector2(uvMax.x, uvMin.y));
                        AddQuad(helper, new Vector2(m, num6) + pixelAdjustedRect.position, new Vector2(num14, pixelAdjustedRect.height) + pixelAdjustedRect.position, base.color, new Vector2(uvMin.x, vector6.y), new Vector2(uvMax.x, outerUV.w));
                    }
                    AddQuad(helper, new Vector2(0f, 0f) + pixelAdjustedRect.position, new Vector2(x, y) + pixelAdjustedRect.position, base.color, new Vector2(outerUV.x, outerUV.y), new Vector2(uvMin.x, uvMin.y));
                    AddQuad(helper, new Vector2(num4, 0f) + pixelAdjustedRect.position, new Vector2(pixelAdjustedRect.width, y) + pixelAdjustedRect.position, base.color, new Vector2(vector6.x, outerUV.y), new Vector2(outerUV.z, uvMin.y));
                    AddQuad(helper, new Vector2(0f, num6) + pixelAdjustedRect.position, new Vector2(x, pixelAdjustedRect.height) + pixelAdjustedRect.position, base.color, new Vector2(outerUV.x, vector6.y), new Vector2(uvMin.x, outerUV.w));
                    AddQuad(helper, new Vector2(num4, num6) + pixelAdjustedRect.position, new Vector2(pixelAdjustedRect.width, pixelAdjustedRect.height) + pixelAdjustedRect.position, base.color, new Vector2(vector6.x, vector6.y), new Vector2(outerUV.z, outerUV.w));
                }
                helper.FillMesh(toFill);
            }
        }
Exemple #39
0
 protected virtual void OnPopulateMesh(Mesh m)
 {
     Rect pixelAdjustedRect = this.GetPixelAdjustedRect();
     Vector4 vector = new Vector4(pixelAdjustedRect.x, pixelAdjustedRect.y, pixelAdjustedRect.x + pixelAdjustedRect.width, pixelAdjustedRect.y + pixelAdjustedRect.height);
     Color32 color = this.color;
     using (VertexHelper helper = new VertexHelper())
     {
         helper.AddVert(new Vector3(vector.x, vector.y), color, new Vector2(0f, 0f));
         helper.AddVert(new Vector3(vector.x, vector.w), color, new Vector2(0f, 1f));
         helper.AddVert(new Vector3(vector.z, vector.w), color, new Vector2(1f, 1f));
         helper.AddVert(new Vector3(vector.z, vector.y), color, new Vector2(1f, 0f));
         helper.AddTriangle(0, 1, 2);
         helper.AddTriangle(2, 3, 0);
         helper.FillMesh(m);
     }
 }
Exemple #40
0
 private void GenerateSlicedSprite(Mesh toFill)
 {
     if (!this.hasBorder)
     {
         this.GenerateSimpleSprite(toFill, false);
     }
     else
     {
         Vector4 outerUV;
         Vector4 innerUV;
         Vector4 padding;
         Vector4 adjustedBorders;
         if (this.overrideSprite != null)
         {
             outerUV         = DataUtility.GetOuterUV(this.overrideSprite);
             innerUV         = DataUtility.GetInnerUV(this.overrideSprite);
             padding         = DataUtility.GetPadding(this.overrideSprite);
             adjustedBorders = this.overrideSprite.border;
         }
         else
         {
             outerUV         = Vector4.zero;
             innerUV         = Vector4.zero;
             padding         = Vector4.zero;
             adjustedBorders = Vector4.zero;
         }
         Rect pixelAdjustedRect = base.GetPixelAdjustedRect();
         adjustedBorders    = this.GetAdjustedBorders((Vector4)(adjustedBorders / this.pixelsPerUnit), pixelAdjustedRect);
         padding            = (Vector4)(padding / this.pixelsPerUnit);
         s_VertScratch[0]   = new Vector2(padding.x, padding.y);
         s_VertScratch[3]   = new Vector2(pixelAdjustedRect.width - padding.z, pixelAdjustedRect.height - padding.w);
         s_VertScratch[1].x = adjustedBorders.x;
         s_VertScratch[1].y = adjustedBorders.y;
         s_VertScratch[2].x = pixelAdjustedRect.width - adjustedBorders.z;
         s_VertScratch[2].y = pixelAdjustedRect.height - adjustedBorders.w;
         for (int i = 0; i < 4; i++)
         {
             s_VertScratch[i].x += pixelAdjustedRect.x;
             s_VertScratch[i].y += pixelAdjustedRect.y;
         }
         s_UVScratch[0] = new Vector2(outerUV.x, outerUV.y);
         s_UVScratch[1] = new Vector2(innerUV.x, innerUV.y);
         s_UVScratch[2] = new Vector2(innerUV.z, innerUV.w);
         s_UVScratch[3] = new Vector2(outerUV.z, outerUV.w);
         using (VertexHelper helper = new VertexHelper())
         {
             for (int j = 0; j < 3; j++)
             {
                 int index = j + 1;
                 for (int k = 0; k < 3; k++)
                 {
                     if ((this.m_FillCenter || (j != 1)) || (k != 1))
                     {
                         int num5 = k + 1;
                         AddQuad(helper, new Vector2(s_VertScratch[j].x, s_VertScratch[k].y), new Vector2(s_VertScratch[index].x, s_VertScratch[num5].y), base.color, new Vector2(s_UVScratch[j].x, s_UVScratch[k].y), new Vector2(s_UVScratch[index].x, s_UVScratch[num5].y));
                     }
                 }
             }
             helper.FillMesh(toFill);
         }
     }
 }
Exemple #41
0
 protected override void OnPopulateMesh(Mesh toFill)
 {
     if (this.font != null)
     {
         this.m_DisableFontTextureRebuiltCallback = true;
         Vector2 size = base.rectTransform.rect.size;
         TextGenerationSettings generationSettings = this.GetGenerationSettings(size);
         this.cachedTextGenerator.Populate(this.text, generationSettings);
         Rect rect = base.rectTransform.rect;
         Vector2 textAnchorPivot = GetTextAnchorPivot(this.m_FontData.alignment);
         Vector2 zero = Vector2.zero;
         zero.x = (textAnchorPivot.x != 1f) ? rect.xMin : rect.xMax;
         zero.y = (textAnchorPivot.y != 0f) ? rect.yMax : rect.yMin;
         Vector2 vector4 = base.PixelAdjustPoint(zero) - zero;
         IList<UIVertex> verts = this.cachedTextGenerator.verts;
         float num = 1f / this.pixelsPerUnit;
         int num2 = verts.Count - 4;
         using (VertexHelper helper = new VertexHelper())
         {
             if (vector4 != Vector2.zero)
             {
                 for (int i = 0; i < num2; i++)
                 {
                     int index = i & 3;
                     this.m_TempVerts[index] = verts[i];
                     this.m_TempVerts[index].position = (Vector3) (this.m_TempVerts[index].position * num);
                     this.m_TempVerts[index].position.x += vector4.x;
                     this.m_TempVerts[index].position.y += vector4.y;
                     if (index == 3)
                     {
                         helper.AddUIVertexQuad(this.m_TempVerts);
                     }
                 }
             }
             else
             {
                 for (int j = 0; j < num2; j++)
                 {
                     int num6 = j & 3;
                     this.m_TempVerts[num6] = verts[j];
                     this.m_TempVerts[num6].position = (Vector3) (this.m_TempVerts[num6].position * num);
                     if (num6 == 3)
                     {
                         helper.AddUIVertexQuad(this.m_TempVerts);
                     }
                 }
             }
             helper.FillMesh(toFill);
         }
         this.m_DisableFontTextureRebuiltCallback = false;
     }
 }
Exemple #42
0
        private void GenerateFilledSprite(Mesh toFill, bool preserveAspect)
        {
            if (this.m_FillAmount < 0.001f)
            {
                using (VertexHelper helper = new VertexHelper())
                {
                    helper.FillMesh(toFill);
                    return;
                }
            }
            Vector4 drawingDimensions = this.GetDrawingDimensions(preserveAspect);
            Vector4 vector2           = (this.overrideSprite == null) ? Vector4.zero : DataUtility.GetOuterUV(this.overrideSprite);

            UIVertex.simpleVert.color = base.color;
            float x = vector2.x;
            float y = vector2.y;
            float z = vector2.z;
            float w = vector2.w;

            if ((this.m_FillMethod == FillMethod.Horizontal) || (this.m_FillMethod == FillMethod.Vertical))
            {
                if (this.fillMethod == FillMethod.Horizontal)
                {
                    float num5 = (z - x) * this.m_FillAmount;
                    if (this.m_FillOrigin == 1)
                    {
                        drawingDimensions.x = drawingDimensions.z - ((drawingDimensions.z - drawingDimensions.x) * this.m_FillAmount);
                        x = z - num5;
                    }
                    else
                    {
                        drawingDimensions.z = drawingDimensions.x + ((drawingDimensions.z - drawingDimensions.x) * this.m_FillAmount);
                        z = x + num5;
                    }
                }
                else if (this.fillMethod == FillMethod.Vertical)
                {
                    float num6 = (w - y) * this.m_FillAmount;
                    if (this.m_FillOrigin == 1)
                    {
                        drawingDimensions.y = drawingDimensions.w - ((drawingDimensions.w - drawingDimensions.y) * this.m_FillAmount);
                        y = w - num6;
                    }
                    else
                    {
                        drawingDimensions.w = drawingDimensions.y + ((drawingDimensions.w - drawingDimensions.y) * this.m_FillAmount);
                        w = y + num6;
                    }
                }
            }
            s_Xy[0] = (Vector3) new Vector2(drawingDimensions.x, drawingDimensions.y);
            s_Xy[1] = (Vector3) new Vector2(drawingDimensions.x, drawingDimensions.w);
            s_Xy[2] = (Vector3) new Vector2(drawingDimensions.z, drawingDimensions.w);
            s_Xy[3] = (Vector3) new Vector2(drawingDimensions.z, drawingDimensions.y);
            s_Uv[0] = (Vector3) new Vector2(x, y);
            s_Uv[1] = (Vector3) new Vector2(x, w);
            s_Uv[2] = (Vector3) new Vector2(z, w);
            s_Uv[3] = (Vector3) new Vector2(z, y);
            using (VertexHelper helper2 = new VertexHelper())
            {
                if (((this.m_FillAmount < 1f) && (this.m_FillMethod != FillMethod.Horizontal)) && (this.m_FillMethod != FillMethod.Vertical))
                {
                    if (this.fillMethod == FillMethod.Radial90)
                    {
                        if (RadialCut(s_Xy, s_Uv, this.m_FillAmount, this.m_FillClockwise, this.m_FillOrigin))
                        {
                            AddQuad(helper2, s_Xy, base.color, s_Uv);
                        }
                    }
                    else if (this.fillMethod == FillMethod.Radial180)
                    {
                        for (int i = 0; i < 2; i++)
                        {
                            float num8;
                            float num9;
                            float num10;
                            float num11;
                            int   num12 = (this.m_FillOrigin <= 1) ? 0 : 1;
                            if ((this.m_FillOrigin == 0) || (this.m_FillOrigin == 2))
                            {
                                num10 = 0f;
                                num11 = 1f;
                                if (i == num12)
                                {
                                    num8 = 0f;
                                    num9 = 0.5f;
                                }
                                else
                                {
                                    num8 = 0.5f;
                                    num9 = 1f;
                                }
                            }
                            else
                            {
                                num8 = 0f;
                                num9 = 1f;
                                if (i == num12)
                                {
                                    num10 = 0.5f;
                                    num11 = 1f;
                                }
                                else
                                {
                                    num10 = 0f;
                                    num11 = 0.5f;
                                }
                            }
                            s_Xy[0].x = Mathf.Lerp(drawingDimensions.x, drawingDimensions.z, num8);
                            s_Xy[1].x = s_Xy[0].x;
                            s_Xy[2].x = Mathf.Lerp(drawingDimensions.x, drawingDimensions.z, num9);
                            s_Xy[3].x = s_Xy[2].x;
                            s_Xy[0].y = Mathf.Lerp(drawingDimensions.y, drawingDimensions.w, num10);
                            s_Xy[1].y = Mathf.Lerp(drawingDimensions.y, drawingDimensions.w, num11);
                            s_Xy[2].y = s_Xy[1].y;
                            s_Xy[3].y = s_Xy[0].y;
                            s_Uv[0].x = Mathf.Lerp(x, z, num8);
                            s_Uv[1].x = s_Uv[0].x;
                            s_Uv[2].x = Mathf.Lerp(x, z, num9);
                            s_Uv[3].x = s_Uv[2].x;
                            s_Uv[0].y = Mathf.Lerp(y, w, num10);
                            s_Uv[1].y = Mathf.Lerp(y, w, num11);
                            s_Uv[2].y = s_Uv[1].y;
                            s_Uv[3].y = s_Uv[0].y;
                            float num13 = !this.m_FillClockwise ? ((this.m_FillAmount * 2f) - (1 - i)) : ((this.fillAmount * 2f) - i);
                            if (RadialCut(s_Xy, s_Uv, Mathf.Clamp01(num13), this.m_FillClockwise, ((i + this.m_FillOrigin) + 3) % 4))
                            {
                                AddQuad(helper2, s_Xy, base.color, s_Uv);
                            }
                        }
                    }
                    else if (this.fillMethod == FillMethod.Radial360)
                    {
                        for (int j = 0; j < 4; j++)
                        {
                            float num15;
                            float num16;
                            float num17;
                            float num18;
                            if (j < 2)
                            {
                                num15 = 0f;
                                num16 = 0.5f;
                            }
                            else
                            {
                                num15 = 0.5f;
                                num16 = 1f;
                            }
                            switch (j)
                            {
                            case 0:
                            case 3:
                                num17 = 0f;
                                num18 = 0.5f;
                                break;

                            default:
                                num17 = 0.5f;
                                num18 = 1f;
                                break;
                            }
                            s_Xy[0].x = Mathf.Lerp(drawingDimensions.x, drawingDimensions.z, num15);
                            s_Xy[1].x = s_Xy[0].x;
                            s_Xy[2].x = Mathf.Lerp(drawingDimensions.x, drawingDimensions.z, num16);
                            s_Xy[3].x = s_Xy[2].x;
                            s_Xy[0].y = Mathf.Lerp(drawingDimensions.y, drawingDimensions.w, num17);
                            s_Xy[1].y = Mathf.Lerp(drawingDimensions.y, drawingDimensions.w, num18);
                            s_Xy[2].y = s_Xy[1].y;
                            s_Xy[3].y = s_Xy[0].y;
                            s_Uv[0].x = Mathf.Lerp(x, z, num15);
                            s_Uv[1].x = s_Uv[0].x;
                            s_Uv[2].x = Mathf.Lerp(x, z, num16);
                            s_Uv[3].x = s_Uv[2].x;
                            s_Uv[0].y = Mathf.Lerp(y, w, num17);
                            s_Uv[1].y = Mathf.Lerp(y, w, num18);
                            s_Uv[2].y = s_Uv[1].y;
                            s_Uv[3].y = s_Uv[0].y;
                            float num19 = !this.m_FillClockwise ? ((this.m_FillAmount * 4f) - (3 - ((j + this.m_FillOrigin) % 4))) : ((this.m_FillAmount * 4f) - ((j + this.m_FillOrigin) % 4));
                            if (RadialCut(s_Xy, s_Uv, Mathf.Clamp01(num19), this.m_FillClockwise, (j + 2) % 4))
                            {
                                AddQuad(helper2, s_Xy, base.color, s_Uv);
                            }
                        }
                    }
                }
                else
                {
                    AddQuad(helper2, s_Xy, base.color, s_Uv);
                }
                helper2.FillMesh(toFill);
            }
        }
Exemple #43
0
 private void GenerateSlicedSprite(Mesh toFill)
 {
     if (!this.hasBorder)
     {
         this.GenerateSimpleSprite(toFill, false);
     }
     else
     {
         Vector4 outerUV;
         Vector4 innerUV;
         Vector4 padding;
         Vector4 adjustedBorders;
         if (this.overrideSprite != null)
         {
             outerUV = DataUtility.GetOuterUV(this.overrideSprite);
             innerUV = DataUtility.GetInnerUV(this.overrideSprite);
             padding = DataUtility.GetPadding(this.overrideSprite);
             adjustedBorders = this.overrideSprite.border;
         }
         else
         {
             outerUV = Vector4.zero;
             innerUV = Vector4.zero;
             padding = Vector4.zero;
             adjustedBorders = Vector4.zero;
         }
         Rect pixelAdjustedRect = base.GetPixelAdjustedRect();
         adjustedBorders = this.GetAdjustedBorders((Vector4) (adjustedBorders / this.pixelsPerUnit), pixelAdjustedRect);
         padding = (Vector4) (padding / this.pixelsPerUnit);
         s_VertScratch[0] = new Vector2(padding.x, padding.y);
         s_VertScratch[3] = new Vector2(pixelAdjustedRect.width - padding.z, pixelAdjustedRect.height - padding.w);
         s_VertScratch[1].x = adjustedBorders.x;
         s_VertScratch[1].y = adjustedBorders.y;
         s_VertScratch[2].x = pixelAdjustedRect.width - adjustedBorders.z;
         s_VertScratch[2].y = pixelAdjustedRect.height - adjustedBorders.w;
         for (int i = 0; i < 4; i++)
         {
             s_VertScratch[i].x += pixelAdjustedRect.x;
             s_VertScratch[i].y += pixelAdjustedRect.y;
         }
         s_UVScratch[0] = new Vector2(outerUV.x, outerUV.y);
         s_UVScratch[1] = new Vector2(innerUV.x, innerUV.y);
         s_UVScratch[2] = new Vector2(innerUV.z, innerUV.w);
         s_UVScratch[3] = new Vector2(outerUV.z, outerUV.w);
         using (VertexHelper helper = new VertexHelper())
         {
             for (int j = 0; j < 3; j++)
             {
                 int index = j + 1;
                 for (int k = 0; k < 3; k++)
                 {
                     if ((this.m_FillCenter || (j != 1)) || (k != 1))
                     {
                         int num5 = k + 1;
                         AddQuad(helper, new Vector2(s_VertScratch[j].x, s_VertScratch[k].y), new Vector2(s_VertScratch[index].x, s_VertScratch[num5].y), base.color, new Vector2(s_UVScratch[j].x, s_UVScratch[k].y), new Vector2(s_UVScratch[index].x, s_UVScratch[num5].y));
                     }
                 }
             }
             helper.FillMesh(toFill);
         }
     }
 }
Exemple #44
0
        protected override void OnPopulateMesh(Mesh toFill)
        {
            Texture tex = mainTexture;

            if (tex != null)
            {
                Vector4 v = Vector4.zero;
                Rect uvRect = new Rect(Vector2.zero, rectTransform.rect.size);
                uvRect.width = Mathf.Ceil(uvRect.width);
                uvRect.height = Mathf.Ceil(uvRect.height);

                int w = Mathf.RoundToInt(tex.width * uvRect.width);
                int h = Mathf.RoundToInt(tex.height * uvRect.height);

                float paddedW = ((w & 1) == 0) ? w : w + 1;
                float paddedH = ((h & 1) == 0) ? h : h + 1;

                v.x = 0f;
                v.y = 0f;
                v.z = w / paddedW;
                v.w = h / paddedH;

                v.x -= rectTransform.pivot.x;
                v.y -= rectTransform.pivot.y;
                v.z -= rectTransform.pivot.x;
                v.w -= rectTransform.pivot.y;

                v.x *= rectTransform.rect.width;
                v.y *= rectTransform.rect.height;
                v.z *= rectTransform.rect.width;
                v.w *= rectTransform.rect.height;

                using (var vh = new VertexHelper())
                {
                    // Add vertices
                    float xStep = (v.z - v.x) / (xSize - 1);
                    float yStep = (v.w - v.y) / (ySize - 1);
                    Vector3 pos = new Vector3(v.x, v.y);
                    for (int x = 0; x < xSize; x++)
                    {
                        for (int y = 0; y < ySize; y++)
                        {
                            for (int index = 0; index < colors.Length; index++)
                            {
                                vh.AddVert(pos, colors[index][y + (x * ySize)], new Vector2(0.25f, 0.25f));
                            }
                            pos.y += yStep;
                        }
                        pos.x += xStep;
                        pos.y = v.y;
                    }

                    // Add triangles
                    for (int y = 0; y < ySize - 1; y++)
                    {
                        for (int x = 0; x < xSize - 1; x++)
                        {
                            for (int index = 0; index < colors.Length; index++)
                            {
                                int pos1 = index + ((y + (x * ySize)) * colors.Length);
                                int pos2 = index + (((y + 1) + (x * ySize)) * colors.Length);
                                int pos3 = index + (((y + 1) + ((x + 1) * ySize)) * colors.Length);
                                int pos4 = index + ((y + ((x + 1) * ySize)) * colors.Length);

                                vh.AddTriangle(pos1, pos2, pos3);
                                vh.AddTriangle(pos3, pos4, pos1);
                            }
                        }
                    }

                    vh.FillMesh(toFill);
                }
            }
        }
Exemple #45
0
 private void GenerateTiledSprite(Mesh toFill)
 {
     Vector4 outerUV;
     Vector4 innerUV;
     Vector4 adjustedBorders;
     Vector2 size;
     if (this.overrideSprite != null)
     {
         outerUV = DataUtility.GetOuterUV(this.overrideSprite);
         innerUV = DataUtility.GetInnerUV(this.overrideSprite);
         adjustedBorders = this.overrideSprite.border;
         size = this.overrideSprite.rect.size;
     }
     else
     {
         outerUV = Vector4.zero;
         innerUV = Vector4.zero;
         adjustedBorders = Vector4.zero;
         size = (Vector2) (Vector2.one * 100f);
     }
     Rect pixelAdjustedRect = base.GetPixelAdjustedRect();
     float num = ((size.x - adjustedBorders.x) - adjustedBorders.z) / this.pixelsPerUnit;
     float num2 = ((size.y - adjustedBorders.y) - adjustedBorders.w) / this.pixelsPerUnit;
     adjustedBorders = this.GetAdjustedBorders((Vector4) (adjustedBorders / this.pixelsPerUnit), pixelAdjustedRect);
     Vector2 uvMin = new Vector2(innerUV.x, innerUV.y);
     Vector2 vector6 = new Vector2(innerUV.z, innerUV.w);
     UIVertex.simpleVert.color = base.color;
     float x = adjustedBorders.x;
     float num4 = pixelAdjustedRect.width - adjustedBorders.z;
     float y = adjustedBorders.y;
     float num6 = pixelAdjustedRect.height - adjustedBorders.w;
     if (((num4 - x) > (num * 100f)) || ((num6 - y) > (num2 * 100f)))
     {
         num = (num4 - x) / 100f;
         num2 = (num6 - y) / 100f;
     }
     using (VertexHelper helper = new VertexHelper())
     {
         Vector2 uvMax = vector6;
         if (this.m_FillCenter)
         {
             for (float i = y; i < num6; i += num2)
             {
                 float num8 = i + num2;
                 if (num8 > num6)
                 {
                     uvMax.y = uvMin.y + (((vector6.y - uvMin.y) * (num6 - i)) / (num8 - i));
                     num8 = num6;
                 }
                 uvMax.x = vector6.x;
                 for (float j = x; j < num4; j += num)
                 {
                     float num10 = j + num;
                     if (num10 > num4)
                     {
                         uvMax.x = uvMin.x + (((vector6.x - uvMin.x) * (num4 - j)) / (num10 - j));
                         num10 = num4;
                     }
                     AddQuad(helper, new Vector2(j, i) + pixelAdjustedRect.position, new Vector2(num10, num8) + pixelAdjustedRect.position, base.color, uvMin, uvMax);
                 }
             }
         }
         if (this.hasBorder)
         {
             uvMax = vector6;
             for (float k = y; k < num6; k += num2)
             {
                 float num12 = k + num2;
                 if (num12 > num6)
                 {
                     uvMax.y = uvMin.y + (((vector6.y - uvMin.y) * (num6 - k)) / (num12 - k));
                     num12 = num6;
                 }
                 AddQuad(helper, new Vector2(0f, k) + pixelAdjustedRect.position, new Vector2(x, num12) + pixelAdjustedRect.position, base.color, new Vector2(outerUV.x, uvMin.y), new Vector2(uvMin.x, uvMax.y));
                 AddQuad(helper, new Vector2(num4, k) + pixelAdjustedRect.position, new Vector2(pixelAdjustedRect.width, num12) + pixelAdjustedRect.position, base.color, new Vector2(vector6.x, uvMin.y), new Vector2(outerUV.z, uvMax.y));
             }
             uvMax = vector6;
             for (float m = x; m < num4; m += num)
             {
                 float num14 = m + num;
                 if (num14 > num4)
                 {
                     uvMax.x = uvMin.x + (((vector6.x - uvMin.x) * (num4 - m)) / (num14 - m));
                     num14 = num4;
                 }
                 AddQuad(helper, new Vector2(m, 0f) + pixelAdjustedRect.position, new Vector2(num14, y) + pixelAdjustedRect.position, base.color, new Vector2(uvMin.x, outerUV.y), new Vector2(uvMax.x, uvMin.y));
                 AddQuad(helper, new Vector2(m, num6) + pixelAdjustedRect.position, new Vector2(num14, pixelAdjustedRect.height) + pixelAdjustedRect.position, base.color, new Vector2(uvMin.x, vector6.y), new Vector2(uvMax.x, outerUV.w));
             }
             AddQuad(helper, new Vector2(0f, 0f) + pixelAdjustedRect.position, new Vector2(x, y) + pixelAdjustedRect.position, base.color, new Vector2(outerUV.x, outerUV.y), new Vector2(uvMin.x, uvMin.y));
             AddQuad(helper, new Vector2(num4, 0f) + pixelAdjustedRect.position, new Vector2(pixelAdjustedRect.width, y) + pixelAdjustedRect.position, base.color, new Vector2(vector6.x, outerUV.y), new Vector2(outerUV.z, uvMin.y));
             AddQuad(helper, new Vector2(0f, num6) + pixelAdjustedRect.position, new Vector2(x, pixelAdjustedRect.height) + pixelAdjustedRect.position, base.color, new Vector2(outerUV.x, vector6.y), new Vector2(uvMin.x, outerUV.w));
             AddQuad(helper, new Vector2(num4, num6) + pixelAdjustedRect.position, new Vector2(pixelAdjustedRect.width, pixelAdjustedRect.height) + pixelAdjustedRect.position, base.color, new Vector2(vector6.x, vector6.y), new Vector2(outerUV.z, outerUV.w));
         }
         helper.FillMesh(toFill);
     }
 }
Exemple #46
0
        private void GenerateFilledSprite(Mesh toFill, bool preserveAspect)
        {
            if (this.m_FillAmount < 0.001f)
            {
                using (VertexHelper helper = new VertexHelper())
                {
                    helper.FillMesh(toFill);
                    return;
                }
            }
            Vector4 drawingDimensions = this.GetDrawingDimensions(preserveAspect);
            Vector4 vector2 = (this.overrideSprite == null) ? Vector4.zero : DataUtility.GetOuterUV(this.overrideSprite);
            UIVertex.simpleVert.color = base.color;
            float x = vector2.x;
            float y = vector2.y;
            float z = vector2.z;
            float w = vector2.w;
            if ((this.m_FillMethod == FillMethod.Horizontal) || (this.m_FillMethod == FillMethod.Vertical))
            {
                if (this.fillMethod == FillMethod.Horizontal)
                {
                    float num5 = (z - x) * this.m_FillAmount;
                    if (this.m_FillOrigin == 1)
                    {
                        drawingDimensions.x = drawingDimensions.z - ((drawingDimensions.z - drawingDimensions.x) * this.m_FillAmount);
                        x = z - num5;
                    }
                    else
                    {
                        drawingDimensions.z = drawingDimensions.x + ((drawingDimensions.z - drawingDimensions.x) * this.m_FillAmount);
                        z = x + num5;
                    }
                }
                else if (this.fillMethod == FillMethod.Vertical)
                {
                    float num6 = (w - y) * this.m_FillAmount;
                    if (this.m_FillOrigin == 1)
                    {
                        drawingDimensions.y = drawingDimensions.w - ((drawingDimensions.w - drawingDimensions.y) * this.m_FillAmount);
                        y = w - num6;
                    }
                    else
                    {
                        drawingDimensions.w = drawingDimensions.y + ((drawingDimensions.w - drawingDimensions.y) * this.m_FillAmount);
                        w = y + num6;
                    }
                }
            }
            s_Xy[0] = (Vector3) new Vector2(drawingDimensions.x, drawingDimensions.y);
            s_Xy[1] = (Vector3) new Vector2(drawingDimensions.x, drawingDimensions.w);
            s_Xy[2] = (Vector3) new Vector2(drawingDimensions.z, drawingDimensions.w);
            s_Xy[3] = (Vector3) new Vector2(drawingDimensions.z, drawingDimensions.y);
            s_Uv[0] = (Vector3) new Vector2(x, y);
            s_Uv[1] = (Vector3) new Vector2(x, w);
            s_Uv[2] = (Vector3) new Vector2(z, w);
            s_Uv[3] = (Vector3) new Vector2(z, y);
            using (VertexHelper helper2 = new VertexHelper())
            {
                if (((this.m_FillAmount < 1f) && (this.m_FillMethod != FillMethod.Horizontal)) && (this.m_FillMethod != FillMethod.Vertical))
                {
                    if (this.fillMethod == FillMethod.Radial90)
                    {
                        if (RadialCut(s_Xy, s_Uv, this.m_FillAmount, this.m_FillClockwise, this.m_FillOrigin))
                        {
                            AddQuad(helper2, s_Xy, base.color, s_Uv);
                        }
                    }
                    else if (this.fillMethod == FillMethod.Radial180)
                    {
                        for (int i = 0; i < 2; i++)
                        {
                            float num8;
                            float num9;
                            float num10;
                            float num11;
                            int num12 = (this.m_FillOrigin <= 1) ? 0 : 1;
                            if ((this.m_FillOrigin == 0) || (this.m_FillOrigin == 2))
                            {
                                num10 = 0f;
                                num11 = 1f;
                                if (i == num12)
                                {
                                    num8 = 0f;
                                    num9 = 0.5f;
                                }
                                else
                                {
                                    num8 = 0.5f;
                                    num9 = 1f;
                                }
                            }
                            else
                            {
                                num8 = 0f;
                                num9 = 1f;
                                if (i == num12)
                                {
                                    num10 = 0.5f;
                                    num11 = 1f;
                                }
                                else
                                {
                                    num10 = 0f;
                                    num11 = 0.5f;
                                }
                            }
                            s_Xy[0].x = Mathf.Lerp(drawingDimensions.x, drawingDimensions.z, num8);
                            s_Xy[1].x = s_Xy[0].x;
                            s_Xy[2].x = Mathf.Lerp(drawingDimensions.x, drawingDimensions.z, num9);
                            s_Xy[3].x = s_Xy[2].x;
                            s_Xy[0].y = Mathf.Lerp(drawingDimensions.y, drawingDimensions.w, num10);
                            s_Xy[1].y = Mathf.Lerp(drawingDimensions.y, drawingDimensions.w, num11);
                            s_Xy[2].y = s_Xy[1].y;
                            s_Xy[3].y = s_Xy[0].y;
                            s_Uv[0].x = Mathf.Lerp(x, z, num8);
                            s_Uv[1].x = s_Uv[0].x;
                            s_Uv[2].x = Mathf.Lerp(x, z, num9);
                            s_Uv[3].x = s_Uv[2].x;
                            s_Uv[0].y = Mathf.Lerp(y, w, num10);
                            s_Uv[1].y = Mathf.Lerp(y, w, num11);
                            s_Uv[2].y = s_Uv[1].y;
                            s_Uv[3].y = s_Uv[0].y;
                            float num13 = !this.m_FillClockwise ? ((this.m_FillAmount * 2f) - (1 - i)) : ((this.fillAmount * 2f) - i);
                            if (RadialCut(s_Xy, s_Uv, Mathf.Clamp01(num13), this.m_FillClockwise, ((i + this.m_FillOrigin) + 3) % 4))
                            {
                                AddQuad(helper2, s_Xy, base.color, s_Uv);
                            }
                        }
                    }
                    else if (this.fillMethod == FillMethod.Radial360)
                    {
                        for (int j = 0; j < 4; j++)
                        {
                            float num15;
                            float num16;
                            float num17;
                            float num18;
                            if (j < 2)
                            {
                                num15 = 0f;
                                num16 = 0.5f;
                            }
                            else
                            {
                                num15 = 0.5f;
                                num16 = 1f;
                            }
                            switch (j)
                            {
                                case 0:
                                case 3:
                                    num17 = 0f;
                                    num18 = 0.5f;
                                    break;

                                default:
                                    num17 = 0.5f;
                                    num18 = 1f;
                                    break;
                            }
                            s_Xy[0].x = Mathf.Lerp(drawingDimensions.x, drawingDimensions.z, num15);
                            s_Xy[1].x = s_Xy[0].x;
                            s_Xy[2].x = Mathf.Lerp(drawingDimensions.x, drawingDimensions.z, num16);
                            s_Xy[3].x = s_Xy[2].x;
                            s_Xy[0].y = Mathf.Lerp(drawingDimensions.y, drawingDimensions.w, num17);
                            s_Xy[1].y = Mathf.Lerp(drawingDimensions.y, drawingDimensions.w, num18);
                            s_Xy[2].y = s_Xy[1].y;
                            s_Xy[3].y = s_Xy[0].y;
                            s_Uv[0].x = Mathf.Lerp(x, z, num15);
                            s_Uv[1].x = s_Uv[0].x;
                            s_Uv[2].x = Mathf.Lerp(x, z, num16);
                            s_Uv[3].x = s_Uv[2].x;
                            s_Uv[0].y = Mathf.Lerp(y, w, num17);
                            s_Uv[1].y = Mathf.Lerp(y, w, num18);
                            s_Uv[2].y = s_Uv[1].y;
                            s_Uv[3].y = s_Uv[0].y;
                            float num19 = !this.m_FillClockwise ? ((this.m_FillAmount * 4f) - (3 - ((j + this.m_FillOrigin) % 4))) : ((this.m_FillAmount * 4f) - ((j + this.m_FillOrigin) % 4));
                            if (RadialCut(s_Xy, s_Uv, Mathf.Clamp01(num19), this.m_FillClockwise, (j + 2) % 4))
                            {
                                AddQuad(helper2, s_Xy, base.color, s_Uv);
                            }
                        }
                    }
                }
                else
                {
                    AddQuad(helper2, s_Xy, base.color, s_Uv);
                }
                helper2.FillMesh(toFill);
            }
        }
Exemple #47
0
    protected override void OnPopulateMesh(Mesh toFill)
    {
        if (font == null)
                return;

            // We don't care if we the font Texture changes while we are doing our Update.
            // The end result of cachedTextGenerator will be valid for this instance.
            // Otherwise we can get issues like Case 619238.
            m_DisableFontTextureRebuiltCallback = true;

            Vector2 extents = rectTransform.rect.size;

            var settings = GetGenerationSettings(extents);
            cachedTextGenerator.Populate(text, settings);

            Rect inputRect = rectTransform.rect;

            // get the text alignment anchor point for the text in local space
            Vector2 textAnchorPivot = GetTextAnchorPivot(m_FontData.alignment);
            Vector2 refPoint = Vector2.zero;
            refPoint.x = (textAnchorPivot.x == 1 ? inputRect.xMax : inputRect.xMin);
            refPoint.y = (textAnchorPivot.y == 0 ? inputRect.yMin : inputRect.yMax);

            // Determine fraction of pixel to offset text mesh.
            Vector2 roundingOffset = PixelAdjustPoint(refPoint) - refPoint;

            // Apply the offset to the vertices
            IList<UIVertex> verts = cachedTextGenerator.verts;
            float unitsPerPixel = 1 / (pixelsPerUnit);
            //Last 4 verts are always a new line...
            int vertCount = verts.Count - 4;

            using (var vh = new VertexHelper())
            {
                if (roundingOffset != Vector2.zero)
                {
                    for (int i = 0; i < vertCount; ++i)
                    {
                        int tempVertsIndex = i & 3;
                        m_TempVerts[tempVertsIndex] = verts[i];
                        m_TempVerts[tempVertsIndex].position *= unitsPerPixel;
                        m_TempVerts[tempVertsIndex].position.x += roundingOffset.x;
                        m_TempVerts[tempVertsIndex].position.y += roundingOffset.y;
                        if (tempVertsIndex == 3)
                            vh.AddUIVertexQuad(m_TempVerts);
                    }
                }
                else
                {
                    for (int i = 0; i < vertCount; ++i)
                    {
                        int tempVertsIndex = i & 3;
                        m_TempVerts[tempVertsIndex] = verts[i];
                        m_TempVerts[tempVertsIndex].position *= unitsPerPixel;
                        if (tempVertsIndex == 3)
                            vh.AddUIVertexQuad(m_TempVerts);
                    }
                }
                vh.FillMesh(toFill);
            }
            m_DisableFontTextureRebuiltCallback = false;
    }
Exemple #48
0
        protected override void OnPopulateMesh(Mesh toFill)
        {
            Texture tex = mainTexture;

            if (tex != null)
            {
                Vector4 v = Vector4.zero;
                Rect uvRect = new Rect(0, 0, Mathf.Ceil(Mathf.Max(1, rectTransform.rect.width)), Mathf.Ceil(Mathf.Max(1, rectTransform.rect.height)));

                int w = Mathf.RoundToInt(tex.width * uvRect.width);
                int h = Mathf.RoundToInt(tex.height * uvRect.height);

                float paddedW = ((w & 1) == 0) ? w : w + 1;
                float paddedH = ((h & 1) == 0) ? h : h + 1;

                v.x = 0f;
                v.y = 0f;
                v.z = w / paddedW;
                v.w = h / paddedH;

                v.x -= rectTransform.pivot.x;
                v.y -= rectTransform.pivot.y;
                v.z -= rectTransform.pivot.x;
                v.w -= rectTransform.pivot.y;

                v.x *= rectTransform.rect.width;
                v.y *= rectTransform.rect.height;
                v.z *= rectTransform.rect.width;
                v.w *= rectTransform.rect.height;

                using (var vh = new VertexHelper())
                {
                    Vector2 whiteUV = new Vector2(0.25f, 0.25f);

                    Vector3 lb;
                    Vector3 lt;
                    Vector3 rt;
                    Vector3 rb;

                    int vert = 0;

                    if (borderSize > 0)
                    {
                        vh.AddVert(new Vector3(v.x, v.y), color, whiteUV);
                        vh.AddVert(new Vector3(v.x, v.w), color, whiteUV);
                        vh.AddVert(new Vector3(v.z, v.w), color, whiteUV);
                        vh.AddVert(new Vector3(v.z, v.y), color, whiteUV);
                        vh.AddTriangle(vert, vert + 1, vert + 2);
                        vh.AddTriangle(vert + 2, vert + 3, vert);
                        vert += 4;

                        v.x += borderSize;
                        v.y += borderSize;
                        v.w -= borderSize;
                        v.z -= borderSize;
                    }

                    switch (direction)
                    {
                        case Slider.Direction.BottomToTop:
                            lb = new Vector3(v.z, v.y);
                            lt = new Vector3(v.x, v.y);
                            rt = new Vector3(v.x, v.w);
                            rb = new Vector3(v.z, v.w);
                            break;
                        case Slider.Direction.LeftToRight:
                            lb = new Vector3(v.x, v.y);
                            lt = new Vector3(v.x, v.w);
                            rt = new Vector3(v.z, v.w);
                            rb = new Vector3(v.z, v.y);
                            break;
                        case Slider.Direction.RightToLeft:
                            lb = new Vector3(v.z, v.y);
                            lt = new Vector3(v.z, v.w);
                            rt = new Vector3(v.x, v.w);
                            rb = new Vector3(v.x, v.y);
                            break;
                        case Slider.Direction.TopToBottom:
                            lb = new Vector3(v.x, v.w);
                            lt = new Vector3(v.z, v.w);
                            rt = new Vector3(v.z, v.y);
                            rb = new Vector3(v.x, v.y);
                            break;
                        default:
                            throw new System.NotImplementedException(direction.ToString());
                    }

                    // Draw checkboard background if required
                    if (displayCheckboard)
                    {
                        switch (direction)
                        {
                            case Slider.Direction.BottomToTop:
                            case Slider.Direction.TopToBottom:
                                Vector2 tempSize = rectTransform.rect.size / 8;
                                uvRect = new Rect(Vector2.zero, new Vector2(tempSize.y, tempSize.x));
                                break;
                            case Slider.Direction.LeftToRight:
                            case Slider.Direction.RightToLeft:
                                uvRect = new Rect(Vector2.zero, rectTransform.rect.size / 8);
                                break;
                            default:
                                throw new System.NotImplementedException(direction.ToString());
                        }
                        uvRect.max = uvRect.max / checkBoardSize;

                        vh.AddVert(lb, new Color32(255, 255, 255, 255), new Vector2(uvRect.xMin, uvRect.yMin));
                        vh.AddVert(lt, new Color32(255, 255, 255, 255), new Vector2(uvRect.xMin, uvRect.yMax));
                        vh.AddVert(rt, new Color32(255, 255, 255, 255), new Vector2(uvRect.xMax, uvRect.yMax));
                        vh.AddVert(rb, new Color32(255, 255, 255, 255), new Vector2(uvRect.xMax, uvRect.yMin));
                        vh.AddTriangle(vert, vert + 1, vert + 2);
                        vh.AddTriangle(vert + 2, vert + 3, vert);
                        vert += 4;
                    }

                    for (int i = 0; i < colors.Length - 1; i++)
                    {
                        // custom left bot and top
                        Vector3 clb = lb + ((rb - lb) * ((float)i / (colors.Length - 1)));
                        Vector3 clt = lt + ((rt - lt) * ((float)i / (colors.Length - 1)));

                        // custom right bot and top
                        Vector3 crb = lb + ((rb - lb) * ((float)(i + 1) / (colors.Length - 1)));
                        Vector3 crt = lt + ((rt - lt) * ((float)(i + 1) / (colors.Length - 1)));

                        // custom center bot and top
                        Vector3 ccb = clb + ((crb - clb) * centerPos);
                        Vector3 cct = clt + ((crt - clt) * centerPos);

                        if (gradient)
                        {
                            Color32 cColor = Color32.Lerp(colors[i].Color, colors[i + 1].Color, 0.5f);

                            vh.AddVert(clb, colors[i].Color, whiteUV);
                            vh.AddVert(clt, colors[i].Color, whiteUV);

                            vh.AddVert(ccb, cColor, whiteUV);
                            vh.AddVert(cct, cColor, whiteUV);

                            vh.AddVert(crb, colors[i + 1].Color, whiteUV);
                            vh.AddVert(crt, colors[i + 1].Color, whiteUV);

                            vh.AddTriangle(vert, vert + 1, vert + 3);
                            vh.AddTriangle(vert + 3, vert + 2, vert);
                            vh.AddTriangle(vert + 2, vert + 3, vert + 5);
                            vh.AddTriangle(vert + 5, vert + 4, vert + 2);
                            vert += 6;
                        }
                        else
                        {
                            vh.AddVert(clb, colors[i].Color, whiteUV);
                            vh.AddVert(clt, colors[i].Color, whiteUV);

                            vh.AddVert(ccb, colors[i].Color, whiteUV);
                            vh.AddVert(cct, colors[i].Color, whiteUV);

                            vh.AddVert(ccb, colors[i + 1].Color, whiteUV);
                            vh.AddVert(cct, colors[i + 1].Color, whiteUV);

                            vh.AddVert(crb, colors[i + 1].Color, whiteUV);
                            vh.AddVert(crt, colors[i + 1].Color, whiteUV);

                            vh.AddTriangle(vert, vert + 1, vert + 3);
                            vh.AddTriangle(vert + 3, vert + 2, vert);
                            vh.AddTriangle(vert + 4, vert + 5, vert + 7);
                            vh.AddTriangle(vert + 7, vert + 6, vert + 4);
                            vert += 8;
                        }

                    }

                    vh.FillMesh(toFill);
                }
            }
        }
    protected override void OnPopulateMesh(Mesh m)
    {
        var Points = new List<Vector2>();

        if (Decay < 0.0f)
            Decay = 0.0f;
        if (Decay > 1.0f)
            Decay = 1.0f;

        if (Gamma < 0.1f)
            Gamma = 0.1f;
        if (Gamma > 10.0f)
            Gamma = 10.0f;
        
        for (int i = 0; i < CurveResolution; i++)
        {
            float zeroOne = (float) i/(float) (CurveResolution - 1);
            float v = Mathf.Pow(zeroOne, Gamma) * Decay;
            Points.Add(new Vector2((float) i / (float) (CurveResolution - 1), 1.0f - v));
        }
        
        var sizeX = rectTransform.rect.width;
        var sizeY = rectTransform.rect.height;
        var offsetX = -rectTransform.pivot.x * rectTransform.rect.width;
        var offsetY = -rectTransform.pivot.y * rectTransform.rect.height;

        if (UseMargins)
        {
            sizeX -= Margin.x;
            sizeY -= Margin.y;
            offsetX += Margin.x / 2f;
            offsetY += Margin.y / 2f;
        }

        var vh = new VertexHelper();

        for (int i = 0; i < Points.Count-1; i++)
        {
            var prev = Points[i];
            var cur = Points[i+1];
            prev = new Vector2(prev.x * sizeX + offsetX, prev.y * sizeY + offsetY);
            cur = new Vector2(cur.x * sizeX + offsetX, cur.y * sizeY + offsetY);

            var normal = new Vector3(cur.x - prev.x, cur.y - prev.y);
            var perp_vector = Vector3.Cross(normal, Vector3.forward).normalized;

            var halfThikness = LineThikness/2;

            var v1 = prev + new Vector2(perp_vector.x * -halfThikness, perp_vector.y * -halfThikness);
            var v2 = prev + new Vector2(perp_vector.x * halfThikness, perp_vector.y * halfThikness);
            var v3 = cur + new Vector2(perp_vector.x * halfThikness, perp_vector.y * halfThikness);
            var v4 = cur + new Vector2(perp_vector.x * -halfThikness, perp_vector.y * -halfThikness);

            vh.AddVert(v1, color, new Vector2(0f, 0f));
            vh.AddVert(v2, color, new Vector2(0f, 1f));
            vh.AddVert(v3, color, new Vector2(1f, 1f));
            vh.AddVert(v4, color, new Vector2(1f, 0f));

            vh.AddTriangle(0 + i*4, 1 + i * 4, 2 + i * 4);
            vh.AddTriangle(2 + i * 4, 3 + i * 4, 0 + i * 4);
            
        }

        vh.FillMesh(m);
    }
Exemple #50
0
 private void GenerateSimpleSprite(Mesh toFill, bool lPreserveAspect)
 {
     Vector4 drawingDimensions = this.GetDrawingDimensions(lPreserveAspect);
     Vector4 vector2 = (this.overrideSprite == null) ? Vector4.zero : DataUtility.GetOuterUV(this.overrideSprite);
     Color color = base.color;
     using (VertexHelper helper = new VertexHelper())
     {
         helper.AddVert(new Vector3(drawingDimensions.x, drawingDimensions.y), color, new Vector2(vector2.x, vector2.y));
         helper.AddVert(new Vector3(drawingDimensions.x, drawingDimensions.w), color, new Vector2(vector2.x, vector2.w));
         helper.AddVert(new Vector3(drawingDimensions.z, drawingDimensions.w), color, new Vector2(vector2.z, vector2.w));
         helper.AddVert(new Vector3(drawingDimensions.z, drawingDimensions.y), color, new Vector2(vector2.z, vector2.y));
         helper.AddTriangle(0, 1, 2);
         helper.AddTriangle(2, 3, 0);
         helper.FillMesh(toFill);
     }
 }