using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using DG.Tweening; using HighlightPlus; using UnityEngine.UI; using UnityEngine.SceneManagement; using UnityEngine.Rendering.Universal; // 引入URP命名空间 using TMPro; public class PartKnowManager : MonoBehaviour { public List partMsgs = new List(); public Transform viewCam; public TextMeshProUGUI tipText; public List partTogs = new List(); public Transform target; //urp相关 public Camera targetCamera; // Start is called before the first frame update void Start() { //ShowPart("前舱盖"); foreach (var part in partTogs) { part.onValueChanged.AddListener((isOn) => OnToggleValueChanged(part, isOn)); } partTogs[0].isOn = true; } /// /// Toggle值改变时的回调 /// private void OnToggleValueChanged(Toggle toggle, bool isOn) { if (isOn) { ShowPart(toggle.name); // 可以在这里添加其他逻辑 // 比如改变颜色、播放声音等 } } void Update() { //if (Input.GetKeyDown(KeyCode.Alpha1)) ShowPart("前舱盖"); //if (Input.GetKeyDown(KeyCode.Alpha2)) ShowPart("配电箱"); //if (Input.GetKeyDown(KeyCode.Alpha3)) ShowPart("发射台"); //if (Input.GetKeyDown(KeyCode.Alpha4)) ShowPart("尾盖"); //if (Input.GetKeyDown(KeyCode.Alpha5)) ShowPart("后舱盖"); } private GameObject NowHighLightObj; private List hideObjs=new List(); private string currectShow; public void ShowPart(string partName) { if (currectShow == partName) return; currectShow = partName; PartMsg msg = GetPart(partName); tipText.text = msg.partStr; if (NowHighLightObj != null) { NowHighLightObj.GetComponent().enabled = false; NowHighLightObj.SetActive(false); } if (hideObjs.Count != 0) //如果有之前隐藏的就先出现 { foreach (GameObject obj in hideObjs) { obj.SetActive(true); } } hideObjs = msg.fadeObjs; if (hideObjs.Count != 0) { foreach (GameObject obj in hideObjs) { obj.SetActive(false); } } NowHighLightObj = msg.partObj; NowHighLightObj.GetComponent().enabled = true; NowHighLightObj.SetActive(true); SetCamToPos(msg); } /// /// 设置相机目标点 /// /// public void SetCamToPos(PartMsg msg) { // viewCam.GetComponent().controlable = false; target.position = msg.camPos.position; //viewCam.GetComponent().SetTarget( msg.camPos); //viewCam.transform.DOMove(msg.camPos.position, 1f).SetEase(Ease.Linear); //viewCam.transform.DORotateQuaternion(msg.camPos.rotation, 1f).SetEase(Ease.Linear).OnComplete(() => { // viewCam.GetComponent().controlable = true; //}); } /// /// 找到对应的部件 /// /// /// public PartMsg GetPart(string partName) { return partMsgs.Find(item => item.partName == partName); } public void OnBackBtnClick() { ReturnMainScene(); } /// /// 返回主场景 /// public void ReturnMainScene() { SceneManager.LoadScene("GameMain"); //SceneLoader.LoadAsync("GameSencePC"); } } [Serializable] public class PartMsg { public string partName; public GameObject partObj; public string partStr; public Transform camPos; public Transform targetPos; public List fadeObjs=new List(); }