大连中石油电子沙盘
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.
 
 
 
 

333 lines
12 KiB

using AX.MessageSystem;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TruckArmRiceData : RecordObjectBase
{
public long GameId;
public bool AllFull;
public bool AllZero;
/// <summary>
/// 是升起还是落下,true为升起
/// </summary>
public bool IsRice;
public bool fifth;
public float part7currentheight;
public bool fourth;
public float part6currentheight;
public bool third;
public float part5currentheight;
public bool second;
public float part4currentheight;
public bool first;
public float part3currentheight;
public float OutArmLength;
}
public class TruckArmRotateData : RecordObjectBase
{
public long GameId;
public RotateArmType ArmType;
public Vector3 EulerAngle;
}
public enum RotateArmType
{
HorizontalBaseSupport,
VerticalBaseSupport,
LastArm,
}
//[DisallowMultipleComponent]
//[RequireComponent(typeof(TruckArmRecord))]
public abstract class ControlTruckArm : MonoBehaviour
{
public CarAnimationCtrl CarAnimationCtrl;
private AgentController Nav;
private bool controlTruckArmFlag;
public bool AutoControlTruckArmFlag;
public float OutArmLength;
public float ArmLength;
public Transform HorizontalBaseSupport;
public Transform VerticalBaseSupport;
public Transform LastArm;
public long GameObjID;
public CloneGameObjInfo gameinfo;
public float LastArmEulerAngleX;
public bool ControlTruckArmFlag
{
get
{
return controlTruckArmFlag;
}
set
{
if (value)
AddListener();
else
RemoveListener();
controlTruckArmFlag = value;
}
}
private EventData QuaternionEventData = null;
private EventData SizeEventData = null;
private Quaternion Beginquaternion = Quaternion.identity;
private float BeginSize = float.Epsilon;
protected Transform SizeChangeTran = null;
protected Transform QuaternionChangeTran = null;
//protected void CreateRotationEvent(Transform changetran)
//{
// if (QuaternionEventData == null)
// {
// this.QuaternionChangeTran = changetran;
// QuaternionEventData = RecordEvent.CreateLinearEventData();
// Beginquaternion = changetran.localRotation;
// }
//}
//protected void CreateSizeEvent(Transform changetran)
//{
// if (SizeEventData == null)
// {
// this.SizeChangeTran = changetran;
// SizeEventData = RecordEvent.CreateLinearEventData();
// BeginSize = OutArmLength;
// }
//}
//protected void AddRotationEvent(Transform trans)
//{
// if (QuaternionEventData != null)
// {
// RotationLinerEventData RotationLinerEventData = new RotationLinerEventData()
// {
// BeginRotation = TransformHelper.ConvertToMyRotation(Beginquaternion),
// EndRotation = TransformHelper.ConvertToMyRotation(trans.transform.localRotation),
// Name = trans.name
// };
// RecordEvent.AddLinearEventData(QuaternionEventData, LinearEventType.Rotation, GameObjID, JsonUtility.ToJson(RotationLinerEventData));
// Beginquaternion = Quaternion.identity;
// QuaternionChangeTran = null;
// QuaternionEventData = null;
// }
//}
//protected void AddSizeEvent(Transform trans)
//{
// if (SizeEventData != null)
// {
// if (BeginSize != float.Epsilon)
// {
// SizeLinerEventData SizeLinerEventData = new SizeLinerEventData()
// {
// BeginSize = BeginSize,
// EndSize = OutArmLength
// };
// RecordEvent.AddLinearEventData(SizeEventData, LinearEventType.ControlArm, GameObjID, JsonUtility.ToJson(SizeLinerEventData));
// BeginSize = float.Epsilon;
// SizeChangeTran = null;
// SizeEventData = null;
// }
// else
// Debug.Log(BeginSize == float.Epsilon);
// }
//}
public abstract void FixedSupport(IMessage message);//固定支架
public abstract void PackUpTheLiftArm(IMessage message);//收回举臂
public abstract void AutoLiftTruckArm(IMessage message);//自动举臂
public abstract void LeftShift_J(IMessage message);
public abstract void LeftShift_U(IMessage message);
public abstract void D(IMessage message);
public abstract void A(IMessage message);
public abstract void S(IMessage message);
public abstract void W(IMessage message);
public abstract void LeftShift_S(IMessage message);
public abstract void LeftShift_W(IMessage message);
//internal abstract void RadioSelect(IMessage obj);
/// <summary>
/// 固定支架注册举臂事件
/// </summary>
protected void AddListener()
{
MessageDispatcher.AddListener("AUTO_LIFT_TRUCK_ARM_COMMAND", AutoLiftTruckArm);
MessageDispatcher.AddListener("LEFTSHIFT_W_COMMAND", LeftShift_W);
MessageDispatcher.AddListener("LEFTSHIFT_S_COMMAND", LeftShift_S);
MessageDispatcher.AddListener("W_COMMAND", W);
MessageDispatcher.AddListener("S_COMMAND", S);
MessageDispatcher.AddListener("A_COMMAND", A);
MessageDispatcher.AddListener("D_COMMAND", D);
MessageDispatcher.AddListener("LEFTSHIFT_U_COMMAND", LeftShift_U);
MessageDispatcher.AddListener("LEFTSHIFT_J_COMMAND", LeftShift_J);
Nav.FixedArmFlag = true;
}
/// <summary>
/// 收回举臂注销举臂事件
/// </summary>
protected void RemoveListener()
{
MessageDispatcher.RemoveListener("LEFTSHIFT_W_COMMAND", LeftShift_W);
MessageDispatcher.RemoveListener("LEFTSHIFT_S_COMMAND", LeftShift_S);
MessageDispatcher.RemoveListener("W_COMMAND", W);
MessageDispatcher.RemoveListener("S_COMMAND", S);
MessageDispatcher.RemoveListener("A_COMMAND", A);
MessageDispatcher.RemoveListener("D_COMMAND", D);
MessageDispatcher.RemoveListener("LEFTSHIFT_U_COMMAND", LeftShift_U);
MessageDispatcher.RemoveListener("LEFTSHIFT_J_COMMAND", LeftShift_J);
MessageDispatcher.RemoveListener("AUTO_LIFT_TRUCK_ARM_COMMAND", AutoLiftTruckArm);
Nav.FixedArmFlag = false;
}
void OnDisable()
{
MessageDispatcher.RemoveListener("PackUpTheLiftArm", PackUpTheLiftArm);
MessageDispatcher.RemoveListener("FixedSupport", FixedSupport);
MessageDispatcher.RemoveListener("RADIO_SELECTED_COMMAND", RadioSelect);
MessageDispatcher.RemoveListener("ReplayEvent", ReplayAgent);
}
void OnEnable()
{
MessageDispatcher.AddListener("PackUpTheLiftArm", PackUpTheLiftArm);
MessageDispatcher.AddListener("FixedSupport", FixedSupport);
MessageDispatcher.AddListener("RADIO_SELECTED_COMMAND", RadioSelect);
MessageDispatcher.AddListener("ReplayEvent", ReplayAgent);
}
void OnDestroy()
{
RemoveListener();
MessageDispatcher.RemoveListener("PackUpTheLiftArm", PackUpTheLiftArm);
MessageDispatcher.RemoveListener("FixedSupport", FixedSupport);
MessageDispatcher.RemoveListener("RADIO_SELECTED_COMMAND", RadioSelect);
MessageDispatcher.RemoveListener("GetButtonUp", GetButtonUp);
MessageDispatcher.RemoveListener("ReplayEvent", ReplayAgent);
}
private void ReplayAgent(IMessage obj)
{
var eventData = (EventData)obj.Data;
if (eventData.eventType == RecordEventType.TruckArmRice)
{
if (eventData.cloneObjType == gameinfo.gameObjType)
{
TruckArmRiceData data = Newtonsoft.Json.JsonConvert.DeserializeObject<TruckArmRiceData>(eventData.json);
if (data.GameId == gameinfo.gameObjID)
{
ReplayArmRice(data);
}
}
}
else if (eventData.eventType == RecordEventType.TruckArmRotation)
{
if (eventData.cloneObjType == gameinfo.gameObjType)
{
TruckArmRotateData data = Newtonsoft.Json.JsonConvert.DeserializeObject<TruckArmRotateData>(eventData.json);
if (data.GameId == gameinfo.gameObjID)
{
ReplayArmRotate(data);
}
}
}
}
public abstract void ReplayArmRice(TruckArmRiceData data);
public abstract void ReplayArmRotate(TruckArmRotateData data);
internal void RadioSelect(IMessage obj)
{
//var gameObjID = (long)obj.Sender;
//if (gameObjID != GameObjID)
//{
// if (RecordEvent.IsRecord())
// {
// if (QuaternionEventData != null)
// AddRotationEvent(QuaternionChangeTran);
// if (SizeEventData != null)
// AddSizeEvent(transform);
// }
//}
}
private void GetButtonUp(IMessage obj)
{
//var gameObjID = (long)obj.Sender;
//if (gameObjID == GameObjID)
//{
// if (RecordEvent.IsRecord())
// {
// if (QuaternionEventData != null)
// AddRotationEvent(QuaternionChangeTran);
// if (SizeEventData != null)
// AddSizeEvent(transform);
// }
//}
}
private void Awake()
{
Nav = GetComponent<AgentController>();
InitObject();
CarAnimationCtrl = GetComponent<CarAnimationCtrl>();
MessageDispatcher.AddListener("GetButtonUp", GetButtonUp);
gameinfo = GetComponent<CloneGameObjInfo>();
}
/// <summary>
/// 赋值展出车臂长度
/// </summary>
/// <param name="outarmlength"></param>
public abstract void SetOutArmLength(float outarmlength);
/// <summary>
/// 赋值车臂总长度
/// </summary>
/// <param name="Height"></param>
public abstract void SetHeight(float Height);
/// <summary>
/// 升起车臂
/// </summary>
/// <param name="weight"> 升起的权重(速度)</param>
public abstract void Raise(float weight);
/// <summary>
/// 下降车臂
/// </summary>
/// <param name="weight">下降的权重(速度)</param>
public abstract void Decline(float weight);
public void AddTruckArmRiceEvent(TruckArmRiceData data)
{
var eventData = new EventData();
eventData.time = RecordManager.Instance.RecordTimer;
eventData.cloneObjType = GetComponent<CloneGameObjInfo>().gameObjType;
eventData.eventType = RecordEventType.TruckArmRice;
eventData.json = Newtonsoft.Json.JsonConvert.SerializeObject(data);
RecordManager.Instance.jsonData.eventDataList.Add(eventData);
}
public void AddTruckArmRotateEvent(TruckArmRotateData data)
{
var eventData = new EventData();
eventData.time = RecordManager.Instance.RecordTimer;
eventData.cloneObjType = GetComponent<CloneGameObjInfo>().gameObjType;
eventData.eventType = RecordEventType.TruckArmRotation;
eventData.json = Newtonsoft.Json.JsonConvert.SerializeObject(data);
RecordManager.Instance.jsonData.eventDataList.Add(eventData);
}
protected abstract void InitObject();
/// <summary>
/// 换算原始角度值为显式值
/// </summary>
/// <param name="x">获取的原始角度值</param>
/// <returns></returns>
protected float CheckValue(float x)
{
if (x >= 180 && x <= 360)
{
x = x - 360;
}
return x;
//举例:假如获取到的localEulerAngles.x = 300,则在显示面板其显示的值为-60=300-360,用此显式值计算
}
}