123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using SC.XR.Unity.Module_InputSystem;
- public class MakeEneutralManager : MonoBehaviour
- {
- // Start is called before the first frame update
- public GameObject[] choiceTypeOfWorkButtons;//选择工种信息按钮
- public Text textX;
- public Text textY;
- private float numX;
- private float numY;
- private int increment;//增量
- private GameObject TypeOfWorlPrefab;//工种
- private string typeOfWork;
- public Game3DInputField button3DKey;
- public TextMesh button3DText;
- public List<GameObject> typeOfEnutralOrenemyList = new List<GameObject>();
- public GameObject fooldObj;//地面碰撞体
- public GameObject handRot;//记录hand子物体的旋转
- private int eneutraNum;
- public static string posEnmeyIndexString;
- public static int posEnmeyIndex;
- private float produceEnmeyDis = 10f;//敌人产生的位置在摄像机前20米
- private Vector3 enemyGpsPos;
- private double gpsNum = 20;
- private SvrPlugin plugin = null;
- float[] gness = new float[3];
- float gpsX, gpsY, gpsZ;
- public TextMesh Tx4;
- public static int MakeEenmyIndex;
- void Start()
- {
- plugin = SvrPlugin.Instance;
- numX = 50;
- numY = 50;
- SetUIText_XorY(numX, numY);
- increment = 50;
- ChangeChoiceTypeOfWorkButtons(3);
- typeOfWork = "EnemyTypeOfWork1";
- TypeOfWorlPrefab = Resources.Load("PlayerTypeOfWork") as GameObject;
- //this.transform.parent = SvrManager.Instance.head.transform;
- //handRot.transform.parent = SvrManager.Instance.head.transform;
- //this.transform.rotation = Quaternion.Euler(0, 0, 0);
- //handRot.transform.rotation = Quaternion.Euler(0, 0, 0);
- eneutraNum = UnityEngine.Random.Range(0, 1000000); //随机下标
- //numX = 999999;
- //numY = 999999;
- //typeOfWork = "s";
- // this.gameObject.SetActive(false);
- }
- public static void ChangeEnemyIndex(string str)
- {
- string[] strs = str.Split(',');
- posEnmeyIndexString = strs[1];
- posEnmeyIndex = int.Parse(posEnmeyIndexString);
- }
- IEnumerator MakeEneutra()
- {
- if (typeOfWork != "" && typeOfWork != null)
- {
- eneutraNum += 1;
- // MakeEenemyPoint();
- yield return new WaitUntil(() => plugin.IsInitialized() == true);
- //plugin.getGnss(ref gpsNum, gness);
- gpsX = gness[0];
- gpsY = 0;
- gpsZ = gness[1];
- enemyGpsPos = new Vector3(gpsX, gpsY, gpsZ);//眼前前方 20米处坐标
- // Debug.Log("20米+++++++++++++++++++++++++++++++++++++++++++++++" + enemyGpsPos);
- Tx4.text = enemyGpsPos.ToString();
- Vector3 linePosition = SvrManager.Instance.head.transform.position;// inputDevicePartUIBase.modelBase.lineIndicate.StartPoint.transform.position;
- Vector3 lineForward = SvrManager.Instance.head.transform.forward;// part.inputDevicePartUIBase.modelBase.lineIndicate.StartPoint.transform.forward;
- Vector3 worldPosition = linePosition + (lineForward * produceEnmeyDis);
- GameObject eneutraOrEnemy = Instantiate(TypeOfWorlPrefab, new Vector3(worldPosition.x, SvrManager.Instance.head.position.y, worldPosition.z), Quaternion.identity);
- //eneutraOrEnemy.transform.parent = GameObject.Find("SceneRoot").transform
- Debug.Log(eneutraOrEnemy.transform.position);
- eneutraOrEnemy.GetComponent<MiniMapFit>().action = "MakeTypeOfWork";
- eneutraOrEnemy.GetComponent<MiniMapFit>().id = eneutraOrEnemy.GetComponent<MiniMapFit>().action + eneutraNum.ToString();
- eneutraOrEnemy.GetComponent<MiniMapFit>().des = "Enemy" + "," + eneutraNum.ToString();//+ enemyInde;
- string posX = (worldPosition.x).ToString();//自身slam坐标
- string posZ = (worldPosition.z).ToString();
- eneutraOrEnemy.GetComponent<MiniMapFit>().pos = posX + "_" + SvrManager.Instance.head.position.y + "_" + posZ;
- eneutraOrEnemy.GetComponent<MiniMapFit>().eul = "";
- eneutraOrEnemy.GetComponent<MiniMapFit>().typeOfWork = typeOfWork;
- eneutraOrEnemy.GetComponent<MiniMapFit>().GpsPlayerPos = worldPosition;
- Debug.Log(worldPosition + "11111111111111111111111111");
- eneutraOrEnemy.GetComponent<MiniMapFit>().thisCurrentMinMapFitIndex = PosCommunication.currentMinMapFitIndex + 1;
- MakeEenmyIndex = eneutraOrEnemy.GetComponent<MiniMapFit>().thisCurrentMinMapFitIndex;
- // eneutraOrEnemy.GetComponent<MiniMapFit>().GpsPlayerPosStr = enemyGpsPos.ToString();// 敌人的Gps坐标。
- eneutraOrEnemy.GetComponent<MiniMapFit>().GpsPlayerPosStr = (worldPosition.x).ToString() + "_" + "0" + "_" + (worldPosition.z).ToString();// 敌人的Gps坐标。
- // Debug.Log(enemyGpsPos + "GpsenrmyGps————————————————————————————————————————");
- // Debug.Log(eneutraOrEnemy.GetComponent<MiniMapFit>().GpsPlayerPosStr + " GPSshu");
- // eneutraOrEnemy.GetComponent<MiniMapFit>().GpsPlayerPos = new Vector3(367300, gpsY, 3457500);
- typeOfEnutralOrenemyList.Add(eneutraOrEnemy);
- HeidThisPanel();
- }
- else
- {
- button3DText.text = "请选择类型";
- }
- }
- public void MakeAIAircraftEneutra(string typeOfWorks, float numx, float numy, float numz)
- {
- if (typeOfWorks != "" && typeOfWorks != null)
- {
- eneutraNum += 1;
- // MakeEenemyPoint();
- TypeOfWorlPrefab = Resources.Load("PlayerTypeOfWork") as GameObject;
- GameObject eneutraOrEnemy = Instantiate(TypeOfWorlPrefab, new Vector3(numX, numy, numY), Quaternion.identity);
- //eneutraOrEnemy.transform.parent = GameObject.Find("SceneRoot").transform;
- eneutraOrEnemy.GetComponent<MiniMapFit>().action = "MakeAIAircraft";
- eneutraOrEnemy.GetComponent<MiniMapFit>().id = eneutraOrEnemy.GetComponent<MiniMapFit>().action + eneutraNum.ToString();
- eneutraOrEnemy.GetComponent<MiniMapFit>().des = "Enemy" + "," + eneutraNum.ToString();//+ enemyInde;
- eneutraOrEnemy.GetComponent<MiniMapFit>().pos = numx.ToString() + "_" + "0" + "_" + numz.ToString();
- eneutraOrEnemy.GetComponent<MiniMapFit>().eul = "";
- eneutraOrEnemy.GetComponent<MiniMapFit>().typeOfWork = typeOfWorks;
- HeidThisPanel();
- }
- else
- {
- button3DText.text = "请选择类型";
- }
- }
- private void HeidThisPanel()
- {
- // this.transform.parent = SvrManager.Instance.head.transform;
- this.transform.localPosition = new Vector3(0, 0.06f, 0.6f);
- this.transform.rotation = Quaternion.Euler(0, 0, 0);
- // fooldObj.GetComponent<BoxCollider>().enabled = true;
- this.gameObject.SetActive(false);
- }
- public void UserChoiceClickTypeOfWrokButton(string buttonName)
- {
- switch (buttonName)
- {
- case "EneutralTypeOfWork1":
- ChangeChoiceTypeOfWorkButtons(0);
- typeOfWork = "EneutralTypeOfWork1";
- break;
- case "EneutralTypeOfWorkTanke":
- ChangeChoiceTypeOfWorkButtons(1);
- typeOfWork = "EneutralTanke";
- break;
- case "EneutralTypeOfWork2":
- ChangeChoiceTypeOfWorkButtons(2);
- typeOfWork = "EneutralTypeOfWork2";
- break;
- case "EnemyTypeOfWork1":
- ChangeChoiceTypeOfWorkButtons(3);
- typeOfWork = "EnemyTypeOfWork1";
- break;
- case "EnemyTypeOfWorkTanke":
- ChangeChoiceTypeOfWorkButtons(4);
- typeOfWork = "EnemyTanke";
- break;
- case "EnemyTypeOfWork2":
- ChangeChoiceTypeOfWorkButtons(5);
- typeOfWork = "EnemyTypeOfWork2";
- break;
- case "HeidThisPanel":
- GameManager.instacne.scence5Iscollision = false;
- HeidThisPanel();
- break;
- }
- }
- private void ChangeChoiceTypeOfWorkButtons(int num)
- {
- for (int i = 0; i < choiceTypeOfWorkButtons.Length; i++)
- {
- if (i == num)
- {
- choiceTypeOfWorkButtons[i].GetComponent<MakeEneutralButton>().SetUserClickThis(true);
- }
- else
- {
- choiceTypeOfWorkButtons[i].GetComponent<MakeEneutralButton>().SetUserClickThis(false);
- }
- }
- }
- public void UserClickXorYButton(string buttonName)
- {
- switch (buttonName)
- {
- case "XaddButton":
- numX += increment;
- SetUIText_XorY(numX, numY);
- break;
- case "XreduceButton":
- numX += -increment;
- SetUIText_XorY(numX, numY);
- break;
- case "YaddButton":
- numY += increment;
- SetUIText_XorY(numX, numY);
- break;
- case "YreduceButton":
- numY += -increment;
- SetUIText_XorY(numX, numY);
- break;
- case "SuerMakeEneutralButton":
- GameManager.instacne.scence5Iscollision = false;
- StartCoroutine(MakeEneutra());
- break;
- }
- }
- private void SetUIText_XorY(float myx, float myy)
- {
- textX.text = myx.ToString();
- textY.text = myy.ToString();
- }
- public GameObject[] map2D_Point;
- private int enemyInde = 0;
- private void MakeEenemyPoint()
- {
- if (PosCommunication.IsPlayerjoin == true)
- {
- enemyInde = posEnmeyIndex;
- }
- for (int i = 0; i < map2D_Point.Length; i++)
- {
- if (enemyInde == i)
- {
- numX = map2D_Point[i].transform.position.x;
- numY = map2D_Point[i].transform.position.z;
- Debug.Log(map2D_Point[i].name + "名字" + numX + " 位置" + numY);
- }
- }
- enemyInde += 1;
- if (enemyInde > map2D_Point.Length)
- {
- enemyInde = 0;//如果大于 map2D_Point.Length则enemyInde=0;
- }
- }
- }
|