93 lines
3.8 KiB
C#
93 lines
3.8 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using DG.Tweening;
|
|
using ZXK.Framework;
|
|
/*******************************************************************************
|
|
*Create By CG
|
|
*Function 设备认知场景控制
|
|
*******************************************************************************/
|
|
namespace ZXK.BYSS
|
|
{
|
|
public class CognizeCtrl : MonoBehaviour
|
|
{
|
|
//拆分-当前展示的模型
|
|
//需要被拆卸物体中二级菜单为拆卸的零部件
|
|
private GameObject _curShowModel = null;
|
|
//点击拆卸时存储合成对应位置
|
|
private Dictionary<Transform, Vector3> _partOrgPosDic = new Dictionary<Transform, Vector3>();
|
|
|
|
private void Awake()
|
|
{
|
|
EventCenterManager.Instance.AddEventListener(EventEnum.ClickEquipment, ClickEquipmentCall);
|
|
EventCenterManager.Instance.AddEventListener(EventEnum.SplitEquipment, SplitEquipmentCall);
|
|
EventCenterManager.Instance.AddEventListener(EventEnum.CombineEquipment, CombineEquipmentCall);
|
|
}
|
|
/// <summary>
|
|
/// 点击切换后显示某个模型
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void ClickEquipmentCall(object sender, System.EventArgs e)
|
|
{
|
|
_partOrgPosDic = new Dictionary<Transform, Vector3>();
|
|
foreach (Transform item in transform)
|
|
{
|
|
Destroy(item.gameObject);
|
|
}
|
|
//显示某个模型
|
|
ClickEquipmentArgs data = e as ClickEquipmentArgs;
|
|
GameObject modelItemPrefab = data.info._ModelPrefab;
|
|
_curShowModel = Instantiate(modelItemPrefab, transform);
|
|
_curShowModel.name = modelItemPrefab.name;
|
|
//显示模型介绍信息
|
|
UI_Manage.Instance.GetPanel("CognizePanel").GetComponent<CognizePanel>().ShowEquipment(data.info._ModelExplain, data.info._ModelName);
|
|
var cameraData = _curShowModel.transform.GetComponent<CameraData>();
|
|
Camera.main.transform.GetComponent<ZhanShiCameraMove>().SetData(cameraData.x,cameraData.y,cameraData.zoom);
|
|
|
|
|
|
|
|
}
|
|
private void SplitEquipmentCall(object sender, System.EventArgs e)
|
|
{
|
|
////储存拆分后位置信息
|
|
string nameTmp = _curShowModel.transform.name.Replace("Prefab", "");
|
|
|
|
if (_partOrgPosDic.Count == 0)
|
|
{//存储合成时需要的位置
|
|
foreach (Transform partTran in _curShowModel.transform.Find(nameTmp))
|
|
{
|
|
_partOrgPosDic.Add(partTran, partTran.position);
|
|
}
|
|
}
|
|
//对接拆分位置
|
|
foreach (Transform partTran in _curShowModel.transform.Find(nameTmp + "Open"))
|
|
{
|
|
foreach (Transform item in _partOrgPosDic.Keys)
|
|
{
|
|
if (item.name.Equals(partTran.name))
|
|
{
|
|
item.position = partTran.position;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
private void CombineEquipmentCall(object sender, System.EventArgs e)
|
|
{
|
|
if (_partOrgPosDic.Count == 0) return;
|
|
foreach (var item in _partOrgPosDic)
|
|
{
|
|
item.Key.position = item.Value;
|
|
}
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
EventCenterManager.Instance.RemoveListener(EventEnum.ClickEquipment, ClickEquipmentCall);
|
|
EventCenterManager.Instance.RemoveListener(EventEnum.SplitEquipment, SplitEquipmentCall);
|
|
EventCenterManager.Instance.RemoveListener(EventEnum.CombineEquipment, CombineEquipmentCall);
|
|
}
|
|
}
|
|
} |