149 lines
4.0 KiB
C#
149 lines
4.0 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] List<Transform> DianLiuCube;
|
|
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);
|
|
}
|
|
}
|
|
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);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// ¹¤¾ßÉú³É·½·¨
|
|
/// </summary>
|
|
public void ToolsShow(GameObject tools)
|
|
{
|
|
GameObject temp = Instantiate(tools, Player.transform);
|
|
temp.transform.localPosition = new Vector3(0.319f,-0.471f,0.87f);
|
|
temp.transform.localRotation = Quaternion.Euler(new Vector3(90,180,0));
|
|
temp.AddComponent<ClampAmmeters>();
|
|
string name = Filter(temp.name,TempChar);
|
|
Debug.Log(name);
|
|
switch (name)
|
|
{
|
|
case "ÍòÓñí":
|
|
break;
|
|
case "ǯÐεçÁ÷±í":
|
|
ToolModelClick tool = temp.GetComponent<ToolModelClick>();
|
|
ClampAmmeters clamp = temp.GetComponent<ClampAmmeters>();
|
|
//tool.onDown.AddListener(clamp.MouseDown);
|
|
tool.onDrag.AddListener(() =>
|
|
{
|
|
clamp.isok = true;
|
|
});
|
|
tool.onExit.AddListener(() =>
|
|
{
|
|
clamp.isok = false;
|
|
});
|
|
|
|
break;
|
|
case "":
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
public string Filter(string str, char[] charsToRemove)
|
|
{
|
|
return String.Concat(str.Split(charsToRemove.ToArray()));
|
|
}
|
|
public Transform NameContrast(string name)
|
|
{
|
|
Transform trans = null;
|
|
if (!string.IsNullOrEmpty(name))
|
|
{
|
|
for (int i = 0; i < DianLiuCube.Count; i++)
|
|
{
|
|
if (DianLiuCube[i].name.Equals(name))
|
|
{
|
|
trans = DianLiuCube[i];
|
|
}
|
|
}
|
|
}
|
|
return trans;
|
|
}
|
|
}
|
|
/// <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;
|
|
}
|