using AX.MessageSystem; using System.Collections; using System.Collections.Generic; using UnityEngine; public class FireManMapIcon : MonoBehaviour { private Camera miniCam; private bool fourthGTransfer = false; //是否开启4G图传面板 public bool updateMap = false; //是否在图传列表上 private CloneGameObjInfo info; private MapIconPair pair; void Start() { miniCam = GameObject.Find("4GCamera").GetComponent(); info = GetComponent(); pair = new MapIconPair(); } void OnEnable() { MessageDispatcher.AddListener("OpenFourthG", FourthGInit); MessageDispatcher.AddListener("4GPersonSelected", FourthGMapSelected); } void OnDestroy() { MessageDispatcher.RemoveListener("OpenFourthG", FourthGInit); MessageDispatcher.RemoveListener("4GPersonSelected", FourthGMapSelected); } void FourthGInit(IMessage obj) { var isOn = (bool)obj.Data; fourthGTransfer = isOn; } void UpdateMap() { Vector3 position = transform.position; Vector3 miniCamPosition = miniCam.transform.position; Vector3 screenPosition = miniCam.WorldToScreenPoint(position); Vector3 miniCamScreenPosition = miniCam.WorldToScreenPoint(miniCamPosition); Vector3 offset = new Vector3(screenPosition.x - miniCamScreenPosition.x, screenPosition.y - miniCamScreenPosition.y, 0); float sizeW = miniCam.pixelWidth; float sizeH = miniCam.pixelHeight; float x = offset.x / sizeW; float y = offset.y / sizeH; float rectx = x * 755; float recty = y * 500; MapIconPair pair = new MapIconPair { gameObjID = GetComponent().gameObjID, //从人物身上获取UserID rectX = rectx, rectY = recty }; //FIXME: 这里不需时刻更新位置,仅当在位置有所变化的情况下更新 if (this.pair.gameObjID != pair.gameObjID || this.pair.rectX != pair.rectX || this.pair.rectY != pair.rectY) { this.pair = pair; MessageDispatcher.SendMessage("4GIconUpdate", pair); } } // Update is called once per frame void Update() { //在图传列表,并且不在四分屏模式下,则实时更新图标位置 if (/*fourthGTransfer == true &&*/ updateMap == true && QuadrupleMode.quadingMode == false) { UpdateMap(); } } /// /// 此消防员在4G图传中被选中时,地图摄像机移动到该消防员正上方 /// /// void FourthGMapSelected(IMessage obj) { var pair = (MapSelectedPair)obj.Data; if (pair.gameObjID == GetComponent().gameObjID && pair.isOn == true) { miniCam.GetComponent().SetTarget(transform); } } } /// /// 更新4G点位位置的传送信息对 /// public class MapIconPair { public long gameObjID; public float rectX; public float rectY; }