上海苏宁宝丽嘉酒店,2020.11.17 15:30改为单机版本,以后合成单机版本可以以此版本为模板
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.
 
 
 
 

102 lines
3.2 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 = 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)
{
}
}