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.
120 lines
4.9 KiB
120 lines
4.9 KiB
using System.Collections; |
|
using System.Collections.Generic; |
|
using UnityEngine; |
|
using AX.MessageSystem; |
|
using AX.InputSystem; |
|
using AX.NetworkSystem; |
|
using System; |
|
using UnityEngine.UI; |
|
|
|
public class CloneFireDeployCar : CloneBase |
|
{ |
|
//UIRoot |
|
private Canvas canvas; |
|
//UI相机 |
|
private Camera uiCamera; |
|
//作战部署顶视图UI |
|
private Transform FireDeployRawImage; |
|
//作战部署顶视图相机 |
|
private Camera FireDeployCamera; |
|
|
|
private KeyValuePair<FireCarEngine, int> typeCar = new KeyValuePair<FireCarEngine, int>(); |
|
|
|
private void Awake() |
|
{ |
|
canvas = GameObject.Find("Canvas").GetComponent<Canvas>(); |
|
uiCamera = GameObject.Find("UICamera").GetComponent<Camera>(); |
|
FireDeployRawImage = GameObject.Find("OperationalPreparations/MainWindow/RawImage").transform; |
|
FireDeployCamera = GameObject.Find("FireDeployCamera").GetComponent<Camera>(); |
|
} |
|
|
|
private void Start() |
|
{ |
|
|
|
} |
|
|
|
public override void Execute(IMessage obj) |
|
{ |
|
var gameObjID = (long)obj.Sender; |
|
var data = ((CloneCmdArgs)obj.Data); |
|
|
|
if (data.cloneObjType == cloneObjType) |
|
{ |
|
for (int i = 0; i < FireEnginesData.Instance.GetAllCas()[data.org.DisplayName].Count; i++) |
|
{ |
|
if (data.fireCarEngine != null && |
|
FireEnginesData.Instance.GetAllCas()[data.org.DisplayName][i].Key.TypeName == data.fireCarEngine.TypeName) |
|
{ |
|
typeCar = FireEnginesData.Instance.GetAllCas()[data.org.DisplayName][i]; |
|
} |
|
} |
|
|
|
if(typeCar.Value <= 0) |
|
{ |
|
return; |
|
} |
|
|
|
var mousePositon = data.mousePosition; |
|
|
|
//获取鼠标点击的点在UI上的坐标 |
|
Vector2 mousePosOnUI; |
|
RectTransformUtility.ScreenPointToLocalPointInRectangle( |
|
FireDeployRawImage.transform as RectTransform, |
|
mousePositon, |
|
canvas.worldCamera, |
|
out mousePosOnUI); |
|
|
|
//获取作战部署顶视图Ui位置(中心点)在UI上的坐标 |
|
Vector2 FireDeployRawImagePos; |
|
RectTransformUtility.ScreenPointToLocalPointInRectangle( |
|
FireDeployRawImage.transform as RectTransform, |
|
uiCamera.WorldToScreenPoint(FireDeployRawImage.position), |
|
canvas.worldCamera, |
|
out FireDeployRawImagePos); |
|
|
|
//克隆点到作战部署顶视图中心点在UI上的偏移量 |
|
Vector2 offset = mousePosOnUI - FireDeployRawImagePos; |
|
|
|
//视口大小高与视口渲染的顶视图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; |
|
|
|
|
|
//顶视图相机的局部坐标系中相对于其中心点的偏移量 |
|
Vector3 localOffset = new Vector3(offset.x * factor_x, offset.y * factor_y, 0); |
|
//鼠标点击在作战部署顶视图上的点映射到世界坐标系中的点 |
|
Vector3 objWorldPos = FireDeployCamera.transform.TransformPoint(localOffset); |
|
|
|
var clonedObj = GameObject.Instantiate(clonePrefab, transform) as GameObject; |
|
clonedObj.GetComponent<RectTransform>().localPosition = mousePosOnUI; |
|
|
|
BaseGameObjInfo baseObjInfo = clonedObj.GetComponent<BaseGameObjInfo>(); |
|
baseObjInfo.gameObjType = cloneObjType; |
|
baseObjInfo.UserID = CurrentUserInfo.mySelf.Id; |
|
|
|
clonedObj.GetComponent<FDTruckMessage>().org = data.org; |
|
clonedObj.GetComponent<FDTruckMessage>().fireCarEngine = data.fireCarEngine; |
|
clonedObj.GetComponent<FDTruckMessage>().objWorldPos = objWorldPos; |
|
clonedObj.GetComponent<FDTruckMessage>().color = data.color; |
|
|
|
clonedObj.transform.Find("Head/orgName").GetComponent<Text>().text = |
|
clonedObj.GetComponent<FDTruckMessage>().org.DisplayName; |
|
clonedObj.transform.Find("Head/CarTypeName").GetComponent<Text>().text = |
|
clonedObj.GetComponent<FDTruckMessage>().fireCarEngine.TypeName; |
|
|
|
clonedObj.transform.Find("Head").GetComponent<Image>().color = data.color; |
|
clonedObj.transform.Find("Line").GetComponent<Image>().color = data.color; |
|
|
|
MessageDispatcher.SendMessage("UPDATE_FIREDEPLOY_EMGINE", |
|
new KeyValuePair<FireCarEngine, Organization>(data.fireCarEngine, data.org)); |
|
|
|
NetworkManager.Default.SendAsync("UPDATE_FIREDEPLOY_EMGINE_SYNC", |
|
new KeyValuePair<FireCarEngine, Organization>(data.fireCarEngine, data.org)); |
|
} |
|
|
|
} |
|
} |
|
|
|
|