171 lines
4.1 KiB
C#
171 lines
4.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class XMZJController : MonoBehaviour
|
|
{
|
|
public static XMZJController Instance;
|
|
|
|
private void Awake()
|
|
{
|
|
Instance = this;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 文本前两个空格
|
|
/// </summary>
|
|
string space = "\u00A0\u00A0\u00A0\u00A0\u00A0\u00A0\u00A0";
|
|
|
|
/// <summary>
|
|
/// 场景展示数据
|
|
/// </summary>
|
|
public SpotInfo sceneInfo;
|
|
|
|
/// <summary>
|
|
/// 展示面板
|
|
/// </summary>
|
|
public GameObject pnlInfo;
|
|
/// <summary>
|
|
/// 场景标题文本控件
|
|
/// </summary>
|
|
public Text txtSceneTitle;
|
|
/// <summary>
|
|
/// 内容标题文本控件
|
|
/// </summary>
|
|
public Text txtTitle;
|
|
/// <summary>
|
|
/// 内容详细文本控件
|
|
/// </summary>
|
|
public Text txtDetailInfo;
|
|
/// <summary>
|
|
/// 内容详细文本控件
|
|
/// </summary>
|
|
public Text txtDetailInfo2;
|
|
/// <summary>
|
|
/// 展品查看位置
|
|
/// </summary>
|
|
public Transform tranModelPos;
|
|
/// <summary>
|
|
/// 展品图片控件
|
|
/// </summary>
|
|
public Image imgDetail;
|
|
/// <summary>
|
|
/// 展品图片控件
|
|
/// </summary>
|
|
public RawImage rawDetail;
|
|
/// <summary>
|
|
/// 展品原始位置
|
|
/// </summary>
|
|
Vector3 originalPos;
|
|
/// <summary>
|
|
/// 展品原始旋转
|
|
/// </summary>
|
|
Quaternion originalRotate;
|
|
/// <summary>
|
|
/// 当前展品Transform
|
|
/// </summary>
|
|
Transform tranCurrentModel;
|
|
/// <summary>
|
|
/// 当前展品数据
|
|
/// </summary>
|
|
SpotInfo currentInfo;
|
|
|
|
void Start()
|
|
{
|
|
ShowInfo(sceneInfo);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 显示展品
|
|
/// </summary>
|
|
/// <param name="info">展品信息</param>
|
|
public void ShowInfo(SpotInfo info)
|
|
{
|
|
currentInfo = info;
|
|
|
|
if (!string.IsNullOrEmpty(info.sceneTitle))
|
|
{
|
|
txtSceneTitle.text = info.sceneTitle;
|
|
txtDetailInfo2.gameObject.SetActive(false);
|
|
txtDetailInfo.gameObject.SetActive(true);
|
|
txtDetailInfo.text = space + info.detailInfo;
|
|
txtDetailInfo.fontSize = info.fontSize;
|
|
}
|
|
else
|
|
{
|
|
txtDetailInfo2.gameObject.SetActive(true);
|
|
txtDetailInfo.gameObject.SetActive(false);
|
|
txtDetailInfo2.text = space + info.detailInfo;
|
|
txtDetailInfo2.fontSize = info.fontSize;
|
|
}
|
|
|
|
txtTitle.text = info.title;
|
|
pnlInfo.SetActive(true);
|
|
rotateDir = info.rotateDir;
|
|
|
|
// 显示图片
|
|
if (!info.showModel && info.spDetail != null)
|
|
{
|
|
imgDetail.gameObject.SetActive(true);
|
|
imgDetail.sprite = info.spDetail;
|
|
}
|
|
else
|
|
{
|
|
imgDetail.gameObject.SetActive(false);
|
|
}
|
|
|
|
// 停止动画
|
|
if (info.anim != null)
|
|
{
|
|
info.anim.Play(0, 0, 0f);
|
|
info.anim.Update(0f);
|
|
info.anim.enabled = false;
|
|
}
|
|
|
|
// 显示模型
|
|
if (info.showModel)
|
|
{
|
|
rawDetail.gameObject.SetActive(true);
|
|
|
|
Transform tran = info.tranModel == null ? info.transform : info.tranModel;
|
|
originalPos = tran.position;
|
|
originalRotate = tran.rotation;
|
|
tran.position = tranModelPos.position;
|
|
tran.rotation = Quaternion.Euler(info.rotateAngle);
|
|
tranCurrentModel = tran;
|
|
}
|
|
else
|
|
{
|
|
rawDetail.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
|
|
public void OnBtnCloseClick()
|
|
{
|
|
pnlInfo.SetActive(false);
|
|
if (tranCurrentModel != null)
|
|
{
|
|
tranCurrentModel.position = originalPos;
|
|
tranCurrentModel.rotation = originalRotate;
|
|
tranCurrentModel = null;
|
|
}
|
|
|
|
if (currentInfo.anim != null)
|
|
{
|
|
currentInfo.anim.enabled = true;
|
|
}
|
|
}
|
|
|
|
public float rotateSpeed = 100f;
|
|
Vector3 rotateDir;
|
|
// public Camera cam;
|
|
|
|
private void Update()
|
|
{
|
|
if (currentInfo.showModel && tranCurrentModel != null)
|
|
{
|
|
tranCurrentModel.Rotate(rotateDir * Time.deltaTime * rotateSpeed, Space.World);
|
|
}
|
|
}
|
|
} |