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.
121 lines
5.5 KiB
121 lines
5.5 KiB
4 years ago
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
using AX.MessageSystem;
|
||
|
using System;
|
||
|
using AX.InputSystem;
|
||
|
|
||
|
public class PublicToolMessage : MonoBehaviour {
|
||
|
|
||
|
public Vector3 objWorldPos;
|
||
|
|
||
|
//作战部署顶视图UI
|
||
|
private Transform FireDeployRawImage;
|
||
|
//作战部署顶视图相机
|
||
|
private Camera FireDeployCamera;
|
||
|
//UIRoot
|
||
|
private Canvas canvas;
|
||
|
|
||
|
private Vector3 mousePosOnUI;
|
||
|
|
||
|
private float orthographicSize;
|
||
|
|
||
|
// 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>();
|
||
|
orthographicSize = FireDeployCamera.orthographicSize;
|
||
|
|
||
|
MessageDispatcher.AddListener("UPDATE_ARROWORWATERSUPPLY_UIWITH", UpdateArrowOrWaterSupplyUIWith);
|
||
|
}
|
||
|
|
||
|
private void OnDestroy()
|
||
|
{
|
||
|
MessageDispatcher.RemoveListener("UPDATE_ARROWORWATERSUPPLY_UIWITH", UpdateArrowOrWaterSupplyUIWith);
|
||
|
}
|
||
|
|
||
|
private void UpdateArrowOrWaterSupplyUIWith(IMessage obj)
|
||
|
{
|
||
|
//Debug.Log("********");
|
||
|
if (transform.GetComponent<BaseGameObjInfo>().gameObjType == CloneObjType.Arrow)
|
||
|
{
|
||
|
var data = (CameraCmdArgs)obj.Data;
|
||
|
|
||
|
orthographicSize -= data.mouseScroll * FireDeployCamera.gameObject.GetComponent<FireDeployCameraManager>().mSpeed;
|
||
|
orthographicSize = Mathf.Clamp(orthographicSize,
|
||
|
FireDeployCamera.gameObject.GetComponent<FireDeployCameraManager>().minDistance,
|
||
|
FireDeployCamera.gameObject.GetComponent<FireDeployCameraManager>().maxDistance);
|
||
|
if (data.mouseScroll == 0 && data.distance != 0)
|
||
|
{
|
||
|
orthographicSize = data.distance;
|
||
|
}
|
||
|
|
||
|
//Debug.Log(FireDeployCamera.orthographicSize + " / " + orthographicSize + " = " + FireDeployCamera.orthographicSize / orthographicSize);
|
||
|
var factor = FireDeployCamera.orthographicSize / orthographicSize;
|
||
|
|
||
|
transform.GetComponent<RectTransform>().sizeDelta =
|
||
|
new Vector2(transform.GetComponent<RectTransform>().sizeDelta.x * factor,
|
||
|
transform.GetComponent<RectTransform>().sizeDelta.y);
|
||
|
|
||
|
transform.transform.Find("Background").GetComponent<RectTransform>().sizeDelta =
|
||
|
new Vector2(transform.transform.Find("Background").GetComponent<RectTransform>().sizeDelta.x * factor,
|
||
|
transform.transform.Find("Background").GetComponent<RectTransform>().sizeDelta.y);
|
||
|
|
||
|
transform.transform.Find("Background/Checkmark").GetComponent<RectTransform>().sizeDelta =
|
||
|
new Vector2(transform.transform.Find("Background/Checkmark").GetComponent<RectTransform>().sizeDelta.x * factor,
|
||
|
transform.transform.Find("Background/Checkmark").GetComponent<RectTransform>().sizeDelta.y);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// 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);
|
||
|
}
|
||
|
|
||
|
if (transform.GetComponent<BaseGameObjInfo>().gameObjType == CloneObjType.Arrow)
|
||
|
{//处理公用工具箭头跟随顶视图相机视野缩放而缩放
|
||
|
|
||
|
var factor = orthographicSize / FireDeployCamera.orthographicSize;
|
||
|
|
||
|
transform.GetComponent<RectTransform>().sizeDelta =
|
||
|
new Vector2(transform.GetComponent<RectTransform>().sizeDelta.x * factor,
|
||
|
transform.GetComponent<RectTransform>().sizeDelta.y);
|
||
|
|
||
|
transform.transform.Find("Background").GetComponent<RectTransform>().sizeDelta =
|
||
|
new Vector2(transform.transform.Find("Background").GetComponent<RectTransform>().sizeDelta.x * factor,
|
||
|
transform.transform.Find("Background").GetComponent<RectTransform>().sizeDelta.y);
|
||
|
|
||
|
transform.transform.Find("Background/Checkmark").GetComponent<RectTransform>().sizeDelta =
|
||
|
new Vector2(transform.transform.Find("Background/Checkmark").GetComponent<RectTransform>().sizeDelta.x * factor,
|
||
|
transform.transform.Find("Background/Checkmark").GetComponent<RectTransform>().sizeDelta.y);
|
||
|
|
||
|
orthographicSize = FireDeployCamera.orthographicSize;
|
||
|
}
|
||
|
}
|
||
|
}
|