343 lines
12 KiB
C#
343 lines
12 KiB
C#
using Components;
|
|
using DG.Tweening;
|
|
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.SceneManagement;
|
|
using UnityEngine.UI;
|
|
|
|
public class GameManager : MonoBehaviour
|
|
{
|
|
public static GameManager Instance;
|
|
public GameObject Player;
|
|
[SerializeField] GameObject QianXing;
|
|
[SerializeField] GameObject WanYon;
|
|
[SerializeField] GameObject YanDianBi;
|
|
char[] TempChar = new char[7] { '(', 'C', 'l', 'o', 'n', 'e', ')' };
|
|
public string dataStr;
|
|
[SerializeField] List<GameObject> GFGame;//光伏板物体
|
|
[SerializeField] SceneData SceneData;//暂时数据
|
|
[SerializeField] List<GameObject> Inverter;
|
|
[SerializeField] Transform trans;
|
|
public StopValveGai WanStopValve;//万用表UI旋钮
|
|
public StopValveGai QianStopValve;//钳形表UI旋钮
|
|
[SerializeField] GameObject NiBianQi;
|
|
[SerializeField] Image XiangWeiUI;//相位UI
|
|
public GameObject temp;
|
|
public List<GameObject> interactive;
|
|
public GameObject RedWanYon;
|
|
public Vector3 RedWanYonPos;
|
|
public GameObject BlackWanYon;
|
|
public Vector3 BlackWanYonPos;
|
|
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 string SceneName;
|
|
public GameObject GanTan;
|
|
public bool GonZuoZheng = false;
|
|
public bool JiaoHu = false;
|
|
public bool YanDian = false;
|
|
[SerializeField] Image HuiFuim;
|
|
public bool redok = false;
|
|
public string redData;
|
|
public DoolsPlayer DoolsPlayer;
|
|
public LadderCtr ladderCtr;
|
|
private Vector3 lastPlayerPos = new Vector3();
|
|
private Vector3 lastPlayereugle = new Vector3();
|
|
public void Awake()
|
|
{
|
|
if (Instance != null)
|
|
{
|
|
Destroy(Instance);
|
|
return;
|
|
}
|
|
Instance = this;
|
|
Scene scene = SceneManager.GetActiveScene();
|
|
SceneName = scene.name;
|
|
if (UIManager.Instance.Reconnection.ison)
|
|
{
|
|
//init();
|
|
}
|
|
}
|
|
// 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('_');
|
|
if (ladderCtr != null)
|
|
UIManager.Instance.bottomCotroller.ladderClick += SetPlayerUpDown;
|
|
int pvwCount = 0;
|
|
if (GlobalFlag.userType == "正常")
|
|
{
|
|
pvwCount = (GlobalFlag.runRL * 1000) / 600;
|
|
}
|
|
else if (GlobalFlag.userType == "异常")
|
|
{
|
|
pvwCount = GlobalFlag.pvwNum;
|
|
}
|
|
|
|
//if (tempStr[tempStr.Length - 1].Equals("有光伏"))
|
|
//{
|
|
// for (int i = 0; i < pvwCount; i++)
|
|
// {
|
|
// GFGame[i].gameObject.SetActive(true);
|
|
// }
|
|
//}
|
|
else
|
|
{
|
|
if (NiBianQi != null)
|
|
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);
|
|
//}
|
|
}
|
|
//if (tempStr[tempStr.Length - 1].Equals("无光伏"))
|
|
//{
|
|
// await FractionManager.Instance.overAsync(5, 10, "检查光伏");
|
|
//}
|
|
}
|
|
/// <summary>
|
|
/// 设置玩家信息
|
|
/// </summary>
|
|
public void SetPlayerUpDown(bool isUpDown)
|
|
{
|
|
if (isUpDown)
|
|
{
|
|
lastPlayerPos = FirstPersonController.transform.position;
|
|
lastPlayereugle = FirstPersonController.transform.eulerAngles;
|
|
Debug.Log("upLadder");
|
|
FirstPersonController.transform.position = ladderCtr.playerPos.position;
|
|
FirstPersonController.transform.eulerAngles = ladderCtr.playerPos.eulerAngles;
|
|
FirstPersonController.GetComponent<Rigidbody>().useGravity = false;
|
|
FirstPersonController.playerCanMove = false;
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("downLadder");
|
|
FirstPersonController.transform.position = lastPlayerPos;
|
|
FirstPersonController.transform.eulerAngles = lastPlayereugle;
|
|
FirstPersonController.GetComponent<Rigidbody>().useGravity = true;
|
|
FirstPersonController.playerCanMove = true;
|
|
}
|
|
}
|
|
|
|
public void init()
|
|
{
|
|
//if (UIManager.Instance.Reconnection.HandGameObject)
|
|
//{
|
|
// ToolsShow(UIManager.Instance.Reconnection.HandGameObject);
|
|
// UIManager.Instance.toolsItemManager.recoverBtn.gameObject.SetActive(true);
|
|
//}
|
|
//Player.transform.GetComponent<FirstPersonController>().enabled = true;
|
|
//Player.transform.localPosition = UIManager.Instance.Reconnection.PlayerPos;
|
|
//Player.transform.localEulerAngles = UIManager.Instance.Reconnection.PlayerRot;
|
|
//HuiFuim.gameObject.SetActive(true);
|
|
//HuiFuim.DOFade(0.8f, 0.25f);
|
|
//HuiFuim.DOFade(0, 0.25f).SetDelay(2).OnComplete(() =>
|
|
//{
|
|
// HuiFuim.gameObject.SetActive(false);
|
|
//});
|
|
//UIManager.Instance.Reconnection.ison = false;
|
|
}
|
|
public void show(string Str)
|
|
{
|
|
if (string.IsNullOrEmpty(Str))
|
|
{
|
|
return;
|
|
}
|
|
DianFuIm.gameObject.SetActive(true);
|
|
DianFuTex.text = Str;
|
|
}
|
|
private void Update()
|
|
{
|
|
if (transform)
|
|
{
|
|
if (DoolsPlayer == null) return;
|
|
switch (interactiveEnum)
|
|
{
|
|
case Interactive.none:
|
|
for (int i = 0; i < interactive.Count; i++)
|
|
{
|
|
if (interactive[i])
|
|
{
|
|
DoolsPlayer.ison = true;
|
|
interactive[i].transform.GetComponent<door_control>().启用交互 = true;
|
|
}
|
|
}
|
|
break;
|
|
case Interactive.YanDian:
|
|
for (int i = 0; i < interactive.Count; i++)
|
|
{
|
|
if (interactive[i])
|
|
{
|
|
DoolsPlayer.ison = false;
|
|
interactive[i].transform.GetComponent<door_control>().启用交互 = false;
|
|
interactive[i].transform.GetComponent<MeshCollider>().enabled = true;
|
|
}
|
|
}
|
|
break;
|
|
case Interactive.QianXing:
|
|
for (int i = 0; i < interactive.Count; i++)
|
|
{
|
|
if (interactive[i])
|
|
{
|
|
DoolsPlayer.ison = true;
|
|
interactive[i].transform.GetComponent<door_control>().启用交互 = true;
|
|
}
|
|
}
|
|
break;
|
|
case Interactive.YanDianOk:
|
|
for (int i = 0; i < interactive.Count; i++)
|
|
{
|
|
interactive[i].transform.GetComponent<MeshCollider>().enabled = false;
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
//if (Input.GetKeyDown(KeyCode.K))
|
|
//{
|
|
// ToolsShow(YanDianBi);
|
|
//}
|
|
}
|
|
/// <summary>
|
|
/// 工具生成方法
|
|
/// </summary>
|
|
public async void ToolsShow(GameObject tools)
|
|
{
|
|
if (Camera.main)
|
|
{
|
|
Camera.main.fieldOfView = 60;
|
|
}
|
|
if (FirstPersonController)
|
|
{
|
|
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);
|
|
if (FractionManager.Instance && GlobalFlag.userType == "异常")
|
|
{
|
|
await FractionManager.Instance.overAsync(6, 10, "测量窃电点");
|
|
}
|
|
redData = "";
|
|
DianFuTex.text = "-";
|
|
switch (name)
|
|
{
|
|
case "万用表":
|
|
WanStopValve.gameObject.SetActive(true);
|
|
QianStopValve.gameObject.SetActive(false);
|
|
GameObject t2 = GameObject.FindGameObjectWithTag("旋转");
|
|
WanStopValve.trans = t2.transform;
|
|
BlackWanYonPos = temp.GetComponent<MultimeterManager>().blackXian.localPosition;
|
|
RedWanYonPos = temp.GetComponent<MultimeterManager>().RedXian.localPosition;
|
|
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);
|
|
GameObject g1 = GameObject.FindGameObjectWithTag("旋转");
|
|
QianStopValve.trans = g1.transform;
|
|
WanStopValve.gameObject.SetActive(false);
|
|
temp.transform.localPosition = new Vector3(0.13f, 0.46f, 0.6f);
|
|
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);
|
|
}
|
|
private void OnDestroy()
|
|
{
|
|
UIManager.Instance.bottomCotroller.ladderClick -= SetPlayerUpDown;
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
UIManager.Instance.bottomCotroller.ladderClick -= SetPlayerUpDown;
|
|
}
|
|
}
|
|
/// <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,
|
|
YanDianOk
|
|
}
|