public static void UpdateLineAlertMesh(this AlertAreaMeshPack _pack, float length, float width, float borderWidth) { var vertices = _pack.vertices; var uv = _pack.uv; vertices[0] = new Vector3(-width, 0, 0); vertices[1] = new Vector3(-width + borderWidth, 0, 0); vertices[2] = new Vector3(width - borderWidth, 0, 0); vertices[3] = new Vector3(width, 0, 0); vertices[4] = new Vector3(-width, 0, length); vertices[5] = new Vector3(-width + borderWidth, 0, length); vertices[6] = new Vector3(width - borderWidth, 0, length); vertices[7] = new Vector3(width, 0, length); var vScale = CalculateVScale(length, borderWidth); uv[4] = new Vector2(0, vScale); uv[5] = new Vector2(0.25f, vScale); uv[6] = new Vector2(0.75f, vScale); uv[7] = new Vector2(1, vScale); _pack.mesh.vertices = _pack.vertices; _pack.mesh.uv = _pack.uv; _pack.mesh.RecalculateBounds(); }
public static void UpdateRadioAlertMesh(this AlertAreaMeshPack _pack, float _radium, float _borderWidth) { var vertices = _pack.vertices; var uv = _pack.uv; var _sectorCount = ((SectorAlertAreaMeshPack)_pack).sectorCount; var totalRadium = _radium + _borderWidth; //var circleLength = Mathf.PI * 2 * _radium; //var vMax = circleLength / _borderWidth; //V坐标的最大值 //var vForEachSector = vMax / _sectorCount; var a = 360f / _sectorCount; var rotInverse = Quaternion.AngleAxis(a, Vector3.up); vertices[0] = Vector3.zero; vertices[1] = vertices[2] = new Vector3(0, 0, _radium); vertices[3] = new Vector3(0, 0, totalRadium); for (int i = 0; i < _sectorCount; ++i) { var index = i * 3 + 4; vertices[index] = vertices[index + 1] = rotInverse * vertices[index - 3]; vertices[index + 2] = rotInverse * vertices[index - 1]; } //var prevRadium = vertices[1].z; //prevRadium = Mathf.Max(prevRadium, 0.1f); //var prevTotalRadium = vertices[3].z; //prevTotalRadium = Mathf.Max(prevTotalRadium, 0.1f); //var multiRadium = _radium / prevRadium; //var multiTotalRadium = totalRadium / prevTotalRadium; //vertices[1] = vertices[2] = new Vector3(0, 0, _radium); //vertices[3] = new Vector3(0, 0, totalRadium); //for (int i = 0; i < _sectorCount; ++i) //{ // var index = i * 3 + 4; // vertices[index] *= multiRadium; // vertices[index + 1] *= multiRadium; // vertices[index + 2] *= multiTotalRadium; //} //for (int i = 0; i < _sectorCount; ++i) //{ // var index = i * 3 + 4; // var currentV = vForEachSector * (i + 1); // uv[index].y = currentV; // uv[index + 1].y = currentV; // uv[index + 2].y = currentV; //} _pack.mesh.vertices = vertices; _pack.mesh.uv = uv; _pack.mesh.RecalculateBounds(); }
public static void UpdateSectorAlertMesh(this AlertAreaMeshPack _pack, float radium, float angle, float borderWidth) { var vertices = _pack.vertices; var uv = _pack.uv; var verticeCount = vertices.Length; var finalIndex = verticeCount - 1; //VERTICES vertices[0] = Vector3.zero; vertices[finalIndex] = new Vector3(0, 0, radium); angle = Mathf.Min(angle, 180); var a = angle * 2f / ((SectorAlertAreaMeshPack)_pack).sectorCount; var rotInverse = Quaternion.AngleAxis(a, Vector3.up); var rotReverse = Quaternion.AngleAxis(-a, Vector3.up); vertices[finalIndex - 1] = rotInverse * new Vector3(0, 0, radium); for (int i = vertices.Length - 4; i >= 8; i -= 2) //右边 { vertices[i] = rotInverse * vertices[i + 2]; } for (int i = vertices.Length - 3; i >= 7; i -= 2) //左边 { vertices[i] = rotReverse * vertices[i + 2]; } vertices[1] = -(vertices[9] - vertices[7]).normalized * borderWidth; vertices[2] = -(vertices[10] - vertices[8]).normalized * borderWidth; vertices[3] = vertices[7] + vertices[1]; vertices[4] = vertices[8] + vertices[2]; vertices[6] = vertices[8]; vertices[5] = vertices[7]; var length = CalculateVScale(radium, borderWidth); for (int i = 3; i < verticeCount; ++i) { uv[i].y = length; } _pack.mesh.vertices = vertices; _pack.mesh.uv = uv; _pack.mesh.RecalculateBounds(); }