You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
177 lines
4.9 KiB
177 lines
4.9 KiB
using DG.Tweening;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class Level1Manager : MonoSingleton<Level1Manager>
|
|
{
|
|
public Transform[] UACGroup;
|
|
public Transform[] WayPointGroup;
|
|
public Button[] Viewbuttons;
|
|
public Camera[] cameraPoints;
|
|
public Text[] xunShiState;
|
|
public Text[] fenPeiState;
|
|
public float _speed;
|
|
public float TurnTime;
|
|
|
|
public GameObject UACView;
|
|
|
|
public GameObject UACTitle;
|
|
|
|
public Button ReturnMainViewBtn;
|
|
|
|
public GameObject VACViewPanel;
|
|
|
|
public Text tougeResultText;
|
|
public GameObject passTip;
|
|
public GameObject passOverTip;
|
|
|
|
private bool isPassOver = false;
|
|
private int UACIndex = 0;
|
|
|
|
public DriveManager driveManager;
|
|
|
|
protected override void Awake()
|
|
{
|
|
|
|
base.Awake();
|
|
|
|
driveManager.Init();
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
for (int i = 0; i < Viewbuttons.Length; i++)
|
|
{
|
|
int index = i;
|
|
Viewbuttons[i].onClick.AddListener(() => {
|
|
//相机视角切换
|
|
for (int j = 0; j < cameraPoints.Length; j++)
|
|
{
|
|
cameraPoints[j].enabled = false;
|
|
}
|
|
cameraPoints[index].enabled = true;
|
|
//无人机标题UI隐藏
|
|
UACTitle.gameObject.SetActive(false);
|
|
|
|
ReturnMainViewBtn.gameObject.SetActive(true);
|
|
UACView.SetActive(true);
|
|
});
|
|
}
|
|
|
|
ReturnMainViewBtn.onClick.AddListener(() => {
|
|
for (int j = 0; j < cameraPoints.Length; j++)
|
|
{
|
|
cameraPoints[j].enabled = false;
|
|
}
|
|
ReturnMainViewBtn.gameObject.SetActive(false);
|
|
//无人机标题UI
|
|
UACTitle.gameObject.SetActive(true);
|
|
|
|
UACView.SetActive(false);
|
|
});
|
|
}
|
|
|
|
|
|
private void Update()
|
|
{
|
|
if ((tougeResultText.text.Contains("Y")||tougeResultText.text.Contains("True")) &&isPassOver==false)
|
|
{
|
|
Debug.Log("执行中");
|
|
UACPolling();
|
|
VACViewPanel.SetActive(true);
|
|
for (int i = 0; i < xunShiState.Length; i++)
|
|
{
|
|
xunShiState[i].text = "巡视中";
|
|
fenPeiState[i].text = (i + 1).ToString() + "号无人机";
|
|
}
|
|
passTip.SetActive(false);
|
|
ReturnMainViewBtn.image.enabled = false;
|
|
ReturnMainViewBtn.image.raycastTarget = false;
|
|
ReturnMainViewBtn.GetComponentInChildren<Text>().enabled = false;
|
|
isPassOver = true;
|
|
}
|
|
}
|
|
|
|
[ContextMenu("执行无人机巡检")]
|
|
private void UACPolling()
|
|
{
|
|
for (int i = 0; i < UACGroup.Length; i++)
|
|
{
|
|
StartCoroutine(TransMove(UACGroup[i], WayPointGroup[i],i+1));
|
|
}
|
|
|
|
}
|
|
|
|
|
|
public IEnumerator TransMove(Transform car, Transform pointArr,int index)
|
|
{
|
|
if (car != null)
|
|
{
|
|
float speed = 0f;
|
|
float t = 0f;
|
|
|
|
Transform[] moveList = new Transform[pointArr.childCount];
|
|
for (int i = 0; i < pointArr.childCount; i++)
|
|
{
|
|
moveList[i] = pointArr.GetChild(i);
|
|
Transform point = moveList[i];
|
|
//WayPoint wayPoint = point.GetComponent<WayPoint>();
|
|
Vector3 Dir = ((point.position) - car.transform.position).normalized;
|
|
|
|
Vector3 lookDir = new Vector3(point.position.x, point.position.y, point.position.z) - car.transform.position;
|
|
Quaternion rot = Quaternion.LookRotation(lookDir);
|
|
|
|
|
|
//******循环判断离路径点距离********
|
|
while (true)
|
|
{
|
|
|
|
yield return new WaitForSeconds(0.02f);
|
|
|
|
if (t < 1)
|
|
{
|
|
t += 0.002f;
|
|
}
|
|
|
|
speed = Mathf.Lerp(8f, _speed, t);
|
|
|
|
|
|
float distance = Vector3.Distance(car.transform.position, point.position);
|
|
|
|
car.transform.position += Dir * speed * Time.deltaTime;
|
|
car.transform.DORotate(new Vector3(car.transform.eulerAngles.x, rot.eulerAngles.y, car.transform.eulerAngles.z), TurnTime, RotateMode.Fast);
|
|
|
|
if (distance <= 1.5f)
|
|
{
|
|
|
|
break;
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
xunShiState[index-1].text = "巡视完成";
|
|
UACIndex++;
|
|
if (UACIndex >= UACGroup.Length)
|
|
{
|
|
|
|
//提示通关
|
|
passOverTip.gameObject.SetActive(true);
|
|
EduCoderTool.WebConnecter.Singleton.SendResultToWeb(true);
|
|
|
|
}
|
|
//回收车辆
|
|
//Car carData = car.GetComponent<Car>();
|
|
//carList.Remove(carData);
|
|
//// Destroy(car.gameObject);
|
|
//ObjectPool.Instance.Unspawn(car.gameObject);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|