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.
104 lines
3.7 KiB
104 lines
3.7 KiB
using System.Collections; |
|
using System.Collections.Generic; |
|
using UnityEngine; |
|
using AX.MessageSystem; |
|
using System; |
|
|
|
public class FDTruckMessage : MonoBehaviour { |
|
|
|
public Organization org; |
|
public FireCarEngine fireCarEngine; |
|
public Vector3 objWorldPos; |
|
public Color color; |
|
|
|
//作战部署顶视图UI |
|
private Transform FireDeployRawImage; |
|
//作战部署顶视图相机 |
|
private Camera FireDeployCamera; |
|
//UIRoot |
|
private Canvas canvas; |
|
|
|
private Vector3 mousePosOnUI; |
|
|
|
private bool isHeadHiden = true;//true表示车,人头顶信息隐藏了;默认为true |
|
private bool isEngineHiden = false;//true表示力量(车,人)已隐藏;默认为false |
|
|
|
// Use this for initialization |
|
void Start () { |
|
FireDeployCamera = GameObject.Find("FireDeployCamera").GetComponent<Camera>(); |
|
FireDeployRawImage = GameObject.Find("OperationalPreparations/MainWindow/RawImage").transform; |
|
canvas = GameObject.Find("Canvas").GetComponent<Canvas>(); |
|
|
|
MessageDispatcher.AddListener("DEPT_ENGINES_HIDE", EnginesHideORShow); |
|
MessageDispatcher.AddListener("DEPT_ENGINES_HEAD_HIDE",EnginesHeadHide); |
|
} |
|
|
|
private void OnDestroy() |
|
{ |
|
MessageDispatcher.RemoveListener("DEPT_ENGINES_HIDE", EnginesHideORShow); |
|
MessageDispatcher.RemoveListener("DEPT_ENGINES_HEAD_HIDE", EnginesHeadHide); |
|
} |
|
|
|
private void EnginesHeadHide(IMessage obj) |
|
{ |
|
var data = (bool)obj.Data; |
|
isHeadHiden = !data; |
|
|
|
if (!isEngineHiden) |
|
{ |
|
transform.Find("Line").gameObject.SetActive(data); |
|
transform.Find("Head").gameObject.SetActive(data); |
|
} |
|
else |
|
{ |
|
LoadPromptWin.Instance.LoadTextPromptWindow("消防车,消防员隐藏时,不能控制头顶信息显隐", 1f); |
|
} |
|
} |
|
|
|
private void EnginesHideORShow(IMessage obj) |
|
{ |
|
var data = (KeyValuePair<Organization, bool>)obj.Data; |
|
if (data.Key.Id == org.Id) |
|
{ |
|
transform.Find("Toggle").gameObject.SetActive(data.Value); |
|
if (!isHeadHiden) |
|
{ |
|
transform.Find("Line").gameObject.SetActive(data.Value); |
|
transform.Find("Head").gameObject.SetActive(data.Value); |
|
} |
|
|
|
isEngineHiden = !data.Value; |
|
} |
|
} |
|
|
|
// Update is called once per frame |
|
void Update () { |
|
|
|
//视口大小高与视口渲染的顶视图UI高的比例 |
|
var factor_y = (FireDeployCamera.orthographicSize * 2) / |
|
FireDeployRawImage.GetComponent<RectTransform>().sizeDelta.y; |
|
//视口大小长与视口渲染的顶视图UI长的比例 |
|
var factor_x = (FireDeployCamera.orthographicSize * 2) * FireDeployCamera.aspect / |
|
FireDeployRawImage.GetComponent<RectTransform>().sizeDelta.x; |
|
|
|
if (!InputManager.isDargUI)//TODO:判断UI是否拖动 |
|
{ |
|
Vector3 localOffset = FireDeployCamera.transform.InverseTransformPoint(objWorldPos); |
|
Vector3 offset = new Vector3(localOffset.x / factor_x, localOffset.y / factor_y, 0); |
|
mousePosOnUI = offset; |
|
|
|
transform.GetComponent<RectTransform>().localPosition = mousePosOnUI; |
|
} |
|
else |
|
{ |
|
mousePosOnUI = transform.GetComponent<RectTransform>().localPosition; |
|
|
|
Vector2 offset = mousePosOnUI; |
|
|
|
//顶视图相机的局部坐标系中相对于其中心点的偏移量 |
|
Vector3 localOffset = new Vector3(offset.x * factor_x, offset.y * factor_y, 0); |
|
//鼠标点击在作战部署顶视图上的点映射到世界坐标系中的点 |
|
objWorldPos = FireDeployCamera.transform.TransformPoint(localOffset); |
|
} |
|
} |
|
}
|
|
|