MakeEneutralManager.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using SC.XR.Unity.Module_InputSystem;
  6. public class MakeEneutralManager : MonoBehaviour
  7. {
  8. // Start is called before the first frame update
  9. public GameObject[] choiceTypeOfWorkButtons;//选择工种信息按钮
  10. public Text textX;
  11. public Text textY;
  12. private float numX;
  13. private float numY;
  14. private int increment;//增量
  15. private GameObject TypeOfWorlPrefab;//工种
  16. private string typeOfWork;
  17. public Game3DInputField button3DKey;
  18. public TextMesh button3DText;
  19. public List<GameObject> typeOfEnutralOrenemyList = new List<GameObject>();
  20. public GameObject fooldObj;//地面碰撞体
  21. public GameObject handRot;//记录hand子物体的旋转
  22. private int eneutraNum;
  23. public static string posEnmeyIndexString;
  24. public static int posEnmeyIndex;
  25. private float produceEnmeyDis = 10f;//敌人产生的位置在摄像机前20米
  26. private Vector3 enemyGpsPos;
  27. private double gpsNum = 20;
  28. private SvrPlugin plugin = null;
  29. float[] gness = new float[3];
  30. float gpsX, gpsY, gpsZ;
  31. public TextMesh Tx4;
  32. public static int MakeEenmyIndex;
  33. void Start()
  34. {
  35. plugin = SvrPlugin.Instance;
  36. numX = 50;
  37. numY = 50;
  38. SetUIText_XorY(numX, numY);
  39. increment = 50;
  40. ChangeChoiceTypeOfWorkButtons(3);
  41. typeOfWork = "EnemyTypeOfWork1";
  42. TypeOfWorlPrefab = Resources.Load("PlayerTypeOfWork") as GameObject;
  43. //this.transform.parent = SvrManager.Instance.head.transform;
  44. //handRot.transform.parent = SvrManager.Instance.head.transform;
  45. //this.transform.rotation = Quaternion.Euler(0, 0, 0);
  46. //handRot.transform.rotation = Quaternion.Euler(0, 0, 0);
  47. eneutraNum = UnityEngine.Random.Range(0, 1000000); //随机下标
  48. //numX = 999999;
  49. //numY = 999999;
  50. //typeOfWork = "s";
  51. // this.gameObject.SetActive(false);
  52. }
  53. public static void ChangeEnemyIndex(string str)
  54. {
  55. string[] strs = str.Split(',');
  56. posEnmeyIndexString = strs[1];
  57. posEnmeyIndex = int.Parse(posEnmeyIndexString);
  58. }
  59. IEnumerator MakeEneutra()
  60. {
  61. if (typeOfWork != "" && typeOfWork != null)
  62. {
  63. eneutraNum += 1;
  64. // MakeEenemyPoint();
  65. yield return new WaitUntil(() => plugin.IsInitialized() == true);
  66. //plugin.getGnss(ref gpsNum, gness);
  67. gpsX = gness[0];
  68. gpsY = 0;
  69. gpsZ = gness[1];
  70. enemyGpsPos = new Vector3(gpsX, gpsY, gpsZ);//眼前前方 20米处坐标
  71. // Debug.Log("20米+++++++++++++++++++++++++++++++++++++++++++++++" + enemyGpsPos);
  72. Tx4.text = enemyGpsPos.ToString();
  73. Vector3 linePosition = SvrManager.Instance.head.transform.position;// inputDevicePartUIBase.modelBase.lineIndicate.StartPoint.transform.position;
  74. Vector3 lineForward = SvrManager.Instance.head.transform.forward;// part.inputDevicePartUIBase.modelBase.lineIndicate.StartPoint.transform.forward;
  75. Vector3 worldPosition = linePosition + (lineForward * produceEnmeyDis);
  76. GameObject eneutraOrEnemy = Instantiate(TypeOfWorlPrefab, new Vector3(worldPosition.x, SvrManager.Instance.head.position.y, worldPosition.z), Quaternion.identity);
  77. //eneutraOrEnemy.transform.parent = GameObject.Find("SceneRoot").transform
  78. Debug.Log(eneutraOrEnemy.transform.position);
  79. eneutraOrEnemy.GetComponent<MiniMapFit>().action = "MakeTypeOfWork";
  80. eneutraOrEnemy.GetComponent<MiniMapFit>().id = eneutraOrEnemy.GetComponent<MiniMapFit>().action + eneutraNum.ToString();
  81. eneutraOrEnemy.GetComponent<MiniMapFit>().des = "Enemy" + "," + eneutraNum.ToString();//+ enemyInde;
  82. string posX = (worldPosition.x).ToString();//自身slam坐标
  83. string posZ = (worldPosition.z).ToString();
  84. eneutraOrEnemy.GetComponent<MiniMapFit>().pos = posX + "_" + SvrManager.Instance.head.position.y + "_" + posZ;
  85. eneutraOrEnemy.GetComponent<MiniMapFit>().eul = "";
  86. eneutraOrEnemy.GetComponent<MiniMapFit>().typeOfWork = typeOfWork;
  87. eneutraOrEnemy.GetComponent<MiniMapFit>().GpsPlayerPos = worldPosition;
  88. Debug.Log(worldPosition + "11111111111111111111111111");
  89. eneutraOrEnemy.GetComponent<MiniMapFit>().thisCurrentMinMapFitIndex = PosCommunication.currentMinMapFitIndex + 1;
  90. MakeEenmyIndex = eneutraOrEnemy.GetComponent<MiniMapFit>().thisCurrentMinMapFitIndex;
  91. // eneutraOrEnemy.GetComponent<MiniMapFit>().GpsPlayerPosStr = enemyGpsPos.ToString();// 敌人的Gps坐标。
  92. eneutraOrEnemy.GetComponent<MiniMapFit>().GpsPlayerPosStr = (worldPosition.x).ToString() + "_" + "0" + "_" + (worldPosition.z).ToString();// 敌人的Gps坐标。
  93. // Debug.Log(enemyGpsPos + "GpsenrmyGps————————————————————————————————————————");
  94. // Debug.Log(eneutraOrEnemy.GetComponent<MiniMapFit>().GpsPlayerPosStr + " GPSshu");
  95. // eneutraOrEnemy.GetComponent<MiniMapFit>().GpsPlayerPos = new Vector3(367300, gpsY, 3457500);
  96. typeOfEnutralOrenemyList.Add(eneutraOrEnemy);
  97. HeidThisPanel();
  98. }
  99. else
  100. {
  101. button3DText.text = "请选择类型";
  102. }
  103. }
  104. public void MakeAIAircraftEneutra(string typeOfWorks, float numx, float numy, float numz)
  105. {
  106. if (typeOfWorks != "" && typeOfWorks != null)
  107. {
  108. eneutraNum += 1;
  109. // MakeEenemyPoint();
  110. TypeOfWorlPrefab = Resources.Load("PlayerTypeOfWork") as GameObject;
  111. GameObject eneutraOrEnemy = Instantiate(TypeOfWorlPrefab, new Vector3(numX, numy, numY), Quaternion.identity);
  112. //eneutraOrEnemy.transform.parent = GameObject.Find("SceneRoot").transform;
  113. eneutraOrEnemy.GetComponent<MiniMapFit>().action = "MakeAIAircraft";
  114. eneutraOrEnemy.GetComponent<MiniMapFit>().id = eneutraOrEnemy.GetComponent<MiniMapFit>().action + eneutraNum.ToString();
  115. eneutraOrEnemy.GetComponent<MiniMapFit>().des = "Enemy" + "," + eneutraNum.ToString();//+ enemyInde;
  116. eneutraOrEnemy.GetComponent<MiniMapFit>().pos = numx.ToString() + "_" + "0" + "_" + numz.ToString();
  117. eneutraOrEnemy.GetComponent<MiniMapFit>().eul = "";
  118. eneutraOrEnemy.GetComponent<MiniMapFit>().typeOfWork = typeOfWorks;
  119. HeidThisPanel();
  120. }
  121. else
  122. {
  123. button3DText.text = "请选择类型";
  124. }
  125. }
  126. private void HeidThisPanel()
  127. {
  128. // this.transform.parent = SvrManager.Instance.head.transform;
  129. this.transform.localPosition = new Vector3(0, 0.06f, 0.6f);
  130. this.transform.rotation = Quaternion.Euler(0, 0, 0);
  131. // fooldObj.GetComponent<BoxCollider>().enabled = true;
  132. this.gameObject.SetActive(false);
  133. }
  134. public void UserChoiceClickTypeOfWrokButton(string buttonName)
  135. {
  136. switch (buttonName)
  137. {
  138. case "EneutralTypeOfWork1":
  139. ChangeChoiceTypeOfWorkButtons(0);
  140. typeOfWork = "EneutralTypeOfWork1";
  141. break;
  142. case "EneutralTypeOfWorkTanke":
  143. ChangeChoiceTypeOfWorkButtons(1);
  144. typeOfWork = "EneutralTanke";
  145. break;
  146. case "EneutralTypeOfWork2":
  147. ChangeChoiceTypeOfWorkButtons(2);
  148. typeOfWork = "EneutralTypeOfWork2";
  149. break;
  150. case "EnemyTypeOfWork1":
  151. ChangeChoiceTypeOfWorkButtons(3);
  152. typeOfWork = "EnemyTypeOfWork1";
  153. break;
  154. case "EnemyTypeOfWorkTanke":
  155. ChangeChoiceTypeOfWorkButtons(4);
  156. typeOfWork = "EnemyTanke";
  157. break;
  158. case "EnemyTypeOfWork2":
  159. ChangeChoiceTypeOfWorkButtons(5);
  160. typeOfWork = "EnemyTypeOfWork2";
  161. break;
  162. case "HeidThisPanel":
  163. GameManager.instacne.scence5Iscollision = false;
  164. HeidThisPanel();
  165. break;
  166. }
  167. }
  168. private void ChangeChoiceTypeOfWorkButtons(int num)
  169. {
  170. for (int i = 0; i < choiceTypeOfWorkButtons.Length; i++)
  171. {
  172. if (i == num)
  173. {
  174. choiceTypeOfWorkButtons[i].GetComponent<MakeEneutralButton>().SetUserClickThis(true);
  175. }
  176. else
  177. {
  178. choiceTypeOfWorkButtons[i].GetComponent<MakeEneutralButton>().SetUserClickThis(false);
  179. }
  180. }
  181. }
  182. public void UserClickXorYButton(string buttonName)
  183. {
  184. switch (buttonName)
  185. {
  186. case "XaddButton":
  187. numX += increment;
  188. SetUIText_XorY(numX, numY);
  189. break;
  190. case "XreduceButton":
  191. numX += -increment;
  192. SetUIText_XorY(numX, numY);
  193. break;
  194. case "YaddButton":
  195. numY += increment;
  196. SetUIText_XorY(numX, numY);
  197. break;
  198. case "YreduceButton":
  199. numY += -increment;
  200. SetUIText_XorY(numX, numY);
  201. break;
  202. case "SuerMakeEneutralButton":
  203. GameManager.instacne.scence5Iscollision = false;
  204. StartCoroutine(MakeEneutra());
  205. break;
  206. }
  207. }
  208. private void SetUIText_XorY(float myx, float myy)
  209. {
  210. textX.text = myx.ToString();
  211. textY.text = myy.ToString();
  212. }
  213. public GameObject[] map2D_Point;
  214. private int enemyInde = 0;
  215. private void MakeEenemyPoint()
  216. {
  217. if (PosCommunication.IsPlayerjoin == true)
  218. {
  219. enemyInde = posEnmeyIndex;
  220. }
  221. for (int i = 0; i < map2D_Point.Length; i++)
  222. {
  223. if (enemyInde == i)
  224. {
  225. numX = map2D_Point[i].transform.position.x;
  226. numY = map2D_Point[i].transform.position.z;
  227. Debug.Log(map2D_Point[i].name + "名字" + numX + " 位置" + numY);
  228. }
  229. }
  230. enemyInde += 1;
  231. if (enemyInde > map2D_Point.Length)
  232. {
  233. enemyInde = 0;//如果大于 map2D_Point.Length则enemyInde=0;
  234. }
  235. }
  236. }