网上演练贵港万达广场(人员密集)
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.
 
 
 

230 lines
8.9 KiB

using AX.InputSystem;
using AX.MessageSystem;
using AX.NetworkSystem;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CloneWarningLine : CloneBase {
[SerializeField]
[Tooltip("距离地面距离")]
public string PrefabPath;
protected float Height = 0;
private Vector3 startPoint;
private Vector3 endPoint;
// private IMessage imessageobj;
private Vector3 lineBeginPoint;
private List<Vector3> pathPoints = new List<Vector3>();
/// <summary>
/// 克隆出的线的父物体预设
/// </summary>
private GameObject parent;
/// <summary>
/// 画线是否超过俩个点
/// </summary>
public bool PointOverTwo;
/// <summary>
/// 线的父物体
/// </summary>
private GameObject parentgameobj;
public Vector3 SizeVec;
void Start()
{
if (parent == null)
{
parent = Resources.Load("LineParent/ParentWarnLine") as GameObject;
}
//TrggerCloneToggle.GetComponent<ToggleRecordByAC>().OutInterFaceToggle = TrggerCloneToggleChange;
}
public override void OnEnable()
{
base.OnEnable();
MessageDispatcher.AddListener("CANCEL_CLONEBTN_SELECTED_COMMAND", CancelSelected);
}
private void CancelSelected(IMessage obj)
{
if (InputManager.cloneObjType == cloneObjType)
{
ResertLine();
}
}
public override void OnDisable()
{
base.OnDisable();
MessageDispatcher.RemoveListener("CANCEL_CLONEBTN_SELECTED_COMMAND", CancelSelected);
}
public override void OnDestroy()
{
base.OnDestroy();
MessageDispatcher.RemoveListener("CANCEL_CLONEBTN_SELECTED_COMMAND", CancelSelected);
}
public override void Execute(IMessage obj)
{
var gameObjID = (long)obj.Sender;
var data = ((CloneCmdArgs)obj.Data);
if (data.cloneObjType == cloneObjType)
{
TwoOrMore(obj);
var hitPoint = data.hitPos;
if (startPoint == Vector3.zero)
{
lineBeginPoint = hitPoint;
startPoint = hitPoint;
return;
}
endPoint = hitPoint;
pathPoints.Add(endPoint);
float distance = Vector3.Distance(startPoint, endPoint);//计算两点的距离
if (distance < 2)
{
pathPoints.Remove(endPoint);
LoadPromptWin.Instance.LoadTextPromptWindow("两点重合", 1f);
return;
}
Vector3 clonedObjPos = (startPoint + endPoint) / 2;
//EntitiesManager.Instance.AddEntity(gameObjID, parentgameobj);
clonedObjPos = new Vector3(clonedObjPos.x, clonedObjPos.y + Height, clonedObjPos.z);
GameObject line = Instantiate(clonePrefab, parentgameobj.transform);
line.name = "line";
line.transform.position = clonedObjPos;
line.transform.forward = (-(endPoint - startPoint)).normalized;//改变线条的朝向
line.transform.localScale = new Vector3(SizeVec.x, SizeVec.y, distance * SizeVec.z);//延长线条,连接两点。
line.AddComponent<BoxCollider>();
line.GetComponent<CloneGameObjInfo>().gameObjID = parentgameobj.GetComponent<BaseGameObjInfo>().gameObjID;
//parentgameobj.GetComponent<ParentLinesMessage>().LineLenght += distance;
//parentgameobj.GetComponent<ParentLinesMessage>().StartHitGameObj = startHitGameobj;
//parentgameobj.GetComponent<ParentLinesMessage>().EndHitGameObj = endHitGameobj;
//parentgameobj.name = CloneObjNameTool.Instance().GetCloneObjectName(cloneObjType);
//SelectedObjs.gameObjs.Add(line);
SelectedObjs.gameObjs.Add(line);
startPoint = endPoint;
Setattribute(data.gameObjID, parentgameobj);
cloneInfoSync(hitPoint);
}
}
public GameObject CreatLine(Vector3 startPoint, Vector3 endPoint)
{
float distance = Vector3.Distance(startPoint, endPoint);//计算两点的距离
if (distance < 2)
{
pathPoints.Remove(endPoint);
LoadPromptWin.Instance.LoadTextPromptWindow("两点重合", 1f);
return null;
}
//parentgameobj.GetComponent<ParentLinesMessage>().LineLenght += distance;
Vector3 clonedObjPos = (startPoint + endPoint) / 2;
clonedObjPos = new Vector3(clonedObjPos.x, clonedObjPos.y + Height, clonedObjPos.z);
return Instantiate(clonePrefab);
}
//设置克隆物体所在楼层等基本属性,属性从点击的对象上获取
public void Setattribute(long HitID, GameObject Clone)
{
var hitObj = EntitiesManager.Instance.GetEntityByID(HitID);
CloneGameObjInfo hitObjInfo = hitObj.GetComponent<CloneGameObjInfo>();
CloneGameObjInfo cloneObjInfo = Clone.GetComponent<CloneGameObjInfo>();
cloneObjInfo.gameObjType = cloneObjType;
cloneObjInfo.UserID = CurrentUserInfo.mySelf.Id;
cloneObjInfo.buildNum = hitObjInfo.buildNum;
cloneObjInfo.floorNum = hitObjInfo.floorNum;
cloneObjInfo.interlayerNum = hitObjInfo.interlayerNum;
}
public void CreatParents(long id)
{
parentgameobj = EntitiesManager.Instance.CreateObj(parent, transform.position, transform , id);//GameObject.Instantiate(parent, transform);
Debug.Log(EntitiesManager.Instance.GetEntityByID(id));
parentgameobj.GetComponent<BaseGameObjInfo>().gameObjType = cloneObjType;
parentgameobj.transform.parent = transform;
parentgameobj.name = cloneObjType.ToString();
}
/// <summary>
/// 是多点创建一个父物体,不是多点,每2点创建一个父物体。
/// </summary>
/// <param name="imessageobj"></param>
public void TwoOrMore(IMessage imessageobj)
{
if (PointOverTwo)
{
if (parentgameobj != null)
{
return;
}
CreatParents((long)imessageobj.Sender);
}
else
{
if (endPoint == Vector3.zero && startPoint != Vector3.zero)
{
CreatParents((long)imessageobj.Sender);
}
if (pathPoints.Count > 0)
{
pathPoints.Clear();
startPoint = Vector3.zero;
endPoint = Vector3.zero;
return;
}
}
}
public void ResertLine()
{
////结束克隆警戒线的同步
//var argsync = new WarnLineSyncDate();
//argsync.SendUserID = CurrentUserInfo.mySelf.Id;
//argsync.IsEnd = true;
//argsync.parentUID = GetComponent<UIdSystem>().Id;
//argsync.name = parentgameobj.name;
//argsync.gameObjID = parentgameobj.GetComponent<BaseGameObjInfo>().gameObjID;
//argsync.gameObjType = parentgameobj.GetComponent<BaseGameObjInfo>().gameObjType;
//argsync.UserID = parentgameobj.GetComponent<BaseGameObjInfo>().UserID;
//argsync.buildNum = parentgameobj.GetComponent<CloneGameObjInfo>().buildNum;
//argsync.floorNum = parentgameobj.GetComponent<CloneGameObjInfo>().floorNum;
//argsync.interlayerNum = parentgameobj.GetComponent<CloneGameObjInfo>().interlayerNum;
//NetworkManager.Default.SendAsync(/*CurrentUserInfo.mySelf.Id,*/ "WARN_LINE_SYNC", argsync);
lineBeginPoint = Vector3.zero;
startPoint = Vector3.zero;
endPoint = Vector3.zero;
// StartHitGameObj = null;
//EndHitGameObj = null;
//LineLenght = 0;
parentgameobj = null;
//cloneObjType = CloneObjType.None;
}
private void cloneInfoSync(Vector3 hitpoint)
{
var argsync = new WarnLineSyncDate();
argsync.SendUserID = CurrentUserInfo.mySelf.Id;
//argsync.IsEnd = false;
argsync.LineBeginPoint = lineBeginPoint;
// argsync.parentUID = GetComponent<UIdSystem>().Id;
//argsync.PrefabsPath = PrefabPath;
argsync.hitpoint = hitpoint;
argsync.name = parentgameobj.name;
argsync.gameObjID = parentgameobj.GetComponent<BaseGameObjInfo>().gameObjID;
argsync.gameObjType = parentgameobj.GetComponent<BaseGameObjInfo>().gameObjType;
argsync.UserID = parentgameobj.GetComponent<BaseGameObjInfo>().UserID;
// argsync.baseGameobjInfo.gameObjType = parentgameobj.GetComponent<BaseGameObjInfo>().gameObjType;
//argsync.baseGameobjInfo.UserID = parentgameobj.GetComponent<BaseGameObjInfo>().UserID;
argsync.buildNum = parentgameobj.GetComponent<CloneGameObjInfo>().buildNum;
argsync.floorNum = parentgameobj.GetComponent<CloneGameObjInfo>().floorNum;
argsync.interlayerNum = parentgameobj.GetComponent<CloneGameObjInfo>().interlayerNum;
NetworkManager.Default.SendAsync(/*CurrentUserInfo.mySelf.Id,*/ "WARN_LINE_SYNC", argsync);
}
}