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.
153 lines
6.2 KiB
153 lines
6.2 KiB
5 years ago
|
using System;
|
||
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using AX.Network.Protocols;
|
||
|
using UnityEngine;
|
||
|
using UnityEngine.SceneManagement;
|
||
|
using AX.Serialization;
|
||
|
using AX.InputSystem;
|
||
|
using AX.MessageSystem;
|
||
|
/// <summary>
|
||
|
/// 管线连接或者删除同步是否可移动信息
|
||
|
/// </summary>
|
||
|
public class HoseConnectOrDelectData
|
||
|
{
|
||
|
public bool Isconnect;
|
||
|
public long StartId;
|
||
|
public long EndId;
|
||
|
public long HoseId;
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 连接管线同步
|
||
|
/// </summary>
|
||
|
public class ASSOCIATED_LINE_SYNC : NetworkMessageBehaviour
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// 线的父物体
|
||
|
/// </summary>
|
||
|
private GameObject parentgameobj;
|
||
|
/// <summary>
|
||
|
/// 克隆出的线的父物体预设
|
||
|
/// </summary>
|
||
|
private GameObject parent;
|
||
|
//private long gameObjId;
|
||
|
//private GameObject startHitGameobj;
|
||
|
// private GameObject endHitGameobj;
|
||
|
// private Vector3 beginLinePoint;
|
||
|
private Vector3 startPoint;
|
||
|
private Vector3 endPoint;
|
||
|
public float Height = 0.2f;
|
||
|
public GameObject clonePrefab;
|
||
|
public Vector3 SizeVec;
|
||
|
void Start()
|
||
|
{
|
||
|
if (parent == null)
|
||
|
{
|
||
|
parent = Resources.Load("LineParent/ParentWaterHoseLine") as GameObject;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
protected override void Execute(BinaryMessage message)
|
||
|
{
|
||
|
InputHistory.Instance.RegisterInputHistory(message);
|
||
|
var info = message.Body.Deserialize<AssociatedLineSyncDate>();
|
||
|
var sender = info.SendUserID;
|
||
|
// gameObjId = info.baseGameobjInfo.gameObjID;
|
||
|
if (InputManager.Instance)
|
||
|
{
|
||
|
if (CurrentUserInfo.mySelf.Id != sender)
|
||
|
{
|
||
|
if (info.startHitGameObjId!=0&&info.endHitGameObjId!=0)
|
||
|
{
|
||
|
Associatedline(info);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
//else
|
||
|
//{
|
||
|
// NetworkSyncHelper.AddSyncData(info);
|
||
|
//}
|
||
|
|
||
|
}
|
||
|
|
||
|
//private void Resert()
|
||
|
//{
|
||
|
// beginLinePoint = Vector3.zero;
|
||
|
// startPoint = Vector3.zero;
|
||
|
// endPoint = Vector3.zero;
|
||
|
// parentgameobj = null;
|
||
|
//}
|
||
|
|
||
|
private void Associatedline(AssociatedLineSyncDate data)
|
||
|
{
|
||
|
//if (startPoint==Vector3.zero)
|
||
|
|
||
|
if (EntitiesManager.Instance.GetEntityByID(data.gameObjID) == null)
|
||
|
{
|
||
|
parentgameobj = EntitiesManager.Instance.CreateObj(parent, transform.position,transform, data.gameObjID);
|
||
|
|
||
|
startPoint = data.LineBeginPoint;
|
||
|
}
|
||
|
else//第三个点及以上,找到前两个点创建的对象,将末位点赋给起点
|
||
|
{
|
||
|
parentgameobj = EntitiesManager.Instance.GetEntityByID(data.gameObjID);
|
||
|
startPoint = parentgameobj.GetComponent<ParentLinesMessage>().EndPoint;
|
||
|
}
|
||
|
|
||
|
endPoint = data.hitpoint;
|
||
|
float distance = Vector3.Distance(startPoint, endPoint);//计算两点的距离
|
||
|
Vector3 clonedObjPos = (startPoint + endPoint) / 2;
|
||
|
// Debug.Log(gameObjID);
|
||
|
//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;
|
||
|
if((endPoint - startPoint)!=Vector3.zero)
|
||
|
{
|
||
|
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;
|
||
|
line.GetComponent<CloneGameObjInfo>().UserID = data.UserID;
|
||
|
parentgameobj.GetComponent<ParentLinesMessage>().LineLenght = data.lenght;
|
||
|
parentgameobj.GetComponent<ParentLinesMessage>().StartHitGameObj = EntitiesManager.Instance.GetEntityByID(data.startHitGameObjId);
|
||
|
parentgameobj.GetComponent<ParentLinesMessage>().EndHitGameObj = EntitiesManager.Instance.GetEntityByID(data.endHitGameObjId);
|
||
|
parentgameobj.GetComponent<ParentLinesMessage>().CreatFiremanID = data.CreatFiremanId;
|
||
|
parentgameobj.GetComponent<ParentLinesMessage>().StartPoint = data.LineBeginPoint;
|
||
|
parentgameobj.GetComponent<ParentLinesMessage>().EndPoint = endPoint;//data.LineEndPoint;
|
||
|
parentgameobj.name = data.name;
|
||
|
parentgameobj.GetComponent<CloneGameObjInfo>().gameObjID = data.gameObjID;
|
||
|
parentgameobj.GetComponent<CloneGameObjInfo>().gameObjType = data.gameObjType;
|
||
|
parentgameobj.GetComponent<CloneGameObjInfo>().UserID = data.UserID;
|
||
|
parentgameobj.GetComponent<CloneGameObjInfo>().buildNum = data.buildNum;
|
||
|
parentgameobj.GetComponent<CloneGameObjInfo>().floorNum = data.floorNum;
|
||
|
parentgameobj.GetComponent<CloneGameObjInfo>().interlayerNum = data.interlayerNum;
|
||
|
ConnectObj(
|
||
|
parentgameobj.GetComponent<ParentLinesMessage>().StartHitGameObj,
|
||
|
parentgameobj.GetComponent<ParentLinesMessage>().EndHitGameObj,
|
||
|
parentgameobj);
|
||
|
//ExpendHose(distance, parentgameobj.GetComponent<ParentLinesMessage>().LineLenght);
|
||
|
|
||
|
// SelectedObjs.gameObjs.Add(line);
|
||
|
// SelectedObjs.gameObjs.Add(parentgameobj);
|
||
|
//startPoint = endPoint;
|
||
|
}
|
||
|
//同步管线连接到物体上的处理
|
||
|
void ConnectObj(GameObject startobj,GameObject endobj,GameObject hose)
|
||
|
{
|
||
|
if (startobj.GetComponent<FireManControl>()||startobj.GetComponent<TruckMessage>()||startobj.GetComponent<WaterConnonController>()
|
||
|
|| endobj.GetComponent<FireManControl>() || endobj.GetComponent<TruckMessage>() || endobj.GetComponent<WaterConnonController>())
|
||
|
{
|
||
|
HoseConnectOrDelectData data = new HoseConnectOrDelectData();
|
||
|
data.StartId = startobj.GetComponent<BaseGameObjInfo>().gameObjID;
|
||
|
data.EndId = endobj.GetComponent<BaseGameObjInfo>().gameObjID;
|
||
|
data.Isconnect = true;
|
||
|
data.HoseId = hose.GetComponent<BaseGameObjInfo>().gameObjID;
|
||
|
MessageDispatcher.SendMessage("HOSE_CONNECT_OR_DELECT",data);
|
||
|
}
|
||
|
}
|
||
|
}
|