GameManager.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. using SC.XR.Unity.Module_InputSystem;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. public class GameManager : MonoBehaviour
  6. {
  7. // Start is called before the first frame update
  8. public static GameManager instacne;
  9. public PosCommunication posCom;
  10. public GameObject obj_model1;
  11. // public GameObject obj_model2;
  12. public GameObject obj_model3;
  13. public GameObject obj_model4,scence4flooreffict;
  14. public GameObject obj_model5, DaoHangMap;
  15. public GameObject makeEneutralPanel;
  16. public GameObject fooldObj;//地面碰撞体
  17. private MakeEneutralManager makeEneutralManager;
  18. public GameObject gameScenes;
  19. public GameObject uiManager;
  20. public GameObject changeUIScenes4or5;
  21. public EnemyMessagerPanelManager enemyMessagerPanelManager_Scenes5;//跟随视野旋转 左右上下
  22. public EnemyMessagerPanelManager enemyMessagerPanelManager_2D;//固定位置界面
  23. public EnemyMessagerPanelManager enemyMessagerPanelManager_3D;//跟随视野旋转,左右 不上下
  24. public string scenesName;
  25. public GameObject gamescence;
  26. public GameObject []scence3button;
  27. public GameObject[] scence4or5button;
  28. Vector3 scence4localposoffset;//scence4与眼镜差值
  29. public bool scence5Iscollision = false;//false 没有发生碰撞满足生成敌人条件,true为发生碰撞不满足生成敌人条件
  30. public float gpsPosInitx ; //367183;// 初始限定的位置 用于全局性质的坐标修改 并用于标定 地图的0,0点
  31. public float gpsPosInitz ;//3457939;
  32. public GameObject PointToNorth;//指北针
  33. public GameObject map3D;// 3d地图 总级
  34. public GameObject map3DParent;//新的 3d地图 父级
  35. public TextMesh delayText; // 右上角延迟显示(暂时先放这里 D)
  36. public Manage navManage;
  37. private void Awake()
  38. {
  39. // Debug.Log("位置X" + gpsPosInitx + "原始位置Z++++++++++++++++" +gpsPosInitz);
  40. instacne = this;
  41. posCom = this.GetComponent<PosCommunication>();
  42. makeEneutralManager = makeEneutralPanel.GetComponent<MakeEneutralManager>();
  43. }
  44. private void Start()
  45. {
  46. gpsPosInitx = 0;
  47. gpsPosInitz = 0;
  48. DispatcherBase.KeyDownDelegateRegister(PartAnyKeyEventDelegate);//点击,出现预支体
  49. //makeEneutralPanel.transform.parent = SvrManager.Instance.head.transform;
  50. //makeEneutralManager.handRot.transform.parent = SvrManager.Instance.head.transform;
  51. //makeEneutralPanel.transform.rotation = Quaternion.Euler(0, 0, 0);
  52. //makeEneutralManager.handRot.transform.rotation = Quaternion.Euler(0, 0, 0);
  53. //makeEneutralPanel.SetActive(false);
  54. changeUIScenes4or5.SetActive(false);
  55. scence4localposoffset = SvrManager.Instance.head.transform.position - obj_model4.transform.position;
  56. NorthTheparentPos();
  57. }
  58. /// <summary>
  59. /// 将指北针放入小地图
  60. /// </summary>
  61. private void NorthTheparentPos()
  62. {
  63. PointToNorth.gameObject.SetActive(true);
  64. PointToNorth.transform.parent = DaoHangMap.transform.Find("huan").gameObject.transform;
  65. PointToNorth.transform.localPosition = new Vector3(0, 0, 0);
  66. PointToNorth.transform.localEulerAngles = new Vector3(0,0,0);
  67. }
  68. private void MoveMap3DPos(float moveX,float moveY,float moveZ)//对3D模式地图进行位移
  69. {
  70. map3D.transform.localPosition = new Vector3(moveX, moveY, moveZ);
  71. }
  72. private void Update()
  73. {
  74. //Debug.Log(posCom.dataPlayerAttributesList.Count);
  75. for (int i = 0; i < posCom.dataPlayerAttributesListOne.Count; i++)
  76. {
  77. if (posCom.dataPlayerAttributesListOne[i].data.message.data2.id.Contains(posCom.dataPAOne.data.message.data2.id))
  78. {
  79. posCom.dataPlayerAttributesListOne[i] = posCom.dataPAOne;
  80. }
  81. posCom.playerTypeOfWorksList[i].GetComponent<MiniMapFit>().action = posCom.dataPlayerAttributesListOne[i].data.message.data2.action;
  82. posCom.playerTypeOfWorksList[i].GetComponent<MiniMapFit>().id = posCom.dataPlayerAttributesListOne[i].data.message.data2.id;
  83. posCom.playerTypeOfWorksList[i].GetComponent<MiniMapFit>().des = posCom.dataPlayerAttributesListOne[i].data.message.data2.des;
  84. posCom.playerTypeOfWorksList[i].GetComponent<MiniMapFit>().pos = posCom.dataPlayerAttributesListOne[i].data.message.data2.pos;
  85. posCom.playerTypeOfWorksList[i].GetComponent<MiniMapFit>().eul = posCom.dataPlayerAttributesListOne[i].data.message.data2.eul;
  86. posCom.playerTypeOfWorksList[i].GetComponent<MiniMapFit>().typeOfWork = posCom.dataPlayerAttributesListOne[i].data.message.data2.typeOfWork;
  87. posCom.playerTypeOfWorksList[i].GetComponent<MiniMapFit>().thisCurrentMinMapFitIndex = PosCommunication.currentMinMapFitIndex;
  88. }
  89. // Debug.Log(posCom.dataPlayerAttributesList.Count);
  90. //for (int i = 0; i < posCom.dataPlayerAttributesList.Count; i++)
  91. //{
  92. // Debug.Log(posCom.dataPlayerAttributesList[i].data.message.dataEnemy.Count);
  93. // Debug.Log(posCom.dataPA.data.message.dataEnemy.Count);
  94. // if (posCom.dataPlayerAttributesList[i].data.message.dataEnemy[i].id.Contains(posCom.dataPA.data.message.dataEnemy[i].id))
  95. // {
  96. // posCom.dataPlayerAttributesList[i] = posCom.dataPA;
  97. // }
  98. // posCom.playerMakeTypeOfWorksList[i].GetComponent<MiniMapFit>().action = posCom.dataPlayerAttributesList[i].data.message.dataEnemy[i].action;
  99. // posCom.playerMakeTypeOfWorksList[i].GetComponent<MiniMapFit>().id = posCom.dataPlayerAttributesList[i].data.message.dataEnemy[i].id;
  100. // posCom.playerMakeTypeOfWorksList[i].GetComponent<MiniMapFit>().des = posCom.dataPlayerAttributesList[i].data.message.dataEnemy[i].des;
  101. // posCom.playerMakeTypeOfWorksList[i].GetComponent<MiniMapFit>().pos = posCom.dataPlayerAttributesList[i].data.message.dataEnemy[i].pos;
  102. // posCom.playerMakeTypeOfWorksList[i].GetComponent<MiniMapFit>().eul = posCom.dataPlayerAttributesList[i].data.message.dataEnemy[i].eul;
  103. // posCom.playerMakeTypeOfWorksList[i].GetComponent<MiniMapFit>().typeOfWork = posCom.dataPlayerAttributesList[i].data.message.dataEnemy[i].typeOfWork;
  104. //}
  105. }
  106. private void LateUpdate()
  107. {
  108. Vector3 Posrotate = new Vector3(0,0 - SvrManager.Instance.head.localEulerAngles.y, 0);//指北针旋转
  109. PointToNorth.transform.localEulerAngles = Posrotate;
  110. // Debug.Log("指北针旋转++++++++++++" + Posrotate.y);
  111. }
  112. public void UserClick(string ButtonName)
  113. {
  114. switch (ButtonName)
  115. {
  116. case "button_To1":
  117. obj_model1.transform.GetChild(0).gameObject.GetComponent<Animator>().SetBool("M1", true);
  118. Invoke("obj_modle2true", 3.5f);
  119. break;
  120. case "OpenScence3":
  121. ButtonBoxManage(0);
  122. if (obj_model5.activeInHierarchy == false && obj_model4.activeInHierarchy == false)
  123. {
  124. obj_model3.SetActive(true);
  125. obj_model4.transform.Find("地形_大").gameObject.GetComponent<Animator>().SetBool("M3", true);
  126. }
  127. if (obj_model5.activeInHierarchy == false || obj_model4.activeInHierarchy == false)
  128. {
  129. DaoHangMap.SetActive(false);
  130. obj_model5.SetActive(false);
  131. obj_model4.transform.Find("地形_大").gameObject.GetComponent<Animator>().SetBool("M3", true);
  132. }
  133. scenesName = "scenes3";
  134. ScencesIntheGameScence("Scenes3_2D");//将3D场景放入gamescence中
  135. Invoke("obj_model3true", 2f);
  136. changeUIScenes4or5.SetActive(false);
  137. enemyMessagerPanelManager_3D.Init();
  138. enemyMessagerPanelManager_Scenes5.Init();
  139. break;
  140. case "OpenScence4":
  141. scenesName = "scenes4";
  142. ButtonBoxManage(1);
  143. if (obj_model5.activeInHierarchy==false&& obj_model3.activeInHierarchy == false)
  144. {
  145. obj_model4.SetActive(true);
  146. }
  147. if (obj_model5.activeInHierarchy == false || obj_model3.activeInHierarchy == false)
  148. {
  149. DaoHangMap.SetActive(false);
  150. obj_model5.SetActive(false);
  151. obj_model3.transform.GetChild(0).gameObject.GetComponent<Animator>().SetBool("M2", true);
  152. }
  153. // ScencesIntheGameScence("Scenes4_3D");//将4场景放入gamescence中
  154. Invoke("obj_model4ture", 2.7f);
  155. enemyMessagerPanelManager_2D.Init();
  156. enemyMessagerPanelManager_Scenes5.Init();
  157. navManage.move.CloseAllLine();
  158. break;
  159. case "OpenScence5":
  160. scenesName = "scenes5";
  161. ButtonBoxManage(2);
  162. obj_model4.transform.Find("地形_大").gameObject.GetComponent<Animator>().SetBool("M3", true);
  163. obj_model3.transform.GetChild(0).gameObject.GetComponent<Animator>().SetBool("M2", true);
  164. Invoke("obj_model5true", 2.7f);
  165. enemyMessagerPanelManager_2D.Init();
  166. enemyMessagerPanelManager_3D.Init();
  167. navManage.move.CloseAllLine();
  168. break;
  169. //case "Scence5ToScence3":
  170. // obj_model5.SetActive(false);
  171. // obj_model3.SetActive(true);
  172. // DaoHangMap.SetActive(false);
  173. // fooldObj.gameObject.SetActive(false);
  174. // break;
  175. case "ButtonFooldPanle":
  176. //float handrot = SvrManager.Instance.head.transform.localEulerAngles.y;
  177. //float gamesScenesRot = uiManager.transform.transform.localEulerAngles.y;
  178. //float makePanelRot = handrot - gamesScenesRot;
  179. // makeEneutralPanel.transform.parent = uiManager.transform;
  180. //makeEneutralPanel.transform.position = new Vector3(makeEneutralPanel.transform.position.x, 0.06f, makeEneutralPanel.transform.position.z);
  181. //makeEneutralPanel.transform.localRotation = Quaternion.Euler(0, makePanelRot, 0);
  182. // fooldObj.GetComponent<BoxCollider>().enabled = false;
  183. makeEneutralPanel.gameObject.SetActive(true);
  184. Vector3 linePosition = SvrManager.Instance.head.transform.position;// inputDevicePartUIBase.modelBase.lineIndicate.StartPoint.transform.position;
  185. Vector3 lineForward = SvrManager.Instance.head.transform.forward;// part.inputDevicePartUIBase.modelBase.lineIndicate.StartPoint.transform.forward;
  186. Vector3 worldPosition = linePosition + (lineForward * 0.5f);
  187. makeEneutralPanel.transform.position = new Vector3(worldPosition.x, worldPosition.y, worldPosition.z);
  188. makeEneutralPanel.transform.rotation = Quaternion.Euler(0, scence3followPos.transform.parent.transform.eulerAngles.y, 0);
  189. break;
  190. case "UserEnterFoold":
  191. fooldObj.GetComponent<MeshRenderer>().material.SetFloat("_Brightness", 0f);
  192. break;
  193. case "UserEixtFoold":
  194. fooldObj.GetComponent<MeshRenderer>().material.SetFloat("_Brightness", 0f);
  195. break;
  196. }
  197. }
  198. /// <summary>
  199. /// scence1切换到场景scences3
  200. /// </summary>
  201. public void obj_modle2true()
  202. {
  203. obj_model1.SetActive(false);
  204. obj_model3.SetActive(true);
  205. }
  206. /// <summary>
  207. /// 打开Scence4
  208. /// </summary>
  209. public void obj_model4ture()
  210. {
  211. ScencesIntheGlasse("Scenes3_2D");//场景2放入眼镜下
  212. obj_model3.SetActive(false);
  213. scence4flooreffict.SetActive(true);
  214. obj_model4.SetActive(true);
  215. changeUIScenes4or5.SetActive(true);
  216. Invoke("Falsescence4Floor", 2.7f);
  217. MapDaoHangShowOrHeid(false);
  218. }
  219. private void Falsescence4Floor()
  220. {
  221. scence4flooreffict.gameObject.SetActive(false);
  222. }
  223. /// <summary>
  224. ///打开Scence3
  225. /// </summary>
  226. public void obj_model3true()
  227. {
  228. // ScencesIntheGlasse("Scenes4_3D");//场景2放入眼镜下
  229. // XieTongButton.gameObject.SetActive(true);
  230. obj_model3.SetActive(true);
  231. obj_model4.SetActive(false);
  232. obj_model5.SetActive(false);
  233. MapDaoHangShowOrHeid(false);
  234. }
  235. /// <summary>
  236. /// 打开Scence5
  237. /// </summary>
  238. public void obj_model5true()
  239. {
  240. ScencesIntheGlasse("Scenes3_2D");//场景2放入眼镜下
  241. //ScencesIntheGlasse("Scenes4_3D");//场景2放入眼镜下
  242. obj_model3.SetActive(false);
  243. obj_model4.SetActive(false);
  244. obj_model5.SetActive(true);
  245. MapDaoHangShowOrHeid(true);
  246. //fooldObj.SetActive(true);
  247. // fooldObj.GetComponent<MeshRenderer>().material.SetFloat("_Brightness", 0f);
  248. changeUIScenes4or5.SetActive(true);
  249. }
  250. public void MapDaoHangShowOrHeid(bool isB)
  251. {
  252. if(isB)
  253. {
  254. DaoHangMap.SetActive(true);
  255. }
  256. else
  257. {
  258. DaoHangMap.SetActive(false);
  259. }
  260. }
  261. /// <summary>
  262. /// 将地形场景放入眼镜下
  263. /// </summary>
  264. public void ScencesIntheGlasse(string Scence)
  265. {
  266. switch (Scence)
  267. {
  268. case "Scenes3_2D":
  269. obj_model3.transform.parent = SvrManager.Instance.head.transform;
  270. Invoke("objmodle3dely", 2.7f);
  271. break;
  272. case "Scenes4_3D":
  273. //obj_model4.transform.parent = SvrManager.Instance.head.transform;
  274. ////obj_model4.transform.localPosition = new Vector3(0.58f, -1.51f, 0.12f);//赋予差值的位置
  275. ////obj_model4.transform.localRotation = Quaternion.Euler(90f, 180f, 0f);
  276. //Invoke("objmodle4dely", 2.7f);
  277. break;
  278. }
  279. }
  280. public void objmodle3dely()
  281. {
  282. // obj_model3.transform.localPosition = new Vector3(0.02f, -0.88f, 1.786f);//赋予差值的位置
  283. obj_model3.transform.localRotation = Quaternion.Euler(0f, 180f, 0f);
  284. }
  285. public void objmodle4dely()
  286. {
  287. obj_model4.transform.localPosition = new Vector3(0.58f, -1.51f, 0.12f);//赋予差值的位置
  288. obj_model4.transform.localRotation = Quaternion.Euler(90f, 180f, 0f);
  289. }
  290. public GameObject scence3followPos;
  291. /// <summary>
  292. /// 将地形场景放入Gamescence下
  293. /// </summary>
  294. public void ScencesIntheGameScence(string Scence)
  295. {
  296. switch (Scence)
  297. {
  298. case "Scenes3_2D":
  299. obj_model3.transform.parent = gamescence.transform;
  300. obj_model3.transform.position = scence3followPos.transform.position;
  301. // Debug.Log(scence3followPos.transform.localPosition + "旋转度");
  302. obj_model3.transform.localRotation = Quaternion.Euler(0, obj_model3.transform.localEulerAngles.y, 0);
  303. break;
  304. // case "Scenes4_3D":
  305. //obj_model4.transform.localPosition = new Vector3(obj_model4.transform.localPosition.x, obj_model4.transform.localPosition.y, 0.12f);
  306. // obj_model4.transform.parent = gamescence.transform;
  307. //obj_model4.transform.localPosition = new Vector3(obj_model4.transform.position.x, -1.7f, obj_model4.transform.position.z);
  308. //obj_model4.transform.localRotation = Quaternion.Euler(90, obj_model4.transform.localEulerAngles.y, 0);
  309. // break;
  310. }
  311. }
  312. public void ButtonBoxManage(int Num)
  313. {
  314. for (int i = 0; i < scence3button.Length; i++)
  315. {
  316. if (Num==i)
  317. {
  318. scence3button[i].gameObject.GetComponent<BoxCollider>().enabled = false;
  319. }
  320. else
  321. {
  322. scence3button[i].gameObject.GetComponent<BoxCollider>().enabled = true;
  323. }
  324. }
  325. for (int i = 0; i < scence4or5button.Length; i++)
  326. {
  327. if (Num == i)
  328. {
  329. scence4or5button[i].gameObject.GetComponent<BoxCollider>().enabled = false;
  330. }
  331. else
  332. {
  333. scence4or5button[i].gameObject.GetComponent<BoxCollider>().enabled = true;
  334. }
  335. }
  336. }
  337. int size = 0;
  338. void PartAnyKeyEventDelegate(InputKeyCode keyCode, InputDevicePartBase part)
  339. {
  340. // Debug.Log("条件++++++++++++++++++++++++scence5Iscollision=" + scence5Iscollision);
  341. if (scenesName == "scenes5"&& scence5Iscollision==false)
  342. {
  343. Debug.Log("david key down");
  344. UserClick("ButtonFooldPanle");
  345. }
  346. else
  347. {
  348. //GameObject go = Resources.Load("Cubess") as GameObject;
  349. //Instantiate(go, new Vector3(3, 1f, 0), Quaternion.identity);
  350. }
  351. }
  352. void OnDestory()
  353. {
  354. DispatcherBase.KeyDownDelegateUnRegister(PartAnyKeyEventDelegate);
  355. }
  356. /// <summary>
  357. /// 满足显示制造敌人面板条件(将方法挂在切换场景按钮上)
  358. /// </summary>
  359. public void PremiseconditionEenemy()
  360. {
  361. scence5Iscollision = false;
  362. }
  363. /// <summary>
  364. /// 不满足显示创造敌人面板条件
  365. /// </summary>
  366. public void UnPremiseconditionEenemy()
  367. {
  368. scence5Iscollision = true;
  369. }
  370. }