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.
344 lines
16 KiB
344 lines
16 KiB
4 years ago
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
using AX.MessageSystem;
|
||
|
using System;
|
||
|
using AX.NetworkSystem;
|
||
|
|
||
|
/// <summary>
|
||
|
/// 水幕水带技能集:目前只有一个出水技能
|
||
|
/// </summary>
|
||
|
public class WaterCurtainHoseSkill
|
||
|
{
|
||
|
public SprayWater SprayWater;
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 水幕水带出水技能
|
||
|
/// </summary>
|
||
|
public struct SprayWater
|
||
|
{
|
||
|
public bool Active;//true:表示出水状态;false:表示未出水状态
|
||
|
}
|
||
|
|
||
|
public class WaterCurtainHoseSkillCtrl : MonoBehaviour
|
||
|
{
|
||
|
public WaterCurtainHoseSkill waterCurtainHoseSkill = new WaterCurtainHoseSkill();
|
||
|
|
||
|
public float startSprayWaterDistance = 2f;//距离水源(水源车,消火栓除外)5米开外出水
|
||
|
public float accumulationDis = 0;
|
||
|
public float spaceDistance = 2f;//在水幕水带上出水的间隔距离,默认1米
|
||
|
public List<Vector3> pathPoints = new List<Vector3>();//水幕水带拐点;用于计算每间隔1米出水的位置
|
||
|
private List<Vector3> sprayWaterPoss = new List<Vector3>();//水幕水带上的出水位置数组
|
||
|
|
||
|
private GameObject WaterCurtain = null;//水幕预设
|
||
|
public bool isClonedWaterCurtain = false;//是否存在水幕特效
|
||
|
|
||
|
public long waterSourceGameObjId = -1;//绑定水幕水带的水源id(只有连接水源绑定水源后,才能出水)
|
||
|
|
||
|
public bool startPointIsWaterSource;//true表示起始端连接水源;false表示末端连接水源
|
||
|
|
||
|
public bool flag;
|
||
|
|
||
|
// Use this for initialization
|
||
|
void Start()
|
||
|
{
|
||
|
MessageDispatcher.AddListener("GET_SPRAYWATER_POSITIONS", GetSprayWaterPositions);
|
||
|
|
||
|
WaterCurtain = Resources.Load("WaterCurtain/WaterCurtain") as GameObject;
|
||
|
}
|
||
|
|
||
|
private void OnDestroy()
|
||
|
{
|
||
|
MessageDispatcher.RemoveListener("GET_SPRAYWATER_POSITIONS", GetSprayWaterPositions);
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 计算水幕水带上出水位置
|
||
|
/// </summary>
|
||
|
/// <param name="obj"></param>
|
||
|
private void GetSprayWaterPositions(IMessage obj)
|
||
|
{
|
||
|
var data = (long)obj.Data;
|
||
|
|
||
|
if (data == transform.GetComponent<BaseGameObjInfo>().gameObjID)
|
||
|
{//判断此脚本所挂载的对象本身是否是当前结束克隆操作的水幕水带
|
||
|
if (pathPoints.Count > 0)
|
||
|
{
|
||
|
sprayWaterPoss.Clear();
|
||
|
|
||
|
GameObject waterSourceObj = EntitiesManager.Instance.GetEntityByID(waterSourceGameObjId);
|
||
|
if (startPointIsWaterSource)
|
||
|
{//顺序获取分割点
|
||
|
|
||
|
if (waterSourceObj != null)
|
||
|
{
|
||
|
if (waterSourceObj.GetComponent<BaseGameObjInfo>().gameObjType == CloneObjType.WaterTanker
|
||
|
|| waterSourceObj.GetComponent<BaseGameObjInfo>().gameObjType == CloneObjType.FoamTruck)
|
||
|
{//水源为水源车
|
||
|
|
||
|
accumulationDis = 0;
|
||
|
|
||
|
for (int i = 0; i < pathPoints.Count; i++)
|
||
|
{
|
||
|
if ((i + 1) < pathPoints.Count)
|
||
|
{
|
||
|
//var distance = Vector3.Distance(pathPoints[i], pathPoints[i + 1]);
|
||
|
//if (accumulationDis < startSprayWaterDistance)
|
||
|
//{
|
||
|
// accumulationDis += distance;
|
||
|
//}
|
||
|
//else
|
||
|
//{
|
||
|
// if (accumulationDis % startSprayWaterDistance == 0)
|
||
|
// {//正好整数段水幕水带子对象加起来为5米长
|
||
|
// sprayWaterPoss.Add(pathPoints[i]);
|
||
|
|
||
|
// var result = (int)(distance / spaceDistance);
|
||
|
// for (int j = 1; j <= result; j++)
|
||
|
// {
|
||
|
// var sprayWaterPos = Vector3.MoveTowards(pathPoints[i], pathPoints[i + 1], spaceDistance * j);
|
||
|
// sprayWaterPoss.Add(sprayWaterPos);
|
||
|
// }
|
||
|
// }
|
||
|
// else
|
||
|
// {//整数段水幕水带子对象加起来已大于5米
|
||
|
// if (!flag)
|
||
|
// {
|
||
|
// var dis = accumulationDis - startSprayWaterDistance;
|
||
|
|
||
|
// var startpos = Vector3.MoveTowards(pathPoints[i - 1], pathPoints[i], startSprayWaterDistance);
|
||
|
|
||
|
// sprayWaterPoss.Add(startpos);
|
||
|
|
||
|
// var res = (int)(dis / spaceDistance);
|
||
|
// for (int j = 1; j <= res; j++)
|
||
|
// {
|
||
|
// var sprayWtPos = Vector3.MoveTowards(startpos, pathPoints[i], spaceDistance * j);
|
||
|
// sprayWaterPoss.Add(sprayWtPos);
|
||
|
// }
|
||
|
|
||
|
// flag = true;
|
||
|
// }
|
||
|
|
||
|
// var result = (int)(distance / spaceDistance);
|
||
|
// for (int j = 1; j <= result; j++)
|
||
|
// {
|
||
|
// var sprayWaterPos = Vector3.MoveTowards(pathPoints[i], pathPoints[i + 1], spaceDistance * j);
|
||
|
// sprayWaterPoss.Add(sprayWaterPos);
|
||
|
// }
|
||
|
// }
|
||
|
//}
|
||
|
var distance = Vector3.Distance(pathPoints[i], pathPoints[i + 1]);
|
||
|
var result = (int)(distance / spaceDistance);
|
||
|
for (int j = 1; j <= result; j++)
|
||
|
{
|
||
|
var sprayWaterPos = Vector3.MoveTowards(pathPoints[i], pathPoints[i + 1], spaceDistance * j);
|
||
|
sprayWaterPoss.Add(sprayWaterPos);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{//消火栓
|
||
|
for (int i = 0; i < pathPoints.Count; i++)
|
||
|
{
|
||
|
if ((i + 1) < pathPoints.Count)
|
||
|
{
|
||
|
//加入每段根据间隔的分割点
|
||
|
var distance = Vector3.Distance(pathPoints[i], pathPoints[i + 1]);
|
||
|
var result = (int)(distance / spaceDistance);
|
||
|
for (int j = 1; j <= result; j++)
|
||
|
{
|
||
|
var sprayWaterPos = Vector3.MoveTowards(pathPoints[i], pathPoints[i + 1], spaceDistance * j);
|
||
|
sprayWaterPoss.Add(sprayWaterPos);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{//倒序获取分割点
|
||
|
|
||
|
if (waterSourceObj != null)
|
||
|
{
|
||
|
if (waterSourceObj.GetComponent<BaseGameObjInfo>().gameObjType == CloneObjType.WaterTanker
|
||
|
|| waterSourceObj.GetComponent<BaseGameObjInfo>().gameObjType == CloneObjType.FoamTruck)
|
||
|
{//水源为水源车
|
||
|
accumulationDis = 0;
|
||
|
|
||
|
for (int i = pathPoints.Count; i > 0; i--)
|
||
|
{
|
||
|
if ((i - 1) > 0)
|
||
|
{
|
||
|
//var distance = Vector3.Distance(pathPoints[i - 1], pathPoints[i - 2]);
|
||
|
//if (accumulationDis < startSprayWaterDistance)
|
||
|
//{
|
||
|
// accumulationDis += distance;
|
||
|
// sprayWaterPoss.Add(pathPoints[i - 1]);
|
||
|
//}
|
||
|
//else
|
||
|
//{
|
||
|
// if (accumulationDis % startSprayWaterDistance == 0)
|
||
|
// {//正好整数段水幕水带子对象加起来为5米长
|
||
|
|
||
|
// sprayWaterPoss.Add(pathPoints[i - 1]);
|
||
|
|
||
|
// //加入每段根据间隔的分割点
|
||
|
// var result = (int)(distance / spaceDistance);
|
||
|
// for (int j = 1; j <= result; j++)
|
||
|
// {
|
||
|
// var sprayWaterPos = Vector3.MoveTowards(pathPoints[i - 1], pathPoints[i - 2], spaceDistance * j);
|
||
|
// sprayWaterPoss.Add(sprayWaterPos);
|
||
|
// }
|
||
|
// }
|
||
|
// else
|
||
|
// {//整数段水幕水带子对象加起来已大于5米
|
||
|
// if (!flag)
|
||
|
// {
|
||
|
// var dis = accumulationDis - startSprayWaterDistance;
|
||
|
|
||
|
// var startpos = Vector3.MoveTowards(pathPoints[i], pathPoints[i - 1], startSprayWaterDistance);
|
||
|
|
||
|
// sprayWaterPoss.Add(startpos);
|
||
|
|
||
|
// var res = (int)(dis / spaceDistance);
|
||
|
// for (int j = 1; j <= res; j++)
|
||
|
// {
|
||
|
// var sprayWtPos = Vector3.MoveTowards(startpos, pathPoints[i - 1], spaceDistance * j);
|
||
|
// sprayWaterPoss.Add(sprayWtPos);
|
||
|
// }
|
||
|
|
||
|
// flag = true;
|
||
|
// }
|
||
|
|
||
|
// var result = (int)(distance / spaceDistance);
|
||
|
// for (int j = 1; j <= result; j++)
|
||
|
// {
|
||
|
// var sprayWaterPos = Vector3.MoveTowards(pathPoints[i - 1], pathPoints[i - 2], spaceDistance * j);
|
||
|
// sprayWaterPoss.Add(sprayWaterPos);
|
||
|
// }
|
||
|
// }
|
||
|
//}
|
||
|
var distance = Vector3.Distance(pathPoints[i - 1], pathPoints[i - 2]);
|
||
|
var result = (int)(distance / spaceDistance);
|
||
|
for (int j = 1; j <= result; j++)
|
||
|
{
|
||
|
var sprayWaterPos = Vector3.MoveTowards(pathPoints[i - 1], pathPoints[i - 2], spaceDistance * j);
|
||
|
sprayWaterPoss.Add(sprayWaterPos);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{//消火栓
|
||
|
for (int i = pathPoints.Count; i > 0; i--)
|
||
|
{
|
||
|
if ((i - 1) > 0)
|
||
|
{
|
||
|
//加入每段根据间隔的分割点
|
||
|
var distance = Vector3.Distance(pathPoints[i - 1], pathPoints[i - 2]);
|
||
|
var result = (int)(distance / spaceDistance);
|
||
|
for (int j = 1; j <= result; j++)
|
||
|
{
|
||
|
var sprayWaterPos = Vector3.MoveTowards(pathPoints[i - 1], pathPoints[i - 2], spaceDistance * j);
|
||
|
sprayWaterPoss.Add(sprayWaterPos);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 水幕水带出水
|
||
|
/// </summary>
|
||
|
public void SprayWaterCurtain(GameObject selectedWaterCurtainHose)
|
||
|
{
|
||
|
foreach (Transform child in selectedWaterCurtainHose.transform)
|
||
|
{
|
||
|
if (child.name == "WaterCurtain")
|
||
|
{
|
||
|
isClonedWaterCurtain = true;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (!isClonedWaterCurtain)
|
||
|
{//选中的水幕水带不存在水幕粒子特效,实例化水幕
|
||
|
CloneGameObjInfo info = selectedWaterCurtainHose.GetComponent<CloneGameObjInfo>();
|
||
|
for (int i = 0; i < sprayWaterPoss.Count; i++)
|
||
|
{
|
||
|
var WCurtain = EntitiesManager.Instance.CreateObj(
|
||
|
WaterCurtain,
|
||
|
sprayWaterPoss[i],
|
||
|
transform,
|
||
|
EntitiesManager.Instance.CreateObjID(CurrentUserInfo.mySelf.Id));
|
||
|
WCurtain.name = "WaterCurtain";
|
||
|
|
||
|
CloneGameObjInfo CloneObjInfo = WCurtain.GetComponent<CloneGameObjInfo>();
|
||
|
CloneObjInfo.gameObjType = info.gameObjType;
|
||
|
CloneObjInfo.UserID = info.UserID;
|
||
|
CloneObjInfo.buildNum = info.buildNum;
|
||
|
CloneObjInfo.floorNum = info.floorNum;
|
||
|
CloneObjInfo.interlayerNum = info.interlayerNum;
|
||
|
|
||
|
//水幕特效克隆同步
|
||
|
WaterCurutainSyncData syncData = new WaterCurutainSyncData();
|
||
|
CloneGameObjInfo WCurtainCloneGameObjInfo = WCurtain.GetComponent<CloneGameObjInfo>();
|
||
|
syncData.gameObjID = WCurtainCloneGameObjInfo.gameObjID;
|
||
|
syncData.gameObjType = WCurtainCloneGameObjInfo.gameObjType;
|
||
|
syncData.UserID = WCurtainCloneGameObjInfo.UserID;
|
||
|
syncData.buildNum = WCurtainCloneGameObjInfo.buildNum;
|
||
|
syncData.floorNum = WCurtainCloneGameObjInfo.floorNum;
|
||
|
syncData.interlayerNum = WCurtainCloneGameObjInfo.interlayerNum;
|
||
|
syncData.SendUserID = CurrentUserInfo.mySelf.Id;
|
||
|
syncData.ClonePosition = sprayWaterPoss[i];
|
||
|
syncData.Name = WCurtain.name;
|
||
|
syncData.ParentGameObjId = info.gameObjID;
|
||
|
NetworkManager.Default.SendAsync("CLONE_WATERCURTAIN_SYNC", syncData);
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{//若存在,则显示即可
|
||
|
foreach (Transform child in selectedWaterCurtainHose.transform)
|
||
|
{
|
||
|
if (child.name == "WaterCurtain")
|
||
|
{
|
||
|
WaterCurutainHideOrShowSyncData syncData = new WaterCurutainHideOrShowSyncData();
|
||
|
syncData.GameObjId = child.GetComponent<CloneGameObjInfo>().gameObjID;
|
||
|
syncData.isShow = true;
|
||
|
NetworkManager.Default.SendAsync("WATERCURTAIN_HIDEORSHOW_SYNC", syncData);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 水幕水带停止出水
|
||
|
/// </summary>
|
||
|
public void StopWaterCurtain(GameObject selectedWaterCurtainHose)
|
||
|
{
|
||
|
foreach (Transform child in selectedWaterCurtainHose.transform)
|
||
|
{
|
||
|
if (child.name == "WaterCurtain")
|
||
|
{
|
||
|
WaterCurutainHideOrShowSyncData syncData = new WaterCurutainHideOrShowSyncData();
|
||
|
syncData.GameObjId = child.GetComponent<CloneGameObjInfo>().gameObjID;
|
||
|
syncData.isShow = false;
|
||
|
NetworkManager.Default.SendAsync("WATERCURTAIN_HIDEORSHOW_SYNC", syncData);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Update is called once per frame
|
||
|
void Update()
|
||
|
{
|
||
|
|
||
|
}
|
||
|
}
|