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.
152 lines
5.9 KiB
152 lines
5.9 KiB
4 years ago
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
using AX.MessageSystem;
|
||
|
using AX.InputSystem;
|
||
|
using AX.NetworkSystem;
|
||
|
using System;
|
||
|
using UnityEngine.UI;
|
||
|
|
||
|
public enum FireDeployPrivateToolType
|
||
|
{
|
||
|
None,
|
||
|
External,
|
||
|
Internal
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 作战部署除供水类的其他类私有工具的克隆
|
||
|
/// </summary>
|
||
|
public class CloneFireDeployPrivateTool : CloneBase
|
||
|
{
|
||
|
public FireDeployPrivateToolType fireDeployPrivateToolType;
|
||
|
|
||
|
//UIRoot
|
||
|
private Canvas canvas;
|
||
|
//UI相机
|
||
|
private Camera uiCamera;
|
||
|
//作战部署顶视图UI
|
||
|
private Transform FireDeployRawImage;
|
||
|
//作战部署顶视图相机
|
||
|
private Camera FireDeployCamera;
|
||
|
|
||
|
private Vector3 prevMousePos = Vector3.zero;//前一个鼠标点
|
||
|
private Vector3 currMousePos = Vector3.zero;//当前鼠标点
|
||
|
|
||
|
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 &&
|
||
|
data.fireDeployPrivateToolType == fireDeployPrivateToolType)
|
||
|
{
|
||
|
var mousePositon = data.mousePosition;
|
||
|
|
||
|
if (prevMousePos == Vector3.zero)
|
||
|
{
|
||
|
prevMousePos = mousePositon;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
currMousePos = mousePositon;
|
||
|
}
|
||
|
|
||
|
if (prevMousePos == Vector3.zero || currMousePos == Vector3.zero)
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
var distance = Vector3.Distance(prevMousePos, currMousePos);
|
||
|
if (Vector3.Distance(prevMousePos, currMousePos) < 2)
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
var divdieMousePos = (prevMousePos + currMousePos) / 2;
|
||
|
|
||
|
//获取鼠标点击的点在UI上的坐标
|
||
|
Vector2 mousePosOnUI;
|
||
|
RectTransformUtility.ScreenPointToLocalPointInRectangle(
|
||
|
FireDeployRawImage.transform as RectTransform,
|
||
|
divdieMousePos,
|
||
|
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;
|
||
|
|
||
|
if (cloneObjType != CloneObjType.Suppress && cloneObjType != CloneObjType.JointAttack)
|
||
|
{
|
||
|
clonedObj.transform.right = ((currMousePos - prevMousePos)).normalized;//改变朝向;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
clonedObj.transform.up = (-(currMousePos - prevMousePos)).normalized;//改变朝向;
|
||
|
}
|
||
|
|
||
|
//if (distance > clonedObj.GetComponent<RectTransform>().sizeDelta.x)
|
||
|
//{//两点距离长度小于预设宽度不改变克隆出来的UI的长度
|
||
|
|
||
|
// var factor = distance / clonedObj.GetComponent<RectTransform>().sizeDelta.x;
|
||
|
// clonedObj.GetComponent<RectTransform>().sizeDelta =
|
||
|
// new Vector2(clonedObj.GetComponent<RectTransform>().sizeDelta.x * factor,
|
||
|
// clonedObj.GetComponent<RectTransform>().sizeDelta.y);
|
||
|
|
||
|
// clonedObj.transform.Find("Background").GetComponent<RectTransform>().sizeDelta =
|
||
|
// new Vector2(clonedObj.transform.Find("Background").GetComponent<RectTransform>().sizeDelta.x * factor,
|
||
|
// clonedObj.transform.Find("Background").GetComponent<RectTransform>().sizeDelta.y);
|
||
|
|
||
|
// clonedObj.transform.Find("Background/Checkmark").GetComponent<RectTransform>().sizeDelta =
|
||
|
// new Vector2(clonedObj.transform.Find("Background/Checkmark").GetComponent<RectTransform>().sizeDelta.x * factor,
|
||
|
// clonedObj.transform.Find("Background/Checkmark").GetComponent<RectTransform>().sizeDelta.y);
|
||
|
//}
|
||
|
|
||
|
BaseGameObjInfo baseObjInfo = clonedObj.GetComponent<BaseGameObjInfo>();
|
||
|
baseObjInfo.gameObjType = cloneObjType;
|
||
|
baseObjInfo.UserID = CurrentUserInfo.mySelf.Id;
|
||
|
|
||
|
clonedObj.GetComponent<PrivateToolMessage>().objWorldPos = objWorldPos;
|
||
|
|
||
|
prevMousePos = currMousePos = Vector3.zero;
|
||
|
}
|
||
|
}
|
||
|
}
|