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.
113 lines
5.4 KiB
113 lines
5.4 KiB
4 years ago
|
using System;
|
||
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using AX.Network.Protocols;
|
||
|
using UnityEngine;
|
||
|
using AX.Serialization;
|
||
|
using AX.MessageSystem;
|
||
|
|
||
|
/// <summary>
|
||
|
/// 水幕水带绑定到水源的数据类
|
||
|
/// </summary>
|
||
|
public class WaterCarBindCurtainHose
|
||
|
{
|
||
|
public long WaterSourceObjId;//水源对象ID
|
||
|
public GameObject WaterCurtainHose;//水幕水带对象
|
||
|
public bool isConnect;//true表示已连接到水源;false表示删除连接到水源的水幕水带
|
||
|
}
|
||
|
|
||
|
public class CLONE_WATERCURTAINHOSE_SYNC : NetworkMessageBehaviour
|
||
|
{
|
||
|
private GameObject WaterCurtainHoseParent;//水幕水带父对象
|
||
|
|
||
|
private void Start()
|
||
|
{
|
||
|
if (WaterCurtainHoseParent == null)
|
||
|
WaterCurtainHoseParent = Resources.Load("ClonePrefabs/Tool/WaterCurtainHoseParent") as GameObject;
|
||
|
}
|
||
|
|
||
|
protected override void Execute(BinaryMessage message)
|
||
|
{
|
||
|
InputHistory.Instance.RegisterInputHistory(message);
|
||
|
|
||
|
var info = message.Body.Deserialize<WaterCurtainHoseSyncData>();
|
||
|
|
||
|
if (InputManager.Instance)
|
||
|
{
|
||
|
if (CurrentUserInfo.mySelf.Id != info.WaterCHoseParentSyncData.SendUserID)
|
||
|
{
|
||
|
if (info.WaterCHoseParentSyncData.gameObjType == GetComponent<CloneWaterCurtainHose>().cloneObjType)
|
||
|
{
|
||
|
if (!EntitiesManager.Instance.GetEntityByID(info.WaterCHoseParentSyncData.gameObjID))
|
||
|
{//每次克隆水幕水带操作,第一次同步需先克隆出水幕水带父对象,和其第一段子对象
|
||
|
var clonedObj = EntitiesManager.Instance.CreateObj(
|
||
|
WaterCurtainHoseParent,
|
||
|
info.WaterCHoseParentSyncData.ClonePosition,
|
||
|
transform,
|
||
|
info.WaterCHoseParentSyncData.gameObjID);
|
||
|
|
||
|
clonedObj.name = info.WaterCHoseParentSyncData.Name;
|
||
|
|
||
|
CloneGameObjInfo cloneObjInfo = clonedObj.GetComponent<CloneGameObjInfo>();
|
||
|
cloneObjInfo.gameObjType = info.WaterCHoseParentSyncData.gameObjType;
|
||
|
cloneObjInfo.UserID = info.WaterCHoseParentSyncData.UserID;
|
||
|
cloneObjInfo.buildNum = info.WaterCHoseParentSyncData.buildNum;
|
||
|
cloneObjInfo.floorNum = info.WaterCHoseParentSyncData.floorNum;
|
||
|
cloneObjInfo.interlayerNum = info.WaterCHoseParentSyncData.interlayerNum;
|
||
|
//克隆子对象第一段
|
||
|
CloneWaterCurtainHoseChild(info.WaterCHoseChildSyncData, clonedObj, info.waterSourceObjId);
|
||
|
}
|
||
|
else
|
||
|
{//后续只需同步处理子对象
|
||
|
CloneWaterCurtainHoseChild(info.WaterCHoseChildSyncData,
|
||
|
EntitiesManager.Instance.GetEntityByID(info.WaterCHoseParentSyncData.gameObjID), info.waterSourceObjId);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void CloneWaterCurtainHoseChild(WaterCHoseChildSyncData WaterCHoseChildSyncData, GameObject parent, long waterSourceObjId)
|
||
|
{
|
||
|
Vector3 clonedObjPos = (WaterCHoseChildSyncData.StartPoint + WaterCHoseChildSyncData.EndPoint) / 2;
|
||
|
clonedObjPos = new Vector3(clonedObjPos.x, clonedObjPos.y + WaterCHoseChildSyncData.Height, clonedObjPos.z);
|
||
|
|
||
|
GameObject WaterCurtainHoseChild = Instantiate(
|
||
|
parent.transform.parent.GetComponent<CloneWaterCurtainHose>().clonePrefab,
|
||
|
clonedObjPos,
|
||
|
Quaternion.identity,
|
||
|
parent.transform) as GameObject;
|
||
|
|
||
|
WaterCurtainHoseChild.GetComponent<BaseGameObjInfo>().SetGameObjID(WaterCHoseChildSyncData.gameObjID);
|
||
|
|
||
|
WaterCurtainHoseChild.transform.forward = (-(WaterCHoseChildSyncData.EndPoint - WaterCHoseChildSyncData.StartPoint)).normalized;//改变线条的朝向
|
||
|
float distance = Vector3.Distance(WaterCHoseChildSyncData.StartPoint, WaterCHoseChildSyncData.EndPoint);//计算两点的距离
|
||
|
WaterCurtainHoseChild.transform.localScale = new Vector3(30f, 30f, distance * 108);//延长线条,连接两点。
|
||
|
WaterCurtainHoseChild.AddComponent<BoxCollider>();
|
||
|
if (!WaterCurtainHoseChild.GetComponent<UIdSystem>())
|
||
|
{
|
||
|
WaterCurtainHoseChild.AddComponent<UIdSystem>().ReassignId((ulong)CurrentUserInfo.mySelf.Id, true);
|
||
|
}
|
||
|
|
||
|
CloneGameObjInfo childCloneObjInfo = WaterCurtainHoseChild.GetComponent<CloneGameObjInfo>();
|
||
|
childCloneObjInfo.gameObjType = WaterCHoseChildSyncData.gameObjType;
|
||
|
childCloneObjInfo.UserID = WaterCHoseChildSyncData.UserID;
|
||
|
|
||
|
childCloneObjInfo.buildNum = WaterCHoseChildSyncData.buildNum;
|
||
|
childCloneObjInfo.floorNum = WaterCHoseChildSyncData.floorNum;
|
||
|
childCloneObjInfo.interlayerNum = WaterCHoseChildSyncData.interlayerNum;
|
||
|
|
||
|
//接收端水幕水带绑定水源
|
||
|
parent.GetComponent<WaterCurtainHoseSkillCtrl>().waterSourceGameObjId = waterSourceObjId;
|
||
|
|
||
|
//接收端水幕水带所连接的水源为车时,在车上绑定所连接的水幕水带
|
||
|
WaterCarBindCurtainHose waterCarBindCurtainHose = new WaterCarBindCurtainHose();
|
||
|
waterCarBindCurtainHose.WaterSourceObjId = waterSourceObjId;
|
||
|
waterCarBindCurtainHose.WaterCurtainHose = parent;
|
||
|
waterCarBindCurtainHose.isConnect = true;
|
||
|
|
||
|
MessageDispatcher.SendMessage("WATERCAR_BIND_CURTAINHOSE", waterCarBindCurtainHose);
|
||
|
}
|
||
|
}
|