Merge branch 'master' of http://git.umayle.com:2023/yulong/NewN_UAVPlane
This commit is contained in:
commit
36d8db289d
|
@ -136,12 +136,18 @@ public class UnmannedAerialVehicleManage : MonoBehaviour
|
||||||
}
|
}
|
||||||
unmannedAerialVehicleManages.Add(this);
|
unmannedAerialVehicleManages.Add(this);
|
||||||
equipmentCommon = GetComponent<EquipmentCommon>();
|
equipmentCommon = GetComponent<EquipmentCommon>();
|
||||||
Formation(1);//默认阵型
|
//Formation(1);//默认阵型
|
||||||
// 订阅布尔值变化事件
|
// 订阅布尔值变化事件
|
||||||
OnActivationChanged += OnActivationChangedHandler;
|
OnActivationChanged += OnActivationChangedHandler;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[ContextMenu("Test")]
|
||||||
|
public void Test()
|
||||||
|
{
|
||||||
|
MatrixFormation(30, 6);//根据想定数据去设置无人机数量
|
||||||
|
}
|
||||||
|
|
||||||
// Update is called once per frame
|
// Update is called once per frame
|
||||||
void Update()
|
void Update()
|
||||||
{
|
{
|
||||||
|
@ -467,6 +473,8 @@ public class UnmannedAerialVehicleManage : MonoBehaviour
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 无人机雁式阵型
|
/// 无人机雁式阵型
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -504,6 +512,8 @@ public class UnmannedAerialVehicleManage : MonoBehaviour
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 矩阵阵型
|
/// 矩阵阵型
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -537,6 +547,47 @@ public class UnmannedAerialVehicleManage : MonoBehaviour
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 根据想定数据去设置无人机数量
|
||||||
|
/// </summary>
|
||||||
|
private void MatrixFormation(int rows, int wrjCount)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < unmannedAerialVehicles.Count; i++)
|
||||||
|
{
|
||||||
|
unmannedAerialVehicles[i].gameObject.SetActive(false);
|
||||||
|
}
|
||||||
|
for (int i = 0; i < wrjCount; i++)
|
||||||
|
{
|
||||||
|
unmannedAerialVehicles[i].gameObject.SetActive(true);
|
||||||
|
}
|
||||||
|
float offsetX = 2.0f; // 子物体之间的水平间距
|
||||||
|
float offsetY = 2.0f; // 子物体之间的垂直间距
|
||||||
|
float offsetZ = 2.0f; // 子物体之间的垂直间距
|
||||||
|
int currentCount = 0;
|
||||||
|
int cols = CanDivideEvenly(totalObjects, rows) ? totalObjects / rows : totalObjects / rows + 1;
|
||||||
|
for (int row = 0; row < rows; row++)
|
||||||
|
{
|
||||||
|
for (int col = 0; col < cols; col++)
|
||||||
|
{
|
||||||
|
if (currentCount < totalObjects)
|
||||||
|
{
|
||||||
|
Vector3 position = new Vector3(col * offsetX, 0, -row * offsetZ);
|
||||||
|
if (unmannedAerialVehicles[currentCount])
|
||||||
|
unmannedAerialVehicles[currentCount].transform.localPosition = position;
|
||||||
|
currentCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
BoxCollider box = transform.GetComponent<BoxCollider>();
|
||||||
|
if (box)
|
||||||
|
{
|
||||||
|
Debug.Log("cols..:" + cols);
|
||||||
|
Debug.Log("rows..:" + rows);
|
||||||
|
box.center = new Vector3(cols - 1, 0, -(wrjCount - 1));
|
||||||
|
box.size = new Vector3(cols * 2, 1, 2 * wrjCount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool CanDivideEvenly(int dividend, int divisor)
|
bool CanDivideEvenly(int dividend, int divisor)
|
||||||
{
|
{
|
||||||
return dividend % divisor == 0;
|
return dividend % divisor == 0;
|
||||||
|
|
Loading…
Reference in New Issue