212 lines
6.9 KiB
C#
212 lines
6.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;
|
|
using UnityEngine.UI;
|
|
|
|
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;
|
|
public StopValve WanStopValve;//万用表UI旋钮
|
|
public StopValve QianStopValve;//钳形表UI旋钮
|
|
[SerializeField] GameObject NiBianQi;
|
|
[SerializeField] Image XiangWeiUI;//相位UI
|
|
public GameObject temp;
|
|
public List<GameObject> 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<interactive>()!=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 = GlobalFlag.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<door_control>().gameObject);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
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;
|
|
}
|
|
//if (Input.GetKeyDown(KeyCode.K))
|
|
//{
|
|
// ToolsShow(QianXing);
|
|
//}
|
|
}
|
|
/// <summary>
|
|
/// 工具生成方法
|
|
/// </summary>
|
|
public void ToolsShow(GameObject tools)
|
|
{
|
|
Camera.main.fieldOfView = 60;
|
|
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<MultimeterManager>();
|
|
temp.GetComponent<MultimeterManager>().Camera = toolsCam;
|
|
temp.GetComponent<ToolModelClick>().line.SetActive(true);
|
|
break;
|
|
case "钳形电流表":
|
|
interactiveEnum = Interactive.QianXing;
|
|
temp.transform.localEulerAngles = 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<TestPenInteractive>();
|
|
break;
|
|
case "相位伏安表":
|
|
temp.transform.localEulerAngles = new Vector3(0, 180, 0);
|
|
temp.AddComponent<AmpereMeter>();
|
|
temp.AddComponent<AmpereMeter>().cam = toolsCam;
|
|
temp.GetComponent<AmpereMeter>().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()));
|
|
}
|
|
/// <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
|
|
}
|