123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class ModelMinMapArrow : MonoBehaviour {
- // Start is called before the first frame update
- public TextMesh textMesh;
- private int mapScaleX = 3000;
- private int mapScaleZ = 3000;
- public string typeOfWrok;
- public bool arrowOrmodel;//true为小箭头,,false为坦克飞机,人模型
- public Material[] arrowmatreial;
- public GameObject[] TypeOfWorkModel;
- private bool isArrowModle;
- private string currentModles;//当前模式
- private bool isNullParnet;
- private GameObject gamesPoint;//用来 记录 arrow针对于地图 的locatPos;
- public bool isOpen;
- public string des;//描述
- public GameObject map3DParent;
- public Transform aIAircraftLookAtpos;
- public Vector3 GpsPos;
- public int ModelMinMapArrowCurrentMinMapFitIndex;
- //public string textGps;//GPS坐标
- void Start() {
- if(typeOfWrok == "AIAircraft") {
- if(aIAircraftLookAtpos != null) {
- aIAircraftLookAtpos.gameObject.transform.parent = transform.parent.transform;
- }
- }
- Debug.Log(this.transform.GetChild(1).name + "名字");
- //textMesh = this.transform.Find("PosTest").GetComponent<TextMesh>();
- // SerColorMg(typeOfWrok);
- if(this.transform.Find("twotext") != null)
- this.transform.Find("twotext").gameObject.SetActive(false);
- textMesh.gameObject.transform.localPosition = new Vector3(textMesh.gameObject.transform.localPosition.x, ModelMinMapArrowCurrentMinMapFitIndex * 3f, textMesh.gameObject.transform.localPosition.z);
- //Debug.Log(textMesh.gameObject.transform.localPosition + "文档位置");
- }
- /*
- *
- *
- *
- *
- *
- */
- /// <summary>
- /// 箭头赋值颜色
- /// </summary>
- public void SerColorMg(string str, bool arrowOrmodle, string currentModle) {
- // this.transform.GetChild(0).gameObject.GetComponent<MeshRenderer>().material.color = ArrowColor;
- isArrowModle = arrowOrmodle;
- currentModles = currentModle;
- switch(str) {
- //友方单位
- case "AIAircraft"://无人机
- if(arrowOrmodle == true) {
- this.transform.GetChild(0).GetComponent<MeshRenderer>().materials[0].mainTexture = arrowmatreial[0].mainTexture;
- }
- ShowGameObj(6);
- textMesh.color = new Color(255f / 255f, 4f / 255f, 4f / 255f);//红色
- break;
- case "FriendlyForcesTypeOfWork1":
- if(arrowOrmodle == true) {
- this.transform.GetChild(0).GetComponent<MeshRenderer>().materials[0].mainTexture = arrowmatreial[0].mainTexture;
- } else {
- ShowGameObj(1);
- textMesh.color = new Color(255f / 255f, 4f / 255f, 4f / 255f);//红色
- }
- break;
- case "FriendlyForcesTypeOfWork2":
- if(arrowOrmodle == true) {
- this.transform.GetChild(0).GetComponent<MeshRenderer>().materials[0].mainTexture = arrowmatreial[0].mainTexture;
- } else {
- ShowGameObj(2);
- textMesh.color = new Color(255f / 255f, 4f / 255f, 4f / 255f);//红色
- }
- break;
- case "FriendlyForcesTank":
- if(arrowOrmodle == true) {
- this.transform.GetChild(0).GetComponent<MeshRenderer>().materials[0].mainTexture = arrowmatreial[0].mainTexture;
- } else {
- ShowGameObj(0);
- textMesh.color = new Color(255f / 255f, 4f / 255f, 4f / 255f);//红色
- }
- break;
- //敌方单位
- case "EnemyTypeOfWork1":
- if(arrowOrmodle == true) {
- this.transform.GetChild(0).GetComponent<MeshRenderer>().materials[0].mainTexture = arrowmatreial[1].mainTexture;
- } else {
- ShowGameObj(4);
- textMesh.color = new Color(0, 125f / 255f, 255f / 255f);//蓝色
- }
- // textMesh.gameObject.transform.localPosition = new Vector3(textMesh.gameObject.transform.localPosition.x, ModelMinMapArrowCurrentMinMapFitIndex * 3f, textMesh.gameObject.transform.localPosition.z);
- Debug.Log(ModelMinMapArrowCurrentMinMapFitIndex + "位置");
- break;
- case "EnemyTypeOfWork2":
- if(arrowOrmodle == true) {
- this.transform.GetChild(0).GetComponent<MeshRenderer>().materials[0].mainTexture = arrowmatreial[1].mainTexture;
- } else {
- ShowGameObj(5);
- textMesh.color = new Color(0, 125f / 255f, 255f / 255f);//蓝色
- }
- break;
- case "EnemyTanke":
- if(arrowOrmodle == true) {
- this.transform.GetChild(0).GetComponent<MeshRenderer>().materials[0].mainTexture = arrowmatreial[1].mainTexture;
- } else {
- ShowGameObj(3);
- textMesh.color = new Color(0, 125f / 255f, 255f / 255f);//蓝色
- }
- break;
- //中方单位
- case "EneutralTypeOfWork1":
- this.transform.GetChild(0).GetComponent<MeshRenderer>().materials[0].mainTexture = arrowmatreial[2].mainTexture;
- break;
- case "EneutralTypeOfWork2":
- this.transform.GetChild(0).GetComponent<MeshRenderer>().materials[0].mainTexture = arrowmatreial[2].mainTexture;
- break;
- case "EneutralTanke":
- this.transform.GetChild(0).GetComponent<MeshRenderer>().materials[0].mainTexture = arrowmatreial[2].mainTexture;
- break;
- }
- if(isArrowModle == false) {
- gamesPoint = Instantiate(Resources.Load("LocatArrowPos") as GameObject, this.transform.transform);
- gamesPoint.transform.parent = this.transform.parent.transform;
- }
- }
- private void ShowGameObj(int index) {
- //if (TypeOfWorkModel[0] == null)
- //{
- // return;//如过没有为空则跳出
- //}
- for(int i = 0; i < TypeOfWorkModel.Length; i++) {
- if(i == index) {
- TypeOfWorkModel[i].SetActive(true);
- } else {
- TypeOfWorkModel[i].SetActive(false);
- }
- }
- }
- /// <summary>
- /// 坐标旋转度赋值
- /// </summary>
- public void TransformMg(Vector3 ArrowPos) {
- //this.transform.position = ArrowPos;
- this.transform.Find("text/PosTest").gameObject.GetComponent<TextMesh>().text = ArrowPos.ToString("");
- // this.transform.rotation = Quaternion.Euler(Arrowrota);
- }
- private void LateUpdate() {
- textMesh.transform.parent.LookAt(new Vector3(SvrManager.Instance.head.transform.position.x, 0, SvrManager.Instance.head.transform.position.z));
- // UpdatePlayerTypeOfWorkMapArrowTrasn(pos);
- }
- private Vector3 playerTypeOfWorkPos;
- private Vector3 playerTypeOfWorkPosStr;
- private string playerPosStr;
- float PlayerGPS_iNIT_X;
- float PlayerGPS_iNIT_Z;
- GameObject gamescenes = null;
- GameObject scenes4_3D = null;
- bool ismap3DParent = false;//True为3DParent移动到箭头下仅运行一次,false为3DParent位移到Gamescence下仅运行一次
- public void SetUpdatePlayerTypeOfWorkMapArrowTrasn(String PlayerPos) {
- playerTypeOfWorkPos = StrSubstringToV3(PlayerPos);
- //Debug.Log("PlayerPos:+===============" + playerTypeOfWorkPos);
- if(isOpen == false) {
- // AudoLookAT(PlayerPos);
- }
- if(typeOfWrok == "AIAircraft") {
- float MyX = (mapScaleX / this.transform.parent.transform.Find("ModelMinMap").transform.localScale.x) * 2;//比例尺
- float MyZ = (mapScaleZ / this.transform.parent.transform.Find("ModelMinMap").transform.localScale.z) * 2;//比例尺
- RangofFloorX(playerTypeOfWorkPos.x);
- RangofFloorZ(playerTypeOfWorkPos.z);
- if(aIAircraftLookAtpos != null) {
- aIAircraftLookAtpos.transform.localPosition = new Vector3(playerTypeOfWorkPos.x / MyX, 0.01f, playerTypeOfWorkPos.z / MyZ);
- // transform.LookAt(new Vector3(aIAircraftLookAtpos.position.x, 0.01f, aIAircraftLookAtpos.position.z));
- transform.LookAt(aIAircraftLookAtpos.transform.position);
- //if (GameManager.instacne.scenesName == "scenes4")
- //{
- // // Debug.Log(transform.localEulerAngles + "旋转度");
- // transform.localEulerAngles = new Vector3(0, transform.localEulerAngles.y, transform.localEulerAngles.z);
- //}
- }
- this.transform.localPosition = new Vector3(playerTypeOfWorkPos.x / MyX, 0.01f, playerTypeOfWorkPos.z / MyZ);
- } else {
- float MyX = (mapScaleX / this.transform.parent.transform.Find("ModelMinMap").transform.localScale.x);//比例尺
- float MyZ = (mapScaleZ / this.transform.parent.transform.Find("ModelMinMap").transform.localScale.z);//比例尺
- Debug.Log(this.gameObject.name + GpsPos.x);
- PlayerGPS_iNIT_X = playerTypeOfWorkPos.x;// - GameManager.instacne.gpsPosInitx;
- PlayerGPS_iNIT_Z = playerTypeOfWorkPos.z;// - GameManager.instacne.gpsPosInitz;
- // Debug.Log("位置X"+ GameManager.instacne.gpsPosInitx + "原始位置Z" + GameManager.instacne.gpsPosInitz);
- // Debug.Log("人物名称: "+ typeOfWrok + "GpsPosX " + GpsPos.x + "GpsPosZ" + GpsPos.z + "+++++++++++++++++++++++++++" + PlayerGPS_iNIT_X + "+++++++" + PlayerGPS_iNIT_Z);
- // RangofFloorX(PlayerGPS_iNIT_X);
- // RangofFloorZ(PlayerGPS_iNIT_Z);
- // Debug.Log((PlayerGPS_iNIT_X *= -1) / MyX + "xxxxxxxxxxxxxxxxxxxxxxxxxxxx");
- if(isArrowModle == false)//置身模式
- {
- //gamesPoint.transform.localPosition = new Vector3(playerTypeOfWorkPos.x / MyX, 0.01f, playerTypeOfWorkPos.z / MyZ);
- //Vector3 localPos = gamesPoint.transform.localPosition;
- //this.transform.Translate(localPos);
- this.transform.localPosition = new Vector3(PlayerGPS_iNIT_Z / MyZ, 0.01f, (PlayerGPS_iNIT_X *= -1) / MyX);
- } else {
- this.transform.localPosition = new Vector3(PlayerGPS_iNIT_Z / MyZ, 0.01f, (PlayerGPS_iNIT_X *= -1) / MyX);
- }
- }
- if(map3DParent != null) {
- if(des == "MakeThisPlayerUser" && GameManager.instacne.scenesName == "scenes4") {
- if(map3DParent != null) {
- map3DParent.SetActive(true);
- isNullParnet = true;
- }
- } else {
- if(map3DParent != null) {
- map3DParent.SetActive(false);
- isNullParnet = false;
- }
- }
- if(isNullParnet) {
- gamescenes = this.transform.parent.parent.parent.gameObject;
- scenes4_3D = this.transform.parent.parent.gameObject;
- map3DParent.transform.parent = this.transform.parent.parent.parent.transform;
- this.transform.parent.parent.parent = map3DParent.transform;
- if(ismap3DParent == false) {
- ismap3DParent = true;//false时,map3DParent仅赋值一次
- map3DParent.transform.position = new Vector3(SvrManager.Instance.head.transform.position.x, -1.7f, SvrManager.Instance.head.transform.position.z);
- map3DParent.transform.eulerAngles = new Vector3(0, GameManager.instacne.scence3followPos.transform.eulerAngles.y, 0);
- }
- } else {
- if(GameManager.instacne.scenesName != "scenes4") {
- if(ismap3DParent == true) {
- ismap3DParent = false;//修改ismap3DParent状态
- }
- if(scenes4_3D != null) {
- scenes4_3D.transform.parent = GameObject.Find("GameScenes").transform;
- map3DParent.transform.parent = this.transform;
- }
- }
- }
- }
- // AudoLookAT(PlayerPos);
- //this.GetComponent<Rigidbody>().transform.localPosition= new Vector3(playerTypeOfWorkPos.x / MyX, 0.01f, playerTypeOfWorkPos.z / MyZ);
- // this.transform.Translate(localPos);
- }
- /// <summary>
- /// 限制Arrow X轴行走范围(0---1000)
- /// </summary>
- public void RangofFloorX(float disX) {
- if(mapScaleX <= disX) {
- if(typeOfWrok == "AIAircraft") {
- disX = mapScaleX;
- playerTypeOfWorkPos.x = disX;//无人机Pos换算方法
- } else {
- disX = mapScaleX;
- PlayerGPS_iNIT_X = disX;//敌人Pos换算方法
- }
- }
- if(0 >= disX) {
- if(typeOfWrok == "AIAircraft") {
- playerTypeOfWorkPos.x = 0;
- } else {
- PlayerGPS_iNIT_X = 0;
- }
- }
- }
- /// <summary>
- /// 限制Arrow Z轴行走范围(0---1000)
- /// </summary>
- public void RangofFloorZ(float disZ) {
- if(mapScaleZ <= PlayerGPS_iNIT_Z) {
- //PlayerGPS_iNIT_Z = mapScaleZ;
- if(typeOfWrok == "AIAircraft") {
- disZ = mapScaleZ;
- playerTypeOfWorkPos.z = disZ;
- } else {
- disZ = mapScaleZ;
- PlayerGPS_iNIT_Z = disZ;
- }
- }
- if(0 >= disZ) {
- if(typeOfWrok == "AIAircraft") {
- playerTypeOfWorkPos.z = 0;
- } else {
- PlayerGPS_iNIT_Z = 0;
- }
- //PlayerGPS_iNIT_Z = 0;
- }
- }
- public void SetUpdateTextPos(String PlayerPos) {
- playerTypeOfWorkPosStr = StrSubstringToV3(PlayerPos);
- //if (typeOfWrok == "FriendlyForcesTypeOfWork1")
- //{
- // Debug.Log("友军坐标" + playerTypeOfWorkPosStr);
- //}
- if(typeOfWrok == "AIAircraft") {
- Vector3 AIAircraft = new Vector3(playerTypeOfWorkPosStr.x + GameManager.instacne.gpsPosInitz, playerTypeOfWorkPosStr.y, playerTypeOfWorkPosStr.z + GameManager.instacne.gpsPosInitz);
- textMesh.text = AIAircraft.ToString();
- } else if(typeOfWrok == "FriendlyForcesTypeOfWork1" || typeOfWrok == "FriendlyForcesTypeOfWork2" || typeOfWrok == "FriendlyForcesTank")//显示友方沙盘坐标
- {
- textMesh.text = playerTypeOfWorkPosStr.ToString();
- }
- }
- public void SetGPSPlayerPos(string GpsPos)//接收gps真实坐标
- {
- //if (typeOfWrok != "AIAircraft")//显示敌方沙盘坐标
- //{
- // textMesh.text = GpsPos.ToString(); ;
- //}
- if(typeOfWrok == "EnemyTypeOfWork1" || typeOfWrok == "EnemyTypeOfWork2" || typeOfWrok == "EnemyTanke")//显示敌方沙盘坐标
- {
- textMesh.text = playerTypeOfWorkPosStr.ToString(); ;
- }
- }
- public 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]));
- }
- private float rotSpeed = 0.5f;
- public void AudoLookAT(string str) {
- Vector3 pos = StrSubstringToV3(str);
- //Quaternion lookRot = Quaternion.LookRotation(pos); //dir为前方节点的pos
- //transform.rotation = Quaternion.Slerp(transform.rotation, lookRot, Mathf.Clamp01(rotSpeed * Time.deltaTime));
- transform.LookAt(new Vector3(pos.x, 0, pos.z));
- }
- }
|