using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Linq; using System.Threading.Tasks; using Unity.VisualScripting; using UnityEngine; 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; [SerializeField] StopValve StopValve; public GameObject temp; [SerializeField] List interactive; public Interactive interactiveEnum = Interactive.none; 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 async void Start() { await initAsync(); for (int i = 0; i < SceneData.GFData; i++) { GFGame[i].gameObject.SetActive(true); } //for (int i = 0; i < SceneData.inverterSum; i++) //{ // //Inverter[i].gameObject.SetActive(true); //} UIManager.Instance.ToolsItemManager.ItemClick.AddListener(ToolsShow); } async Task initAsync() { try { Datas.Add(await HttpTool.GetJsonAsync($"http://111.229.30.246:10013/Handler/Taiqu.ashx?action=changjing&bianhao={dataStr}")); } catch (Exception ex) { Debug.LogError(ex.Message); } } private void Update() { if (Input.GetKeyDown(KeyCode.Q)) { ToolsShow(QianXing); } //if(Input.GetKeyDown(KeyCode.W)) //{ // ToolsShow(WanYon); //} if (Input.GetKeyDown(KeyCode.E)) { ToolsShow(YanDianBi); } 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; } } /// /// 工具生成方法 /// public void ToolsShow(GameObject tools) { if (temp != null) { Destroy(temp.gameObject); } temp = Instantiate(tools, Player.transform); UIManager.Instance.ToolsItemManager.currentTool = temp; string name = Filter(temp.name, TempChar); Debug.Log(name); switch (name) { case "万用表": StopValve.trans = temp.transform; break; case "钳形电流表": interactiveEnum = Interactive.QianXing; temp.transform.localRotation = Quaternion.Euler(new Vector3(90, 180, 0)); temp.transform.localPosition = new Vector3(0.312f, 0.316f, 0.618f); break; case "验电笔": interactiveEnum = Interactive.YanDian; temp.transform.localPosition = new Vector3(0.307f, 0.504f, 0.654f); temp.AddComponent(); break; default: Insta(temp); 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 }