using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Linq; using System.Threading.Tasks; using Unity.VisualScripting; using UnityEngine; using UnityEngine.UI; public class GameManager : MonoBehaviour { public static GameManager ins; public GameObject Player; public CameraManager CameraManager; List tools; [SerializeField] GameObject QianXing; [SerializeField] GameObject WanYon; [SerializeField] GameObject YanDianBi; char[] TempChar = new char[7] { '(', 'C', 'l', 'o', 'n', 'e', ')' }; public string dataStr; [SerializeField] List Datas = new List(); [SerializeField] List GFGame;//光伏板物体 [SerializeField] SceneData SceneData;//暂时数据 [SerializeField] List Inverter; [SerializeField] Transform trans; public StopValve WanStopValve;//万用表UI旋钮 public StopValve QianStopValve;//钳形表UI旋钮 [SerializeField] GameObject NiBianQi; [SerializeField] Image XiangWeiUI;//相位UI public GameObject temp; public List interactive; public GameObject RedWanYon; public GameObject BlackWanYon; public GameObject FuAnBiao; public Interactive interactiveEnum = Interactive.none; public Transform biaojiPos; public Camera toolsCam; public Image MultimeterIm; public Image DianFuIm; public Text DianFuTex; [SerializeField] FirstPersonController FirstPersonController; public void Awake() { if (ins != null) { Destroy(ins); return; } ins = this; //Debug.Log(trans.GetComponent()!=null?true:false); } // Start is called before the first frame update private void Start() { UIManager.Instance.ToolsItemManager.ItemClick.AddListener(ToolsShow); UIManager.Instance.ToolsItemManager.recoverEvent.AddListener(() => { WanStopValve.gameObject.SetActive(false); QianStopValve.gameObject.SetActive(false); DianFuIm.gameObject.SetActive(false); interactiveEnum = Interactive.none; FirstPersonController.enabled = true; }); string sceneInfo = "三相_无互感器_无光伏"; var tempStr = sceneInfo.Split('_'); int pvwCount = (GlobalFlag.pvw * 1000) / 295; if (tempStr[tempStr.Length-1].Equals("有光伏")) { for (int i = 0; i < pvwCount; i++) { GFGame[i].gameObject.SetActive(true); } } else { NiBianQi.gameObject.SetActive(false); } for (int i = 0; i < Inverter.Count; i++) { if (sceneInfo.Equals(Inverter[i].name)) { GameObject obj = Instantiate(Inverter[i]); obj.transform.localPosition = biaojiPos.localPosition; obj.transform.localEulerAngles = biaojiPos.localEulerAngles; interactive.Add(obj.GetComponentInChildren().gameObject) ; } } } private void Update() { //switch (interactiveEnum) //{ // case Interactive.none: // for (int i = 0; i < interactive.Count; i++) // { // interactive[i].transform.GetComponent().启用交互 = true; // } // break; // case Interactive.YanDian: // for (int i = 0; i < interactive.Count; i++) // { // interactive[i].transform.GetComponent().启用交互 = false; // } // break; // case Interactive.QianXing: // for (int i = 0; i < interactive.Count; i++) // { // interactive[i].transform.GetComponent().启用交互 = true; // } // break; // default: // break; //} if (Input.GetKeyDown(KeyCode.K)) { ToolsShow(QianXing); } } /// /// 工具生成方法 /// public void ToolsShow(GameObject tools) { FirstPersonController.enabled = false; if (temp != null) { Destroy(temp.gameObject); } temp = Instantiate(tools, Player.transform); temp.transform.localPosition = new Vector3(0.12f,0.46f,0.81f); UIManager.Instance.ToolsItemManager.currentTool = temp; string name = Filter(temp.name, TempChar); Debug.Log(name); switch (name) { case "万用表": WanStopValve.gameObject.SetActive(true); QianStopValve.gameObject.SetActive(false); GameObject t2 = GameObject.FindGameObjectWithTag("旋转"); WanStopValve.trans = t2.transform; temp.GetComponent(); temp.GetComponent().Camera = toolsCam; temp.GetComponent().line.SetActive(true); break; case "钳形电流表": interactiveEnum = Interactive.QianXing; temp.transform.localRotation = Quaternion.Euler(new Vector3(90, 180, 0)); QianStopValve.trans = temp.transform.Find("旋转"); WanStopValve.gameObject.SetActive(false); QianStopValve.gameObject.SetActive(true); break; case "验电笔": interactiveEnum = Interactive.YanDian; temp.transform.localPosition = new Vector3(0.307f, 0.504f, 0.654f); temp.AddComponent(); break; case "相位伏安表": temp.transform.localEulerAngles = new Vector3(0, 180, 0); temp.AddComponent(); temp.AddComponent().cam = toolsCam; temp.GetComponent().im = XiangWeiUI; FuAnBiao = temp; break; default: Insta(temp); WanStopValve.gameObject.SetActive(false); QianStopValve.gameObject.SetActive(false); break; } } public string Filter(string str, char[] charsToRemove) { return String.Concat(str.Split(charsToRemove.ToArray())); } /// /// 克隆位置更改 /// public void Insta(GameObject GameObj) { GameObj.transform.localPosition = new Vector3(Player.transform.position.x + 0.43f, Player.transform.position.y + 0.66f, Player.transform.position.z + 1.5f); } } /// /// 后台读的数据 /// [Serializable] public class datas { public bool state; public string message; public data2s data; } [Serializable] public class data2s { public string isguangfu; public string jxfs; public string zhbl; } public enum Interactive { none, YanDian, QianXing }