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.
514 lines
19 KiB
514 lines
19 KiB
using AX.InputSystem; |
|
using AX.MessageSystem; |
|
using System; |
|
using System.Collections; |
|
using System.Collections.Generic; |
|
using UnityEngine; |
|
|
|
public enum RotateType |
|
{ |
|
part1, |
|
part2, |
|
transform, |
|
} |
|
//[DisallowMultipleComponent] |
|
//[RequireComponent(typeof(SprayHeadRecord))] |
|
public class ControlSprayHead : MonoBehaviour |
|
{ |
|
public Transform part1; |
|
public Transform part2; |
|
public Transform water; |
|
public float Scale; |
|
public ParticleEnum particleenum; |
|
internal long GameObjID; |
|
public bool IsSpray |
|
{ |
|
get |
|
{ |
|
return water.gameObject.activeSelf; |
|
} |
|
|
|
set |
|
{ |
|
water.gameObject.SetActive(value); |
|
SetAnimAndHose(value); |
|
if (!value) |
|
particleenum = ParticleEnum.None; |
|
} |
|
} |
|
private void Start() |
|
{ |
|
GameObjID = GetComponent<BaseGameObjInfo>().GameObjID; |
|
} |
|
internal virtual void InitGameObject() |
|
{ |
|
water = TransformHelper.FindChild(transform, "Hose"); |
|
part1 = TransformHelper.FindChild(transform, "Sprayer"); |
|
if (part2 == null) |
|
part2 = part1; |
|
if (part1 == null) |
|
part1 = water; |
|
}//初始化物体 |
|
void OnDisable() |
|
{ |
|
MessageDispatcher.RemoveListener("EQUALS_COMMAND", PressureUp); |
|
MessageDispatcher.RemoveListener("MINUS_COMMAND", PressureDown); |
|
MessageDispatcher.RemoveListener("U_COMMAND", U); |
|
MessageDispatcher.RemoveListener("J_COMMAND", J); |
|
MessageDispatcher.RemoveListener("H_COMMAND", H); |
|
MessageDispatcher.RemoveListener("K_COMMAND", K); |
|
MessageDispatcher.RemoveListener("CHANGE_PARTICLE_TYPE_COMMAND", ChangeParticle); |
|
MessageDispatcher.RemoveListener("SprayWater", SprayWater); |
|
MessageDispatcher.RemoveListener("SprayFoam", SprayFoam); |
|
MessageDispatcher.RemoveListener("Decontamination", Decontamination); |
|
MessageDispatcher.RemoveListener("RADIO_SELECTED_COMMAND", RadioSelect); |
|
} |
|
|
|
|
|
void OnEnable() |
|
{ |
|
// MessageDispatcher.AddListener("ReplayEvent", ReplayAgent); |
|
MessageDispatcher.AddListener("EQUALS_COMMAND", PressureUp); |
|
MessageDispatcher.AddListener("MINUS_COMMAND", PressureDown); |
|
MessageDispatcher.AddListener("U_COMMAND", U); |
|
MessageDispatcher.AddListener("J_COMMAND", J); |
|
MessageDispatcher.AddListener("H_COMMAND", H); |
|
MessageDispatcher.AddListener("K_COMMAND", K); |
|
MessageDispatcher.AddListener("CHANGE_PARTICLE_TYPE_COMMAND", ChangeParticle); |
|
MessageDispatcher.AddListener("SprayWater", SprayWater); |
|
MessageDispatcher.AddListener("SprayFoam", SprayFoam); |
|
MessageDispatcher.AddListener("Decontamination", Decontamination); |
|
MessageDispatcher.AddListener("RADIO_SELECTED_COMMAND", RadioSelect); |
|
} |
|
|
|
private void Decontamination(IMessage obj) |
|
{ |
|
var gameObjID = (long)obj.Sender; |
|
if (gameObjID == GameObjID) |
|
if (water) |
|
{ |
|
if (RecordEvent.IsReplay())//回放不执行泡沫喷水(当改变特效时候改变) |
|
return; |
|
if ((bool)obj.Data) |
|
MessageDispatcher.SendMessage("CHANGE_PARTICLE_TYPE_COMMAND", new ParticleTypeCmdArgs() { ParticleType = ParticleEnum.Decontamination }); |
|
else |
|
IsSpray = false; |
|
} |
|
} |
|
|
|
void OnDestroy() |
|
{ |
|
MessageDispatcher.RemoveListener("ReplayEvent", ReplayAgent); |
|
MessageDispatcher.RemoveListener("EQUALS_COMMAND", PressureUp); |
|
MessageDispatcher.RemoveListener("MINUS_COMMAND", PressureDown); |
|
MessageDispatcher.RemoveListener("U_COMMAND", U); |
|
MessageDispatcher.RemoveListener("J_COMMAND", J); |
|
MessageDispatcher.RemoveListener("H_COMMAND", H); |
|
MessageDispatcher.RemoveListener("K_COMMAND", K); |
|
MessageDispatcher.RemoveListener("CHANGE_PARTICLE_TYPE_COMMAND", ChangeParticle); |
|
MessageDispatcher.RemoveListener("SprayWater", SprayWater); |
|
MessageDispatcher.RemoveListener("SprayFoam", SprayFoam); |
|
MessageDispatcher.RemoveListener("Decontamination", Decontamination); |
|
MessageDispatcher.RemoveListener("RADIO_SELECTED_COMMAND", RadioSelect); |
|
MessageDispatcher.RemoveListener("WaterSwitch", WaterSwitch); |
|
MessageDispatcher.RemoveListener("GetButtonUp", GetButtonUp); |
|
//MessageDispatcher.AddListener("ReplayForm", ReplayForm); |
|
} |
|
|
|
|
|
|
|
private void GetButtonUp(IMessage obj) |
|
{ |
|
var gameObjID = (long)obj.Sender; |
|
if (gameObjID == GameObjID) |
|
{ |
|
if (RecordEvent.IsRecord()) |
|
{ |
|
if (LinearEventData != null) |
|
AddRotationEvent(QuaternionChangeTran); |
|
if (SizeLinearEventData != null) |
|
AddSizeEvent(QuaternionChangeTran); |
|
} |
|
} |
|
} |
|
private void WaterSwitch(IMessage obj) |
|
{ |
|
var gameObjID = (long)obj.Sender; |
|
if (gameObjID == GameObjID) |
|
{ |
|
IsSpray = (bool)obj.Data; |
|
} |
|
} |
|
|
|
private void RadioSelect(IMessage obj) |
|
{ |
|
var gameObjID = (long)obj.Sender; |
|
if (gameObjID != GameObjID) |
|
{ |
|
if (RecordEvent.IsRecord()) |
|
{ |
|
if (LinearEventData != null) |
|
AddRotationEvent(QuaternionChangeTran); |
|
if (SizeLinearEventData != null) |
|
AddSizeEvent(QuaternionChangeTran); |
|
} |
|
} |
|
} |
|
EventData LinearEventData = null; |
|
Quaternion Beginquaternion = Quaternion.identity; |
|
public Transform QuaternionChangeTran = null; |
|
EventData SizeLinearEventData = null; |
|
private float BeginSize = float.Epsilon; |
|
public Transform SizeChangeTran = null; |
|
public void CreateRotationEvent(Transform changetran) |
|
{ |
|
if (LinearEventData == null) |
|
{ |
|
if (Beginquaternion == Quaternion.identity) |
|
{ |
|
this.QuaternionChangeTran = changetran; |
|
LinearEventData = RecordEvent.CreateLinearEventData(); |
|
Beginquaternion = changetran.localRotation; |
|
} |
|
} |
|
} |
|
|
|
public void CreateSizeEvent(Transform changetran) |
|
{ |
|
if (SizeLinearEventData == null) |
|
{ |
|
this.SizeChangeTran = changetran; |
|
SizeLinearEventData = RecordEvent.CreateLinearEventData(); |
|
BeginSize = Scale; |
|
} |
|
} |
|
public void AddRotationEvent(Transform trans) |
|
{ |
|
if (LinearEventData != null) |
|
{ |
|
RotationLinerEventData RotationLinerEventData = new RotationLinerEventData() |
|
{ |
|
BeginRotation = TransformHelper.ConvertToMyRotation(Beginquaternion), |
|
EndRotation = TransformHelper.ConvertToMyRotation(trans.transform.localRotation), |
|
Name = trans.name |
|
}; |
|
RecordEvent.AddLinearEventData(LinearEventData, LinearEventType.Rotation, GameObjID, JsonUtility.ToJson(RotationLinerEventData)); |
|
Beginquaternion = Quaternion.identity; |
|
QuaternionChangeTran = null; |
|
LinearEventData = null; |
|
} |
|
} |
|
protected void AddSizeEvent(Transform trans) |
|
{ |
|
if (SizeLinearEventData != null) |
|
{ |
|
if (BeginSize != float.Epsilon) |
|
{ |
|
SizeLinerEventData SizeLinerEventData = new SizeLinerEventData() |
|
{ |
|
BeginSize = BeginSize, |
|
EndSize = Scale |
|
}; |
|
RecordEvent.AddLinearEventData(SizeLinearEventData, LinearEventType.Size, GameObjID, JsonUtility.ToJson(SizeLinerEventData)); |
|
BeginSize = float.Epsilon; |
|
SizeChangeTran = null; |
|
SizeLinearEventData = null; |
|
} |
|
else |
|
Debug.Log(BeginSize == float.Epsilon); |
|
} |
|
} |
|
private void ReplayAgent(IMessage obj) |
|
{ |
|
|
|
var eventData = (EventData)obj.Data; |
|
if (eventData.eventType == RecordEventType.ChangeSprayHeadParticle) |
|
{ |
|
var data = JsonUtility.FromJson<ChangeSprayHeadParticleEventData>(eventData.json); |
|
if (data.GameId == GameObjID) |
|
{ |
|
if (data.ParticleEnum!=-1) |
|
{ |
|
if (gameObject.CompareTag("Player")) |
|
{ |
|
gameObject.GetComponent<FiremanControlSprayHead>().SetAnimAndHose(true); |
|
} |
|
IsSpray = true; |
|
particleenum = (ParticleEnum)data.ParticleEnum; |
|
|
|
ResManage.Instance.LoadParticleInEnum(particleenum, this.transform, data.Scale); |
|
} |
|
else |
|
{ |
|
water.GetComponentInChildren<ParticleControlOfType>().SetScaleValue(data.Scale); |
|
} |
|
} |
|
} |
|
else if (eventData.eventType == RecordEventType.SprayRotate) |
|
{ |
|
var data = Newtonsoft.Json.JsonConvert.DeserializeObject<SprayRotateRecordData>(eventData.json); |
|
if (data.objectName == GameObjID.ToString()) |
|
{ |
|
if (data.RotateType == RotateType.part1) |
|
{ |
|
part1.localEulerAngles = data.localEulerAngles; |
|
} |
|
else if (data.RotateType == RotateType.part2) |
|
{ |
|
part2.localEulerAngles = data.localEulerAngles; |
|
} |
|
else if (data.RotateType == RotateType.transform) |
|
{ |
|
transform.localEulerAngles = data.localEulerAngles; |
|
} |
|
} |
|
} |
|
} |
|
public void Increase(float Weight) |
|
{ |
|
water.GetComponentInChildren<ParticleControlOfType>().Increase(Weight); |
|
Scale = water.GetComponentInChildren<ParticleControlOfType>().GetScaleValue(); |
|
} |
|
internal virtual void PressureUp(IMessage message) |
|
{ |
|
var gameObjID = (long)message.Sender; |
|
if (gameObjID == GameObjID) |
|
if (water && IsSpray) |
|
{ |
|
var Weight = ((WeightCmdArgs)message.Data).Weight; |
|
if (RecordEvent.IsRecord()) |
|
CreateSizeEvent(water); |
|
Increase(Weight); |
|
|
|
ChangeSprayHeadParticleEventData data = new ChangeSprayHeadParticleEventData |
|
{ |
|
GameId = GameObjID, |
|
Scale = Scale, |
|
ParticleEnum = -1, |
|
}; |
|
|
|
RecordEvent.AddEventData(CloneObjType.None, RecordEventType.ChangeSprayHeadParticle, JsonUtility.ToJson(data)); |
|
} |
|
} |
|
public void Decrease(float Weight) |
|
{ |
|
water.GetComponentInChildren<ParticleControlOfType>().Decrease(Weight); |
|
Scale = water.GetComponentInChildren<ParticleControlOfType>().GetScaleValue(); |
|
} |
|
internal virtual void PressureDown(IMessage message) |
|
{ |
|
var gameObjID = (long)message.Sender; |
|
if (gameObjID == GameObjID) |
|
if (water && IsSpray) |
|
{ |
|
var Weight = ((WeightCmdArgs)message.Data).Weight; |
|
if (RecordEvent.IsRecord()) |
|
CreateSizeEvent(water); |
|
Decrease(Weight); |
|
ChangeSprayHeadParticleEventData data = new ChangeSprayHeadParticleEventData |
|
{ |
|
GameId = GameObjID, |
|
Scale = Scale, |
|
ParticleEnum = -1, |
|
}; |
|
|
|
RecordEvent.AddEventData(CloneObjType.None, RecordEventType.ChangeSprayHeadParticle, JsonUtility.ToJson(data)); |
|
} |
|
} |
|
internal virtual void ChangeParticle(IMessage obj) |
|
{ |
|
//var gameObjID = (long)obj.Sender; |
|
if (SelectedObjs.selectedObj == gameObject || SelectedObjs.selectedCharacters.Contains(gameObject)) |
|
if (water) |
|
{ |
|
var particletype = ((ParticleTypeCmdArgs)obj.Data); |
|
IsSpray = true; |
|
if (particleenum != particletype.ParticleType) |
|
{ |
|
|
|
particleenum = particletype.ParticleType; |
|
ResManage.Instance.LoadParticleInEnum(particletype.ParticleType, this.transform, Scale); |
|
//switch (particleenum) |
|
//{ |
|
// case ParticleEnum.WaterStraight: |
|
// Scale = 1f;//.3 |
|
// break; |
|
// case ParticleEnum.WaterFlower://3 |
|
// break; |
|
// case ParticleEnum.WaterFog://5 |
|
// break; |
|
// case ParticleEnum.Froth: |
|
// Scale = 6f;//5 |
|
// break; |
|
// case ParticleEnum.DryPowder: |
|
// break; |
|
// default: |
|
// break; |
|
//} |
|
//water.GetComponentInChildren<ParticleControlOfType>().SetScaleValue(Scale); |
|
|
|
//记录改变喷水特效 |
|
if (RecordEvent.IsRecord()) |
|
{ |
|
var ChangeSprayHeadParticleEventData = new ChangeSprayHeadParticleEventData() |
|
{ |
|
GameId = GameObjID, |
|
Scale = Scale, |
|
ParticleEnum = (int)particleenum, |
|
}; |
|
RecordEvent.AddEventData(CloneObjType.None, RecordEventType.ChangeSprayHeadParticle, JsonUtility.ToJson(ChangeSprayHeadParticleEventData)); |
|
} |
|
} |
|
} |
|
} |
|
internal virtual void U(IMessage message) |
|
{ |
|
var gameObjID = (long)message.Sender; |
|
if (gameObjID == GameObjID) |
|
{ |
|
//if (RecordEvent.IsRecord()) |
|
// CreateRotationEvent(part1); |
|
var speed = ((WeightCmdArgs)message.Data).Weight; |
|
float x = part1.localEulerAngles.x; |
|
float y = part1.localEulerAngles.y; |
|
x = CheckValue(x); |
|
x -= speed; |
|
x = Mathf.Clamp(x, -50, 15); |
|
part1.localEulerAngles = new Vector3(x, y, 0); |
|
AddRotateEvent(part1.localEulerAngles, RotateType.part1); |
|
} |
|
} |
|
internal virtual void J(IMessage message) |
|
{ |
|
var gameObjID = (long)message.Sender; |
|
if (gameObjID == GameObjID) |
|
{ |
|
//if (RecordEvent.IsRecord()) |
|
// CreateRotationEvent(part1); |
|
var speed = ((WeightCmdArgs)message.Data).Weight; |
|
float x = part1.localEulerAngles.x; |
|
float y = part1.localEulerAngles.y; |
|
x = CheckValue(x); |
|
x += speed; |
|
x = Mathf.Clamp(x, -50, 15); |
|
part1.localEulerAngles = new Vector3(x, y, 0); |
|
AddRotateEvent(part1.localEulerAngles, RotateType.part1); |
|
} |
|
} |
|
internal virtual void H(IMessage message) |
|
{ |
|
var gameObjID = (long)message.Sender; |
|
if (gameObjID == GameObjID) |
|
{ |
|
//if (RecordEvent.IsRecord()) |
|
// CreateRotationEvent(part1); |
|
var speed = ((WeightCmdArgs)message.Data).Weight; |
|
float x = part1.localEulerAngles.x; |
|
float y = part1.localEulerAngles.y; |
|
y = CheckValue(y); |
|
y -= speed; |
|
y = Mathf.Clamp(y, -90, 90); |
|
part1.localEulerAngles = new Vector3(x, y, 0); |
|
AddRotateEvent(part1.localEulerAngles, RotateType.part1); |
|
} |
|
} |
|
internal virtual void K(IMessage message) |
|
{ |
|
var gameObjID = (long)message.Sender; |
|
if (gameObjID == GameObjID) |
|
{ |
|
//if (RecordEvent.IsRecord()) |
|
// CreateRotationEvent(part1); |
|
var speed = ((WeightCmdArgs)message.Data).Weight; |
|
float x = part1.localEulerAngles.x; |
|
float y = part1.localEulerAngles.y; |
|
y = CheckValue(y); |
|
y += speed; |
|
y = Mathf.Clamp(y, -90, 90); |
|
part1.localEulerAngles = new Vector3(x, y, 0); |
|
AddRotateEvent(part1.localEulerAngles, RotateType.part1); |
|
} |
|
} |
|
public void AddRotateEvent(Vector3 localEulerAngles, RotateType type) |
|
{ |
|
if (ReplaySetting.PlayStatus == PlayStatus.isEditor && RecordManager.Instance.recordStatus == RecordStatus.normal) |
|
{ |
|
var eventData = new EventData(); |
|
eventData.time = RecordManager.Instance.RecordTimer; |
|
eventData.cloneObjType = GetComponent<BaseGameObjInfo>().gameObjType; |
|
eventData.eventType = RecordEventType.SprayRotate; |
|
SprayRotateRecordData data = new SprayRotateRecordData |
|
{ |
|
objectName = GameObjID.ToString(), |
|
localEulerAngles = localEulerAngles, |
|
RotateType = type, |
|
}; |
|
eventData.json = Newtonsoft.Json.JsonConvert.SerializeObject(data); |
|
RecordManager.Instance.jsonData.eventDataList.Add(eventData); |
|
//RecordManager.Instance.SaveEventToSever(eventData, true).Forget(); |
|
} |
|
} |
|
internal virtual void SprayWater(IMessage message) |
|
{ |
|
var gameObjID = (long)message.Sender; |
|
if (gameObjID == GameObjID) |
|
if (water) |
|
{ |
|
|
|
if ((bool)message.Data) |
|
{ |
|
if (RecordEvent.IsReplay())//回放不显示选择喷水方式面板 |
|
return; |
|
WaterFlowAttribute.GetInstance.gameObject.SetActive(true); |
|
WaterFlowAttribute.GetInstance.Show(particleenum); |
|
} |
|
else |
|
{ |
|
if (WaterFlowAttribute.GetInstance.gameObject.activeSelf) |
|
WaterFlowAttribute.GetInstance.gameObject.SetActive(false); |
|
IsSpray = false; |
|
} |
|
} |
|
} |
|
internal virtual void SprayFoam(IMessage message) |
|
{ |
|
var gameObjID = (long)message.Sender; |
|
if (gameObjID == GameObjID) |
|
if (water) |
|
{ |
|
if (RecordEvent.IsReplay())//回放不执行泡沫喷水(当改变特效时候改变) |
|
return; |
|
if ((bool)message.Data) |
|
MessageDispatcher.SendMessage("CHANGE_PARTICLE_TYPE_COMMAND", new ParticleTypeCmdArgs() { ParticleType = ParticleEnum.Froth }); |
|
else |
|
IsSpray = false; |
|
} |
|
} |
|
private void Awake() |
|
{ |
|
InitGameObject(); |
|
MessageDispatcher.AddListener("ReplayEvent", ReplayAgent); |
|
MessageDispatcher.AddListener("WaterSwitch", WaterSwitch); |
|
MessageDispatcher.AddListener("GetButtonUp", GetButtonUp); |
|
// MessageDispatcher.AddListener("ReplayForm", ReplayForm); |
|
} |
|
/// <summary> |
|
/// 换算原始角度值为显式值 |
|
/// </summary> |
|
/// <param name="x">获取的原始角度值</param> |
|
/// <returns></returns> |
|
protected float CheckValue(float x) |
|
{ |
|
if (x >= 180 && x <= 360) |
|
{ |
|
x = x - 360; |
|
} |
|
return x; |
|
//举例:假如获取到的localEulerAngles.x = 300,则在显示面板其显示的值为-60=300-360,用此显式值计算 |
|
} |
|
|
|
internal virtual void SetAnimAndHose(bool value) |
|
{ |
|
|
|
} |
|
}
|
|
|