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; } /// /// 文本前两个空格 /// string space = "\u00A0\u00A0\u00A0\u00A0\u00A0\u00A0\u00A0"; /// /// 场景展示数据 /// public SpotInfo sceneInfo; /// /// 展示面板 /// public GameObject pnlInfo; /// /// 场景标题文本控件 /// public Text txtSceneTitle; /// /// 内容标题文本控件 /// public Text txtTitle; /// /// 内容详细文本控件 /// public Text txtDetailInfo; /// /// 内容详细文本控件 /// public Text txtDetailInfo2; /// /// 展品查看位置 /// public Transform tranModelPos; /// /// 展品图片控件 /// public Image imgDetail; /// /// 展品图片控件 /// public RawImage rawDetail; /// /// 展品原始位置 /// Vector3 originalPos; /// /// 展品原始旋转 /// Quaternion originalRotate; /// /// 当前展品Transform /// Transform tranCurrentModel; /// /// 当前展品数据 /// SpotInfo currentInfo; void Start() { ShowInfo(sceneInfo); } /// /// 显示展品 /// /// 展品信息 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); } } }