void OnPopulateMeshPoints(VertexHelper vh) { vh.Clear(); Color32 c32 = color; foreach (var p in points) { vh.AddQuad(new Vector3(p.x - 1, p.y + 1, 0), new Vector3(p.x + 1, p.y + 1, 0), new Vector3(p.x - 1, p.y - 1, 0), new Vector3(p.x + 1, p.y - 1, 0), c32); } // material.color = color; canvasRenderer.SetMaterial(material, Texture2D.whiteTexture); }
/// <summary> /// 折れ線を描く.(交点を面取りする.) /// </summary> void OnPopulateMeshLineStripTruncated(VertexHelper vh) { vh.Clear(); var pointsLength = points.Length; if (pointsLength == 0) { return; } else if (pointsLength == 1) { // draw point. OnPopulateMeshPoints(vh); return; } Color32 c32 = color; // for (var idx = 0; idx < pointsLength; ++idx) // { // var pos = points[idx]; // current position. // Debug.Log("pos[" + idx + "]:" + pos); // } var prevPos = points[0]; // prev position. var currPos = points[1]; // current position. var pcLine = currPos - prevPos; var pcLineVecRot90 = pcLine.GetRot90Deg(); pcLineVecRot90.Normalize(); pcLineVecRot90 = pcLineVecRot90 * width * 0.5f; var prevT = prevPos + pcLineVecRot90; var prevB = prevPos - pcLineVecRot90; var currT = currPos + pcLineVecRot90; var currB = currPos - pcLineVecRot90; for (var idx = 2; idx < pointsLength; ++idx) { var nextPos = points[idx]; // current position. var cnLine = nextPos - currPos; var cnLineVecRot90 = cnLine.GetRot90Deg(); cnLineVecRot90.Normalize(); cnLineVecRot90 = cnLineVecRot90 * width * 0.5f; var currT2 = currPos + cnLineVecRot90; var currB2 = currPos - cnLineVecRot90; var nextT = nextPos + cnLineVecRot90; var nextB = nextPos - cnLineVecRot90; vh.AddQuad(prevT, currT, prevB, currB, c32); var pcAim = Vector2Ex.GetAimRad(prevPos, currPos); var cnAim = Vector2Ex.GetAimRad(currPos, nextPos); if (pcAim < cnAim) { vh.AddTriangle(currPos, currB2, currB, c32); } else { vh.AddTriangle(currT, currT2, currPos, c32); } prevPos = currPos; // prev position. currPos = nextPos; // points[idx] // current position. pcLine = cnLine; pcLineVecRot90 = cnLineVecRot90; prevT = currT2; prevB = currB2; currT = nextT; currB = nextB; } vh.AddQuad(prevT, currT, prevB, currB, c32); canvasRenderer.SetMaterial(material, Texture2D.whiteTexture); }