This commit is contained in:
账号名 2024-01-23 19:48:42 +08:00
parent 1e15d4915c
commit 9f3e9b7673
2 changed files with 36 additions and 36 deletions

View File

@ -475,8 +475,8 @@ BoxCollider:
m_IsTrigger: 0 m_IsTrigger: 0
m_Enabled: 1 m_Enabled: 1
serializedVersion: 2 serializedVersion: 2
m_Size: {x: 14, y: 1, z: 8} m_Size: {x: 3.1049147, y: 0.9891114, z: 3.2810247}
m_Center: {x: 0, y: 0, z: -3} m_Center: {x: 0.060157776, y: 0.11486983, z: -1.1351347}
--- !u!114 &1432105532577387308 --- !u!114 &1432105532577387308
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@ -710,40 +710,40 @@ public class UnmannedAerialVehicleManage : MonoBehaviour
/// </summary> /// </summary>
public void MatrixFormation(int rows, int wrjCount) public void MatrixFormation(int rows, int wrjCount)
{ {
for (int i = 0; i < unmannedAerialVehicles.Count; i++) //for (int i = 0; i < unmannedAerialVehicles.Count; i++)
{ //{
unmannedAerialVehicles[i].gameObject.SetActive(false); // unmannedAerialVehicles[i].gameObject.SetActive(false);
} //}
for (int i = 0; i < wrjCount; i++) //for (int i = 0; i < wrjCount; i++)
{ //{
unmannedAerialVehicles[i].gameObject.SetActive(true); // unmannedAerialVehicles[i].gameObject.SetActive(true);
} //}
float offsetX = 2.0f; // 子物体之间的水平间距 //float offsetX = 2.0f; // 子物体之间的水平间距
float offsetY = 2.0f; // 子物体之间的垂直间距 //float offsetY = 2.0f; // 子物体之间的垂直间距
float offsetZ = 2.0f; // 子物体之间的垂直间距 //float offsetZ = 2.0f; // 子物体之间的垂直间距
int currentCount = 0; //int currentCount = 0;
int cols = CanDivideEvenly(totalObjects, rows) ? totalObjects / rows : totalObjects / rows + 1; //int cols = CanDivideEvenly(totalObjects, rows) ? totalObjects / rows : totalObjects / rows + 1;
for (int row = 0; row < rows; row++) //for (int row = 0; row < rows; row++)
{ //{
for (int col = 0; col < cols; col++) // for (int col = 0; col < cols; col++)
{ // {
if (currentCount < totalObjects) // if (currentCount < totalObjects)
{ // {
Vector3 position = new Vector3(col * offsetX, 0, -row * offsetZ); // Vector3 position = new Vector3(col * offsetX, 0, -row * offsetZ);
if (unmannedAerialVehicles[currentCount]) // if (unmannedAerialVehicles[currentCount])
unmannedAerialVehicles[currentCount].transform.localPosition = position; // unmannedAerialVehicles[currentCount].transform.localPosition = position;
currentCount++; // currentCount++;
} // }
} // }
} //}
BoxCollider box = transform.GetComponent<BoxCollider>(); //BoxCollider box = transform.GetComponent<BoxCollider>();
if (box) //if (box)
{ //{
//Debug.Log("cols..:" + cols); // //Debug.Log("cols..:" + cols);
//Debug.Log("rows..:" + rows); // //Debug.Log("rows..:" + rows);
box.center = new Vector3(cols - 1, 0, -(wrjCount - 1)); // box.center = new Vector3(cols - 1, 0, -(wrjCount - 1));
box.size = new Vector3(cols * 2, 1, 2 * wrjCount); // box.size = new Vector3(cols * 2, 1, 2 * wrjCount);
} //}
} }
bool CanDivideEvenly(int dividend, int divisor) bool CanDivideEvenly(int dividend, int divisor)