Unity使用bounds绘制不规则图形边框
Unity使用bounds绘制不规则图形边框
for (int i = 0; i < screenList.Count; i++)
{
if (screenList[i].activeSelf == true)
{
Bounds bounds = screenList[i].GetComponent().mesh.bounds;
float x = bounds.size.x * screenList[i].transform.localScale.x;
// float y = bounds.size.y * screenList[i].transform.localScale.y;
float z = bounds.size.z * screenList[i].transform.localScale.z;
//计算矩形框顶点位置
Vector3 leftUp = new Vector3(bounds.center.x - x / 2, 0, bounds.center.z + z / 2);
Vector3 rightUp = new Vector3(bounds.center.x + x / 2, 0, bounds.center.z + z / 2);
Vector3 rightDown = new Vector3(bounds.center.x + x / 2, 0, bounds.center.z - z / 2);
Vector3 leftDown = new Vector3(bounds.center.x - x / 2, 0, bounds.center.z - z / 2);
//旋转后的矩形框顶点
Vector3 lur = RotateRound(leftUp, screenList[i].transform.position, Vector3.up, screenList[i].transform.rotation.eulerAngles.y);
Vector3 rur = RotateRound(rightUp, screenList[i].transform.position, Vector3.up, screenList[i].transform.rotation.eulerAngles.y);
Vector3 rdr = RotateRound(rightDown, screenList[i].transform.position, Vector3.up, screenList[i].transform.rotation.eulerAngles.y);
Vector3 ldr = RotateRound(leftDown, screenList[i].transform.position, Vector3.up, screenList[i].transform.rotation.eulerAngles.y);
//平移后的矩形框顶点
Vector3 lu = new Vector3(lur.x + screenList[i].transform.position.x, 0, lur.z + screenList[i].transform.position.z);
Vector3 ru = new Vector3(rur.x + screenList[i].transform.position.x, 0, rur.z + screenList[i].transform.position.z);
Vector3 rd = new Vector3(rdr.x + screenList[i].transform.position.x, 0, rdr.z + screenList[i].transform.position.z);
Vector3 ld = new Vector3(ldr.x + screenList[i].transform.position.x, 0, ldr.z + screenList[i].transform.position.z);
//显示矩形框
Debug.DrawLine(ld, lu, Color.green);
Debug.DrawLine(ld, rd, Color.green);
Debug.DrawLine(ru, lu, Color.green);
Debug.DrawLine(ru, rd, Color.green);
}
///
/// 围绕某点旋转指定角度
///
/// 自身坐标
/// 旋转中心
/// 围绕旋转轴
/// 旋转角度
///
private Vector3 RotateRound(Vector3 position, Vector3 center, Vector3 axis, float angle)
{
return Quaternion.AngleAxis(angle, axis) * (position - center) + center;
}
- 在Unity中使用uGUI绘制自定义图形(饼状图 雷达图)
- 在Unity中使用UGUI修改Mesh绘制几何图形
- 使用R语言绘制其他图形之相关系数图
- 基本图形绘制Quartz2d的的使用
- 使用unity绘制旋转的三角形
- VS2010 使用TeeChart绘图控件 - 之二 - 绘制图形(折线图,柱状图)
- iOS开发UI篇—Quartz2D使用(绘制基本图形)
- 使用cnavas绘制图形解锁
- 使用unity的mesh绘制三菱柱的碰撞体(3d三角形)
- iOS 使用UIBezierPath与CABasicAnimation绘制图形
- 使用HTML5进行SVG矢量图形绘制的入门教程
- 我使用过的Linux命令之dot - 绘制DOT语言脚本描述的图形
- VS2010 使用TeeChart绘图控件 - 之二 - 绘制图形(折线图,柱状图)
- DX中使用顶点缓存和索引缓存绘制图形
- 图形绘制之——Canvas详解(二)-Path路径使用
- 开始使用SmartDraw绘制开发中的各种图形
- c#画笔Pen使用路径绘制图形
- VS2010 使用TeeChart画图控件 - 之二 - 绘制图形(折线图,柱状图)
- android绘制2D图形(扫盲贴)--使用android.graphics类
- VS2010 使用TeeChart绘图控件 - 之二 - 绘制图形(折线图,柱状图)