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

159 lines
5.3 KiB

using AX.MessageSystem;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RobotControl : BaseTransformChange {
public Transform head;
public ParticleControlOfType waterControl;
protected override void Awake()
{
head = transform.Find("Gunturret");
waterControl= TransformHelper.FindChild(transform, "WaterStraight").GetComponentInChildren<ParticleControlOfType>();
base.Awake();
}
protected override void ReplayEvent(IMessage obj)
{
var eventData = (EventData)obj.Data;
if (eventData.eventType == RecordEventType.WaterSprayA)
{
RecordSprayerRotation data = JsonUtility.FromJson<RecordSprayerRotation>(eventData.json);
if (data.gameObjID == GetComponent<BaseGameObjInfo>().gameObjID)
{
head.localEulerAngles = data.rotation;
}
}
else if (eventData.eventType == RecordEventType.WaterSprayPlus)
{
if (eventData.json == gameObject.name)
{
waterControl.Increase(1f);
}
}
else if (eventData.eventType == RecordEventType.WaterSprayMinus)
{
if (eventData.json == gameObject.name)
{
waterControl.Decrease(1f);
}
}
}
protected override void D(IMessage obj)
{
var gameObjID = (long)obj.Sender;
if (gameObjID == GetComponent<BaseGameObjInfo>().GameObjID)
{
head.Rotate(0, Time.deltaTime * 40, 0, Space.Self);
AddRecordADEvent();
}
}
protected override void A(IMessage obj)
{
var gameObjID = (long)obj.Sender;
if (gameObjID == GetComponent<BaseGameObjInfo>().GameObjID)
{
head.Rotate(0, -Time.deltaTime * 40, 0, Space.Self);
AddRecordADEvent();
}
}
protected override void J(IMessage obj)
{
var gameObjID = (long)obj.Sender;
if (gameObjID == GetComponent<BaseGameObjInfo>().GameObjID)
{
if (checkZ(head.localEulerAngles.z))
{
head.Rotate(0, 0, -Time.deltaTime * 40, Space.Self);
AddRecordADEvent();
}
else
{
if (head.localEulerAngles.z<=330&&head.localEulerAngles.z>100)
{
head.localEulerAngles=new Vector3 (head.localEulerAngles.x, head.localEulerAngles.y, 331);
}
if (head.localEulerAngles.z <= 100 && head.localEulerAngles.z >= 40)
{
head.localEulerAngles = new Vector3(head.localEulerAngles.x, head.localEulerAngles.y, 39);
}
}
}
}
protected override void U(IMessage obj)
{
var gameObjID = (long)obj.Sender;
if (gameObjID == GetComponent<BaseGameObjInfo>().GameObjID)
{
if (checkZ(head.localEulerAngles.z))
{
head.Rotate( 0, 0, Time.deltaTime * 40, Space.Self);
AddRecordADEvent();
}
else
{
if (head.localEulerAngles.z <= 330 && head.localEulerAngles.z > 100)
{
head.localEulerAngles = new Vector3(head.localEulerAngles.x, head.localEulerAngles.y, 331);
}
if (head.localEulerAngles.z <= 100 && head.localEulerAngles.z >= 40)
{
head.localEulerAngles = new Vector3(head.localEulerAngles.x, head.localEulerAngles.y, 39);
}
}
}
}
private bool checkZ(float z)
{
bool can = true;
if ((z > 330 && z <= 360) || (z >= 0 && z < 40))
can = true;
else
{
can = false;
}
return can;
}
protected override void PressureDown(IMessage obj)
{
var gameObjID = (long)obj.Sender;
if (gameObjID == GetComponent<BaseGameObjInfo>().GameObjID)
{
waterControl.Decrease(0.5f);
AddRecordEvent(RecordEventType.WaterSprayMinus);
}
}
protected override void PressureUp(IMessage obj)
{
var gameObjID = (long)obj.Sender;
if (gameObjID == GetComponent<BaseGameObjInfo>().GameObjID)
{
waterControl.Increase(0.5f);
AddRecordEvent(RecordEventType.WaterSprayPlus);
}
}
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 = head.localEulerAngles;
eventData.json = JsonUtility.ToJson(data);
RecordManager.Instance.jsonData.eventDataList.Add(eventData);
}
}
public float GetWaterScale()
{
return waterControl.GetScaleValue();
}
public void SetWaterScale(float value)
{
waterControl.SetScaleValue(value);
}
}