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.
228 lines
7.8 KiB
228 lines
7.8 KiB
using AX.InputSystem; |
|
using AX.MessageSystem; |
|
using System.Collections; |
|
using System.Collections.Generic; |
|
using UnityEngine; |
|
|
|
public class HookPipeControl : BaseTransformChange { |
|
public ParticleControlOfType water; |
|
protected override void Awake() |
|
{ |
|
base.Awake(); |
|
water = transform.Find("WaterStraight").GetComponent<ParticleControlOfType>(); |
|
MessageDispatcher.AddListener("W_COMMAND", WCommond); |
|
MessageDispatcher.AddListener("S_COMMAND", SCommond); |
|
|
|
} |
|
protected override void OnDestroy() |
|
{ |
|
base.OnDestroy(); |
|
MessageDispatcher.RemoveListener("W_COMMAND", WCommond); |
|
MessageDispatcher.RemoveListener("S_COMMAND", SCommond); |
|
|
|
} |
|
private void SCommond(IMessage message) |
|
{ |
|
var gameObjID = (long)message.Sender; |
|
if (gameObjID == GetComponent<CloneGameObjInfo>().GameObjID) |
|
{ |
|
if (!GetComponent<ObjDrag>().enabled) |
|
{//连接水源后会设置不可拖动,连接水源后不能上下拖动 |
|
return; |
|
} |
|
var speed = ((WeightCmdArgs)message.Data).Weight; |
|
if (transform.position.y - speed > 0) |
|
{ |
|
transform.position -= Vector3.up * speed; |
|
} |
|
YDragData arg = new YDragData() |
|
{ |
|
name = gameObject.name, |
|
id = GetComponent<CloneGameObjInfo>().GameObjID, |
|
Position = transform.position, |
|
}; |
|
RecordEvent.AddEventData(CloneObjType.None, RecordEventType.ObjDraging, JsonUtility.ToJson(arg)); |
|
|
|
} |
|
} |
|
|
|
private void WCommond(IMessage message) |
|
{ |
|
var gameObjID = (long)message.Sender; |
|
if (gameObjID == GetComponent<CloneGameObjInfo>().GameObjID) |
|
{ |
|
if (!GetComponent<ObjDrag>().enabled) |
|
{//连接水源后会设置不可拖动,连接水源后不能上下拖动 |
|
return; |
|
} |
|
var speed = ((WeightCmdArgs)message.Data).Weight; |
|
if (transform.position.y > 0) |
|
{ |
|
transform.position += Vector3.up * speed; |
|
} |
|
YDragData arg = new YDragData() |
|
{ |
|
name = gameObject.name, |
|
id = GetComponent<CloneGameObjInfo>().GameObjID, |
|
Position = transform.position, |
|
}; |
|
RecordEvent.AddEventData(CloneObjType.None, RecordEventType.ObjDraging, JsonUtility.ToJson(arg)); |
|
|
|
} |
|
} |
|
protected override void ReplayEvent(IMessage obj) |
|
{ |
|
var eventData = (EventData)obj.Data; |
|
if (eventData.eventType == RecordEventType.WaterSprayU) |
|
{ |
|
RecordSprayerRotation data = JsonUtility.FromJson<RecordSprayerRotation>(eventData.json); |
|
if (data.gameObjID == GetComponent<BaseGameObjInfo>().gameObjID) |
|
{ |
|
transform.localEulerAngles = data.rotation; |
|
} |
|
} |
|
else if (eventData.eventType == RecordEventType.WaterSprayA) |
|
{ |
|
RecordSprayerRotation data = JsonUtility.FromJson<RecordSprayerRotation>(eventData.json); |
|
if (data.gameObjID == GetComponent<BaseGameObjInfo>().gameObjID) |
|
{ |
|
transform.localEulerAngles = data.rotation; |
|
} |
|
} |
|
else if (eventData.eventType == RecordEventType.WaterSprayPlus) |
|
{ |
|
if (eventData.json == gameObject.name) |
|
{ |
|
water.Increase(0.1f); |
|
} |
|
} |
|
else if (eventData.eventType == RecordEventType.WaterSprayMinus) |
|
{ |
|
if (eventData.json == gameObject.name) |
|
{ |
|
water.Decrease(0.1f); |
|
} |
|
} |
|
else if (eventData.eventType == RecordEventType.ObjDraging) |
|
{ |
|
YDragData data = JsonUtility.FromJson<YDragData>(eventData.json); |
|
if (data.name == gameObject.name) |
|
{ |
|
transform.position = data.Position; |
|
} |
|
} |
|
} |
|
protected override void D(IMessage obj) |
|
{ |
|
var gameObjID = (long)obj.Sender; |
|
if (gameObjID == GetComponent<BaseGameObjInfo>().GameObjID) |
|
{ |
|
RotateD(); |
|
//AddRecordEvent(RecordEventType.WaterSprayD); |
|
AddRecordADEvent(); |
|
} |
|
} |
|
protected override void A(IMessage obj) |
|
{ |
|
var gameObjID = (long)obj.Sender; |
|
if (gameObjID == GetComponent<BaseGameObjInfo>().GameObjID) |
|
{ |
|
RotateA(); |
|
//AddRecordEvent(RecordEventType.WaterSprayA); |
|
AddRecordADEvent(); |
|
} |
|
} |
|
protected override void J(IMessage obj) |
|
{ |
|
var gameObjID = (long)obj.Sender; |
|
if (gameObjID == GetComponent<BaseGameObjInfo>().GameObjID) |
|
{ |
|
RotateJ(); |
|
//AddRecordEvent(RecordEventType.WaterSprayJ); |
|
AddRecordUJEvent(); |
|
} |
|
} |
|
protected override void U(IMessage obj) |
|
{ |
|
var gameObjID = (long)obj.Sender; |
|
if (gameObjID == GetComponent<BaseGameObjInfo>().GameObjID) |
|
{ |
|
RotateU(); |
|
//AddRecordEvent(RecordEventType.WaterSprayU); |
|
AddRecordUJEvent(); |
|
} |
|
} |
|
protected override void PressureDown(IMessage obj) |
|
{ |
|
var gameObjID = (long)obj.Sender; |
|
if (gameObjID == GetComponent<BaseGameObjInfo>().GameObjID) |
|
{ |
|
water.Decrease(0.5f); |
|
AddRecordEvent(RecordEventType.WaterSprayMinus); |
|
} |
|
} |
|
|
|
protected override void PressureUp(IMessage obj) |
|
{ |
|
var gameObjID = (long)obj.Sender; |
|
if (gameObjID == GetComponent<BaseGameObjInfo>().GameObjID) |
|
{ |
|
water.Increase(0.5f); |
|
AddRecordEvent(RecordEventType.WaterSprayPlus); |
|
} |
|
} |
|
private void RotateU() |
|
{ |
|
transform.Rotate(0, -Time.deltaTime * 40, 0, Space.Self); |
|
} |
|
private void RotateJ() |
|
{ |
|
transform.Rotate(0, Time.deltaTime * 40, 0, Space.Self); |
|
} |
|
private void RotateA() |
|
{ |
|
transform.Rotate(0, 0, Time.deltaTime * 40, Space.Self); |
|
} |
|
private void RotateD() |
|
{ |
|
transform.Rotate(0, 0, -Time.deltaTime * 40, Space.Self); |
|
} |
|
private void AddRecordUJEvent() |
|
{ |
|
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.WaterSprayU; |
|
RecordSprayerRotation data = new RecordSprayerRotation(); |
|
data.gameObjID = GetComponent<BaseGameObjInfo>().gameObjID; |
|
data.rotation = transform.localEulerAngles; |
|
eventData.json = JsonUtility.ToJson(data); |
|
RecordManager.Instance.jsonData.eventDataList.Add(eventData); |
|
} |
|
} |
|
private void AddRecordADEvent() |
|
{ |
|
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.WaterSprayA; |
|
RecordSprayerRotation data = new RecordSprayerRotation(); |
|
data.gameObjID = GetComponent<BaseGameObjInfo>().gameObjID; |
|
data.rotation = obj.transform.localEulerAngles; |
|
eventData.json = JsonUtility.ToJson(data); |
|
RecordManager.Instance.jsonData.eventDataList.Add(eventData); |
|
} |
|
} |
|
public float GetWaterScale() |
|
{ |
|
return water.GetScaleValue(); |
|
} |
|
public void SetWaterScale(float value) |
|
{ |
|
water.SetScaleValue(value); |
|
} |
|
}
|
|
|