123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class MapCircularSignManager : MonoBehaviour {
- // Start is called before the first frame update
- public GameObject[] TypeOfWorkModel;
- public GameObject messagePanel;
- public GameObject initRot;
- public Text nameText;
- public Text posText;
- public Text posTextX, posTextZ;
- public Text disText;
- public TextMesh objHeadUpPostext;
- public GameObject dangerousPanl;
- private float angleSpeed = 2000f;
- public string targetPos;
- private bool isRotate = true;
- private Vector3 typeOfWorkPosV3;
- private Vector3 typeOfWorkRotV3;
- // private GameObject PlayerTypeLogoPoint;//产生的人物标识点(小圆球)
- public string nameStr, endPosV3, endRotV3;//界面最终显示的值
- public float endDis;//距离
- private string typeOfWorks;
- private string changeUTF8TypeOfWorks;
- public Vector3 GpsEnemyPos;//敌人真实的Gps坐标
- public float a;
- public float b;
- public float c;
- public Text duifang;
- public Text ziji;
- public Text zuizhong;
- public enum TypeOfWork {
- typeNull,
- FriendlyForcesTypeOfWork1,
- FriendlyForcesTypeOfWork2,
- FriendlyForcesTank,
- EnemyTypeOfWork1,
- EnemyTypeOfWork2,
- EnemyTanke,
- EneutralTypeOfWork1,
- EneutralTypeOfWork2,
- EneutralTanke,
- AIAircraft,
- }
- public TypeOfWork typeOfWork;
- private float playerY;
- private void Start() {
- UserExit();
- playerY = SvrManager.Instance.head.position.y;
- // AddPlayerTypeOfWorkLogoPoint();
- //duifang.text = a.ToString();
- //ziji.text = b.ToString();
- //zuizhong.text = c.ToString();
- }
- //public void AddPlayerTypeOfWorkLogoPoint()
- //{
- //GameObject PlayerPoint = Resources.Load("sphere") as GameObject;
- // PlayerTypeLogoPoint = Instantiate(PlayerPoint) as GameObject;
- // Debug.Log(PlayerTypeLogoPoint.name + "加载物体");
- // PlayerTypeLogoPoint.transform.parent = GameObject.Find("GameScenes/Scenes5/huan").transform;
- // PlayerTypeLogoPoint.transform.localPosition = new Vector3(0, 0, 0);
- // PlayerTypeLogoPoint.transform.rotation = Quaternion.Euler(0, 0, 0);
- // PlayerTypeLogoPoint.GetComponent<LookAtPlayer>().player = this.gameObject.transform.GetChild(0).gameObject;
- //}
- public void SetTypeOfWork(string str) {
- typeOfWorks = str;
- switch(str) {
- case "AIAircraft":
- typeOfWork = TypeOfWork.AIAircraft;
- objHeadUpPostext.color = new Color(255f / 255f, 4f / 255f, 4f / 255f);//红色
- break;
- //友方单位
- case "FriendlyForcesTypeOfWork1":
- typeOfWork = TypeOfWork.FriendlyForcesTypeOfWork1;
- objHeadUpPostext.color = new Color(255f / 255f, 4f / 255f, 4f / 255f);//红色
- break;
- case "FriendlyForcesTypeOfWork2":
- typeOfWork = TypeOfWork.FriendlyForcesTypeOfWork2;
- objHeadUpPostext.color = new Color(255f / 255f, 4f / 255f, 4f / 255f);//红色
- break;
- case "FriendlyForcesTank":
- typeOfWork = TypeOfWork.FriendlyForcesTank;
- objHeadUpPostext.color = new Color(255f / 255f, 4f / 255f, 4f / 255f);//红色
- break;
- //敌方单位
- case "EnemyTypeOfWork1":
- typeOfWork = TypeOfWork.EnemyTypeOfWork1;
- objHeadUpPostext.color = new Color(0, 125f / 255f, 255f / 255f);//蓝色
- break;
- case "EnemyTypeOfWork2":
- typeOfWork = TypeOfWork.EnemyTypeOfWork2;
- objHeadUpPostext.color = new Color(0, 125f / 255f, 255f / 255f);//蓝色
- break;
- case "EnemyTanke":
- typeOfWork = TypeOfWork.EnemyTanke;
- objHeadUpPostext.color = new Color(0, 125f / 255f, 255f / 255f);//蓝色
- break;
- //中方单位
- case "EneutralTypeOfWork1":
- typeOfWork = TypeOfWork.EneutralTypeOfWork1;
- break;
- case "EneutralTypeOfWork2":
- typeOfWork = TypeOfWork.EneutralTypeOfWork2;
- break;
- case "EneutralTanke":
- typeOfWork = TypeOfWork.EneutralTanke;
- break;
- }
- TyepEnum();
- }
- private void TyepEnum() {
- switch(typeOfWork) {
- case TypeOfWork.typeNull:
- ShowGameObj(-1);
- break;
- case TypeOfWork.FriendlyForcesTypeOfWork1:
- ShowGameObj(0);
- break;
- case TypeOfWork.FriendlyForcesTypeOfWork2:
- ShowGameObj(1);
- break;
- case TypeOfWork.FriendlyForcesTank:
- ShowGameObj(2);
- break;
- case TypeOfWork.EnemyTypeOfWork1:
- ShowGameObj(3);
- break;
- case TypeOfWork.EnemyTypeOfWork2:
- ShowGameObj(4);
- break;
- case TypeOfWork.EnemyTanke:
- ShowGameObj(5);
- break;
- case TypeOfWork.EneutralTypeOfWork1:
- ShowGameObj(6);
- break;
- case TypeOfWork.EneutralTypeOfWork2:
- ShowGameObj(7);
- break;
- case TypeOfWork.EneutralTanke:
- ShowGameObj(8);
- break;
- case TypeOfWork.AIAircraft:
- ShowGameObj(9);
- break;
- }
- }
- /// <summary>
- /// 跟随 设备使用者 并看向指定目标
- /// </summary>
- private void LateUpdate() {
- //if(typeOfWorks == "FriendlyForcesTypeOfWork1") {
- // var velocity = Vector3.zero;
- // Vector3 handPos = new Vector3(SvrManager.Instance.head.transform.position.x, SvrManager.Instance.head.transform.position.y - 1.7f, SvrManager.Instance.head.transform.position.z);
- // // Vector3 handPos = new Vector3(SvrManager.Instance.head.transform.position.x, -1.72f, SvrManager.Instance.head.transform.position.z);
- // transform.position = Vector3.SmoothDamp(this.transform.position, handPos, ref velocity, 0.001f, 1000f);
- // if(typeOfWorks == "EnemyTypeOfWork1" || typeOfWorks == "EnemyTypeOfWork2" || typeOfWorks == "EnemyTanke")//造的敌人单位
- // {
- // //ThisInitRotLookAt(GpsEnemyPos.x + "_" + GpsEnemyPos.y + "_" + GpsEnemyPos.z);
- // ThisInitRotLookAt(targetPos);
- // } else if(typeOfWorks == "FriendlyForcesTypeOfWork1" || typeOfWorks == "FriendlyForcesTypeOfWork2" || typeOfWorks == "FriendlyForcesTank") {
- // ThisInitRotLookAt(targetPos);
- // } else if(typeOfWorks == "AIAircraft") {
- // ThisInitRotLookAt(targetPos);
- // }
- //} else if(typeOfWorks == "EneutralTypeOfWork1" || typeOfWorks == "EneutralTypeOfWork2" || typeOfWorks == "EneutralTanke") {
- var velocity = Vector3.zero;
- Vector3 handPos = new Vector3(SvrManager.Instance.head.transform.position.x, playerY - 1.72f, SvrManager.Instance.head.transform.position.z);
- // Vector3 handPos = new Vector3(SvrManager.Instance.head.transform.position.x, -1.72f, SvrManager.Instance.head.transform.position.z);
- transform.position = Vector3.SmoothDamp(this.transform.position, handPos, ref velocity, 0.001f, 1000f);
- if(typeOfWorks == "EnemyTypeOfWork1" || typeOfWorks == "EnemyTypeOfWork2" || typeOfWorks == "EnemyTanke")//造的敌人单位
- {
- //ThisInitRotLookAt(GpsEnemyPos.x + "_" + GpsEnemyPos.y + "_" + GpsEnemyPos.z);
- ThisInitRotLookAt(targetPos);
- } else if(typeOfWorks == "FriendlyForcesTypeOfWork1" || typeOfWorks == "FriendlyForcesTypeOfWork2" || typeOfWorks == "FriendlyForcesTank") {
- ThisInitRotLookAt(targetPos);
- } else if(typeOfWorks == "AIAircraft") {
- ThisInitRotLookAt(targetPos);
- }
- // }
- SetTextvalue(nameStr, endPosV3, DisTance());
- }
- /// <summary>
- /// 根据 枚举 显示对应游戏物体
- /// </summary>
- /// <param name="index">0:友军1 ,1:友军2 ,2:友军坦克 ,3:敌军1 ,4:敌军2 ,5:敌军坦克</param>
- private void ShowGameObj(int index) {
- for(int i = 0; i < TypeOfWorkModel.Length; i++) {
- if(i == index) {
- TypeOfWorkModel[i].SetActive(true);
- } else {
- TypeOfWorkModel[i].SetActive(false);
- }
- }
- }
- public void SetTextvalue(string name, string pos, float dis) {
- typeOfWorkPosV3 = StrSubstringToV3(endPosV3);
- // typeOfWorkRotV3 = StrSubstringToV3(endRotV3);
- string v3Posx = typeOfWorkPosV3.x.ToString("f2");
- string v3Posy = typeOfWorkPosV3.y.ToString("f2");
- string v3Posz = typeOfWorkPosV3.z.ToString("f2");
- string v3Rotx = typeOfWorkPosV3.x.ToString("f2");
- string v3Roty = typeOfWorkPosV3.y.ToString("f2");
- string v3Rotz = typeOfWorkPosV3.z.ToString("f2");
- endPosV3 = v3Posx + "," + 0 + "," + v3Posz;
- endRotV3 = v3Rotx + "," + 0 + "," + v3Rotz;
- nameText.text = name;
- Debug.Log(name);
- if(name != "" || name != null) {
- string[] names = name.Split(',');
- UTF8ChangeName(typeOfWorks, names);
- }
- Vector3 v3Pos = StrSubstringToV3(pos);
- //去掉小数点
- double dispos = Math.Round(dis);
- disText.text = dispos.ToString() + "米";//距离
- if(typeOfWorks == "EnemyTypeOfWork1" || typeOfWorks == "EnemyTypeOfWork2" || typeOfWorks == "EnemyTanke")//造的敌人单位
- {
- posTextX.text = (GpsEnemyPos.x).ToString();
- posTextZ.text = (GpsEnemyPos.z).ToString();
- // objHeadUpPostext.text = GpsEnemyPos.ToString(); 显示gps
- objHeadUpPostext.text = dispos.ToString() + "米";//距离
- dangerousPanl.gameObject.SetActive(true);
- } else if(typeOfWorks == "FriendlyForcesTypeOfWork1" || typeOfWorks == "FriendlyForcesTypeOfWork2" || typeOfWorks == "FriendlyForcesTank")//造玩家单位
- {
- posTextX.text = (v3Pos.x).ToString();
- posTextZ.text = (v3Pos.z).ToString();
- //objHeadUpPostext.text = v3Pos.ToString();显示gps
- objHeadUpPostext.text = dispos.ToString() + "米";//距离
- dangerousPanl.gameObject.SetActive(false);
- }
- //10.30改
- else if(typeOfWorks == "AIAircraft") {
- float AIPosX = v3Pos.x + GameManager.instacne.gpsPosInitx;
- float AIPosZ = v3Pos.x + GameManager.instacne.gpsPosInitx;
- posTextX.text = AIPosX.ToString();
- posTextZ.text = AIPosZ.ToString();
- // objHeadUpPostext.text = AIPosX + "," + "0" + "," + AIPosZ;
- objHeadUpPostext.text = dispos.ToString() + "米";//距离
- dangerousPanl.gameObject.SetActive(false);
- }
- //10.30改
- }
- public void UTF8ChangeName(string str, string[] names) {
- if(str == "EnemyTypeOfWork1") {
- changeUTF8TypeOfWorks = "敌方陆军";
- nameText.color = new Color(0, 125f / 255f, 255f / 255f);//蓝色
- } else if(str == "EnemyTypeOfWork2") {
- changeUTF8TypeOfWorks = "敌方飞机";
- nameText.color = new Color(0, 125f / 255f, 255f / 255f);//蓝色
- } else if(str == "EnemyTanke") {
- changeUTF8TypeOfWorks = "敌方坦克";
- nameText.color = new Color(0, 125f / 255f, 255f / 255f);//蓝色
- } else if(str == "FriendlyForcesTypeOfWork1") {
- changeUTF8TypeOfWorks = "我方陆军";
- nameText.color = new Color(255f / 255f, 4f / 255f, 4f / 255f);//红色
- } else if(str == "FriendlyForcesTypeOfWork2") {
- changeUTF8TypeOfWorks = "我方飞机";
- nameText.color = new Color(255f / 255f, 4f / 255f, 4f / 255f);//红色
- } else if(str == "FriendlyForcesTank") {
- changeUTF8TypeOfWorks = "我方坦克";
- nameText.color = new Color(255f / 255f, 4f / 255f, 4f / 255f);//红色
- } else if(str == "AIAircraft") {
- changeUTF8TypeOfWorks = "我方无人机";
- nameText.color = new Color(255f / 255f, 4f / 255f, 4f / 255f);//红色
- }
- nameText.text = changeUTF8TypeOfWorks + names[1].ToString();
- }
- private bool isOpen;
- private float openShowTimer = 3;
- private float openShowInitTimer = 3;
- public void UserEnter() {
- isOpen = true;
- }
- public void UserExit() {
- // isOpen = false;
- }
- private void Update() {
- if(isOpen) {
- messagePanel.SetActive(true);
- if(openShowTimer > 0) {
- openShowTimer -= Time.deltaTime;
- } else {
- messagePanel.SetActive(false);
- openShowTimer = openShowInitTimer;
- isOpen = false;
- }
- }
- }
- private float DisTance() {
- // float diss = Vector3.Distance(StrSubstringToV3(endPosV3), SvrManager.Instance.head.transform.position);
- //Vector3 playerGpsPos = PosCommunication.shadowPos;
- float diss = 0;
- if(typeOfWorks == "EnemyTypeOfWork1" || typeOfWorks == "EnemyTypeOfWork2" || typeOfWorks == "EnemyTanke")//造的敌人单位
- {
- Debug.Log(GpsEnemyPos + "敌人的位置" + PosCommunication.shadowPosStatic + "自己的位置");
- diss = Vector3.Distance(GpsEnemyPos, PosCommunication.shadowPosStatic);
- } else if(typeOfWorks == "FriendlyForcesTypeOfWork1" || typeOfWorks == "FriendlyForcesTypeOfWork2" || typeOfWorks == "FriendlyForcesTank") {
- // Debug.Log(StrSubstringToV3(targetPos) + "友军的位置" + PosCommunication.shadowPos + "我的位置");
- diss = Vector3.Distance(StrSubstringToV3(targetPos), PosCommunication.shadowPosStatic);
- }
- //10.30修改,飞机暂时使用Slam值
- else if(typeOfWorks == "AIAircraft") {
- diss = Vector3.Distance(StrSubstringToV3(targetPos), SvrManager.Instance.head.transform.position);
- }
- //10.30修改
- return diss;
- }
- private float gpsX, gpsY, gpsZ;//用来做位置换算
- Vector3 v3Pos;
- public void ThisInitRotLookAt(string pos) {
- //posText.text = pos;//显示协同场景模型坐标位置
- //10.29修改 x和z是相反位置
- if(typeOfWorks == "EnemyTypeOfWork1" || typeOfWorks == "EnemyTypeOfWork2" || typeOfWorks == "EnemyTanke")//造的敌人单位
- {
- v3Pos = StrSubstringToV3(pos);
- } else if(typeOfWorks == "FriendlyForcesTypeOfWork1" || typeOfWorks == "FriendlyForcesTypeOfWork2" || typeOfWorks == "FriendlyForcesTank") {
- // Vector3 targetV3 = StrSubstringToV3(pos);
- //gpsX = targetV3.x - PosCommunication.shadowPos.x;
- //gpsY = targetV3.y - PosCommunication.shadowPos.y;
- //gpsZ = targetV3.z - PosCommunication.shadowPos.z;
- // v3Pos = new Vector3(gpsX, gpsY, gpsZ);
- v3Pos = StrSubstringToV3(pos);
- } else if(typeOfWorks == "AIAircraft") {
- v3Pos = StrSubstringToV3(pos);
- }
- // x和z是相反位置
- //10.29修改
- if(targetPos != null) {
- //Vector3 vec = (target.position - initRot.transform.position);
- Vector3 vecs = new Vector3(v3Pos.x - initRot.transform.position.x, 0, v3Pos.z - initRot.transform.position.z);
- Quaternion rotate = Quaternion.LookRotation(vecs);
- initRot.transform.localRotation = Quaternion.Slerp(initRot.transform.localRotation, rotate, angleSpeed);
- }
- }
- public static Vector3 StrSubstringToV3(string str) {
- if(str == null) {
- return new Vector3();
- }
- string[] s = str.Split('_');
- return new Vector3(float.Parse(s[0]), float.Parse(s[1]), float.Parse(s[2]));
- }
- }
|