//using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using System.Linq; using DG.Tweening; using HighlightingSystem; using System.Reflection; using HXSJFrameWork; public class ModelManager : MonoBehaviour { [HideInInspector] public static ModelManager instance; [HideInInspector] public List devices; [HideInInspector] public List peoples; [HideInInspector] public List spacePoints; [HideInInspector] public List expPoints; //监控 [HideInInspector] public List camList; //客户 [HideInInspector] public List clients; //柜台 [HideInInspector] public List counters; //空间Icon private List spaceIconList; //空间Icon特效光圈 private List spaceEffectList; //分区 private GameObject _spaceArea; //异常Icon private List expIconList; //热力图 private Heatmap heatmap; //人员点位热力图 private HeatPointManager m_heatpoint; //切换热力图特效 private ParticleSystem changePage;//切换页面时的特效 //屋顶 private Transform wuDing; //3DCanvas public Transform iconPanel; private void Awake() { instance = this; } // Start is called before the first frame update void Start() { expIconList = new List(); wuDing = transform.Find("WuDing"); iconPanel = transform.Find("3DIconPanel"); _spaceArea = transform.Find("fenqu").gameObject; changePage = transform.Find("ChangeHeatmapEffect").GetComponent(); heatmap = GetComponentInChildren(true); m_heatpoint = GetComponentInChildren(true); InitData(); InitDevice(); InitPeople(); InitClient(); LoadSpacePointIcon(); //RandomHeatValue(); } private float time; // Update is called once per frame void Update() { //测试demo,动态随机热力图效果 time += Time.deltaTime; if (time > 1) { time = 0; //RandomHeatValue(); //RandomUpdateHeatValue(); } } #region 初始时获取数据 /// /// 根据类型初始化所有数据 /// void InitData() { devices = new List(); spacePoints = new List(); expPoints = new List(); peoples=new List(); camList = new List(); clients = new List(); counters = new List(); foreach (ModelItem item in transform.GetComponentsInChildren(true)) { if (item.modelType == ModelType.Device) { devices.Add(item); if (item.deviceType == DeviceType.SheXiangTou) camList.Add(item); } else if (item.modelType == ModelType.SpacePoint) spacePoints.Add(item); else if (item.modelType == ModelType.ExpEvent) expPoints.Add(item); else if (item.modelType == ModelType.Worker) { //电子工牌 //devices.Add(item); peoples.Add(item); } else if(item.modelType == ModelType.Client) clients.Add(item); else if (item.modelType == ModelType.counter) counters.Add(item); } } /// /// 初始化设备 /// private void InitDevice() { foreach (var item in devices) { //工牌暂时同人员一样 if (item.deviceType != DeviceType.GongPai) { if (item.GetComponent() == null) { item.gameObject.AddComponent(); } item.GetComponent().deviceType = item.deviceType; //todo:传入设备索引 //item.GetComponent().index = 0; } } } /// /// 初始化人员 /// private void InitPeople() { foreach (var item in peoples) { if (item.GetComponent() == null) { item.gameObject.AddComponent(); } } } /// /// 初始化客户 /// private void InitClient() { foreach (var item in clients) { if (item.GetComponent() == null) { item.gameObject.AddComponent(); } } } /// /// 初始化柜台 /// private void InitCounter() { foreach (var item in clients) { if (item.GetComponent() == null) { item.gameObject.AddComponent(); } } } #endregion /// /// 加载异常Icon /// public void LoadExpIcon() { GameObject obj = Resources.Load(ResourcePath._exp3DIcon); for (int i = 0; i < expPoints.Count; i++) { GameObject icon = GameObject.Instantiate(obj); //icon.transform.parent = iconPanel; icon.GetComponent().SetParent(iconPanel); icon.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f); icon.transform.position = expPoints[i].transform.position; if (icon.GetComponent() == null) icon.AddComponent(); expIconList.Add(icon.GetComponent()); icon.name = expPoints[i].name; icon.GetComponent().InitExpIcon(expPoints[i].GetComponent().expType,i); } //测试,第一个摄像头警告 camList[2].GetComponent()._isCamWarm = true; } /// /// 根据异常名称找到对应的异常点位 /// /// 异常名称 /// public GameObject FindExpPointByName(string name) { foreach (var item in expPoints) { if (item.name == name) return item.gameObject; } return null; } /// /// 关闭异常 /// public void CloseExpIcon() { foreach (var item in expIconList) { Destroy(item.gameObject); } expIconList.Clear(); foreach (var item in camList) { item.GetComponent()._isCamWarm=false; } } /// /// 加载空间点Icon /// public void LoadSpacePointIcon() { spaceIconList = new List(); spaceEffectList = new List(); GameObject obj= Resources.Load(ResourcePath._space3DIcon); GameObject objeffect = Resources.Load(ResourcePath._space3DEffect); foreach (var item in spacePoints) { GameObject icon = GameObject.Instantiate(obj); GameObject effect = GameObject.Instantiate(objeffect); //icon.transform.parent = iconPanel; effect.transform.SetParent(item.transform); effect.transform.localPosition = Vector3.zero; icon.GetComponent().SetParent(iconPanel); icon.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f); icon.transform.position = new Vector3(item.transform.position.x, item.transform.position.y+0.5f, item.transform.position.z); icon.transform.Find("Image/Text").GetComponent().text= item.name; if (icon.GetComponent() == null) { icon.AddComponent(); } if (!icon.GetComponent()) icon.AddComponent(); icon.GetComponent().Cam=Camera.main.transform; spaceIconList.Add(icon); spaceEffectList.Add(effect); //默认分区隐藏 //icon.gameObject.SetActive(false); //effect.gameObject.SetActive(false); } } /// /// 根据设备类型,找到一个设备 /// /// public GameObject FindDeviceByType(DeviceType type) { foreach (var item in devices) { if (item.deviceType == type) return item.gameObject; } return null; } /// /// 根据设备类型和索引,找到一个设备 /// /// public GameObject FindDeviceByTypeAndID(DeviceType type,int index) { int curindex = -1; foreach (var item in devices) { if (item.deviceType == type) { curindex++; if(curindex==index) return item.gameObject; } } return null; } /// /// 单体化模型360展示 /// /// public void SingleModel(GameObject obj) { //将上一个单体化物体隐藏 if (Main.intance.CurentSingleObj != null) { Main.intance.singleCam.GetComponent().ChangeObjLayer(Main.intance.CurentSingleObj, "Default"); } //显示单体化展示页面 Main.intance.CurentSinglePage.SetActive(true); //将当前物体设置为单体化360观察的物体 Main.intance.CurentSingleObj = obj; Main.intance.singleCam.GetComponent().SetTarget(obj.transform); Debug.Log("设备单体化"+obj); //设置模型为正视角 Main.intance.singleCam.GetComponent().ChangeObjLayer(Main.intance.CurentSingleObj, "single360"); Main.intance.ShowSingleModel(true); } /// /// 是否显示空间Icon /// /// public void ShowSpaceIcon(bool isShow) { Debug.Log("空间Icon" + isShow); foreach (var item in spaceIconList) { item.SetActive(isShow); } ShowSpaceEffect(isShow); } /// /// 是否显示空间icon下的蓝色光圈特效 /// /// public void ShowSpaceEffect(bool show) { foreach (var item in spaceEffectList) { item.SetActive(show); } } /// /// 显示分区块 /// /// public void ShowSpaceArea(bool isshow) { _spaceArea.SetActive(isshow); } /// /// 播放切换页面的特效 /// public void ShowChangePageEffect() { changePage.Play(); } /// /// 根据类型高亮设备 /// /// 索引从1开始 public void HighLightDeviceOn(int index) { foreach (ModelItem device in devices) { if (device.GetComponent().deviceType.GetHashCode() == index) { AddHighLightComponent(device.gameObject); device.GetComponent().TweenStart(); } } } /// /// 根据设备类型关闭高亮 /// /// 索引从1开始 public void HighLightDeviceOff(int index) { foreach (ModelItem device in devices) { if (device.GetComponent().deviceType.GetHashCode() == index) { if (device.GetComponent()) device.GetComponent().TweenStop(); } } } /// ///关闭所有设备高亮 /// public void HighLightOff() { foreach (ModelItem device in devices) { if (device.GetComponent()) device.GetComponent().TweenStop(); } } /// /// 添加闪烁边缘光 /// private void AddHighLightComponent(GameObject obj) { if (!obj.GetComponent()) { Highlighter h = obj.AddComponent(); h.overlay = true; } } /// /// 摄像头进入房间内部,隐藏空间3DIcon,显示屋顶 /// public void CameraNear(bool isNear) { //ShowSpaceIcon(!isNear); wuDing.gameObject.SetActive(isNear); //当视角拉进时,缩小异常Icon if (expIconList.Count>0) { float expIconScale = isNear ? 0.1f : 0.5f; Vector3 expEffectScale = isNear ? new Vector3(0.3f,0.3f,0.3f) : Vector3.one; foreach (Exception3DIcon icomn in expIconList) { icomn.transform.localScale = new Vector3(expIconScale, expIconScale, expIconScale); icomn.transform.Find("effect").transform.localScale = expEffectScale; } } } /// /// 综合管理允许单体化显示 /// /// public void CanSingle(bool istrue) { foreach(ModelItem device in devices) { if (device.GetComponent()) device.GetComponent().isSingle = istrue; } foreach (ModelItem item in peoples) { item.GetComponent().isSingle = istrue; } } /// /// 高亮闪烁3秒后关闭 /// /// 高亮物体 public void LightFlashCount(GameObject obj) { float a = 0; LightFlash(obj, true); DOTween.To(() => a, x => a = x, 1, 3).OnComplete(() => { LightFlash(obj, false); }); } /// /// 高亮闪烁 /// /// 高亮物体 /// 是否高亮 public void LightFlash(GameObject obj,bool on) { if (!obj.GetComponent()) obj.AddComponent(); if (on) obj.GetComponent().TweenStart(); else obj.GetComponent().TweenStop(); } #region 热力图(弃用) //热力图点位 public List heatPoints; //世界坐标 public List m_Vector3s; //X:半径(0,2);Y:强度(0,1) public List m_Vector2s; //切换热力图时的特效 private ParticleSystem _changeHeatmapEffect; /// /// 随机热力图热点值(测试) /// private void RandomHeatValue() { heatPoints.Clear(); for (int i = 0; i < 20; i++) { heatPoints.Add(new HeatPoint() { point = new Vector3(Random.Range(-13, 13f),0, Random.Range(-9f, 7f)), radius = Random.Range(1f, 2f), intensity = Random.Range(1f, 2) }); //heatmap.AddHeatPoint(heatPoints[i].point, heatPoints[i].radius, heatPoints[i].intensity); } UpdateHeatValue(); } /// /// 显示和关闭热力图 /// /// public void ShowHeatmap(bool isShow) { if (isShow) { //播放切换热力图特效 //if (!_changeHeatmapEffect) //{ // _changeHeatmapEffect = GameObject.Instantiate(Resources.Load(ResourcePath._changeHeatmapEffect).GetComponent()); // _changeHeatmapEffect.transform.SetParent(transform); // _changeHeatmapEffect.transform.localPosition = new Vector3(0,0.2f,0); //} //_changeHeatmapEffect.Play(); //_changeHeatmapEffect.gameObject.SetActive(false); //_changeHeatmapEffect.gameObject.SetActive(true); //Invoke("InvokeShowHeatmap", 4); InvokeShowHeatmap(); //ShowSpaceIcon(true); } else { heatmap.gameObject.SetActive(false); //ShowSpaceIcon(false); } } /// /// 延时显示热力图,等特效播放两秒后显示 /// private void InvokeShowHeatmap() { UpdateHeatValue(); heatmap.gameObject.SetActive(true); } /// /// 更新热力值 /// public void UpdateHeatValue() { heatmap.SetHeatPoints(heatPoints.Select((v) => new HeatPoint() { point = v.point, radius = v.radius, intensity = v.intensity })); } /// /// 随机动态更新热力值 /// public void RandomUpdateHeatValue() { //随机其中一个值 int randomIndex=Random.Range(0, heatPoints.Count()); heatPoints[randomIndex] = new HeatPoint() { point = new Vector3(Random.Range(-13, 13f), 0, Random.Range(-8f, 6f)), radius = Random.Range(0f, 2f), intensity = Random.Range(0f, 2) }; heatmap.SetHeatPoints(heatPoints.Select((v) => new HeatPoint() { point = v.point, radius = v.radius, intensity = v.intensity })); } #endregion #region 热力图 /// /// 显示热力图 /// public void ShowHeatPoint() { m_heatpoint.gameObject.SetActive(true); Main.intance.heatPointDes.SetActive(true); } /// /// 隐藏热力图 /// public void HideHeatPoint() { m_heatpoint.gameObject.SetActive(false); Main.intance.heatPointDes.SetActive(false); } #endregion } public enum ModelType { Device,//设备 Worker,//人员 SpacePoint,//空间点 ExpEvent,//异常事件 Model,//模型 Client,//客户 counter//柜台 } public enum DeviceType { NONE,//不为设备 YuShouLiZhongDuan,//预受理终端 JiaoFeiJi,//缴费机 YeWuJi,//业务机 FaPiaoDaYinJi,//发票打印机 GongPai,//工牌 WangShangGuoWangYunZhongDuan,//网上国网云终端 SheXiangTou//摄像头 } [System.Serializable] public class HeatPoint { /// /// 世界坐标系位置 /// public Vector3 point; /// /// 半径 /// public float radius; /// /// 强度 /// public float intensity; }