bool GenerateCollisionShapeFromEnemies() { if (GSB_SceneManager.Instance.SelectionMesh != null) { for (var i = 0; i < SelectingEnemies.Count; ++i) { _shapeVertices2D[i].x = SelectingEnemies[i].transform.position.x; _shapeVertices2D[i].y = SelectingEnemies[i].transform.position.y; } _triangulator.Init(_shapeVertices2D, SelectingEnemies.Count); int[] indices = _triangulator.Triangulate(); Mesh shapeMesh = null; var setTriangles = false; if (GSB_SceneManager.Instance.SelectionMesh.sharedMesh == null) { setTriangles = true; shapeMesh = new Mesh(); GSB_SceneManager.Instance.SelectionMesh.sharedMesh = shapeMesh; } else { shapeMesh = GSB_SceneManager.Instance.SelectionMesh.sharedMesh; } if (_shapeVertices3D == null || SelectingEnemies.Count > _shapeVertices3D.Length) { _shapeVertices3D = new Vector3[SelectingEnemies.Count]; } for (int i = 0; i < SelectingEnemies.Count; i++) { _shapeVertices3D[i].x = _shapeVertices2D[i].x; _shapeVertices3D[i].y = _shapeVertices2D[i].y; _shapeVertices3D[i].z = -0.15f; } if (shapeMesh != null) { shapeMesh.vertices = _shapeVertices3D; if (setTriangles) { shapeMesh.triangles = indices; } shapeMesh.RecalculateBounds(); } if (indices.Length == 3 && SelectingEnemies.Count == 4) { return(false); } return(true); } return(false); }