上海杨浦大连路地铁站单机版电子沙盘
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.
 
 
 
 

183 lines
6.0 KiB

using AX.MessageSystem;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RobotAttribute : ToolAttribute {
public GameObject water;
public WaterReceiver receiver;
public bool IsAutoSwing;
public Transform SwingTrans;
private Vector3 orirotate;
private float timer;
protected override void Awake()
{
orirotate = SwingTrans.transform.localEulerAngles;
water = transform.Find("Gunturret/WaterStraight").gameObject;
water.SetActive(false);
receiver = GetComponent<WaterReceiver>();
gameObjType = CloneObjType.Robot;
typeName = "灭火机器人";
MessageDispatcher.AddListener("WaterSourceChanged", WaterSourceChanged);
MessageDispatcher.AddListener("WaterSeparaterChange", WaterseparadChange);
MessageDispatcher.AddListener("AutoSwing", AutoSwingCon);
base.Awake();
}
protected override void OnDestroy()
{
base.OnDestroy();
MessageDispatcher.RemoveListener("WaterSourceChanged", WaterSourceChanged);
MessageDispatcher.RemoveListener("WaterSeparaterChange", WaterseparadChange);
MessageDispatcher.RemoveListener("AutoSwing", AutoSwingCon);
}
private void AutoSwingCon(IMessage obj)
{
if ((long)obj.Data==GetComponent<BaseGameObjInfo>().gameObjID)
{
IsAutoSwing = !IsAutoSwing;
AddExecuteEvent();
}
}
private void AddExecuteEvent()
{
if (ReplaySetting.PlayStatus == PlayStatus.isEditor && RecordManager.Instance.recordStatus == RecordStatus.normal)
{
var eventData = new EventData();
var msg = GetComponent<CloneGameObjInfo>();
eventData.time = RecordManager.Instance.RecordTimer;
eventData.cloneObjType = msg.gameObjType;
eventData.eventType = RecordEventType.AutoSwing;
var data = new RecordWaterReceiver();
data.IsAutoSwing = IsAutoSwing;
data.ID = GetComponent<BaseGameObjInfo>().gameObjID;
string json = JsonUtility.ToJson(data);
eventData.json = json;
RecordManager.Instance.jsonData.eventDataList.Add(eventData);
}
}
protected override void ExecuteEvent(IMessage obj)
{
base.ExecuteEvent(obj);
var eventData = (EventData)obj.Data;
if (eventData.eventType == RecordEventType.AutoSwing && eventData.cloneObjType == gameObjType)
{
var arg = JsonUtility.FromJson<RecordWaterReceiver>(eventData.json);
if (arg.ID==GetComponent<BaseGameObjInfo>().gameObjID)
{
IsAutoSwing = arg.IsAutoSwing;
}
}
}
private void WaterseparadChange(IMessage obj)
{
var data = (Waterseparadata)obj.Data;
var msg = GetComponent<CloneGameObjInfo>();
if (msg.gameObjID == data.receiveId)
{
receiver.hasSupplier = data.IsContent;
if (msg.gameObjID == data.receiveId && data.IsContent == false && task == "灭火")
{
task = "待命";
Execute(task);
}
}
}
protected override void Execute(string TaskName)
{
task = TaskName;
if (TaskName.Contains("灭火"))
{
//if (receiver.hasSupplier == true)
//{
// water.SetActive(true);
//}
//else
//{
// ResourceLoadWindow.Instance.LoadTextHintWindow("请先连接水源", 2);
// task = "待命";
//}
if (receiver.hasSupplier == true)
{
// WaterType type = GetSupplerWaterType(receiver);
// if (type !=WaterType.none)
{
water.SetActive(true);
}
//else
//{
// ResourceLoadWindow.Instance.LoadTextHintWindow("请先连接水源", 2);
//}
}
else
{
ResourceLoadWindow.Instance.LoadTextHintWindow("请先连接水源", 2);
}
}
else
{
water.SetActive(false);
}
if (TaskName.Contains("自动摇摆"))
{
IsAutoSwing = true;
}
else
{
IsAutoSwing = false;
SwingTrans.localEulerAngles = orirotate;
}
}
private WaterType GetSupplerWaterType(WaterReceiver receiver)
{
WaterType type = WaterType.none;
GameObject waterline = EntitiesManager.Instance.GetEntityByID(receiver.waterlinelist[0]);
GameObject suppler = EntitiesManager.Instance.GetEntityByID(waterline.GetComponent<WaterLineInfo>().SupplierID);
type = suppler.GetComponent<WaterSupplier>().WaterReceiverType;
return type;
}
private void WaterSourceChanged(IMessage obj)
{
var data = (WaterConnectionData)obj.Data;
var msg = GetComponent<CloneGameObjInfo>();
if (msg.gameObjID == data.receiverID && data.connected == false && task == "灭火")
{
task = "待命";
Execute(task);
}
}
private void Update()
{
if (IsAutoSwing)
{
timer += Time.deltaTime;
if (timer > 12f)
{
timer = 0f;
}
else if (timer < 3)
{
SwingTrans.localEulerAngles += new Vector3(0, Time.deltaTime * 10, 0);
}
else if (timer < 6)
{
SwingTrans.localEulerAngles += new Vector3(0, -Time.deltaTime * 10, 0);
}
else if (timer < 9)
{
SwingTrans.localEulerAngles += new Vector3(0, -Time.deltaTime * 10, 0);
}
else if (timer < 12)
{
SwingTrans.localEulerAngles += new Vector3(0, Time.deltaTime * 10, 0);
}
}
}
}