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.
131 lines
3.7 KiB
131 lines
3.7 KiB
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class AISys : MonoBehaviour
|
|
{
|
|
|
|
public static AISys Instance = null;
|
|
|
|
//工人AI数量
|
|
public int _workerNum = 2;
|
|
//工人工作点
|
|
public Transform[] _workPoints;
|
|
//工人移动点
|
|
public Transform[] _movePoints;
|
|
//AI父物体
|
|
public Transform _AIPreant;
|
|
//AI事故点
|
|
public Transform Pass1AccidentPoint;
|
|
//Ai小地图图标父物体
|
|
public Transform _AIIconPreant;
|
|
|
|
public AI_Worker[] _workerGroup;
|
|
|
|
public bool[] pointIsUse;
|
|
|
|
[Header("员工监测相机")]
|
|
public Transform _workCheckCamera;
|
|
|
|
public void Init()
|
|
{
|
|
|
|
Instance = this;
|
|
//工作点与移动点赋值
|
|
_workPoints = new Transform[GameObject.FindGameObjectWithTag("WorkPointGroup").transform.childCount];
|
|
_movePoints= new Transform[GameObject.FindGameObjectWithTag("MovePointGroup").transform.childCount];
|
|
for (int i = 0; i < _workPoints.Length; i++)
|
|
{
|
|
_workPoints[i] = GameObject.FindGameObjectWithTag("WorkPointGroup").transform.GetChild(i).transform;
|
|
}
|
|
for (int i = 0; i < _movePoints.Length; i++)
|
|
{
|
|
_movePoints[i]= GameObject.FindGameObjectWithTag("MovePointGroup").transform.GetChild(i).transform;
|
|
}
|
|
//创建工人实例
|
|
_workerNum = _workPoints.Length;
|
|
_workerGroup = CreatAIAtPoint("Prefab/Gongren_01", _workPoints, _workerNum, new Vector3(2, 2, 2), "Prefab/man");
|
|
|
|
//检查每个点位是否有人
|
|
pointIsUse = new bool[_movePoints.Length];
|
|
}
|
|
|
|
public AI_Worker[] CreatAIAtPoint(string path,Transform[] points,int num,Vector3 scale,string iconPath= "")
|
|
{
|
|
|
|
AI_Worker[] workers=new AI_Worker[num];
|
|
for (int i = 0; i < num; i++)
|
|
{
|
|
|
|
GameObject go= Const.LoadPrefab(path, points[i].position, Vector3.zero, scale);
|
|
|
|
go.transform.SetParent(_AIPreant);
|
|
AI_Worker aI_Worker = go.AddComponent<AI_Worker>();
|
|
if (i < 10)
|
|
{
|
|
aI_Worker.ID = "0" + (i + 1);
|
|
}
|
|
else
|
|
{
|
|
aI_Worker.ID = (i + 1).ToString();
|
|
}
|
|
workers[i] = aI_Worker;
|
|
workers[i].PointIdenx = i;
|
|
|
|
if (iconPath != "")
|
|
{
|
|
GameObject icon = Const.LoadPrefab(iconPath);
|
|
icon.transform.SetParent(_AIIconPreant);
|
|
icon.transform.GetChild(0).GetComponent<Text>().text = aI_Worker.ID;
|
|
}
|
|
}
|
|
return workers;
|
|
|
|
}
|
|
|
|
public void Accident(int passIndex)
|
|
{
|
|
switch (passIndex)
|
|
{
|
|
case 1:
|
|
int index = 0;
|
|
index = Random.Range(0, _workerGroup.Length);
|
|
_workerGroup[index].Accident();
|
|
Debug.Log(index);
|
|
GameRoot.Instance.menuWnd.CheckPeople(index);
|
|
//_workCheckCamera.position = _workerGroup[index].transform.position + new Vector3(0, 7, 5);
|
|
//_workCheckCamera.LookAt(_workerGroup[index].transform);
|
|
|
|
break;
|
|
case 2:
|
|
|
|
for (int i = 0; i < _workerGroup.Length; i++)
|
|
{
|
|
_workerGroup[i].isCheck = true;
|
|
}
|
|
break;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
public void ShowFangKuang(int index,bool b)
|
|
{
|
|
|
|
_workerGroup[index].isCheck = b;
|
|
_workerGroup[index].transform.Find("FangKuang").gameObject.SetActive(true);
|
|
|
|
}
|
|
|
|
public void ResetWorker()
|
|
{
|
|
for (int i = 0; i < _workerGroup.Length; i++)
|
|
{
|
|
_workerGroup[i].isCheck = false;
|
|
_workerGroup[i].isWorkOver = false;
|
|
}
|
|
}
|
|
|
|
}
|