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.
532 lines
15 KiB
532 lines
15 KiB
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
using UnityEngine.UI;
|
|
|
|
public class GameManagerForZhuanWan : GameManager
|
|
{
|
|
|
|
|
|
public static GameManagerForZhuanWan Instance = null;
|
|
|
|
public bool isZhuanWan = false;
|
|
|
|
[HideInInspector]
|
|
public int probabilityNum = 0;
|
|
|
|
int TempIndex = 0;
|
|
|
|
public List<string> _haveItemList = new List<string>();
|
|
public Text mainAearTxt;
|
|
private int mainAearNum=0;
|
|
public GameObject fangzhitongji;
|
|
|
|
public Button NextPassBtn;
|
|
public GameObject Pass1UI_Trans;
|
|
public GameObject Pass2UI_Trans;
|
|
public GameObject TuoZhuaiUI_Trans;
|
|
public Transform GuanChaUI_Trans;
|
|
public GameObject Pass1RenderView;
|
|
public GameObject Pass2InfoWnd;
|
|
public Text RoadStateTxt;
|
|
[Header("窗口与功能类")]
|
|
public DriveManager driveManager;
|
|
public ZhuanWanData ZhuanWanData;
|
|
|
|
|
|
[Header("检测框是否开启自适应")]
|
|
public bool OpenKuangAutoScale = false;
|
|
public Vector2 kuangScale;
|
|
public float kuangDistanceValue = 3;
|
|
|
|
public Transform kuangPreant;
|
|
public string tougeMsg = "";
|
|
|
|
public bool isPassOver = false;
|
|
public bool EducoderPassOver = false;
|
|
public UnityEvent EducoderPassAction;
|
|
|
|
public Transform CameraSetGroup;
|
|
public CameraSet[] cameraSets;
|
|
|
|
public bool openZheDang = true;
|
|
|
|
/// <summary>
|
|
/// 是否是正常车流
|
|
/// </summary>
|
|
private bool _isNormalRoadState = true;
|
|
public bool isNormalRoadState
|
|
{
|
|
set
|
|
{
|
|
_isNormalRoadState = value;
|
|
}
|
|
get
|
|
{
|
|
return _isNormalRoadState;
|
|
}
|
|
}
|
|
|
|
private int actionSelected;
|
|
public int ActionSelected
|
|
{
|
|
set
|
|
{
|
|
actionSelected = value;
|
|
}
|
|
get
|
|
{
|
|
return actionSelected;
|
|
}
|
|
}
|
|
|
|
public int KuangIndex = 0;
|
|
public Button viewTheActionBtn;
|
|
public GameObject SafetyTip;
|
|
public GameObject eventWnd;
|
|
public GameObject tip;
|
|
public Text stepTipTxt;
|
|
[Header("拦路空气墙")]
|
|
public GameObject RightWall;
|
|
public GameObject LeftWall;
|
|
|
|
|
|
[Header("关卡摄像机")]
|
|
public MoveCamera pass1Camera;
|
|
public MoveCamera pass1RenderCamera;
|
|
|
|
[Header("设备观察点")]
|
|
private Dictionary<string, Transform> _OBPointsDict = new Dictionary<string, Transform>();
|
|
private Dictionary<string, Transform> _SheXiangDianDict = new Dictionary<string, Transform>();
|
|
[Header("设备放置父物体")]
|
|
public Transform fangzhiPreant;
|
|
public int leastItemNum = 3;
|
|
[Header("分析窗口")]
|
|
public GameObject AnalyWnd;
|
|
|
|
[Header("事故干预窗口")]
|
|
public GameObject EventBtn;
|
|
|
|
[Header("提示标志")]
|
|
public Image TipTypeImg;
|
|
public Text TipTypeTxt;
|
|
[Header("观察按钮额外事件")]
|
|
public UnityEvent guanchaEvent;
|
|
|
|
[HideInInspector]
|
|
public float tipScale = 1; //车辆速度超速Tip
|
|
public GameObject actionTip;
|
|
|
|
|
|
private void Awake()
|
|
{
|
|
Instance = this;
|
|
ZhuanWanData.Init();
|
|
}
|
|
private void Start()
|
|
{
|
|
|
|
|
|
//注册观察点
|
|
for (int i = 0; i < fangzhiPreant.childCount; i++)
|
|
{
|
|
Transform viewPoint = fangzhiPreant.GetChild(i).Find("观察点").transform;
|
|
RegisetOBPoint(fangzhiPreant.GetChild(i).name, viewPoint);
|
|
|
|
}
|
|
//注册摄像点
|
|
GameObject[] gos = GameObject.FindGameObjectsWithTag("SheXiangDian");
|
|
for (int i = 0; i < gos.Length; i++)
|
|
{
|
|
if (!_SheXiangDianDict.ContainsKey(gos[i].name))
|
|
{
|
|
_SheXiangDianDict.Add(gos[i].name, gos[i].transform);
|
|
}
|
|
}
|
|
//步骤跳转按钮
|
|
NextPassBtn.onClick.AddListener(() =>
|
|
{
|
|
if (_haveItemList.Count >= leastItemNum)
|
|
{
|
|
TuoZhuaiUI_Trans.transform.Find("tuozhuaiTool").gameObject.SetActive(false);
|
|
NextPassBtn.gameObject.SetActive(false);
|
|
//更改Tip
|
|
stepTipTxt.text = "阶段二:选择录制传感数据的设备(可多选)";
|
|
Pass2UI_Trans.gameObject.SetActive(true);
|
|
fangzhitongji.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
ShowTip("请至少完成" + leastItemNum + "处主要放置区域以上,以及2种以上不同的传感器部署");
|
|
}
|
|
});
|
|
|
|
kuangPreant.gameObject.SetActive(false);
|
|
|
|
//for (int i = 0; i < cameraSets.Length; i++)
|
|
//{
|
|
// cameraSets[i].Init();
|
|
//}
|
|
}
|
|
|
|
|
|
public bool CheckAearHaveItem(string aearID)
|
|
{
|
|
if (_haveItemList.Contains(aearID))
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public void CheckItemCount(GameObject obj)
|
|
{
|
|
if (mainAearNum >= leastItemNum)
|
|
{
|
|
|
|
driveManager.gameObject.SetActive(true);
|
|
stepTipTxt.transform.parent.gameObject.SetActive(false);
|
|
TuoZhuaiUI_Trans.transform.Find("tuozhuaiTool").gameObject.SetActive(false);
|
|
Pass2UI_Trans.gameObject.SetActive(true);
|
|
obj.SetActive(false);
|
|
|
|
}
|
|
else
|
|
{
|
|
ShowTip("检测不通过,请完成" + leastItemNum + "处主要区域的布置,以及2种以上不同的传感器部署");
|
|
}
|
|
}
|
|
private void Update()
|
|
{
|
|
|
|
if (Input.GetKey(KeyCode.LeftShift) && Input.GetKey(KeyCode.K))
|
|
{
|
|
AnalyWnd.SetActive(false);
|
|
//TODO显示方框跟踪和速度
|
|
ShowAnalysisResults(pass1Camera.GetComponent<Camera>());
|
|
//显示事故干预按钮
|
|
EventBtn.SetActive(true);
|
|
|
|
stepTipTxt.text = "阶段三:添加事故干预措施,防止车辆超速过弯侧翻";
|
|
}
|
|
|
|
if (tougeMsg.Contains("Y") || tougeMsg.Contains("Succeed"))
|
|
{
|
|
//ShowAnalysisResults(pass1Camera.GetComponent<Camera>());
|
|
AnalyWnd.SetActive(false);
|
|
kuangPreant.gameObject.SetActive(true);
|
|
if (isZhuanWan)
|
|
{
|
|
ShowAnalysisResults(pass1Camera.GetComponent<Camera>());
|
|
AnalyWnd.SetActive(false);
|
|
//显示事故干预按钮
|
|
EventBtn.SetActive(true);
|
|
}
|
|
|
|
EducoderPassOver = true;
|
|
tougeMsg = "";
|
|
EducoderPassAction.Invoke();
|
|
}
|
|
|
|
|
|
PassOverCheck();
|
|
|
|
mainAearNum = int.Parse( mainAearTxt.text.ToString());
|
|
}
|
|
/// <summary>
|
|
/// 通关检测
|
|
/// </summary>
|
|
private void PassOverCheck()
|
|
{
|
|
if (EducoderPassOver&&isPassOver)
|
|
{
|
|
SendResult();
|
|
}
|
|
}
|
|
|
|
public void SendResult()
|
|
{
|
|
//TODO虚仿通关提示
|
|
|
|
//头哥通关提示
|
|
EduCoderTool.WebConnecter.Singleton.SendResultToWeb(true);
|
|
}
|
|
|
|
public void SetPassOver(bool isOver)
|
|
{
|
|
isPassOver = isOver;
|
|
}
|
|
|
|
public void OpenCarCheck()
|
|
{
|
|
//AnalyWnd.SetActive(false);
|
|
//TODO显示方框跟踪和速度
|
|
ShowAnalysisResults(pass1Camera.GetComponent<Camera>());
|
|
//显示事故干预按钮
|
|
// EventBtn.SetActive(true);
|
|
|
|
stepTipTxt.text = "阶段三:检测车辆以及桥梁载荷";
|
|
}
|
|
|
|
public void SetCarTipScale(float value)
|
|
{
|
|
tipScale = value;
|
|
|
|
}
|
|
|
|
public void SetKuangAutoScale(bool b)
|
|
{
|
|
OpenKuangAutoScale = b;
|
|
|
|
}
|
|
private void ShowAnalysisResults(Camera camera)
|
|
{
|
|
StartCoroutine(AnalysisResults(camera));
|
|
}
|
|
|
|
IEnumerator AnalysisResults(Camera camera)
|
|
{
|
|
while (true)
|
|
{
|
|
yield return new WaitForEndOfFrame();
|
|
for (int i = 0; i < driveManager.carList.Count; i++)
|
|
{
|
|
if (!driveManager.carList[i].isChecked)
|
|
{
|
|
GameObject go = GameObject.Instantiate(Resources.Load<GameObject>("Prefab/检测框"), kuangPreant);
|
|
ZoneUI zoneUI = go.AddComponent<ZoneUI>();
|
|
//颜色随机
|
|
float r = Random.RandomRange(0f, 1f);
|
|
float g = Random.RandomRange(0f, 1f);
|
|
float b = Random.RandomRange(0f, 1f);
|
|
Color color = new Vector4(r, g, b, 1);
|
|
go.GetComponent<Image>().color = color;
|
|
for (int j = 0; j < go.transform.childCount; j++)
|
|
{
|
|
go.transform.GetChild(j).GetComponent<Text>().color = color;
|
|
}
|
|
zoneUI.target = driveManager.carList[i].transform;
|
|
zoneUI._camera = camera;
|
|
zoneUI.isScreen = true;
|
|
driveManager.carList[i].isChecked = true;
|
|
driveManager.carList[i].kuang = go;
|
|
//初始化检车框
|
|
CheckKuang kuang = go.GetComponent<CheckKuang>();
|
|
kuang._car = driveManager.carList[i];
|
|
kuang._camera = camera;
|
|
kuang.Init(driveManager.carList[i].CarType, driveManager.carList[i].overSpeed);
|
|
}
|
|
else
|
|
{
|
|
//判断框是否可见
|
|
Vector3 viewPos = camera.WorldToViewportPoint(driveManager.carList[i].transform.position);
|
|
if (viewPos.x > 0 && viewPos.x < 1)
|
|
{
|
|
if (viewPos.y > 0 && viewPos.y < 1)
|
|
{
|
|
if (viewPos.z >= camera.nearClipPlane && viewPos.z <= Const.Pass1CameraFarClip)
|
|
{
|
|
driveManager.carList[i].kuang.SetActive(true);
|
|
|
|
}
|
|
else
|
|
{
|
|
driveManager.carList[i].kuang.SetActive(false);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
driveManager.carList[i].kuang.SetActive(false);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 观察点注册
|
|
/// </summary>
|
|
/// <param name="name"></param>
|
|
/// <param name="point"></param>
|
|
public void RegisetOBPoint(string name, Transform point)
|
|
{
|
|
if (!_OBPointsDict.ContainsKey(name))
|
|
{
|
|
_OBPointsDict.Add(name, point);
|
|
}
|
|
}
|
|
public Transform GetOBPoint(string name)
|
|
{
|
|
Transform point = null;
|
|
if (_OBPointsDict.TryGetValue(name, out point))
|
|
{
|
|
return point;
|
|
}
|
|
return null;
|
|
}
|
|
public void RegisetItem(string name, DragCheck checker)
|
|
{
|
|
if (!_haveItemList.Contains(name))
|
|
{
|
|
_haveItemList.Add(name);
|
|
//添加观察按钮到目标区域
|
|
GameObject go = GameObject.Instantiate(Resources.Load<GameObject>("Prefab/观察按钮"), TuoZhuaiUI_Trans.transform);
|
|
ZoneUI zoneUI = go.AddComponent<ZoneUI>();
|
|
zoneUI.target = checker.GetComponent<ZoneUI>().target;
|
|
zoneUI._camera = checker.GetComponent<ZoneUI>()._camera;
|
|
zoneUI.offset.x = -50;
|
|
//给按钮添加观察功能
|
|
go.GetComponent<Button>().onClick.AddListener(() =>
|
|
{
|
|
TuoZhuaiUI_Trans.gameObject.SetActive(false);
|
|
GuanChaUI_Trans.gameObject.SetActive(true);
|
|
Transform point = GetOBPoint(checker.gameObject.name);
|
|
pass1Camera.MoveToPoint(point);
|
|
//启动控件
|
|
//pass1RenderCamera.gameObject.SetActive(true); //此处激活摄像机代码已放入ModelClickEvent
|
|
Pass1RenderView.SetActive(true);
|
|
Pass2InfoWnd.SetActive(true);
|
|
//启动速度检测
|
|
ZhuanWanData.OpenChecker(name);
|
|
//开启框的自适应
|
|
SetKuangAutoScale(true);
|
|
SetCarTipScale(0.2f);
|
|
|
|
if (guanchaEvent != null)
|
|
{
|
|
guanchaEvent.Invoke();
|
|
}
|
|
|
|
//CameraSet重置
|
|
ResetCameraSet();
|
|
});
|
|
}
|
|
|
|
}
|
|
|
|
public void ActionStart()
|
|
{
|
|
switch (actionSelected)
|
|
{
|
|
case 1:
|
|
|
|
SafetyTip.SetActive(true);
|
|
int num = Random.Range(1, 10);
|
|
if (num >= probabilityNum)
|
|
{
|
|
|
|
StartCoroutine(CeFanAction());
|
|
}
|
|
|
|
break;
|
|
case 2:
|
|
|
|
//EventChecker[] eventCheckers = GameObject.FindObjectsOfType<EventChecker>();
|
|
//for (int i = 0; i < eventCheckers.Length; i++)
|
|
//{
|
|
// eventCheckers[i].isOpenSoundTip = true;
|
|
//}
|
|
TipTypeImg.sprite = Resources.Load<Sprite>("image/sound");
|
|
TipTypeImg.color = Color.green;
|
|
TipTypeTxt.text = "一超速语音提示标识";
|
|
driveManager.carTipType = CarTipType.语音提示;
|
|
int num2 = Random.Range(1, 10);
|
|
if (num2 >= probabilityNum)
|
|
{
|
|
StartCoroutine(CeFanAction());
|
|
}
|
|
break;
|
|
}
|
|
|
|
eventWnd.SetActive(false);
|
|
Time.timeScale = 1;
|
|
|
|
}
|
|
|
|
IEnumerator CeFanAction()
|
|
{
|
|
|
|
float time = Random.Range(0, 4.5f);
|
|
yield return new WaitForSeconds(time);
|
|
ZhuanWanManager.Instance.StartCeFan();
|
|
//if (DriveManager.Instance.eventCar == null)
|
|
//{
|
|
|
|
// StartCoroutine(CeFanAction());
|
|
//}
|
|
//else
|
|
//{
|
|
// TempIndex++;
|
|
// if (TempIndex > 1)
|
|
// {
|
|
// DriveManager.Instance.eventCar.CeFan();
|
|
// // SendResult();
|
|
// }
|
|
// else
|
|
// {
|
|
// StartCoroutine(CeFanAction());
|
|
// }
|
|
|
|
|
|
//}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 进入正常车流
|
|
/// </summary>
|
|
public void EnterNormalState()
|
|
{
|
|
driveManager.gameObject.SetActive(true);
|
|
RoadStateTxt.gameObject.SetActive(true);
|
|
}
|
|
|
|
public void ShowTip(string str)
|
|
{
|
|
tip.SetActive(true);
|
|
tip.transform.GetChild(0).GetComponent<Text>().text = str;
|
|
StartTimeAction(1.5f, () => { tip.SetActive(false); });
|
|
}
|
|
|
|
public void SetInfoPanelSpeed(float speed)
|
|
{
|
|
ZhuanWanData.SetSpeedTxt(speed);
|
|
}
|
|
|
|
|
|
public void ResetCameraSet()
|
|
{
|
|
|
|
for (int i = 0; i < cameraSets.Length; i++)
|
|
{
|
|
cameraSets[i].isEnabled = false;
|
|
}
|
|
|
|
}
|
|
public void SetAciteveSheXiangTool(CameraSet cameraSet)
|
|
{
|
|
if (cameraSet != null)
|
|
{
|
|
for (int i = 0; i < cameraSets.Length; i++)
|
|
{
|
|
cameraSets[i].isEnabled = false;
|
|
}
|
|
|
|
cameraSet.isEnabled = true;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|