173 lines
4.9 KiB
C#
173 lines
4.9 KiB
C#
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<GameObject> 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> Datas = new List<datas>();
|
|
[SerializeField] List<GameObject> GFGame;//¹â·ü°åÎïÌå
|
|
[SerializeField] SceneData SceneData;//ÔÝʱÊý¾Ý
|
|
[SerializeField] List<GameObject> Inverter;
|
|
[SerializeField] Transform trans;
|
|
[SerializeField] StopValve StopValve;
|
|
public GameObject temp;
|
|
[SerializeField] List<GameObject> interactive;
|
|
public Interactive interactiveEnum = Interactive.none;
|
|
public void Awake()
|
|
{
|
|
if (ins != null)
|
|
{
|
|
Destroy(ins);
|
|
return;
|
|
}
|
|
ins = this;
|
|
//Debug.Log(trans.GetComponent<interactive>()!=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<datas>($"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<door_control>().ÆôÓý»»¥ = true;
|
|
}
|
|
break;
|
|
case Interactive.YanDian:
|
|
for (int i = 0; i < interactive.Count; i++)
|
|
{
|
|
interactive[i].transform.GetComponent<door_control>().ÆôÓý»»¥ = false;
|
|
}
|
|
break;
|
|
case Interactive.QianXing:
|
|
for (int i = 0; i < interactive.Count; i++)
|
|
{
|
|
interactive[i].transform.GetComponent<door_control>().ÆôÓý»»¥ = true;
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// ¹¤¾ßÉú³É·½·¨
|
|
/// </summary>
|
|
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<TestPenInteractive>();
|
|
break;
|
|
default:
|
|
Insta(temp);
|
|
break;
|
|
}
|
|
}
|
|
public string Filter(string str, char[] charsToRemove)
|
|
{
|
|
return String.Concat(str.Split(charsToRemove.ToArray()));
|
|
}
|
|
/// <summary>
|
|
/// ¿Ë¡λÖøü¸Ä
|
|
/// </summary>
|
|
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);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// ºǫ́¶ÁµÄÊý¾Ý
|
|
/// </summary>
|
|
[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
|
|
}
|