221 lines
6.2 KiB
C#
221 lines
6.2 KiB
C#
|
using System.Collections.Generic;
|
|||
|
using System;
|
|||
|
using System.IO;
|
|||
|
|
|||
|
namespace Thousandto.Cinematic
|
|||
|
{
|
|||
|
//关键帧对象
|
|||
|
[Serializable]
|
|||
|
public class CinematicKeyframe : ICinematic
|
|||
|
{
|
|||
|
|
|||
|
public int Keyframe;
|
|||
|
public List<CinematicEventData> EventData;
|
|||
|
//下一个位移点占整个曲线的百分比
|
|||
|
public float TransPercentageInCurve;
|
|||
|
|
|||
|
[NonSerialized]
|
|||
|
public bool Selected;
|
|||
|
[NonSerialized]
|
|||
|
public bool HasSyncTrans;
|
|||
|
[NonSerialized]
|
|||
|
public CinematicKeyframe PreEventData;
|
|||
|
[NonSerialized]
|
|||
|
public CinematicKeyframe NextKeyframe;
|
|||
|
[NonSerialized]
|
|||
|
public CinematicKeyframe NextTransKeyframe; //下一个包含位移的关键帧,可能会跳过多帧
|
|||
|
[NonSerialized]
|
|||
|
public Action<bool> RefreshCallback;
|
|||
|
|
|||
|
[NonSerialized]
|
|||
|
public CinematicEventData AnimEvent;
|
|||
|
[NonSerialized]
|
|||
|
public CinematicEventData TransformEvent;
|
|||
|
|
|||
|
[NonSerialized]
|
|||
|
public bool NeedSetPositionNow = true;
|
|||
|
|
|||
|
public override void WriteAll(BinaryWriter bw)
|
|||
|
{
|
|||
|
PrepareWriter(bw);
|
|||
|
WriteInt(Keyframe);
|
|||
|
WriteList(EventData);
|
|||
|
WriteFloat(TransPercentageInCurve);
|
|||
|
}
|
|||
|
|
|||
|
public override void ReadAll(BinaryReader rd)
|
|||
|
{
|
|||
|
PrepareReader(rd);
|
|||
|
Keyframe = ReadInt();
|
|||
|
EventData = ReadList<CinematicEventData>();
|
|||
|
TransPercentageInCurve = ReadFloat();
|
|||
|
}
|
|||
|
|
|||
|
public CinematicKeyframe()
|
|||
|
{
|
|||
|
Selected = false;
|
|||
|
Keyframe = -1;
|
|||
|
EventData = new List<CinematicEventData>();
|
|||
|
}
|
|||
|
|
|||
|
public void SetData(int frame)
|
|||
|
{
|
|||
|
Keyframe = frame;
|
|||
|
EventData = new List<CinematicEventData>();
|
|||
|
OnRefreshEditor();
|
|||
|
}
|
|||
|
|
|||
|
public void SetData(int frame, List<CinematicEventData> eData)
|
|||
|
{
|
|||
|
Keyframe = frame;
|
|||
|
EventData = eData;
|
|||
|
|
|||
|
for(int i = 0; i < eData.Count; ++i)
|
|||
|
{
|
|||
|
if(eData[i].EventTypeEx == KeyFrameEvent.坐标变换)
|
|||
|
{
|
|||
|
TransformEvent = eData[i];
|
|||
|
}
|
|||
|
|
|||
|
if(eData[i].EventTypeEx == KeyFrameEvent.播放动作)
|
|||
|
{
|
|||
|
AnimEvent = eData[i];
|
|||
|
}
|
|||
|
}
|
|||
|
OnRefreshEditor();
|
|||
|
}
|
|||
|
|
|||
|
public void AddEvent(CinematicEventData eData)
|
|||
|
{
|
|||
|
if (eData.EventTypeEx == KeyFrameEvent.坐标变换)
|
|||
|
{
|
|||
|
TransformEvent = eData;
|
|||
|
}
|
|||
|
|
|||
|
if (eData.EventTypeEx == KeyFrameEvent.播放动作)
|
|||
|
{
|
|||
|
AnimEvent = eData;
|
|||
|
}
|
|||
|
|
|||
|
EventData.Add(eData);
|
|||
|
|
|||
|
OnRefreshEditor();
|
|||
|
}
|
|||
|
|
|||
|
public void RemoveEvent(int index)
|
|||
|
{
|
|||
|
if(EventData.Count > index)
|
|||
|
{
|
|||
|
var forRemove = EventData[index];
|
|||
|
EventData.RemoveAt(index);
|
|||
|
|
|||
|
if(forRemove.EventTypeEx == KeyFrameEvent.坐标变换)
|
|||
|
{
|
|||
|
TransformEvent = null;
|
|||
|
}
|
|||
|
|
|||
|
if(forRemove.EventTypeEx == KeyFrameEvent.播放动作)
|
|||
|
{
|
|||
|
AnimEvent = null;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
OnRefreshEditor();
|
|||
|
}
|
|||
|
|
|||
|
public void RemoveTransEventWhileHasSyncEvent()
|
|||
|
{
|
|||
|
bool hasSyncEvent = false;
|
|||
|
int transEventIndex = -1;
|
|||
|
for(int i = 0; i < EventData.Count; ++i)
|
|||
|
{
|
|||
|
if(EventData[i].EventTypeEx == KeyFrameEvent.同步到本地相机坐标 ||
|
|||
|
EventData[i].EventTypeEx == KeyFrameEvent.同步到本地角色坐标)
|
|||
|
{
|
|||
|
if (!hasSyncEvent && transEventIndex != -1)
|
|||
|
{
|
|||
|
EventData.RemoveAt(transEventIndex);
|
|||
|
i--;
|
|||
|
}
|
|||
|
|
|||
|
hasSyncEvent = true;
|
|||
|
}
|
|||
|
if(EventData[i].EventTypeEx == KeyFrameEvent.坐标变换)
|
|||
|
{
|
|||
|
if (hasSyncEvent)
|
|||
|
EventData.RemoveAt(i--);
|
|||
|
else
|
|||
|
transEventIndex = i;
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
//当有数据改变时,通知CinematicKeyframeEditor刷新数据, 参数为true时,销毁对象
|
|||
|
public void OnRefreshEditor(bool destroy = false)
|
|||
|
{
|
|||
|
if (RefreshCallback != null) RefreshCallback(destroy);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
public void SetSelected()
|
|||
|
{
|
|||
|
if (Keyframe >= 0)
|
|||
|
Selected = true;
|
|||
|
else
|
|||
|
Selected = false;
|
|||
|
}
|
|||
|
|
|||
|
public CinematicEventData GetTransEvent()
|
|||
|
{
|
|||
|
for(int i = 0; i < EventData.Count; ++i)
|
|||
|
{
|
|||
|
if (EventData[i].EventTypeEx == KeyFrameEvent.坐标变换) return TransformEvent = EventData[i];
|
|||
|
}
|
|||
|
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
public CinematicEventData GetAnimEvent()
|
|||
|
{
|
|||
|
for (int i = 0; i < EventData.Count; ++i)
|
|||
|
{
|
|||
|
if (EventData[i].EventTypeEx == KeyFrameEvent.播放动作) return AnimEvent = EventData[i];
|
|||
|
}
|
|||
|
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
public List<CinematicEventData> CloneEventData()
|
|||
|
{
|
|||
|
List<CinematicEventData> eData = new List<CinematicEventData>();
|
|||
|
for(int i = 0; i < EventData.Count; ++i)
|
|||
|
{
|
|||
|
eData.Add(EventData[i].Clone());
|
|||
|
}
|
|||
|
|
|||
|
return eData;
|
|||
|
}
|
|||
|
|
|||
|
[NonSerialized]
|
|||
|
private CinematicEventData _syncTransEvent;
|
|||
|
public CinematicEventData GetSyncTransEvent()
|
|||
|
{
|
|||
|
if (_syncTransEvent == null)
|
|||
|
{
|
|||
|
for (int i = 0; i < EventData.Count; ++i)
|
|||
|
{
|
|||
|
if (EventData[i].EventTypeEx == KeyFrameEvent.同步到本地相机坐标 ||
|
|||
|
EventData[i].EventTypeEx == KeyFrameEvent.同步到本地角色坐标)
|
|||
|
{
|
|||
|
_syncTransEvent = EventData[i];
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
return _syncTransEvent;
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|