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.
94 lines
2.9 KiB
94 lines
2.9 KiB
using AX.MessageSystem; |
|
using System; |
|
using System.Collections; |
|
using System.Collections.Generic; |
|
using UnityEngine; |
|
|
|
public class LinerRotationReplay : MonoBehaviour |
|
{ |
|
|
|
void Start() |
|
{ |
|
MessageDispatcher.AddListener("ReplayEvent", ReplayAgent); |
|
MessageDispatcher.AddListener("PlayStatusChanged", PlayStatusChanged); |
|
} |
|
|
|
private void PlayStatusChanged(IMessage obj) |
|
{ |
|
var playStatus = ReplaySetting.PlayStatus; |
|
switch (playStatus) |
|
{ |
|
case PlayStatus.normal: |
|
pairs.Clear(); |
|
break; |
|
case PlayStatus.isReplay: |
|
|
|
break; |
|
case PlayStatus.isEditor: |
|
pairs.Clear(); |
|
break; |
|
default: |
|
break; |
|
} |
|
} |
|
|
|
List<Pair> pairs = new List<Pair>(); |
|
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.Rotation) |
|
return; |
|
var data1 = JsonUtility.FromJson<RotationLinerEventData>(data.Data); |
|
Transform tran = TransformHelper.FindChild(EntitiesManager.Instance.GetEntityByID(data.GameId).transform, data1.Name); |
|
|
|
var pair = new Pair() |
|
{ |
|
Time = 0f, |
|
keyValuePair = new KeyValuePair<float, Action<float, int>>(data.TimeLength, |
|
(time, index) => |
|
{ |
|
tran.localRotation = Quaternion.Lerp(tran.localRotation, TransformHelper.ConvertToQuaternion(data1.EndRotation), time * 2f); |
|
if (tran.localRotation == TransformHelper.ConvertToQuaternion(data1.EndRotation)) |
|
if (index <= pairs.Count) |
|
pairs.RemoveAt(index); |
|
|
|
}) |
|
}; |
|
pairs.Add(pair); |
|
} |
|
} |
|
public float speed; |
|
void FixedUpdate() |
|
{ |
|
if (RecordEvent.IsReplayPause()) |
|
return; |
|
for (int i = 0; i < pairs.Count; i++) |
|
{ |
|
if (pairs[i].Time >= pairs[i].keyValuePair.Key) |
|
{ |
|
pairs.RemoveAt(i); |
|
break; |
|
} |
|
pairs[i].Time += Time.deltaTime; |
|
if (pairs[i].Time <= pairs[i].keyValuePair.Key) |
|
{ |
|
speed = Time.deltaTime * GlobalVariable.ReplaySpeed; |
|
pairs[i].keyValuePair.Value.Invoke(speed, i); |
|
} |
|
} |
|
} |
|
|
|
private void OnDestroy() |
|
{ |
|
MessageDispatcher.RemoveListener("ReplayEvent", ReplayAgent); |
|
MessageDispatcher.RemoveListener("PlayStatusChanged", PlayStatusChanged); |
|
} |
|
} |
|
public class Pair |
|
{ |
|
public float Time; |
|
public KeyValuePair<float, Action<float, int>> keyValuePair; |
|
}
|
|
|