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.
334 lines
16 KiB
334 lines
16 KiB
4 years ago
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
using AX.MessageSystem;
|
||
|
using System;
|
||
|
using UnityEngine.UI;
|
||
|
|
||
|
public class FireDeploySYNCHandle : MonoBehaviour
|
||
|
{
|
||
|
|
||
|
public static FireDeploySYNCHandle Instance;
|
||
|
|
||
|
public GameObject ClonePrefab;
|
||
|
public CloneObjType CloneType;
|
||
|
|
||
|
//作战部署顶视图UI
|
||
|
private Transform FireDeployRawImage;
|
||
|
//作战部署顶视图相机
|
||
|
private Camera FireDeployCamera;
|
||
|
|
||
|
private Vector3 mousePosOnUI;
|
||
|
|
||
|
public FireDepolySYNCInfo fireDepolySYNCInfo;
|
||
|
|
||
|
private void Awake()
|
||
|
{
|
||
|
MessageDispatcher.AddListener("FDSYNC_HANDLE", FDSYNCHandle);
|
||
|
|
||
|
FireDeployRawImage = GameObject.Find("OperationalPreparations/MainWindow/RawImage").transform;
|
||
|
FireDeployCamera = GameObject.Find("FireDeployCamera").GetComponent<Camera>();
|
||
|
}
|
||
|
|
||
|
// Use this for initialization
|
||
|
void Start()
|
||
|
{
|
||
|
|
||
|
}
|
||
|
|
||
|
private void OnDestroy()
|
||
|
{
|
||
|
MessageDispatcher.RemoveListener("FDSYNC_HANDLE", FDSYNCHandle);
|
||
|
}
|
||
|
|
||
|
// Update is called once per frame
|
||
|
void Update()
|
||
|
{
|
||
|
|
||
|
}
|
||
|
|
||
|
private void FDSYNCHandle(IMessage obj)
|
||
|
{
|
||
|
|
||
|
var data = (FireDeploySYNCDATA)obj.Data;
|
||
|
if (data.gameObjType == CloneType && ClonePrefab != null)
|
||
|
{
|
||
|
if (CloneType == CloneObjType.FDWaterTanker
|
||
|
|| CloneType == CloneObjType.FDFoamTruck
|
||
|
|| CloneType == CloneObjType.FDAerialTowerTruck
|
||
|
|| CloneType == CloneObjType.FDHighSprayingTruck
|
||
|
|| CloneType == CloneObjType.FDLadderTruck
|
||
|
|| CloneType == CloneObjType.FDSmokeExhaustTruck
|
||
|
|| CloneType == CloneObjType.FDRescueVehicle
|
||
|
|| CloneType == CloneObjType.FDApparatus
|
||
|
|| CloneType == CloneObjType.FDLightingAppliance
|
||
|
|| CloneType == CloneObjType.FDAirSupplyTruck
|
||
|
|| CloneType == CloneObjType.FDForcibleEntryTruck
|
||
|
)
|
||
|
{
|
||
|
List<long> ids = new List<long>();
|
||
|
foreach (Transform child in transform)
|
||
|
{
|
||
|
ids.Add(child.GetComponent<BaseGameObjInfo>().gameObjID);
|
||
|
}
|
||
|
|
||
|
//视口大小高与视口渲染的顶视图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 = FireDeployCamera.transform.InverseTransformPoint(data.clonePos);
|
||
|
Vector3 offset = new Vector3(localOffset.x / factor_x, localOffset.y / factor_y, 0);
|
||
|
mousePosOnUI = offset;
|
||
|
|
||
|
if (ids.Contains(data.gameObjID))
|
||
|
{//只更新状态
|
||
|
GameObject gameObj = EntitiesManager.Instance.GetEntityByID(data.gameObjID);
|
||
|
|
||
|
gameObj.GetComponent<RectTransform>().localPosition = mousePosOnUI;
|
||
|
|
||
|
gameObj.GetComponent<FDTruckMessage>().objWorldPos = data.clonePos;
|
||
|
gameObj.GetComponent<RectTransform>().localEulerAngles = data.eulerAngles;
|
||
|
gameObj.GetComponent<FDTruckMessage>().fireCarEngine = data.fireCarEngine;
|
||
|
gameObj.GetComponent<FDTruckMessage>().org = data.org;
|
||
|
gameObj.GetComponent<FDTruckMessage>().color = data.color;
|
||
|
}
|
||
|
else
|
||
|
{//生成新实例
|
||
|
|
||
|
var clonedObj = GameObject.Instantiate(ClonePrefab, transform) as GameObject;
|
||
|
clonedObj.GetComponent<RectTransform>().localPosition = mousePosOnUI;
|
||
|
|
||
|
EntitiesManager.Instance.RemoveEntity(clonedObj.GetComponent<BaseGameObjInfo>().gameObjID, clonedObj);
|
||
|
clonedObj.GetComponent<BaseGameObjInfo>().gameObjID = data.gameObjID;
|
||
|
EntitiesManager.Instance.AddEntity(clonedObj.GetComponent<BaseGameObjInfo>().gameObjID, clonedObj);
|
||
|
|
||
|
clonedObj.GetComponent<BaseGameObjInfo>().gameObjType = data.gameObjType;
|
||
|
clonedObj.GetComponent<BaseGameObjInfo>().UserID = data.UserID;
|
||
|
|
||
|
clonedObj.GetComponent<RectTransform>().localEulerAngles = data.eulerAngles;
|
||
|
|
||
|
clonedObj.GetComponent<FDTruckMessage>().objWorldPos = data.clonePos;
|
||
|
clonedObj.GetComponent<FDTruckMessage>().fireCarEngine = data.fireCarEngine;
|
||
|
clonedObj.GetComponent<FDTruckMessage>().org = data.org;
|
||
|
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;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (CloneType == CloneObjType.FDFireMan)
|
||
|
{
|
||
|
List<long> ids = new List<long>();
|
||
|
foreach (Transform child in transform)
|
||
|
{
|
||
|
ids.Add(child.GetComponent<BaseGameObjInfo>().gameObjID);
|
||
|
}
|
||
|
|
||
|
//视口大小高与视口渲染的顶视图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 = FireDeployCamera.transform.InverseTransformPoint(data.clonePos);
|
||
|
Vector3 offset = new Vector3(localOffset.x / factor_x, localOffset.y / factor_y, 0);
|
||
|
mousePosOnUI = offset;
|
||
|
|
||
|
if (ids.Contains(data.gameObjID))
|
||
|
{//只更新状态
|
||
|
GameObject gameObj = EntitiesManager.Instance.GetEntityByID(data.gameObjID);
|
||
|
gameObj.GetComponent<RectTransform>().localPosition = mousePosOnUI;
|
||
|
|
||
|
gameObj.GetComponent<FDFireManMessage>().objWorldPos = data.clonePos;
|
||
|
gameObj.GetComponent<RectTransform>().localEulerAngles = data.eulerAngles;
|
||
|
gameObj.GetComponent<FDFireManMessage>().org = data.org;
|
||
|
gameObj.GetComponent<FDFireManMessage>().color = data.color;
|
||
|
}
|
||
|
else
|
||
|
{//生成新实例
|
||
|
|
||
|
var clonedObj = GameObject.Instantiate(ClonePrefab, transform) as GameObject;
|
||
|
clonedObj.GetComponent<RectTransform>().localPosition = mousePosOnUI;
|
||
|
|
||
|
EntitiesManager.Instance.RemoveEntity(clonedObj.GetComponent<BaseGameObjInfo>().gameObjID, clonedObj);
|
||
|
clonedObj.GetComponent<BaseGameObjInfo>().gameObjID = data.gameObjID;
|
||
|
EntitiesManager.Instance.AddEntity(clonedObj.GetComponent<BaseGameObjInfo>().gameObjID, clonedObj);
|
||
|
|
||
|
clonedObj.GetComponent<BaseGameObjInfo>().gameObjType = data.gameObjType;
|
||
|
clonedObj.GetComponent<BaseGameObjInfo>().UserID = data.UserID;
|
||
|
|
||
|
clonedObj.GetComponent<RectTransform>().localEulerAngles = data.eulerAngles;
|
||
|
|
||
|
clonedObj.GetComponent<FDFireManMessage>().objWorldPos = data.clonePos;
|
||
|
clonedObj.GetComponent<FDFireManMessage>().org = data.org;
|
||
|
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;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (CloneType == CloneObjType.Arrow
|
||
|
|| CloneType == CloneObjType.DirectWaterSupply
|
||
|
|| CloneType == CloneObjType.RelayWaterSupply
|
||
|
|| CloneType == CloneObjType.CouplingWaterSupply
|
||
|
|| CloneType == CloneObjType.WaterLineWaterSupply
|
||
|
|| CloneType == CloneObjType.SuctionFeedWaterSupply
|
||
|
|| CloneType == CloneObjType.HandPumpWaterSupply
|
||
|
|| CloneType == CloneObjType.FloatingFirePumpWaterSupply)
|
||
|
{
|
||
|
List<long> ids = new List<long>();
|
||
|
foreach (Transform child in transform)
|
||
|
{
|
||
|
ids.Add(child.GetComponent<BaseGameObjInfo>().gameObjID);
|
||
|
}
|
||
|
|
||
|
//视口大小高与视口渲染的顶视图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 = FireDeployCamera.transform.InverseTransformPoint(data.clonePos);
|
||
|
Vector3 offset = new Vector3(localOffset.x / factor_x, localOffset.y / factor_y, 0);
|
||
|
mousePosOnUI = offset;
|
||
|
|
||
|
if (ids.Contains(data.gameObjID))
|
||
|
{//只更新状态
|
||
|
GameObject gameObj = EntitiesManager.Instance.GetEntityByID(data.gameObjID);
|
||
|
|
||
|
gameObj.GetComponent<RectTransform>().localPosition = mousePosOnUI;
|
||
|
if (CloneType != CloneObjType.Arrow)
|
||
|
{
|
||
|
gameObj.GetComponent<PrivateToolMessage>().objWorldPos = data.clonePos;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
gameObj.GetComponent<PublicToolMessage>().objWorldPos = data.clonePos;
|
||
|
}
|
||
|
|
||
|
gameObj.GetComponent<RectTransform>().localEulerAngles = data.eulerAngles;
|
||
|
|
||
|
gameObj.GetComponent<RectTransform>().sizeDelta = new Vector2(data.rectTransformWith,
|
||
|
gameObj.GetComponent<RectTransform>().sizeDelta.y);
|
||
|
gameObj.transform.Find("Background").GetComponent<RectTransform>().sizeDelta =
|
||
|
new Vector2(data.rectTransformWith,
|
||
|
gameObj.transform.Find("Background").GetComponent<RectTransform>().sizeDelta.y);
|
||
|
gameObj.transform.Find("Background/Checkmark").GetComponent<RectTransform>().sizeDelta = new Vector2(
|
||
|
data.rectTransformWith,
|
||
|
gameObj.transform.Find("Background/Checkmark").GetComponent<RectTransform>().sizeDelta.y);
|
||
|
}
|
||
|
else
|
||
|
{//生成新实例
|
||
|
|
||
|
var clonedObj = GameObject.Instantiate(ClonePrefab, transform) as GameObject;
|
||
|
clonedObj.GetComponent<RectTransform>().localPosition = mousePosOnUI;
|
||
|
|
||
|
EntitiesManager.Instance.RemoveEntity(clonedObj.GetComponent<BaseGameObjInfo>().gameObjID, clonedObj);
|
||
|
clonedObj.GetComponent<BaseGameObjInfo>().gameObjID = data.gameObjID;
|
||
|
EntitiesManager.Instance.AddEntity(clonedObj.GetComponent<BaseGameObjInfo>().gameObjID, clonedObj);
|
||
|
|
||
|
clonedObj.GetComponent<BaseGameObjInfo>().gameObjType = data.gameObjType;
|
||
|
clonedObj.GetComponent<BaseGameObjInfo>().UserID = data.UserID;
|
||
|
|
||
|
clonedObj.GetComponent<RectTransform>().localEulerAngles = data.eulerAngles;
|
||
|
|
||
|
if (CloneType != CloneObjType.Arrow)
|
||
|
{
|
||
|
clonedObj.GetComponent<PrivateToolMessage>().objWorldPos = data.clonePos;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
clonedObj.GetComponent<PublicToolMessage>().objWorldPos = data.clonePos;
|
||
|
}
|
||
|
|
||
|
clonedObj.GetComponent<RectTransform>().sizeDelta = new Vector2(data.rectTransformWith,
|
||
|
clonedObj.GetComponent<RectTransform>().sizeDelta.y);
|
||
|
|
||
|
clonedObj.transform.Find("Background").GetComponent<RectTransform>().sizeDelta =
|
||
|
new Vector2(data.rectTransformWith,
|
||
|
clonedObj.transform.Find("Background").GetComponent<RectTransform>().sizeDelta.y);
|
||
|
|
||
|
clonedObj.transform.Find("Background/Checkmark").GetComponent<RectTransform>().sizeDelta = new Vector2(
|
||
|
data.rectTransformWith,
|
||
|
clonedObj.transform.Find("Background/Checkmark").GetComponent<RectTransform>().sizeDelta.y);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
if (data.gameObjType == CloneType && ClonePrefab != null
|
||
|
&& transform.GetComponent<CloneFireDeployPrivateTool>()
|
||
|
&& data.fireDeployPrivateToolType == transform.GetComponent<CloneFireDeployPrivateTool>().fireDeployPrivateToolType)
|
||
|
{
|
||
|
if (CloneType == CloneObjType.CutOff
|
||
|
|| CloneType == CloneObjType.BreakThrough
|
||
|
|| CloneType == CloneObjType.Segment
|
||
|
|| CloneType == CloneObjType.Suppress
|
||
|
|| CloneType == CloneObjType.PincerAttack
|
||
|
|| CloneType == CloneObjType.JointAttack)
|
||
|
{
|
||
|
List<long> ids = new List<long>();
|
||
|
foreach (Transform child in transform)
|
||
|
{
|
||
|
ids.Add(child.GetComponent<BaseGameObjInfo>().gameObjID);
|
||
|
}
|
||
|
|
||
|
//视口大小高与视口渲染的顶视图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 = FireDeployCamera.transform.InverseTransformPoint(data.clonePos);
|
||
|
Vector3 offset = new Vector3(localOffset.x / factor_x, localOffset.y / factor_y, 0);
|
||
|
mousePosOnUI = offset;
|
||
|
|
||
|
if (ids.Contains(data.gameObjID))
|
||
|
{//只更新状态
|
||
|
GameObject gameObj = EntitiesManager.Instance.GetEntityByID(data.gameObjID);
|
||
|
|
||
|
gameObj.GetComponent<RectTransform>().localPosition = mousePosOnUI;
|
||
|
gameObj.GetComponent<PrivateToolMessage>().objWorldPos = data.clonePos;
|
||
|
|
||
|
gameObj.GetComponent<RectTransform>().localEulerAngles = data.eulerAngles;
|
||
|
}
|
||
|
else
|
||
|
{//生成新实例
|
||
|
|
||
|
var clonedObj = GameObject.Instantiate(ClonePrefab, transform) as GameObject;
|
||
|
clonedObj.GetComponent<RectTransform>().localPosition = mousePosOnUI;
|
||
|
|
||
|
EntitiesManager.Instance.RemoveEntity(clonedObj.GetComponent<BaseGameObjInfo>().gameObjID, clonedObj);
|
||
|
clonedObj.GetComponent<BaseGameObjInfo>().gameObjID = data.gameObjID;
|
||
|
EntitiesManager.Instance.AddEntity(clonedObj.GetComponent<BaseGameObjInfo>().gameObjID, clonedObj);
|
||
|
|
||
|
clonedObj.GetComponent<BaseGameObjInfo>().gameObjType = data.gameObjType;
|
||
|
clonedObj.GetComponent<BaseGameObjInfo>().UserID = data.UserID;
|
||
|
|
||
|
clonedObj.GetComponent<RectTransform>().localEulerAngles = data.eulerAngles;
|
||
|
clonedObj.GetComponent<PrivateToolMessage>().objWorldPos = data.clonePos;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
}
|