/// <summary> /// 创建半圆形防空区域 /// </summary> /// <param name="origin">中心点</param> /// <param name="radius">半径</param> /// <param name="angle">张角(默认90度)</param> public void CreateHemisphere(Vector3 origin, float radius, Color color, int angle = 90) { Mesh mesh = GLDraw.CreateHemisphere(origin, radius, 90, color.Int32()); Game.GraphicsModule.AddGraphics(Camera.main, () => { ShapeMaterial.SetPass(0); Graphics.DrawMeshNow(mesh, Matrix4x4.identity); }); }
/// <summary> /// 创建扇形防空区 /// </summary> /// <param name="id"> 命令ID,用作字典key </param> /// <param name="origin">起始点</param> /// <param name="tarPoint">水平最远距离点</param> /// <param name="alpha">横向张角</param> /// <param name="theta">纵向张角</param> public void CreateSector(Vector3 origin, Vector3 tarPoint, float alpha, float theta, Color color) { Vector3[] vertices = PhysicsMath.GetSectorPoints_2(origin, tarPoint, alpha, theta); Mesh mesh = GLDraw.CreatePolygon(vertices, color.Int32()); Game.GraphicsModule.AddGraphics(Camera.main, () => { ShapeMaterial.SetPass(0); Graphics.DrawMeshNow(mesh, Matrix4x4.identity); }); }
/// <summary> /// 创建通用多边形区域 /// </summary> /// <param name="id"> 命令ID,用作字典key </param> /// <param name="list">下底面点链表</param> /// <param name="height">高度</param> public void CreatePolygon(List <Vector3> list, float height, Color color) { Vector3[] vector3s = PhysicsMath.CheckVector(list); // 使数组逆时针排序 Mesh mesh = GLDraw.CreatePolygon(vector3s, height, color.Int32()); // 画出图形 Game.GraphicsModule.AddGraphics(Camera.main, () => { ShapeMaterial.SetPass(0); Graphics.DrawMeshNow(mesh, Matrix4x4.identity); }); }
/// <summary> /// 创建圆柱形区域 /// </summary> /// <param name="id"> 命令ID,用作字典key </param> /// <param name="point"> 圆心点 </param> /// <param name="radius"> 半径 </param> /// <param name="height"> 高度 </param> public void CreateCylinder(Vector3 point, float radius, float height, Color color) { Mesh mesh = GLDraw.CreateCylinder(point, radius, height, color.Int32()); // 画出图形 Debug.Log(color.Int32().Color()); Game.GraphicsModule.AddGraphics(Camera.main, () => { ShapeMaterial.SetPass(0); Graphics.DrawMeshNow(mesh, Matrix4x4.identity); }); }
private void OnPostRender() { pos = transform.position + transform.forward * 10 + transform.up * 5 + transform.right * 7; shapesMaterial.SetPass(0); Graphics.DrawMeshNow(GLDraw.CreateArrow(Color.red, 1), pos, Quaternion.Euler(90, 0, 0)); GL.Begin(GL.LINES); GL.Color(Color.red); GL.Vertex(pos); GL.Vertex(pos - Vector3.forward * 1); GL.End(); }
/// <summary> /// 创建空中走廊 /// </summary> /// <param name="id"> 命令ID,用作字典key </param> /// <param name="list">中心点链表</param> /// <param name="width">宽度</param> /// <param name="height">高度</param> public void CreateAirCorridorSpace(List <Vector3> list, float width, float height, Color color) { //Vector3[] vertices = PhysicsMath.GetAirCorridorSpace(list, width, height); // 获取点集 //DrawTriangles.DrawAirCorridorSpace(vertices, meshFilter, lineRenderers); // 画出图形 Mesh mesh = GLDraw.CreateLineMesh(list, width, height, color.Int32()); Game.GraphicsModule.AddGraphics(Camera.main, () => { ShapeMaterial.SetPass(0); Graphics.DrawMeshNow(mesh, Matrix4x4.identity); }); }
/// <summary> /// 绘制坐标系箭头 /// </summary> private void DrawCoordinateArrow(Transform target) { Vector3 position = target.position; Vector3 euler = target.eulerAngles; // 画坐标轴的箭头 (箭头的锥顶不是它自身坐标的forword) Mesh meshX = GLDraw.CreateArrow(m_SelectedAxis == RuntimeHandleAxis.X ? m_SelectedColor : Color.red, m_ArrowScale * m_ScreenScale); Graphics.DrawMeshNow(meshX, position + target.right * m_HandleScale * m_ScreenScale, target.rotation * Quaternion.Euler(0, 0, -90)); Mesh meshY = GLDraw.CreateArrow(m_SelectedAxis == RuntimeHandleAxis.Y ? m_SelectedColor : Color.green, m_ArrowScale * m_ScreenScale); Graphics.DrawMeshNow(meshY, position + target.up * m_HandleScale * m_ScreenScale, target.rotation); Mesh meshZ = GLDraw.CreateArrow(m_SelectedAxis == RuntimeHandleAxis.Z ? m_SelectedColor : Color.blue, m_ArrowScale * m_ScreenScale); Graphics.DrawMeshNow(meshZ, position + target.forward * m_HandleScale * m_ScreenScale, target.rotation * Quaternion.Euler(90, 0, 0)); }
/// <summary> /// 创建两个圆柱,近距火力支援等待空域 /// </summary> /// <param name="id"> 命令ID,用作字典key </param> /// <param name="point">低点圆柱的底面圆心点</param> /// <param name="radius">半径</param> /// <param name="height">圆柱高度</param> /// <param name="heightDifference">两个圆柱的高度差</param> public void DoubleCylinder(Vector3 point, float radius, float height, float heightDifference, Color color) { // 下面圆柱 Mesh meshUp = GLDraw.CreateCylinder(point, radius, height, color.Int32()); // 上面圆柱 Vector3 highPoint = point + Vector3.up * (height + heightDifference); Mesh meshDown = GLDraw.CreateCylinder(highPoint, radius, height); Game.GraphicsModule.AddGraphics(Camera.main, () => { ShapeMaterial.SetPass(0); Graphics.DrawMeshNow(meshUp, Matrix4x4.identity); Graphics.DrawMeshNow(meshDown, Matrix4x4.identity); }); }
/// <summary> /// 绘制坐标系小正方体 /// </summary> private void DrawCoordinateCube(Transform target) { Vector3 position = target.position; Vector3 euler = target.eulerAngles; // 画坐标轴的小方块 m_ShapesMaterial.SetPass(0); Mesh meshX = GLDraw.CreateCube(m_SelectedAxis == RuntimeHandleAxis.X ? m_SelectedColor : Color.red, Vector3.zero, m_CubeScale * m_ScreenScale); Graphics.DrawMeshNow(meshX, position + target.right * m_HandleScale * m_ScreenScale, target.rotation * Quaternion.Euler(0, 0, -90)); Mesh meshY = GLDraw.CreateCube(m_SelectedAxis == RuntimeHandleAxis.Y ? m_SelectedColor : Color.green, Vector3.zero, m_CubeScale * m_ScreenScale); Graphics.DrawMeshNow(meshY, position + target.up * m_HandleScale * m_ScreenScale, target.rotation); Mesh meshZ = GLDraw.CreateCube(m_SelectedAxis == RuntimeHandleAxis.Z ? m_SelectedColor : Color.blue, Vector3.zero, m_CubeScale * m_ScreenScale); Graphics.DrawMeshNow(meshZ, position + target.forward * m_HandleScale * m_ScreenScale, target.rotation * Quaternion.Euler(90, 0, 0)); Mesh meshO = GLDraw.CreateCube(m_SelectedAxis == RuntimeHandleAxis.XYZ ? m_SelectedColor : Color.white, Vector3.zero, m_CubeScale * m_ScreenScale); Graphics.DrawMeshNow(meshO, position, target.rotation); }
/// <summary> /// 创建紫色杀伤盒 /// </summary> /// <param name="id"> 命令ID,用作字典key </param> /// <param name="list">底面四点链表</param> /// <param name="lower">下限高度</param> /// <param name="Ceiling">上限高度</param> public void CreateKillBox(List <Vector3> list, float lower, float Ceiling, Color color) { // 第一个杀伤盒 Vector3[] vector3s1 = PhysicsMath.CheckVector(list); // 使数组逆时针排序 Mesh mesh0 = GLDraw.CreatePolygon(vector3s1, lower, color.Int32()); // 画出图形 // 第二个杀伤盒 List <Vector3> CeilingList = new List <Vector3>(); // 中层顶点集合 foreach (var item in list) { CeilingList.Add(item + Vector3.up * lower); } Vector3[] vector3s2 = PhysicsMath.CheckVector(CeilingList); // 使数组逆时针排序 Mesh mesh1 = GLDraw.CreatePolygon(vector3s2, Ceiling - lower, color.Int32()); // 画出图形 Game.GraphicsModule.AddGraphics(Camera.main, () => { ShapeMaterial.SetPass(0); Graphics.DrawMeshNow(mesh0, Matrix4x4.identity); Graphics.DrawMeshNow(mesh1, Matrix4x4.identity); }); }