216 lines
5.7 KiB
C#
216 lines
5.7 KiB
C#
using HighlightingSystem;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using UnityEngine.EventSystems;
|
||
using UnityEngine.XR;
|
||
|
||
public class DeviceClick : MonoBehaviour
|
||
{
|
||
//设备编号
|
||
public int index;
|
||
//设备类型
|
||
public DeviceType deviceType;
|
||
//是否允许单体化展示
|
||
public bool isSingle = false;
|
||
|
||
private GameObject warmIcon;
|
||
|
||
//摄像头是否警告
|
||
private bool isCamWarm;
|
||
public bool _isCamWarm { get {
|
||
return isCamWarm;
|
||
} set {
|
||
isCamWarm=value;
|
||
if(value)
|
||
AddWarmIcon();
|
||
else
|
||
RemovWarmIcon();
|
||
|
||
} }
|
||
void Start()
|
||
{
|
||
AddGameObjectCollider();
|
||
}
|
||
|
||
private void Awake()
|
||
{
|
||
|
||
}
|
||
|
||
|
||
|
||
void Update()
|
||
{
|
||
|
||
}
|
||
private void OnMouseUp()
|
||
{
|
||
if (EventSystem.current.IsPointerOverGameObject())
|
||
{
|
||
Debug.Log("鼠标在UI上");
|
||
return;
|
||
}
|
||
|
||
ViewCenter();
|
||
//摄像头弹窗
|
||
if (deviceType == DeviceType.SheXiangTou)
|
||
{
|
||
Main.intance.m_htmlPanel.CallFunction("showCarema");
|
||
return;
|
||
}
|
||
if (!isSingle)
|
||
return;
|
||
//开启高亮,闪烁3秒后关闭高亮
|
||
LightFlashOn();
|
||
Invoke("LightFlahOff", 6);
|
||
|
||
if (deviceType != DeviceType.GongPai)
|
||
ShowSingle();
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 视角居中
|
||
/// </summary>
|
||
void ViewCenter()
|
||
{
|
||
Debug.Log("model" + transform.name);
|
||
//获取模型中心点位置(加上模型方向*3)X轴方向朝前
|
||
Vector3 playerPos = transform.position + transform.right * 3;
|
||
//相机面向设备
|
||
Quaternion angle = Quaternion.LookRotation(-transform.right);
|
||
if (Main.intance.isAddY)
|
||
{
|
||
playerPos = new Vector3(playerPos.x, playerPos.y+0.5f, playerPos.z);
|
||
}
|
||
else
|
||
{
|
||
playerPos = new Vector3(playerPos.x, playerPos.y, playerPos.z);
|
||
}
|
||
Debug.Log("pos" + playerPos + ";angle" + angle);
|
||
//Main.intance.mainCamera.GetComponent<CameraView>().CameraMoveTarget(playerPos, angle);
|
||
Main.intance.CameraMoveTarget(playerPos, angle);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 单体化展示
|
||
/// </summary>
|
||
void ShowSingle()
|
||
{
|
||
if (deviceType != DeviceType.SheXiangTou)
|
||
{
|
||
//当设备类型不为摄像头时,显示设备信息弹窗(传入设备ID)
|
||
Main.intance.m_htmlPanel.CallFunction("clickShowDetails", deviceType.GetHashCode()-1);
|
||
}
|
||
|
||
|
||
//将上一个单体化物体隐藏
|
||
if (Main.intance.CurentSingleObj != null)
|
||
{
|
||
Main.intance.singleCam.GetComponent<Camera360>().ChangeObjLayer(Main.intance.CurentSingleObj, "Default");
|
||
}
|
||
//显示单体化展示页面
|
||
Main.intance.CurentSinglePage.SetActive(true);
|
||
//将当前物体设置为单体化360观察的物体
|
||
Main.intance.CurentSingleObj = gameObject;
|
||
//Main.intance.singleCam.GetComponent<Camera360>().SetTarget(transform.GetComponent<MeshRenderer>().bounds.center);
|
||
Main.intance.singleCam.GetComponent<Camera360>().SetTarget(transform);
|
||
Main.intance.singleCam.GetComponent<Camera360>().ChangeObjLayer(gameObject, "single360");
|
||
Main.intance.ShowSingleModel(true);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 在自身添加碰撞体
|
||
/// </summary>
|
||
/// <param name="gameObject"></param>
|
||
public void AddGameObjectCollider()
|
||
{
|
||
|
||
//获取物体的最小包围盒
|
||
Bounds itemBound = GetLocalBounds(gameObject);
|
||
|
||
if (!gameObject.GetComponent<Collider>())
|
||
{
|
||
gameObject.AddComponent<BoxCollider>();
|
||
gameObject.GetComponent<BoxCollider>().size = itemBound.size;
|
||
gameObject.GetComponent<BoxCollider>().center = itemBound.center - transform.position;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获得对象的最小包围盒
|
||
/// </summary>
|
||
public static Bounds GetLocalBounds(GameObject target)
|
||
{
|
||
MeshRenderer[] mfs = target.GetComponentsInChildren<MeshRenderer>();
|
||
|
||
Bounds bounds = new Bounds();
|
||
if (mfs.Length != 0)
|
||
{
|
||
bounds = mfs[0].bounds;
|
||
foreach (MeshRenderer mf in mfs)
|
||
{
|
||
bounds.Encapsulate(mf.bounds);
|
||
}
|
||
}
|
||
return bounds;
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 添加摄像头警告Icon
|
||
/// </summary>
|
||
void AddWarmIcon() {
|
||
GameObject obj = Resources.Load<GameObject>(ResourcePath._camWarn3DIcon);
|
||
GameObject icon = GameObject.Instantiate(obj);
|
||
warmIcon = icon;
|
||
icon.GetComponent<RectTransform>().SetParent(ModelManager.instance.iconPanel);
|
||
icon.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);
|
||
icon.transform.position = transform.position;
|
||
if (icon.GetComponent<CamWarn3DIcon>() == null)
|
||
icon.AddComponent<CamWarn3DIcon>();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 移除摄像头警告
|
||
/// </summary>
|
||
void RemovWarmIcon()
|
||
{
|
||
if (warmIcon)
|
||
Destroy(warmIcon);
|
||
}
|
||
/// <summary>
|
||
/// 开启高亮
|
||
/// </summary>
|
||
void LightFlashOn()
|
||
{
|
||
LightFlash(true);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 关闭高亮
|
||
/// </summary>
|
||
void LightFlahOff() {
|
||
LightFlash(false);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 高亮闪烁两下
|
||
/// </summary>
|
||
/// <param name="on"></param>
|
||
void LightFlash(bool on)
|
||
{
|
||
if(!GetComponent<Highlighter>())
|
||
gameObject.AddComponent<Highlighter>();
|
||
|
||
if(on)
|
||
GetComponent<Highlighter>().TweenStart();
|
||
else
|
||
GetComponent<Highlighter>().TweenStop();
|
||
}
|
||
}
|
||
|
||
|
||
|