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.
269 lines
9.4 KiB
269 lines
9.4 KiB
using AX.MessageSystem; |
|
using System; |
|
using System.Collections; |
|
using System.Collections.Generic; |
|
using UnityEngine; |
|
|
|
//[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 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); |
|
} |
|
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.LinearData) |
|
//{ |
|
// var data = JsonUtility.FromJson<LinearData>(eventData.json); |
|
// if ((LinearEventType)data.LinearEventType != LinearEventType.Size) |
|
// return; |
|
// if (data.GameId != GameObjID) |
|
// return; |
|
// SizeLinerEventData SizeLinerEventData = JsonUtility.FromJson<SizeLinerEventData>(data.Data); |
|
// if (SizeLinerEventData.EndSize > OutArmLength) |
|
// { |
|
// this.Raise(SizeLinerEventData.EndSize); |
|
// } |
|
// if (SizeLinerEventData.EndSize < OutArmLength) |
|
// { |
|
// this.Decline(SizeLinerEventData.EndSize); |
|
// } |
|
//} |
|
} |
|
|
|
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); |
|
} |
|
/// <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); |
|
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,用此显式值计算 |
|
} |
|
}
|
|
|