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.
237 lines
8.3 KiB
237 lines
8.3 KiB
4 years ago
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
using AX.MessageSystem;
|
||
|
using System;
|
||
|
using AX.InputSystem;
|
||
|
|
||
|
public class Waterseparadata
|
||
|
{
|
||
|
public bool IsContent;
|
||
|
public long receiveId;
|
||
|
public WaterType watertype;
|
||
|
}
|
||
|
[Serializable]
|
||
|
public class YDragData
|
||
|
{
|
||
|
public string name;
|
||
|
public long id;
|
||
|
public Vector3 Position;
|
||
|
}
|
||
|
public class WaterSeparaterControl : MonoBehaviour
|
||
|
{
|
||
|
private long gameID;
|
||
|
private WaterSupplier WaterSupplier;
|
||
|
private WaterReceiver WaterReceiver;
|
||
|
// Start is called before the first frame update
|
||
|
void Awake()
|
||
|
{
|
||
|
WaterSupplier = GetComponent<WaterSupplier>();
|
||
|
WaterReceiver = GetComponent<WaterReceiver>();
|
||
|
MessageDispatcher.AddListener("W_COMMAND", WCommond);
|
||
|
MessageDispatcher.AddListener("S_COMMAND", SCommond);
|
||
|
MessageDispatcher.AddListener("U_COMMAND", U);
|
||
|
MessageDispatcher.AddListener("J_COMMAND", J);
|
||
|
MessageDispatcher.AddListener("ReplayEvent", ReplayEventPos);
|
||
|
MessageDispatcher.AddListener("WaterSourceChanged", WaterSourceChange);
|
||
|
MessageDispatcher.AddListener("ReplayEvent", ReplayEvent);
|
||
|
|
||
|
}
|
||
|
private void Start()
|
||
|
{
|
||
|
gameID = GetComponent<CloneGameObjInfo>().gameObjID;
|
||
|
}
|
||
|
private void OnDestroy()
|
||
|
{
|
||
|
MessageDispatcher.RemoveListener("W_COMMAND", WCommond);
|
||
|
MessageDispatcher.RemoveListener("S_COMMAND", SCommond);
|
||
|
MessageDispatcher.RemoveListener("U_COMMAND", U);
|
||
|
MessageDispatcher.RemoveListener("J_COMMAND", J);
|
||
|
MessageDispatcher.RemoveListener("ReplayEvent", ReplayEventPos);
|
||
|
MessageDispatcher.RemoveListener("WaterSourceChanged", WaterSourceChange);
|
||
|
MessageDispatcher.RemoveListener("ReplayEvent", ReplayEvent);
|
||
|
}
|
||
|
|
||
|
private void WaterSourceChange(IMessage obj)
|
||
|
{
|
||
|
WaterConnectionData data = (WaterConnectionData)obj.Data;
|
||
|
if (data.receiverID == gameID)
|
||
|
{
|
||
|
|
||
|
if (data.supplierID == -1)
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
if (EntitiesManager.Instance.GetEntityByID(data.supplierID) == null)
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
WaterType sourcetype = EntitiesManager.Instance.GetEntityByID(data.supplierID).GetComponent<WaterSupplier>().WaterReceiverType;
|
||
|
|
||
|
if (data.connected)
|
||
|
{
|
||
|
WaterSupplier.WaterReceiverType = sourcetype;
|
||
|
for (int i = 0; i < WaterSupplier.waterLineInfos.Count; i++)
|
||
|
{
|
||
|
GameObject waterline = EntitiesManager.Instance.GetEntityByID(WaterSupplier.waterLineInfos[i]);
|
||
|
Waterseparadata wdata = new Waterseparadata()
|
||
|
{
|
||
|
IsContent = data.connected,
|
||
|
receiveId = waterline.GetComponent<WaterLineInfo>().ReceiverID,
|
||
|
watertype = WaterSupplier.WaterReceiverType,
|
||
|
};
|
||
|
MessageDispatcher.SendMessage("WaterSeparaterChange", wdata);
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
for (int i = 0; i < WaterSupplier.waterLineInfos.Count; i++)
|
||
|
{
|
||
|
GameObject waterline = EntitiesManager.Instance.GetEntityByID(WaterSupplier.waterLineInfos[i]);
|
||
|
if (waterline)
|
||
|
{
|
||
|
Waterseparadata wdata = new Waterseparadata()
|
||
|
{
|
||
|
IsContent = data.connected,
|
||
|
receiveId = waterline.GetComponent<WaterLineInfo>().ReceiverID,
|
||
|
watertype = WaterSupplier.WaterReceiverType,
|
||
|
};
|
||
|
MessageDispatcher.SendMessage("WaterSeparaterChange", wdata);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
WaterSupplier.WaterReceiverType = WaterType.none;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
private void ReplayEventPos(IMessage obj)
|
||
|
{
|
||
|
var eventData = (EventData)obj.Data;
|
||
|
if (eventData.eventType == RecordEventType.ObjDraging)
|
||
|
{
|
||
|
YDragData data = JsonUtility.FromJson<YDragData>(eventData.json);
|
||
|
if (data.name == gameObject.name)
|
||
|
transform.position = data.Position;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
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 void J(IMessage obj)
|
||
|
{
|
||
|
var gameObjID = (long)obj.Sender;
|
||
|
if (gameObjID == GetComponent<BaseGameObjInfo>().GameObjID)
|
||
|
{
|
||
|
|
||
|
RotateJ();
|
||
|
//AddRecordEvent(RecordEventType.WaterSprayJ);
|
||
|
AddRecordUJEvent();
|
||
|
}
|
||
|
}
|
||
|
protected void U(IMessage obj)
|
||
|
{
|
||
|
var gameObjID = (long)obj.Sender;
|
||
|
if (gameObjID == GetComponent<BaseGameObjInfo>().GameObjID)
|
||
|
{
|
||
|
RotateU();
|
||
|
//AddRecordEvent(RecordEventType.WaterSprayU);
|
||
|
AddRecordUJEvent();
|
||
|
}
|
||
|
}
|
||
|
private void RotateU()
|
||
|
{
|
||
|
transform.Rotate(-Time.deltaTime * 40, 0,0, Space.Self);
|
||
|
}
|
||
|
private void RotateJ()
|
||
|
{
|
||
|
transform.Rotate( Time.deltaTime * 40,0,0, 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);
|
||
|
}
|
||
|
}
|
||
|
protected 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.ObjDraging)
|
||
|
//{
|
||
|
// YDragData data = JsonUtility.FromJson<YDragData>(eventData.json);
|
||
|
// if (data.name == gameObject.name)
|
||
|
// {
|
||
|
// transform.position = data.Position;
|
||
|
// }
|
||
|
//}
|
||
|
}
|
||
|
}
|