コード例 #1
1
ファイル: Gradient.cs プロジェクト: l980305284/UGUIPlugin
    public override void ModifyMesh(VertexHelper helper)
    {
        if (!IsActive() || helper.currentVertCount == 0)
             return;

         List<UIVertex> vertices = new List<UIVertex>();
         helper.GetUIVertexStream(vertices);

         float bottomY = vertices[0].position.y;
         float topY = vertices[0].position.y;

         for (int i = 1; i < vertices.Count; i++)
         {
             float y = vertices[i].position.y;
             if (y > topY)
             {
                 topY = y;
             }
             else if (y < bottomY)
             {
                 bottomY = y;
             }
         }

         float uiElementHeight = topY - bottomY;

         UIVertex v = new UIVertex();

         for (int i = 0; i < helper.currentVertCount; i++)
         {
             helper.PopulateUIVertex(ref v, i);
             v.color = Color32.Lerp(bottomColor, topColor, (v.position.y - bottomY) / uiElementHeight);
             helper.SetUIVertex(v, i);
         }
    }
コード例 #2
0
 static public int constructor(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.UIVertex o;
         o = new UnityEngine.UIVertex();
         pushValue(l, true);
         pushValue(l, o);
         return(2);
     }
     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
 }
コード例 #3
0
		public static void SetCharacterInfoToVertex(UIVertex[] verts, UguiNovelTextCharacter character, Font font )
		{

			float minX,maxX,minY,maxY;
			Vector2 uvBottomLeft,uvBottomRight,uvTopRight,uvTopLeft;
			float offsetY;
#if UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6
			//Y座標はフォントアセットのサイズと、文字のサイズを使ってこんな式で計算できる。
			//理屈はわからん!
			offsetY = font.fontSize + 0.1f*(character.FontSize-font.fontSize);

			//positionの設定
			minX = character.charInfo.vert.xMin;
			maxX = character.charInfo.vert.xMax;

			minY = character.charInfo.vert.yMin;
			maxY = character.charInfo.vert.yMax;

			Rect uv = character.charInfo.uv;
			//Flipp処理
			if (character.charInfo.flipped)
			{
				uvBottomLeft = new Vector2(uv.xMax, uv.yMin);
				uvBottomRight = new Vector2(uv.xMax, uv.yMax);
				uvTopLeft = new Vector2(uv.xMin, uv.yMin);
				uvTopRight = new Vector2(uv.xMin, uv.yMax);
			}
			else
			{
				uvBottomLeft = new Vector2(uv.xMin, uv.yMax);
				uvBottomRight = new Vector2(uv.xMax, uv.yMax);
				uvTopLeft = new Vector2(uv.xMin, uv.yMin);
				uvTopRight = new Vector2(uv.xMax, uv.yMin);
			}
#else
			offsetY = 0.1f * (character.FontSize);

			//座標の設定
			minX = character.charInfo.minX;
			maxX = character.charInfo.maxX;
			minY = character.charInfo.minY;
			maxY = character.charInfo.maxY;

			uvBottomLeft = character.charInfo.uvBottomLeft;
			uvBottomRight = character.charInfo.uvBottomRight;
			uvTopRight = character.charInfo.uvTopRight;
			uvTopLeft = character.charInfo.uvTopLeft;
#endif
			//座標の設定
			verts[0].position.x = verts[3].position.x = minX + character.PositionX;
			verts[1].position.x = verts[2].position.x = maxX + character.PositionX;
			verts[0].position.y = verts[1].position.y = minY + character.PositionY + offsetY;
			verts[2].position.y = verts[3].position.y = maxY + character.PositionY + offsetY;

			verts[0].uv0 = uvBottomLeft;
			verts[1].uv0 = uvBottomRight;
			verts[2].uv0 = uvTopRight;
			verts[3].uv0 = uvTopLeft;
		}
コード例 #4
0
		private UIVertex multiplyColor(UIVertex vertex, Color color)
		{
			if (MultiplyTextColor)
				vertex.color = Multiply (vertex.color, color);
			else
				vertex.color = color;
			return vertex;
		}
コード例 #5
0
 static public int set_uv1(IntPtr l)
 {
     UnityEngine.UIVertex o = (UnityEngine.UIVertex)checkSelf(l);
     UnityEngine.Vector2  v;
     checkType(l, 2, out v);
     o.uv1 = v;
     setBack(l, o);
     return(0);
 }
コード例 #6
0
 static public int set_color(IntPtr l)
 {
     UnityEngine.UIVertex o = (UnityEngine.UIVertex)checkSelf(l);
     UnityEngine.Color32  v;
     checkType(l, 2, out v);
     o.color = v;
     setBack(l, o);
     return(0);
 }
コード例 #7
0
 static public int set_position(IntPtr l)
 {
     UnityEngine.UIVertex o = (UnityEngine.UIVertex)checkSelf(l);
     UnityEngine.Vector3  v;
     checkType(l, 2, out v);
     o.position = v;
     setBack(l, o);
     return(0);
 }
コード例 #8
0
 /// <summary>
 /// <para>Add a quad to the stream.</para>
 /// </summary>
 /// <param name="verts">4 Vertices representing the quad.</param>
 public void AddUIVertexQuad(UIVertex[] verts)
 {
     int currentVertCount = this.currentVertCount;
     for (int i = 0; i < 4; i++)
     {
         this.AddVert(verts[i].position, verts[i].color, verts[i].uv0, verts[i].uv1, verts[i].normal, verts[i].tangent);
     }
     this.AddTriangle(currentVertCount, currentVertCount + 1, currentVertCount + 2);
     this.AddTriangle(currentVertCount + 2, currentVertCount + 3, currentVertCount);
 }
コード例 #9
0
 public override void ModifyMesh(VertexHelper vh)
 {
     UIVertex vertex = new UIVertex();
     for (int i = 0; i < vh.currentVertCount; i++)
     {
         vh.PopulateUIVertex(ref vertex, i);
         vertex.uv1 = new Vector2(vertex.position.x, vertex.position.y);
         vh.SetUIVertex(vertex, i);
     }
 }
コード例 #10
0
		public void SetVertices(UIVertex[] vertices, int size)
		{
			if (size > 65535)
			{
				Debug.LogWarning(UnityString.Format("Number of vertices set exceeds {0}, rendering of this element will be skipped", new object[]
				{
					65535
				}), this);
				size = 0;
			}
			this.SetVerticesInternalArray(vertices, size);
		}
コード例 #11
0
 public static int constructor(IntPtr l)
 {
     try {
         UnityEngine.UIVertex o;
         o=new UnityEngine.UIVertex();
         pushValue(l,o);
         return 1;
     }
     catch(Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return 0;
     }
 }
コード例 #12
0
 static void UIVertex_simpleVert(JSVCall vc)
 {
     if (vc.bGet)
     {
         var result = UnityEngine.UIVertex.simpleVert;
         JSMgr.datax.setObject((int)JSApi.SetType.Rval, result);
     }
     else
     {
         UnityEngine.UIVertex arg0 = (UnityEngine.UIVertex)JSMgr.datax.getObject((int)JSApi.GetType.Arg);
         UnityEngine.UIVertex.simpleVert = arg0;
     }
 }
コード例 #13
0
 public static int constructor(IntPtr l)
 {
     try {
         UnityEngine.UIVertex o;
         o=new UnityEngine.UIVertex();
         pushValue(l,true);
         pushValue(l,o);
         return 2;
     }
     catch(Exception e) {
         return error(l,e);
     }
 }
コード例 #14
0
 static public int constructor(IntPtr l)
 {
     try {
         UnityEngine.UIVertex o;
         o = new UnityEngine.UIVertex();
         pushValue(l, o);
         return(1);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
コード例 #15
0
 protected UIVertex[] SetVBO(Vector2[] vertices, Vector2[] uvs)
 {
     var vbo = new UIVertex[4];
     for (var i = 0; i < vertices.Length; i++)
     {
         var vert = UIVertex.simpleVert;
         vert.color = color;
         vert.position = vertices[i];
         vert.uv0 = uvs[i];
         vbo[i] = vert;
     }
     return vbo;
 }
コード例 #16
0
 static public int constructor(IntPtr l)
 {
     try {
         UnityEngine.UIVertex o;
         o = new UnityEngine.UIVertex();
         pushValue(l, true);
         pushValue(l, o);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
コード例 #17
0
    // TODO: This could all be optimised by calculating the four weighting factors once
    // and re-using the result for all attributes
    UIVertex Bilerp(UIVertex v0, UIVertex v1, UIVertex v2, UIVertex v3, float a, float b)
    {
        UIVertex output;
        output.position = Bilerp(v0.position, v1.position, v2.position, v3.position, a, b);
        output.normal = Bilerp(v0.normal, v1.normal, v2.normal, v3.normal, a, b);

        // Bilerping w is almost certainly not the right thing to do here
        output.tangent = Bilerp(v0.tangent, v1.tangent, v2.tangent, v3.tangent, a, b);

        output.uv0 = Bilerp(v0.uv0, v1.uv0, v2.uv0, v3.uv0, a, b);
        output.uv1 = Bilerp(v0.uv1, v1.uv1, v2.uv1, v3.uv1, a, b);
        output.color = Bilerp(v0.color, v1.color, v2.color, v3.color, a, b);
        return output;
    }
コード例 #18
0
ファイル: UIVertex.cs プロジェクト: randomize/VimConfig
 static UIVertex()
 {
     s_DefaultColor = new Color32(0xff, 0xff, 0xff, 0xff);
     s_DefaultTangent = new Vector4(1f, 0f, 0f, -1f);
     UIVertex vertex = new UIVertex {
         position = Vector3.zero,
         normal = Vector3.back,
         tangent = s_DefaultTangent,
         color = s_DefaultColor,
         uv0 = Vector2.zero,
         uv1 = Vector2.zero
     };
     simpleVert = vertex;
 }
コード例 #19
0
    public override void ModifyMesh(VertexHelper vh)
    {
        if (!IsActive())
            return;

        UIVertex vert = new UIVertex();
        for (int i = 0; i < vh.currentVertCount; i++)
        {
            vh.PopulateUIVertex(ref vert, i);
            vert.uv1.x = (i >> 1);
            vert.uv1.y = ((i >> 1) ^ (i & 1));
            vh.SetUIVertex(vert, i);
        }
    }
コード例 #20
0
 static void UIVertex_uv0(JSVCall vc)
 {
     if (vc.bGet)
     {
         UnityEngine.UIVertex _this = (UnityEngine.UIVertex)vc.csObj;
         var result = _this.uv0;
         JSApi.setVector2S((int)JSApi.SetType.Rval, result);
     }
     else
     {
         UnityEngine.Vector2  arg0  = (UnityEngine.Vector2)JSApi.getVector2S((int)JSApi.GetType.Arg);
         UnityEngine.UIVertex _this = (UnityEngine.UIVertex)vc.csObj;
         _this.uv0 = arg0;
         JSMgr.changeJSObj(vc.jsObjID, _this);
     }
 }
コード例 #21
0
 static void UIVertex_color(JSVCall vc)
 {
     if (vc.bGet)
     {
         UnityEngine.UIVertex _this = (UnityEngine.UIVertex)vc.csObj;
         var result = _this.color;
         JSMgr.datax.setObject((int)JSApi.SetType.Rval, result);
     }
     else
     {
         UnityEngine.Color32  arg0  = (UnityEngine.Color32)JSMgr.datax.getObject((int)JSApi.GetType.Arg);
         UnityEngine.UIVertex _this = (UnityEngine.UIVertex)vc.csObj;
         _this.color = arg0;
         JSMgr.changeJSObj(vc.jsObjID, _this);
     }
 }
コード例 #22
0
    // Use this for initialization
    void Start()
    {
        Color32 color = new Color32(255, 0, 0, 255);
        //color = new Color32();
        UIVertex[] data = new UIVertex[] {
            new UIVertex() { position = new Vector3(0f, 0f, 0f), color = color  },
            new UIVertex() { position = new Vector3(0f, 50f, 0f), color = color },
            new UIVertex() { position = new Vector3(50f, 50f, 50f), color = color },
            new UIVertex() { position = new Vector3(50f, 0f, 50f), color = color }
        };

        CanvasRenderer canvasRender = GetComponent<CanvasRenderer>();
        canvasRender.Clear();
        Material defaultMaterial = new Material(Shader.Find ("UI/Default"));
        canvasRender.SetMaterial(defaultMaterial, null);
        canvasRender.SetVertices(data, data.Length);
        Debug.Log("start");
    }
コード例 #23
0
ファイル: Gradient.cs プロジェクト: cg0206/Unity3d.UI.Windows
		private void ApplyVertexColor(ref UIVertex vertex, Color color) {

			switch (this.colorMode) {
				
				case ColorMode.Additive:
					vertex.color += color;
					break;
					
				case ColorMode.Multiply:
					vertex.color *= color;
					break;
					
				case ColorMode.Overwrite:
					vertex.color = color;
					break;

			}

		}
コード例 #24
0
		private UIVertex calcCenterVertex(UIVertex top, UIVertex bottom)
		{
			UIVertex center;
			center.normal = (top.normal + bottom.normal) / 2;
			center.position = (top.position + bottom.position) / 2;
			center.tangent = (top.tangent + bottom.tangent) / 2;
			center.uv0 = (top.uv0 + bottom.uv0) / 2;
			center.uv1 = (top.uv1 + bottom.uv1) / 2;

			if (MultiplyTextColor) {
				//multiply color
				var color = Color.Lerp(top.color, bottom.color, 0.5f);
				center.color = Multiply (color, colorCenter);
			} else {
				center.color = colorCenter;
			}

			return center;
		}
コード例 #25
0
    public void Add(IList<Vector2> outter, IList<Vector2> inner, IList<Color> colors = null)
    {
        if(outter.Count != inner.Count){
            Debug.Log("Outter's count not equal Inner");
            return;
        }

        if(colors != null && colors.Count != outter.Count-1){
            Debug.Log("colors' count not valid");
            return;
        }

        int startIndex = this.mSize*4;

        int count = startIndex + (outter.Count-1)*4;
        if(count > vertlist.Count){
            vertlist.AddRange(new UIVertex[count - vertlist.Count]);
        }

        UIVertex[] rect = new UIVertex[4];
        for(int i=0; i < outter.Count-1; i++){
            Color color = colors != null ? colors[i] : Color.white;

            rect[0].position = DrawHelper.Vector2To3(outter[i]);
            rect[0].color = color;
            rect[1].position = DrawHelper.Vector2To3(outter[i+1]);
            rect[1].color = color;
            rect[2].position = DrawHelper.Vector2To3(inner[i+1]);
            rect[2].color = color;
            rect[3].position = DrawHelper.Vector2To3(inner[i]);
            rect[3].color = color;

            for(int j=0; j < 4; j++){
                vertlist[startIndex + i*4 + j] = rect[j];
            }

            this.mSize++;
        }
    }
コード例 #26
0
ファイル: CanvasRenderer.cs プロジェクト: randomize/VimConfig
 public void SetVertices(UIVertex[] vertices, int size)
 {
     Mesh mesh = new Mesh();
     List<Vector3> inVertices = new List<Vector3>();
     List<Color32> inColors = new List<Color32>();
     List<Vector2> uvs = new List<Vector2>();
     List<Vector2> list4 = new List<Vector2>();
     List<Vector3> inNormals = new List<Vector3>();
     List<Vector4> inTangents = new List<Vector4>();
     List<int> list7 = new List<int>();
     for (int i = 0; i < size; i += 4)
     {
         for (int j = 0; j < 4; j++)
         {
             inVertices.Add(vertices[i + j].position);
             inColors.Add(vertices[i + j].color);
             uvs.Add(vertices[i + j].uv0);
             list4.Add(vertices[i + j].uv1);
             inNormals.Add(vertices[i + j].normal);
             inTangents.Add(vertices[i + j].tangent);
         }
         list7.Add(i);
         list7.Add(i + 1);
         list7.Add(i + 2);
         list7.Add(i + 2);
         list7.Add(i + 3);
         list7.Add(i);
     }
     mesh.SetVertices(inVertices);
     mesh.SetColors(inColors);
     mesh.SetNormals(inNormals);
     mesh.SetTangents(inTangents);
     mesh.SetUVs(0, uvs);
     mesh.SetUVs(1, list4);
     mesh.SetIndices(list7.ToArray(), MeshTopology.Triangles, 0);
     this.SetMesh(mesh);
     UnityEngine.Object.DestroyImmediate(mesh);
 }
コード例 #27
0
    // Use this for initialization
    void Start()
    {
        Mesh mesh = meshGObj.GetComponent<MeshFilter>().sharedMesh;

        if(material == null){
            material = new Material(Shader.Find("UI/Default"));
            Debug.LogWarning("createMat");
        }

        CanvasRenderer canvasRenderer = GetComponent<CanvasRenderer>();

        Vector3[] vertices = mesh.vertices;
        int[] triangles = mesh.triangles;
        Vector3[] normals = mesh.normals;
        Vector4[] tangents = mesh.tangents;

        Vector2[] UVs = mesh.uv;

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

        for (int i = 0; i < triangles.Length; ++i){
            UIVertex temp = new UIVertex();
            temp.position = vertices[triangles[i]];
            temp.uv0 = UVs[triangles[i]];
            temp.normal = normals[triangles[i]];
            temp.tangent = tangents[triangles[i]];
            temp.color = Color.white;
            uiVertices.Add (temp);
            if (i%3 == 0)
                uiVertices.Add (temp);
        }

        canvasRenderer.Clear ();
        canvasRenderer.SetMaterial(material, null);
        canvasRenderer.SetVertices(uiVertices);
    }
コード例 #28
0
    private void SetVertices(UIVertex[] vertices, int size)
    {
        List<Vector3> list = new List<Vector3> ();
        List<Color32> list2 = new List<Color32> ();
        List<Vector2> list3 = new List<Vector2> ();
        List<Vector2> list4 = new List<Vector2> ();
        List<Vector3> list5 = new List<Vector3> ();
        List<Vector4> list6 = new List<Vector4> ();
        List<int> list7 = new List<int> ();
        for (int i = 0; i < size; i += 4)
        {
            for (int j = 0; j < 4; j++)
            {
                list.Add (vertices [i + j].position);
                list2.Add (vertices [i + j].color);
                list3.Add (vertices [i + j].uv0);
                list4.Add (vertices [i + j].uv1);
                list5.Add (vertices [i + j].normal);
                list6.Add (vertices [i + j].tangent);
            }
            list7.Add (i);
            list7.Add (i + 1);
            list7.Add (i + 2);
            list7.Add (i + 2);
            list7.Add (i + 3);
            list7.Add (i);
        }

        mesh.SetVertices (list);
        mesh.SetColors (list2);
        mesh.SetNormals (list5);
        mesh.SetTangents (list6);
        mesh.SetUVs (0, list3);
        mesh.SetUVs (1, list4);
        mesh.SetIndices (list7.ToArray (), MeshTopology.Triangles, 0);
        canvasRender.SetMesh (mesh);
    }
コード例 #29
0
        public override void ModifyMesh(VertexHelper helper)
        {
            for (int i = 0; i < helper.currentVertCount; i++)
            {
                UIVertex vert = new UIVertex();
                helper.PopulateUIVertex(ref vert, i);

                if (currentChar < 0)
                {
                    vert.color = Color.clear;
                }
                else
                {
                    if (i / 4 > currentChar)
                    {
                        vert.color = Color.clear;
                    }
                }

                helper.SetUIVertex(vert, i);
            }
        }
コード例 #30
0
ファイル: TMPro_UGUI_Private.cs プロジェクト: davetheo/Smash3
        // Fill Vertex Buffers for Characters
        void FillCharacterVertexBuffers(int i, int index_X4)
        {
            //int meshIndex = m_textInfo.characterInfo[index].meshIndex;
            //int index2 = m_meshAllocCount[meshIndex];
            TMP_CharacterInfo[] characterInfoArray = m_textInfo.characterInfo;
            m_textInfo.characterInfo[i].vertexIndex = (short)(index_X4);

            // Setup Vertices for Characters or Sprites
            UIVertex bottomLeft = new UIVertex();
            bottomLeft.position = characterInfoArray[i].vertex_BL.position;
            bottomLeft.uv0 = characterInfoArray[i].vertex_BL.uv;
            bottomLeft.uv1 = characterInfoArray[i].vertex_BL.uv2;
            bottomLeft.color = characterInfoArray[i].vertex_BL.color;
            bottomLeft.normal = characterInfoArray[i].vertex_BL.normal;
            bottomLeft.tangent = characterInfoArray[i].vertex_BL.tangent;
            m_uiVertices[0 + index_X4] = bottomLeft;
            //m_textInfo.meshInfo.meshArrays[meshIndex][index2 + 0] = bottomLeft;
            

            UIVertex topLeft = new UIVertex();
            topLeft.position = characterInfoArray[i].vertex_TL.position;
            topLeft.uv0 = characterInfoArray[i].vertex_TL.uv;
            topLeft.uv1 = characterInfoArray[i].vertex_TL.uv2;
            topLeft.color = characterInfoArray[i].vertex_TL.color;
            topLeft.normal = characterInfoArray[i].vertex_TL.normal;
            topLeft.tangent = characterInfoArray[i].vertex_TL.tangent;
            m_uiVertices[1 + index_X4] = topLeft;
            //m_textInfo.meshInfo.meshArrays[meshIndex][index2 + 1] = topLeft;
            

            UIVertex topRight = new UIVertex();
            topRight.position = characterInfoArray[i].vertex_TR.position;
            topRight.uv0 = characterInfoArray[i].vertex_TR.uv;
            topRight.uv1 = characterInfoArray[i].vertex_TR.uv2;
            topRight.color = characterInfoArray[i].vertex_TR.color;
            topRight.normal = characterInfoArray[i].vertex_TR.normal;
            topRight.tangent = characterInfoArray[i].vertex_TR.tangent;
            m_uiVertices[2 + index_X4] = topRight;
            //m_textInfo.meshInfo.meshArrays[meshIndex][index2 + 2] = topRight;
            

            UIVertex bottomRight = new UIVertex();
            bottomRight.position = characterInfoArray[i].vertex_BR.position;
            bottomRight.uv0 = characterInfoArray[i].vertex_BR.uv;
            bottomRight.uv1 = characterInfoArray[i].vertex_BR.uv2;
            bottomRight.color = characterInfoArray[i].vertex_BR.color;
            bottomRight.normal = characterInfoArray[i].vertex_BR.normal;
            bottomRight.tangent = characterInfoArray[i].vertex_BR.tangent;
            m_uiVertices[3 + index_X4] = bottomRight;
            //m_textInfo.meshInfo.meshArrays[meshIndex][index2 + 3] = bottomRight;

            //m_meshAllocCount[meshIndex] += 4;
        }
コード例 #31
0
ファイル: UIMeshLine.cs プロジェクト: cupsster/drawLine
    UIVertex[] DrawLine(int index, VertexHelper vh, UIVertex[] prvLineVert=null)
    {
        UIVertex[] prvVert = null;
        float ratio = GetLength(index)/lineLength;
        float ratioEnd = GetLength(index + 1)/lineLength;

        if (IsCurve(index))
        {
            float curveLength = 0f;
            float currentRatio = ratio;
            for (int n = 0; n < divideCount; n++)
            {
                Vector3 p0 = EvaluatePoint(index, 1f / divideCount * n);
                Vector3 p1 = EvaluatePoint(index, 1f / divideCount * (n + 1));
                curveLength += Vector2.Distance(p0, p1);
            }

            for (int n = 0; n < divideCount; n++)
            {
                Vector3 p0 = EvaluatePoint(index, 1f / divideCount * n);
                Vector3 p1 = EvaluatePoint(index, 1f / divideCount * (n + 1));

                Color c0 = useGradient ? gradient.Evaluate(currentRatio) : color;
                float deltaRatio = Vector2.Distance(p0, p1) / curveLength * (ratioEnd - ratio);
                currentRatio += deltaRatio;
                Color c1 = useGradient ? gradient.Evaluate(currentRatio) : color;

                ///check final
                //float length = GetLength(index + 1);
                bool isFinal = false;
                if (currentRatio > m_lengthRatio)
                {
                    currentRatio -= deltaRatio;
                    float targetlength = lineLength * m_lengthRatio;
                    Vector3 lineVector = p1 - p0;
                    p1 = p0 + lineVector.normalized * (targetlength - lineLength * currentRatio);
                    isFinal = true;
                }

                if (roundEdge && index == 0 && n == 0)
                {
                    DrawRoundEdge(vh, p0, p1, c0);
                }
                if (roundEdge && (index == points.Count - 2 && n == divideCount - 1 || isFinal))
                {
                    DrawRoundEdge(vh, p1, p0, c1);
                }

                var quad = MakeQuad(vh, p0, p1, c0, c1, prvVert);

                if (fillLineJoint && prvLineVert != null)
                {
                    FillJoint(vh, quad[0], quad[1], prvLineVert, c0);
                    prvLineVert = null;
                }

                if (isFinal)
                    break;

                if (prvVert == null) { prvVert = new UIVertex[2]; }
                prvVert[0] = quad[3];
                prvVert[1] = quad[2];
            }
        }
        else
        {
            Vector3 p0 = points[index].point;
            Vector3 p1 = points[index + 1].point;

            Color c0 = useGradient ? gradient.Evaluate(ratio) : color;
            Color c1 = useGradient ? gradient.Evaluate(ratioEnd) : color;

            //todo length check
            float length = GetLength(index + 1);
            bool isFinal = false;
            if (CheckLength(length))
            {
                float targetlength = lineLength * m_lengthRatio;
                Vector3 lineVector = p1 - p0;
                p1 = p0 + lineVector.normalized * (targetlength - GetLength(index));
                isFinal = true;
            }

            if (roundEdge && index == 0)
            {
                DrawRoundEdge(vh, p0, p1, c0);
            }
            if (roundEdge && (index == points.Count - 2 || isFinal))
            {
                DrawRoundEdge(vh, p1, p0, c1);
            }
            
            var quad = MakeQuad(vh, p0, p1, c0, c1);

            if (fillLineJoint && prvLineVert != null)
            {
                FillJoint(vh, quad[0], quad[1], prvLineVert, c0);
                prvLineVert = null;
            }

            if (prvVert == null) { prvVert = new UIVertex[2]; }
            prvVert[0] = quad[3];
            prvVert[1] = quad[2];
        }
        return prvVert;
    } 
コード例 #32
0
 static public int get_uv1(IntPtr l)
 {
     UnityEngine.UIVertex o = (UnityEngine.UIVertex)checkSelf(l);
     pushValue(l, o.uv1);
     return(1);
 }
コード例 #33
0
 private bool SetQuadPositions(UIVertex[] verts, Vector3 center, Rect inside)
 {
     return SetQuadPositions(verts, center, inside, 0f);
 }
コード例 #34
0
 public void DrawSprite(UIVertex[] uiVertices, int spriteCount)
 {
     if (m_inlineGraphicCanvasRenderer == null) m_inlineGraphicCanvasRenderer = m_inlineGraphic.GetComponent<CanvasRenderer>();
                
     m_inlineGraphicCanvasRenderer.SetVertices(uiVertices, spriteCount * 4);
     m_inlineGraphic.UpdateMaterial();
     
 }
コード例 #35
0
ファイル: TMPro_UGUI_Private.cs プロジェクト: arahis/Swiper
        // Fill Vertex Buffers for Sprites
        void FillSpriteVertexBuffers(int i, int spriteIndex_X4)
        {
            m_textInfo.characterInfo[i].vertexIndex = (short)(spriteIndex_X4);
            TMP_CharacterInfo[] characterInfoArray = m_textInfo.characterInfo;

            //Debug.Log(m_visibleSpriteCount);
            UIVertex[] spriteVertices = m_inlineGraphics.uiVertex;
            //m_textInfo.characterInfo[i].uiVertices = spriteVertices;

            UIVertex uiVertex = new UIVertex();

            uiVertex.position = characterInfoArray[i].vertex_BL.position;
            uiVertex.uv0 = characterInfoArray[i].vertex_BL.uv;
            uiVertex.color = characterInfoArray[i].vertex_BL.color;
            spriteVertices[spriteIndex_X4 + 0] = uiVertex;

            uiVertex.position = characterInfoArray[i].vertex_TL.position;
            uiVertex.uv0 = characterInfoArray[i].vertex_TL.uv;
            uiVertex.color = characterInfoArray[i].vertex_TL.color;
            spriteVertices[spriteIndex_X4 + 1] = uiVertex;

            uiVertex.position = characterInfoArray[i].vertex_TR.position;
            uiVertex.uv0 = characterInfoArray[i].vertex_TR.uv;
            uiVertex.color = characterInfoArray[i].vertex_TR.color;
            spriteVertices[spriteIndex_X4 + 2] = uiVertex;

            uiVertex.position = characterInfoArray[i].vertex_BR.position;
            uiVertex.uv0 = characterInfoArray[i].vertex_BR.uv;
            uiVertex.color = characterInfoArray[i].vertex_BR.color;
            spriteVertices[spriteIndex_X4 + 3] = uiVertex;  

            m_inlineGraphics.SetUIVertex(spriteVertices);
        }
コード例 #36
0
ファイル: UIMeshLine.cs プロジェクト: cupsster/drawLine
    void FillJoint( VertexHelper vh, UIVertex vp0, UIVertex vp1, UIVertex[] prvLineVert, Color color)
    {
        Vector3 forwardWidthVector = vp1.position - vp0.position;
        Vector3 prvWidthVector = prvLineVert[1].position - prvLineVert[0].position;

        Vector3 prvVector = Vector3.Cross(prvWidthVector, new Vector3(0, 0, 1));
        
        Vector3 p0;
        Vector3 p1;
        Vector3 center = (vp0.position + vp1.position) / 2f;
                               
        if(Vector3.Dot(prvVector, forwardWidthVector) > 0)
        {
            p0 = vp1.position;
            p1 = prvLineVert[1].position;
        }
        else
        {
            p0 = vp0.position;
            p1 = prvLineVert[0].position;
        }

        Vector3 cp0 = (p0 + p1- center*2).normalized * width *0.5f + center;

        float angle = Vector3.Angle(p0 - center, p1 - center);

        int currentVert = vh.currentVertCount;
        int divideCount = (int)(angle / fillDivideAngle);
        if(divideCount == 0) { divideCount = 1; }

        float unit = 1f / divideCount;

        vh.AddVert(center, color, Vector2.zero);
        vh.AddVert(p0, color, Vector2.zero);
        for (int n = 0; n < divideCount; n++)
        {
            vh.AddVert(Curve.CalculateBezier(p0, p1, cp0, unit *(n+1)), color, Vector2.zero);
            vh.AddTriangle(currentVert, currentVert + 1 + n, currentVert + 2 + n);
        } 
    }
コード例 #37
0
        private bool SetQuadPositions(UIVertex[] verts, Vector3 center, Rect inside, float offset)
        {
            // Set position
            float half = (pixelSize / 2) + offset;

            // Get corner positions, and clamp them inside the rect
            float minX = Mathf.Clamp(center.x - half, inside.xMin, inside.xMax);
            float minY = Mathf.Clamp(center.y - half, inside.yMin, inside.yMax);
            float maxX = Mathf.Clamp(center.x + half, inside.xMin, inside.xMax);
            float maxY = Mathf.Clamp(center.y + half, inside.yMin, inside.yMax);

            // Check if this quad has either a width or height of 0, if so, return false
            if (Mathf.Approximately(minX, maxX) || Mathf.Approximately(minY, maxY))
                return false;

            // Set the positions of the quad
            verts[0].position = new Vector3(minX, minY);
            verts[1].position = new Vector3(minX, maxY);
            verts[2].position = new Vector3(maxX, maxY);
            verts[3].position = new Vector3(maxX, minY);

            return true;
        }
コード例 #38
0
ファイル: UIMeshLine.cs プロジェクト: cupsster/drawLine
    /// <summary>
    /// v0          v2  
    /// ┌─────┐  ↑
    /// p0   quad   p1  width 
    /// └─────┘  ↓
    /// v1          v3
    /// 
    ///
    /// </summary>
    /// <param name="prvVert"> v0, v1 </param>
    /// <returns> {v0,v1,v2,v3}:UIVertex </returns>
    UIVertex[] MakeQuad(VertexHelper vh, Vector3 p0, Vector3 p1, Color c0, Color c1, UIVertex[] prvVert=null)
    {
        Vector3 lineVector = p1 - p0;
        Vector3 widthVector = Vector3.Cross(lineVector, new Vector3(0, 0, 1));
        widthVector.Normalize();
        UIVertex[] verts = new UIVertex[4];
        if (prvVert != null)
        {
            verts[0] = prvVert[0];
            verts[1] = prvVert[1];
        }
        else
        {
            verts[0].position = p0 + widthVector * width * 0.5f;
            verts[1].position = p0 - widthVector * width * 0.5f;
        }
        verts[0].uv0 = new Vector2(0, 0);
        verts[1].uv0 = new Vector2(1, 0);
        verts[2].position = p1 - widthVector * width * 0.5f; verts[2].uv0 = new Vector2(1, 1);
        verts[3].position = p1 + widthVector * width * 0.5f; verts[3].uv0 = new Vector2(0, 1);

        verts[0].color = c0;
        verts[1].color = c0;
        verts[2].color = c1;
        verts[3].color = c1;

        vh.AddUIVertexQuad(verts);
        return verts;
    }
コード例 #39
0
 public void SetUIVertex (UIVertex[] uiVertex)
 {
     m_uiVertex = uiVertex;
 }
コード例 #40
0
        protected override void OnPopulateMesh(VertexHelper vh)
        {
            Texture tex = mainTexture;

            vh.Clear();
            if (tex != null)
            {
                Rect r = GetPixelAdjustedRect();
                Vector4 v = new Vector4(r.x, r.y, r.x + r.width, r.y + r.height);

                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);
                }
            }
        }