using AX.MessageSystem;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using UnityEngine.EventSystems;
//Author:ZCG
//CreatTime:12/26/2017
///
/// 水炮
///
public class WaterCannon : BaseTransformChange
{
public Transform head;//炮头
//字段
public float RecordPingPongSpeed { get; private set; }
public float RecordWaterSpeed { get; private set; }
public bool RecordOpenPingPong { get; private set; }
public bool RecordPutOutFire { get; private set; }
protected override void ReplayEvent(IMessage obj)
{
var eventData = (EventData)obj.Data;
if (eventData.eventType == RecordEventType.WaterSprayU)
{
RecordSprayerRotation data = JsonUtility.FromJson(eventData.json);
if (data.gameObjID == GetComponent().gameObjID)
{
head.transform.localEulerAngles = data.rotation;
}
}
else if (eventData.eventType == RecordEventType.WaterSprayA)
{
RecordSprayerRotation data = JsonUtility.FromJson(eventData.json);
if (data.gameObjID == GetComponent().gameObjID)
{
base.obj.transform.localEulerAngles = data.rotation;
}
}
else if(eventData.eventType == RecordEventType.WaterSprayPlus)
{
if(eventData.json == gameObject.name)
{
waterControl.Increase(0.5f);
}
}
else if(eventData.eventType ==RecordEventType.WaterSprayMinus)
{
if (eventData.json == gameObject.name)
{
waterControl.Decrease(0.5f);
}
}
}
protected virtual void Init()
{
y = true;
transformType = TransformType.Rotation;
valueChanage = ValueChange.PingPong;
min = -90;
max = 90;
}
private void setSkill(IMessage obj)
{
var gameObjID = GetComponent().GameObjID;
if((long)obj.Data == gameObjID)
{
PutOutFire();
}
}
protected override void PressureUp(IMessage obj)
{
//出水变大
var gameObjID = (long)obj.Sender;
if (gameObjID == GetComponent().GameObjID)
{
waterControl.Increase(0.5f);
AddRecordEvent(RecordEventType.WaterSprayPlus);
}
}
protected override void PressureDown(IMessage obj)
{
//出水变小
var gameObjID = (long)obj.Sender;
if (gameObjID == GetComponent().GameObjID)
{
waterControl.Decrease(0.5f);
AddRecordEvent(RecordEventType.WaterSprayMinus);
}
}
protected override void U(IMessage obj)
{
var gameObjID = (long)obj.Sender;
if (gameObjID == GetComponent().GameObjID)
{
if (head.localRotation.x < -0.1)
{
head.Rotate(Vector3.right * Time.deltaTime * 100);
AddRecordUJEvent();
}
}
}
protected override void J(IMessage obj)
{
var gameObjID = (long)obj.Sender;
if (gameObjID == GetComponent().GameObjID)
{
if (head.localRotation.x > -0.9)
{
head.Rotate(Vector3.right * Time.deltaTime * -100);
AddRecordUJEvent();
}
}
}
protected override void A(IMessage obj)
{
var gameObjID = (long)obj.Sender;
if (gameObjID == GetComponent().GameObjID)
{
if (base.obj.localRotation.y > -0.8)
{
base.obj.Rotate(Vector3.up * Time.deltaTime * -100);
AddRecordADEvent();
}
}
}
protected override void D(IMessage obj)
{
var gameObjID = (long)obj.Sender;
if (gameObjID == GetComponent().GameObjID)
{
if (base.obj.localRotation.y < 0.8)
{
base.obj.Rotate(Vector3.up * Time.deltaTime * 100);
AddRecordADEvent();
}
}
}
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().gameObjType;
eventData.eventType = RecordEventType.WaterSprayU;
RecordSprayerRotation data = new RecordSprayerRotation();
data.gameObjID = GetComponent().gameObjID;
data.rotation = head.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().gameObjType;
eventData.eventType = RecordEventType.WaterSprayA;
RecordSprayerRotation data = new RecordSprayerRotation();
data.gameObjID = GetComponent().gameObjID;
data.rotation = obj.transform.localEulerAngles;
eventData.json = JsonUtility.ToJson(data);
RecordManager.Instance.jsonData.eventDataList.Add(eventData);
}
}
public ParticleControlOfType waterControl;
protected override void Awake()
{
obj = transform.Find("Rotate");
head = obj.Find("Head");
Init();
waterControl = obj.Find("Head/WaterStraight/WaterStraightPos/WaterStraight").GetComponentInChildren();
waterControl.gameObject.SetActive(false);
base.Awake();
}
public float GetWaterScale()
{
return waterControl.GetScaleValue();
}
public void SetWaterScale(float value)
{
waterControl.SetScaleValue(value);
}
protected override void Start()
{
RecordPutOutFire = openWater;
RecordOpenPingPong = openPingPong;
RecordPingPongSpeed = speed;
RecordWaterSpeed = waterControl.GetScaleValue();
}
///
/// 是否打开水炮
///
private bool openWater;
///
/// 是否开启摇摆
private bool openPingPong;
protected override void UpdateTransform()
{
if (openPingPong)
base.UpdateTransform();
}
public void SetOpenPingPong(bool value)
{
openPingPong = value;
}
public void SetOpenWater(bool value)
{
openWater = value;
if (openWater)
OpenWaterCannon();
else
CloseWaterCannon();
}
///
/// 打开水炮
///
public void OpenWaterCannon()
{
waterControl.gameObject.SetActive(true);
}
///
/// 关闭水炮
///
public void CloseWaterCannon()
{
waterControl.gameObject.SetActive(false);
//GetComponent().enabled = true;
}
///
/// 获取摇摆速度
///
public float GetPingPongSpeed()
{
return speed;
}
///
/// 设置射水速度
///
public void SetWaterSpeed(float value)
{
waterControl.SetScaleValue(value);
}
///
/// 设置摇摆速度
///
///
public void SetPingPongSpeed(float value)
{
speed = value;
}
///
/// 开启摇摆
///
///
public void OpenPingPong()
{
openPingPong = !openPingPong;
}
///
/// 打开关闭水炮
///
///
public void PutOutFire()
{
openWater = !openWater;
if (openWater)
OpenWaterCannon();
else
CloseWaterCannon();
}
public void Confirm()
{
RecordPingPongSpeed = speed;
RecordWaterSpeed = waterControl.GetScaleValue();
RecordOpenPingPong = openPingPong;
RecordPutOutFire = openWater;
}
public void Revocation()
{
SetWaterSpeed(RecordWaterSpeed);
SetPingPongSpeed(RecordPingPongSpeed);
OpenWaterCannon();
}
///
/// 默认初始化
///
public void PutOutFireInitialize()
{
openWater = true;
openPingPong = true;
Confirm();
}
}
public class RecordSprayerRotation
{
public long gameObjID;
public Vector3 rotation;
}