贺州人民医院电子沙盘
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.
 
 
 
 

119 lines
4.0 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using AX.MessageSystem;
using System;
public class ObjRotate : MonoBehaviour
{
public float rotateSpeed = 60;
// Use this for initialization
protected virtual void Start()
{
MessageDispatcher.AddListener("ReplayEvent", ReplayEventRoate);
}
protected virtual void AddRecordEventRoage(RecordEventType type)
{
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.Rotate;
RotateData data = new RotateData()
{
gamename = gameObject.name,
localEulerAngles = transform.localEulerAngles,
};
eventData.json = Newtonsoft.Json.JsonConvert.SerializeObject(data);
RecordManager.Instance.jsonData.eventDataList.Add(eventData);
}
}
protected virtual void ReplayEventRoate(IMessage obj)
{
var eventData = (EventData)obj.Data;
if (eventData.eventType == RecordEventType.Rotate)
{
RotateData data = Newtonsoft.Json.JsonConvert.DeserializeObject<RotateData>(eventData.json);
if (data.gamename == gameObject.name)
{
transform.localEulerAngles = data.localEulerAngles;
}
}
}
// Update is called once per frame
void Update()
{
}
void OnEnable()
{
MessageDispatcher.AddListener("LEFT_ROTATE_COMMAND", LeftRotate);
MessageDispatcher.AddListener("RIGHT_ROTATE_COMMAND", RightRotate);
MessageDispatcher.AddListener("UP_ROTATE_COMMAND", UpRotate);
MessageDispatcher.AddListener("DOWN_ROTATE_COMMAND", DownRotate);
}
void OnDisable()
{
MessageDispatcher.RemoveListener("LEFT_ROTATE_COMMAND", LeftRotate);
MessageDispatcher.RemoveListener("RIGHT_ROTATE_COMMAND", RightRotate);
MessageDispatcher.RemoveListener("UP_ROTATE_COMMAND", UpRotate);
MessageDispatcher.RemoveListener("DOWN_ROTATE_COMMAND", DownRotate);
}
void OnDestroy()
{
MessageDispatcher.RemoveListener("LEFT_ROTATE_COMMAND", LeftRotate);
MessageDispatcher.RemoveListener("RIGHT_ROTATE_COMMAND", RightRotate);
MessageDispatcher.RemoveListener("UP_ROTATE_COMMAND", UpRotate);
MessageDispatcher.RemoveListener("DOWN_ROTATE_COMMAND", DownRotate);
MessageDispatcher.RemoveListener("ReplayEvent", ReplayEventRoate);
}
protected virtual void LeftRotate(IMessage obj)
{
if (SelectedObjs.selectedObj == gameObject || (SelectedObjs.selectedCharacters.Count>0&&gameObject == SelectedObjs.selectedCharacters[0]))
{
if (gameObject.GetComponent<ControlTruckArm>())
{
if (gameObject.GetComponent<ControlTruckArm>().ControlTruckArmFlag)
{
return;
}
}
transform.Rotate(0, -Time.deltaTime * rotateSpeed, 0, Space.World);
AddRecordEventRoage(RecordEventType.LeftRotate);
}
}
protected virtual void RightRotate(IMessage obj)
{
if (SelectedObjs.selectedObj == gameObject|| (SelectedObjs.selectedCharacters.Count > 0 && gameObject == SelectedObjs.selectedCharacters[0]))
{
if (gameObject.GetComponent<ControlTruckArm>())
{
if (gameObject.GetComponent<ControlTruckArm>().ControlTruckArmFlag)
{
return;
}
}
transform.Rotate(0, Time.deltaTime * rotateSpeed, 0, Space.World);
AddRecordEventRoage(RecordEventType.RightRotate);
}
}
protected virtual void UpRotate(IMessage obj)
{
}
protected virtual void DownRotate(IMessage obj)
{
}
}