You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
126 lines
3.8 KiB
126 lines
3.8 KiB
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class InfoWnd : MonoBehaviour
|
|
{
|
|
|
|
[Header("小地图")]
|
|
public Transform mapPoint1;
|
|
public Transform mapPoint2;
|
|
public Transform[] mapTransGroup;
|
|
public RectTransform poivt;
|
|
public RectTransform MiniSuiDao;
|
|
[HideInInspector]
|
|
public RectTransform[] miniMapIconGroup;
|
|
public float miniMapWidth;
|
|
public float miniMapHeight;
|
|
private Vector2 mapAspect;
|
|
private Vector2[] miniMapTransPos;
|
|
[Header("监控")]
|
|
public Transform viewCameraPearent;
|
|
private GameObject[] viewCameraGroup;
|
|
public Dropdown viewDropdown;
|
|
[Header("时间")]
|
|
public Text timeTxt;
|
|
|
|
public Text testTxt;
|
|
[Header("当前分辨率")]
|
|
public float _screenWidth;
|
|
public float _screenHeight;
|
|
|
|
|
|
|
|
public void Init()
|
|
{
|
|
//小地图长宽
|
|
mapAspect.x = Mathf.Abs(mapPoint1.position.z - mapPoint2.position.z);
|
|
mapAspect.y = Mathf.Abs(mapPoint1.position.x - mapPoint2.position.x);
|
|
//AI Icon
|
|
miniMapIconGroup = new RectTransform[AISys.Instance._AIIconPreant.childCount];
|
|
for (int i = 0; i < miniMapIconGroup.Length; i++)
|
|
{
|
|
miniMapIconGroup[i] = AISys.Instance._AIIconPreant.GetChild(i).GetComponent<RectTransform>();
|
|
}
|
|
miniMapTransPos = new Vector2[miniMapIconGroup.Length];
|
|
|
|
mapTransGroup = new Transform[AISys.Instance._workerGroup.Length];
|
|
for (int i = 0; i < mapTransGroup.Length; i++)
|
|
{
|
|
mapTransGroup[i] = AISys.Instance._workerGroup[i].transform;
|
|
}
|
|
|
|
//初始化监控窗口
|
|
InitViewCamera();
|
|
InitDropdown();
|
|
|
|
miniMapWidth = MiniSuiDao.rect.width;
|
|
miniMapHeight =MiniSuiDao.rect.height;
|
|
|
|
_screenHeight = 1080;
|
|
_screenWidth = 1920;
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
CalcMiniMapTrans(miniMapIconGroup);
|
|
timeTxt.text = System.DateTime.Now.Hour.ToString()+":"+ System.DateTime.Now.Minute.ToString()+":"+ System.DateTime.Now.Second.ToString();
|
|
//Debug.Log("X-"+ Screen.width/1920f );
|
|
// Debug.Log("Y-" + Screen.height/1080f );
|
|
// miniMapWidth = 545*( 1920f/Screen.width);
|
|
// miniMapHeight =200*( 1080f/Screen.height);
|
|
testTxt.text = "宽:" + Screen.width + "-高:" + Screen.height;
|
|
if(Input.GetKey(KeyCode.LeftShift)&& Input.GetKey(KeyCode.T))
|
|
{
|
|
testTxt.gameObject.SetActive(true);
|
|
}
|
|
}
|
|
|
|
private void InitViewCamera()
|
|
{
|
|
|
|
viewCameraGroup = new GameObject[viewCameraPearent.childCount];
|
|
for (int i = 0; i < viewCameraPearent.childCount; i++)
|
|
{
|
|
viewCameraGroup[i] = viewCameraPearent.GetChild(i).gameObject;
|
|
}
|
|
|
|
}
|
|
|
|
public void ShowViewCamera(int index)
|
|
{
|
|
for (int i = 0; i < viewCameraGroup.Length; i++)
|
|
{
|
|
viewCameraGroup[i].SetActive(false);
|
|
}
|
|
viewCameraGroup[index].SetActive(true);
|
|
}
|
|
|
|
public void CalcMiniMapTrans(RectTransform[] group)
|
|
{
|
|
|
|
for (int i = 0; i < group.Length; i++)
|
|
{
|
|
|
|
//(单位坐标x,y/地面长,宽)*小地图高,宽 693-40
|
|
miniMapTransPos[i].x = Mathf.Abs(mapTransGroup[i].position.z-mapPoint1.position.z) / (mapAspect.x / miniMapWidth)+poivt.localPosition.x;
|
|
miniMapTransPos[i].y = Mathf.Abs(mapTransGroup[i].position.x- mapPoint1.position.x) / (mapAspect.y /miniMapHeight)+ poivt.localPosition.y ;
|
|
miniMapTransPos[i].x *= (Screen.width/_screenWidth);
|
|
miniMapTransPos[i].y *= ( Screen.height/_screenHeight);
|
|
group[i].localPosition = miniMapTransPos[i];
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
private void InitDropdown()
|
|
{
|
|
viewDropdown.onValueChanged.AddListener((int a) => {
|
|
ShowViewCamera(viewDropdown.value);
|
|
});
|
|
}
|
|
|
|
}
|