169 lines
4.0 KiB
C#
169 lines
4.0 KiB
C#
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<PartMsg> partMsgs = new List<PartMsg>();
|
|
|
|
public Transform viewCam;
|
|
public TextMeshProUGUI tipText;
|
|
|
|
public List<Toggle> partTogs = new List<Toggle>();
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Toggle值改变时的回调
|
|
/// </summary>
|
|
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<GameObject> hideObjs=new List<GameObject>();
|
|
|
|
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<HighlightEffect>().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<HighlightEffect>().enabled = true;
|
|
NowHighLightObj.SetActive(true);
|
|
SetCamToPos(msg);
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置相机目标点
|
|
/// </summary>
|
|
/// <param name="partName"></param>
|
|
public void SetCamToPos(PartMsg msg)
|
|
{
|
|
|
|
// viewCam.GetComponent<CameraOrbit>().controlable = false;
|
|
target.position = msg.camPos.position;
|
|
//viewCam.GetComponent<CameraOrbit>().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<CameraOrbit>().controlable = true;
|
|
//});
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 找到对应的部件
|
|
/// </summary>
|
|
/// <param name="partName"></param>
|
|
/// <returns></returns>
|
|
public PartMsg GetPart(string partName)
|
|
{
|
|
return partMsgs.Find(item => item.partName == partName);
|
|
}
|
|
|
|
|
|
public void OnBackBtnClick()
|
|
{
|
|
ReturnMainScene();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 返回主场景
|
|
/// </summary>
|
|
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<GameObject> fadeObjs=new List<GameObject>();
|
|
|
|
|
|
}
|