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().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; } } /// /// 跟随 设备使用者 并看向指定目标 /// 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()); } /// /// 根据 枚举 显示对应游戏物体 /// /// 0:友军1 ,1:友军2 ,2:友军坦克 ,3:敌军1 ,4:敌军2 ,5:敌军坦克 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])); } }