696 lines
19 KiB
C#
696 lines
19 KiB
C#
//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<ModelItem> devices;
|
||
[HideInInspector]
|
||
public List<ModelItem> peoples;
|
||
[HideInInspector]
|
||
public List<ModelItem> spacePoints;
|
||
[HideInInspector]
|
||
public List<ModelItem> expPoints;
|
||
//监控
|
||
[HideInInspector]
|
||
public List<ModelItem> camList;
|
||
//客户
|
||
[HideInInspector]
|
||
public List<ModelItem> clients;
|
||
//柜台
|
||
[HideInInspector]
|
||
public List<ModelItem> counters;
|
||
//空间Icon
|
||
private List<GameObject> spaceIconList;
|
||
//空间Icon特效光圈
|
||
private List<GameObject> spaceEffectList;
|
||
//分区
|
||
public GameObject _spaceArea;
|
||
|
||
//异常Icon
|
||
private List<Exception3DIcon> 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<Exception3DIcon>();
|
||
wuDing = transform.Find("吊顶");
|
||
iconPanel = transform.Find("3DIconPanel");
|
||
//_spaceArea = transform.Find("fenqu").gameObject;
|
||
changePage = transform.Find("ChangeHeatmapEffect").GetComponent<ParticleSystem>();
|
||
heatmap = GetComponentInChildren<Heatmap>(true);
|
||
m_heatpoint = GetComponentInChildren<HeatPointManager>(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 初始时获取数据
|
||
|
||
/// <summary>
|
||
/// 根据类型初始化所有数据
|
||
/// </summary>
|
||
void InitData()
|
||
{
|
||
devices = new List<ModelItem>();
|
||
spacePoints = new List<ModelItem>();
|
||
expPoints = new List<ModelItem>();
|
||
peoples=new List<ModelItem>();
|
||
camList = new List<ModelItem>();
|
||
clients = new List<ModelItem>();
|
||
counters = new List<ModelItem>();
|
||
foreach (ModelItem item in transform.GetComponentsInChildren<ModelItem>(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);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 初始化设备
|
||
/// </summary>
|
||
private void InitDevice()
|
||
{
|
||
foreach (var item in devices)
|
||
{
|
||
//工牌暂时同人员一样
|
||
if (item.deviceType != DeviceType.GongPai)
|
||
{
|
||
if (item.GetComponent<DeviceClick>() == null)
|
||
{
|
||
item.gameObject.AddComponent<DeviceClick>();
|
||
}
|
||
item.GetComponent<DeviceClick>().deviceType = item.deviceType;
|
||
//todo:传入设备索引
|
||
//item.GetComponent<DeviceClick>().index = 0;
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 初始化人员
|
||
/// </summary>
|
||
private void InitPeople() {
|
||
foreach (var item in peoples)
|
||
{
|
||
if (item.GetComponent<PeopleClick>() == null)
|
||
{
|
||
item.gameObject.AddComponent<PeopleClick>();
|
||
}
|
||
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 初始化客户
|
||
/// </summary>
|
||
private void InitClient()
|
||
{
|
||
foreach (var item in clients)
|
||
{
|
||
if (item.GetComponent<ClientClick>() == null)
|
||
{
|
||
item.gameObject.AddComponent<ClientClick>();
|
||
}
|
||
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 初始化柜台
|
||
/// </summary>
|
||
private void InitCounter()
|
||
{
|
||
foreach (var item in clients)
|
||
{
|
||
if (item.GetComponent<CounterClick>() == null)
|
||
{
|
||
item.gameObject.AddComponent<CounterClick>();
|
||
}
|
||
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// 加载异常Icon
|
||
/// </summary>
|
||
public void LoadExpIcon() {
|
||
|
||
GameObject obj = Resources.Load<GameObject>(ResourcePath._exp3DIcon);
|
||
for (int i = 0; i < expPoints.Count; i++)
|
||
{
|
||
GameObject icon = GameObject.Instantiate(obj);
|
||
//icon.transform.parent = iconPanel;
|
||
icon.GetComponent<RectTransform>().SetParent(iconPanel);
|
||
icon.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);
|
||
icon.transform.position = expPoints[i].transform.position;
|
||
if (icon.GetComponent<Exception3DIcon>() == null)
|
||
icon.AddComponent<Exception3DIcon>();
|
||
expIconList.Add(icon.GetComponent<Exception3DIcon>());
|
||
icon.name = expPoints[i].name;
|
||
icon.GetComponent<Exception3DIcon>().InitExpIcon(expPoints[i].GetComponent<ModelItem>().expType,i);
|
||
}
|
||
//测试,第一个摄像头警告
|
||
camList[2].GetComponent<DeviceClick>()._isCamWarm = true;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据异常名称找到对应的异常点位
|
||
/// </summary>
|
||
/// <param name="name">异常名称</param>
|
||
/// <returns></returns>
|
||
public GameObject FindExpPointByName(string name)
|
||
{
|
||
foreach (var item in expPoints) {
|
||
if (item.name == name)
|
||
return item.gameObject;
|
||
}
|
||
return null;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 关闭异常
|
||
/// </summary>
|
||
|
||
public void CloseExpIcon()
|
||
{
|
||
foreach (var item in expIconList)
|
||
{
|
||
Destroy(item.gameObject);
|
||
}
|
||
expIconList.Clear();
|
||
foreach (var item in camList)
|
||
{
|
||
item.GetComponent<DeviceClick>()._isCamWarm=false;
|
||
}
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 加载空间点Icon
|
||
/// </summary>
|
||
public void LoadSpacePointIcon() {
|
||
spaceIconList = new List<GameObject>();
|
||
spaceEffectList = new List<GameObject>();
|
||
GameObject obj= Resources.Load<GameObject>(ResourcePath._space3DIcon);
|
||
GameObject objeffect = Resources.Load<GameObject>(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<RectTransform>().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>().text= item.name;
|
||
if (icon.GetComponent<LookAtCam>() == null)
|
||
{
|
||
icon.AddComponent<LookAtCam>();
|
||
}
|
||
if (!icon.GetComponent<Space3DIcon>())
|
||
icon.AddComponent<Space3DIcon>();
|
||
icon.GetComponent<LookAtCam>().Cam=Camera.main.transform;
|
||
spaceIconList.Add(icon);
|
||
spaceEffectList.Add(effect);
|
||
//默认分区隐藏
|
||
//icon.gameObject.SetActive(false);
|
||
//effect.gameObject.SetActive(false);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据设备类型,找到一个设备
|
||
/// </summary>
|
||
/// <param name="type"></param>
|
||
public GameObject FindDeviceByType(DeviceType type)
|
||
{
|
||
foreach (var item in devices)
|
||
{
|
||
if (item.deviceType == type)
|
||
return item.gameObject;
|
||
}
|
||
return null;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据设备类型和索引,找到一个设备
|
||
/// </summary>
|
||
/// <param name="type"></param>
|
||
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;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 单体化模型360展示
|
||
/// </summary>
|
||
/// <param name="obj"></param>
|
||
public void SingleModel(GameObject obj)
|
||
{
|
||
//将上一个单体化物体隐藏
|
||
if (Main.intance.CurentSingleObj != null)
|
||
{
|
||
Main.intance.singleCam.GetComponent<Camera360>().ChangeObjLayer(Main.intance.CurentSingleObj, "Default");
|
||
}
|
||
//显示单体化展示页面
|
||
Main.intance.CurentSinglePage.SetActive(true);
|
||
//将当前物体设置为单体化360观察的物体
|
||
Main.intance.CurentSingleObj = obj;
|
||
Main.intance.singleCam.GetComponent<Camera360>().SetTarget(obj.transform);
|
||
Debug.Log("设备单体化"+obj);
|
||
//设置模型为正视角
|
||
Main.intance.singleCam.GetComponent<Camera360>().ChangeObjLayer(Main.intance.CurentSingleObj, "single360");
|
||
Main.intance.ShowSingleModel(true);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 是否显示空间Icon
|
||
/// </summary>
|
||
/// <param name="isShow"></param>
|
||
public void ShowSpaceIcon(bool isShow)
|
||
{
|
||
Debug.Log("空间Icon" + isShow);
|
||
foreach (var item in spaceIconList)
|
||
{
|
||
item.SetActive(isShow);
|
||
}
|
||
ShowSpaceEffect(isShow);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 是否显示空间icon下的蓝色光圈特效
|
||
/// </summary>
|
||
/// <param name="show"></param>
|
||
public void ShowSpaceEffect(bool show)
|
||
{
|
||
foreach (var item in spaceEffectList)
|
||
{
|
||
item.SetActive(show);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 显示分区块
|
||
/// </summary>
|
||
/// <param name="isshow"></param>
|
||
public void ShowSpaceArea(bool isshow)
|
||
{
|
||
_spaceArea.SetActive(isshow);
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 播放切换页面的特效
|
||
/// </summary>
|
||
public void ShowChangePageEffect()
|
||
{
|
||
changePage.Play();
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 根据类型高亮设备
|
||
/// </summary>
|
||
/// <param name="index">索引从1开始</param>
|
||
public void HighLightDeviceOn(int index)
|
||
{
|
||
foreach (ModelItem device in devices) {
|
||
if (device.GetComponent<ModelItem>().deviceType.GetHashCode() == index)
|
||
{
|
||
AddHighLightComponent(device.gameObject);
|
||
device.GetComponent<Highlighter>().TweenStart();
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据设备类型关闭高亮
|
||
/// </summary>
|
||
/// <param name="index">索引从1开始</param>
|
||
public void HighLightDeviceOff(int index)
|
||
{
|
||
foreach (ModelItem device in devices)
|
||
{
|
||
if (device.GetComponent<ModelItem>().deviceType.GetHashCode() == index)
|
||
{
|
||
if (device.GetComponent<Highlighter>())
|
||
device.GetComponent<Highlighter>().TweenStop();
|
||
}
|
||
}
|
||
}
|
||
/// <summary>
|
||
///关闭所有设备高亮
|
||
/// </summary>
|
||
public void HighLightOff()
|
||
{
|
||
foreach (ModelItem device in devices)
|
||
{
|
||
if (device.GetComponent<Highlighter>())
|
||
device.GetComponent<Highlighter>().TweenStop();
|
||
}
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 添加闪烁边缘光
|
||
/// </summary>
|
||
private void AddHighLightComponent(GameObject obj)
|
||
{
|
||
if (!obj.GetComponent<Highlighter>())
|
||
{
|
||
Highlighter h = obj.AddComponent<Highlighter>();
|
||
h.overlay = true;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 摄像头进入房间内部,隐藏空间3DIcon,显示屋顶
|
||
/// </summary>
|
||
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;
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// 综合管理允许单体化显示
|
||
/// </summary>
|
||
/// <param name="istrue"></param>
|
||
public void CanSingle(bool istrue)
|
||
{
|
||
foreach(ModelItem device in devices)
|
||
{
|
||
if (device.GetComponent<DeviceClick>())
|
||
device.GetComponent<DeviceClick>().isSingle = istrue;
|
||
|
||
}
|
||
|
||
foreach (ModelItem item in peoples)
|
||
{
|
||
item.GetComponent<PeopleClick>().isSingle = istrue;
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 高亮闪烁3秒后关闭
|
||
/// </summary>
|
||
/// <param name="obj">高亮物体</param>
|
||
public void LightFlashCount(GameObject obj)
|
||
{
|
||
float a = 0;
|
||
LightFlash(obj, true);
|
||
DOTween.To(() => a, x => a = x, 1, 3).OnComplete(() =>
|
||
{
|
||
LightFlash(obj, false);
|
||
});
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 高亮闪烁
|
||
/// </summary>
|
||
/// <param name="obj">高亮物体</param>
|
||
/// <param name="on">是否高亮</param>
|
||
public void LightFlash(GameObject obj,bool on)
|
||
{
|
||
if (!obj.GetComponent<Highlighter>())
|
||
obj.AddComponent<Highlighter>();
|
||
|
||
if (on)
|
||
obj.GetComponent<Highlighter>().TweenStart();
|
||
else
|
||
obj.GetComponent<Highlighter>().TweenStop();
|
||
}
|
||
|
||
|
||
#region 热力图(弃用)
|
||
//热力图点位
|
||
public List<HeatPoint> heatPoints;
|
||
//世界坐标
|
||
public List<Vector3> m_Vector3s;
|
||
//X:半径(0,2);Y:强度(0,1)
|
||
public List<Vector2> m_Vector2s;
|
||
//切换热力图时的特效
|
||
private ParticleSystem _changeHeatmapEffect;
|
||
|
||
/// <summary>
|
||
/// 随机热力图热点值(测试)
|
||
/// </summary>
|
||
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();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 显示和关闭热力图
|
||
/// </summary>
|
||
/// <param name="isShow"></param>
|
||
public void ShowHeatmap(bool isShow)
|
||
{
|
||
if (isShow)
|
||
{
|
||
|
||
|
||
//播放切换热力图特效
|
||
//if (!_changeHeatmapEffect)
|
||
//{
|
||
// _changeHeatmapEffect = GameObject.Instantiate(Resources.Load<GameObject>(ResourcePath._changeHeatmapEffect).GetComponent<ParticleSystem>());
|
||
// _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);
|
||
}
|
||
|
||
}
|
||
/// <summary>
|
||
/// 延时显示热力图,等特效播放两秒后显示
|
||
/// </summary>
|
||
private void InvokeShowHeatmap()
|
||
{
|
||
UpdateHeatValue();
|
||
heatmap.gameObject.SetActive(true);
|
||
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 更新热力值
|
||
/// </summary>
|
||
public void UpdateHeatValue() {
|
||
heatmap.SetHeatPoints(heatPoints.Select((v) => new HeatPoint()
|
||
{
|
||
point = v.point,
|
||
radius = v.radius,
|
||
intensity = v.intensity
|
||
}));
|
||
}
|
||
|
||
/// <summary>
|
||
/// 随机动态更新热力值
|
||
/// </summary>
|
||
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 热力图
|
||
/// <summary>
|
||
/// 显示热力图
|
||
/// </summary>
|
||
public void ShowHeatPoint()
|
||
{
|
||
m_heatpoint.gameObject.SetActive(true);
|
||
Main.intance.heatPointDes.SetActive(true);
|
||
}
|
||
/// <summary>
|
||
/// 隐藏热力图
|
||
/// </summary>
|
||
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
|
||
{
|
||
/// <summary>
|
||
/// 世界坐标系位置
|
||
/// </summary>
|
||
public Vector3 point;
|
||
|
||
/// <summary>
|
||
/// 半径
|
||
/// </summary>
|
||
public float radius;
|
||
|
||
/// <summary>
|
||
/// 强度
|
||
/// </summary>
|
||
public float intensity;
|
||
} |