142 lines
4.1 KiB
C#
142 lines
4.1 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEditor;
|
||
using UnityEngine;
|
||
using UnityEngine.EventSystems;
|
||
|
||
public class PeopleClick : MonoBehaviour
|
||
{
|
||
//人员编号
|
||
public int index;
|
||
//是否允许单体化展示
|
||
public bool isSingle = false;
|
||
|
||
void Start()
|
||
{
|
||
AddGameObjectCollider();
|
||
}
|
||
|
||
|
||
void Update()
|
||
{
|
||
|
||
|
||
}
|
||
private void OnMouseUp()
|
||
{
|
||
if (EventSystem.current.IsPointerOverGameObject())
|
||
{
|
||
Debug.Log("鼠标在UI上");
|
||
return;
|
||
}
|
||
|
||
ViewCenter();
|
||
if (!isSingle)
|
||
return;
|
||
Debug.Log("显示人员详情");
|
||
Main.intance.m_htmlPanel.CallFunction("clickShowPersonnel", 5);
|
||
//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);
|
||
Debug.Log("pos" + playerPos + ";angle" + angle);
|
||
//Main.intance.mainCamera.GetComponent<CameraView>().CameraMoveTarget(playerPos, angle);
|
||
Main.intance.CameraMoveTarget(playerPos, angle);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 单体化展示
|
||
/// </summary>
|
||
void ShowSingle()
|
||
{
|
||
//设备信息弹窗
|
||
Main.intance.m_htmlPanel.CallFunction("U3DShowPeopleDetails", 0);
|
||
|
||
//将上一个单体化物体隐藏
|
||
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);
|
||
Main.intance.singleCam.GetComponent<Camera360>().ChangeObjLayer(Main.intance.CurentSingleObj, "single360");
|
||
Main.intance.ShowSingleModel(true);
|
||
}
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// 在自身添加碰撞体
|
||
/// </summary>
|
||
/// <param name="gameObject"></param>
|
||
public void AddGameObjectCollider()
|
||
{
|
||
|
||
//获取物体的最小包围盒
|
||
Bounds itemBound = GetSkinBounds(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 childbounds = mf.bounds;
|
||
childbounds.size = new Vector3(mf.bounds.size.x/ mf.transform.localScale.x, mf.bounds.size.y / mf.transform.localScale.y, mf.bounds.size.z / mf.transform.localScale.z);
|
||
bounds.Encapsulate(childbounds);
|
||
}
|
||
}
|
||
return bounds;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获得对象的最小包围盒
|
||
/// </summary>
|
||
public static Bounds GetSkinBounds(GameObject target)
|
||
{
|
||
SkinnedMeshRenderer[] mfs = target.GetComponentsInChildren<SkinnedMeshRenderer>();
|
||
|
||
Bounds bounds = new Bounds();
|
||
if (mfs.Length != 0)
|
||
{
|
||
bounds = mfs[0].bounds;
|
||
foreach (SkinnedMeshRenderer mf in mfs)
|
||
{
|
||
Bounds childbounds = mf.bounds;
|
||
childbounds.size = new Vector3(mf.bounds.size.x / mf.transform.localScale.x, mf.bounds.size.y / mf.transform.localScale.y, mf.bounds.size.z / mf.transform.localScale.z);
|
||
bounds.Encapsulate(childbounds);
|
||
}
|
||
}
|
||
return bounds;
|
||
}
|
||
}
|