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.
102 lines
4.2 KiB
102 lines
4.2 KiB
4 years ago
|
using System;
|
||
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using AX.MessageSystem;
|
||
|
using UnityEngine;
|
||
|
using AX.InputSystem;
|
||
|
using AX.NetworkSystem;
|
||
|
using UnityEngine.UI;
|
||
|
|
||
|
public class CloneFireDeployFireMan : CloneBase
|
||
|
{
|
||
|
//UIRoot
|
||
|
private Canvas canvas;
|
||
|
//UI相机
|
||
|
private Camera uiCamera;
|
||
|
//作战部署顶视图UI
|
||
|
private Transform FireDeployRawImage;
|
||
|
//作战部署顶视图相机
|
||
|
private Camera FireDeployCamera;
|
||
|
|
||
|
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 && FireEnginesData.Instance.GetAllPersons()[data.org.DisplayName] > 0)
|
||
|
{
|
||
|
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<FDFireManMessage>().org = data.org;
|
||
|
clonedObj.GetComponent<FDFireManMessage>().objWorldPos = objWorldPos;
|
||
|
clonedObj.GetComponent<FDFireManMessage>().color = data.color;
|
||
|
|
||
|
clonedObj.transform.Find("Head/orgName").GetComponent<Text>().text =
|
||
|
clonedObj.GetComponent<FDFireManMessage>().org.DisplayName;
|
||
|
clonedObj.transform.Find("Head/CarTypeName").GetComponent<Text>().text ="消防员";
|
||
|
|
||
|
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));
|
||
|
}
|
||
|
}
|
||
|
}
|