天津23维预案
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.
 
 
 
 
 
 

192 lines
6.7 KiB

using UnityEngine;
using System.Collections;
using AX.TrackRecord;
using AX.MessageSystem;
using System;
/// <summary>
/// 消防员和消防车身上的水炮控制
/// </summary>
public abstract class BaseShuiQiangControl : MonoBehaviour {
float TIMESTAMP = 1.0f;
float timer = 0f;
float THRESHOLD = 10.0f;
Vector3 lastFrame;
Vector3 currentFrame;
Vector3 lastFrame2;
Vector3 currentFrame2;
float lastScale = 1;
float currentScale = 1;
public GameObject part1;
public GameObject part2;
protected GameObject water;
void Awake () {
timer = TIMESTAMP;
InitGameObject();
if (part2 == null)
{
part2 = part1;
}
MessageDispatcher.AddListener("Equals", ShuiQiangThrowMax);
MessageDispatcher.AddListener("Minus", ShuiQiangThrowMin);
MessageDispatcher.AddListener("H", ShuiQiangLeftRotate);
MessageDispatcher.AddListener("K", ShuiQiangRightRotate);
//MessageDispatcher.AddListener("ShuiQiangUpRotate", ShuiQiangUpRotate);
//MessageDispatcher.AddListener("ShuiQiangDownRotate", ShuiQiangDownRotate);
//MessageDispatcher.AddListener("ShuiPaoUpRotate", ShuiPaoUpRotate);
//MessageDispatcher.AddListener("ShuiPaoDownRotate", ShuiPaoDownRotate);
MessageDispatcher.AddListener("U", U);
MessageDispatcher.AddListener("J", J);
lastFrame = part1.transform.localEulerAngles;
}
public virtual void J(IMessage message)
{
if ((string)message.Data == this.gameObject.name)
{
ShuiQiangDownRotate();
}
}
public virtual void U(IMessage message)
{
if ((string)message.Data == this.gameObject.name)
{
ShuiQiangUpRotate();
}
}
void OnDestroy()
{
MessageDispatcher.RemoveListener("Equals", ShuiQiangThrowMax);
MessageDispatcher.RemoveListener("Minus", ShuiQiangThrowMin);
MessageDispatcher.RemoveListener("H", ShuiQiangLeftRotate);
MessageDispatcher.RemoveListener("K", ShuiQiangRightRotate);
//MessageDispatcher.RemoveListener("ShuiQiangUpRotate", ShuiQiangUpRotate);
//MessageDispatcher.RemoveListener("ShuiQiangDownRotate", ShuiQiangDownRotate);
//MessageDispatcher.RemoveListener("ShuiPaoUpRotate", ShuiPaoUpRotate);
//MessageDispatcher.RemoveListener("ShuiPaoDownRotate", ShuiPaoDownRotate);
MessageDispatcher.RemoveListener("U", U);
MessageDispatcher.RemoveListener("J", J);
}
public abstract void InitGameObject();//初始化物体
//水炮变大
public virtual void ShuiQiangThrowMax(IMessage message)
{
if ((string)message.Data == this.gameObject.name)
{
if (water.transform.childCount > 0)
{
ParticleSystemControl scale = water.transform.GetChild(0).GetComponent<ParticleSystemControl>();
scale.particleScaleControl += Time.deltaTime * 0.5f;
}
}
}
//水炮变小
public virtual void ShuiQiangThrowMin(IMessage message)
{
if ((string)message.Data == this.gameObject.name)
{
if (water.transform.childCount > 0)
{
ParticleSystemControl scale = water.transform.GetChild(0).GetComponent<ParticleSystemControl>();
scale.particleScaleControl -= Time.deltaTime * 0.5f;
}
}
}
//水炮向左
public virtual void ShuiQiangLeftRotate(IMessage message)
{
if ((string)message.Data == this.gameObject.name)
{
if (MySceneManager.GetActiveScene().name.Contains("5"))
{
part1.transform.Rotate(0, -Time.deltaTime * 40, 0, Space.World);
}
else
{
part1.transform.Rotate(0, -Time.deltaTime * 40, 0, Space.Self);
}
}
}
//水炮向右
public virtual void ShuiQiangRightRotate(IMessage message)
{
if ((string)message.Data == this.gameObject.name)
{
if (MySceneManager.GetActiveScene().name.Contains("5"))
{
part1.transform.Rotate(0, Time.deltaTime * 40, 0, Space.World);
}
else
{
part1.transform.Rotate(0, Time.deltaTime * 40, 0, Space.Self);
}
}
}
/// <summary>
/// 水枪向上
/// </summary>
public void ShuiQiangUpRotate()
{
part1.transform.Rotate(-Time.deltaTime * 40, 0, 0, Space.Self);
}
/// <summary>
/// 水枪向下
/// </summary>
public void ShuiQiangDownRotate()
{
part1.transform.Rotate(Time.deltaTime * 40, 0, 0, Space.Self);
}
protected void Update() {
if (timer > 0)
{
timer -= Time.deltaTime;
}
else
{
currentFrame = part1.transform.localEulerAngles;
if (water.transform.childCount>0 && water.transform.GetChild(0).GetComponent<ParticleSystemControl>())
{
currentScale = water.transform.GetChild(0).GetComponent<ParticleSystemControl>().particleScaleControl;
if (Vector3.Distance(currentFrame, lastFrame) > THRESHOLD ||
Mathf.Abs(lastScale - currentScale) > 0.1f ||
Vector3.Distance(currentFrame2, lastFrame2) > THRESHOLD)
{
if (RecordManager.Instance.IsRecording)
{
MessageDispatcher.SendMessage("RecordFineTuningEvent", (object)this.name);//////////水炮上绑RecordFineTuningEvent脚本
Debug.Log("rotate: -------" + Vector3.Distance(currentFrame, lastFrame));
}
}
lastFrame = currentFrame;
lastFrame2 = currentFrame2;
lastScale = currentScale;
timer = TIMESTAMP;
}
if (gameObject.name.Contains("zmc"))
{
currentFrame2 = part2.transform.localEulerAngles;
if (Vector3.Distance(currentFrame, lastFrame) > THRESHOLD ||
Vector3.Distance(currentFrame2, lastFrame2) > THRESHOLD)
{
if (RecordManager.Instance.IsRecording)
{
MessageDispatcher.SendMessage("RecordFineTuningEvent", (object)this.name);//////////水炮上绑RecordFineTuningEvent脚本
Debug.Log("rotate: -------" + Vector3.Distance(currentFrame, lastFrame));
}
}
lastFrame = currentFrame;
lastFrame2 = currentFrame2;
timer = TIMESTAMP;
}
}
}
}