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().gameObjType; eventData.eventType = type; eventData.json = gameObject.name; RecordManager.Instance.jsonData.eventDataList.Add(eventData); } } protected virtual void ReplayEventRoate(IMessage obj) { var eventData = (EventData)obj.Data; if (eventData.json == gameObject.name) { if (eventData.eventType == RecordEventType.LeftRotate) { transform.Rotate(0, -Time.deltaTime * rotateSpeed, 0, Space.World); } else if (eventData.eventType == RecordEventType.RightRotate) { transform.Rotate(0, Time.deltaTime * rotateSpeed, 0, Space.World); } } } // 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) { transform.Rotate(0, -Time.deltaTime * rotateSpeed, 0, Space.World); AddRecordEventRoage(RecordEventType.LeftRotate); } } protected virtual void RightRotate(IMessage obj) { if (SelectedObjs.selectedObj == gameObject) { transform.Rotate(0, Time.deltaTime * rotateSpeed, 0, Space.World); AddRecordEventRoage(RecordEventType.RightRotate); } } protected virtual void UpRotate(IMessage obj) { } protected virtual void DownRotate(IMessage obj) { } }