LiveTimelineEyeData support

This commit is contained in:
左右看
2023-07-06 02:48:51 +08:00
parent c6641f85d1
commit 998ec9d14f
21 changed files with 573 additions and 279 deletions
@@ -0,0 +1,27 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Gallop.Live.Cutt
{
public struct FacialDataUpdateInfo // TypeDefIndex: 29410
{
// Fields
public LiveTimelineKeyFacialFaceData faceCur; // 0x0
public LiveTimelineKeyFacialFaceData faceNext; // 0x8
public LiveTimelineKeyFacialMouthData mouth; // 0x10
public LiveTimelineKeyFacialEyeData eyeCur; // 0x18
public LiveTimelineKeyFacialEyeData eyeNext; // 0x20
public LiveTimelineKeyFacialEyebrowData eyebrow; // 0x28
public LiveTimelineKeyFacialEyeTrackData eyeTrack; // 0x30
public LiveTimelineKeyFacialEarData ear; // 0x38
public LiveTimelineKeyFacialEffectData effect; // 0x40
public int faceKeyIndex; // 0x48
public int mouthKeyIndex; // 0x4C
public int eyeKeyIndex; // 0x50
public int eyebrowKeyIndex; // 0x54
public int eyeTrackKeyIndex; // 0x58
public int earKeyIndex; // 0x5C
public int effectKeyIndex; // 0x60
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d23729e48867d7143b85da3439885191
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -14,8 +14,10 @@ namespace Gallop.Live.Cutt
//public abstract string Description { get; set; }
//public abstract int depthCounter { get; }
LiveTimelineKey FindCurrentKey(float currentTime);
public abstract LiveTimelineKeyIndex TimeKeyIndex { get; }
LiveTimelineKeyIndex FindCurrentKey(float currentTime);
LiveTimelineKeyIndex UpdateCurrentKey(float currentTime);
}
}
@@ -27,6 +27,8 @@ namespace Gallop.Live.Cutt
public event Action<LiveTimelineKeyLipSyncData, float> OnUpdateLipSync;
public event Action<FacialDataUpdateInfo, float> OnUpdateFacial;
public void CopyValues<T>(T from, T to)
{
var json = JsonUtility.ToJson(from);
@@ -93,6 +95,7 @@ namespace Gallop.Live.Cutt
{
AlterUpdate_CharaMotionSequence(liveTime);
AlterUpdate_LipSync(liveTime);
AlterUpdate_FacialData(liveTime);
}
public void AlterUpdate_CharaMotionSequence(float liveTime)
@@ -103,23 +106,68 @@ namespace Gallop.Live.Cutt
}
}
public void AlterUpdate_FacialData(float liveTime)
{
var facialDataList = data.worksheetList[0].facial1Set;
FacialDataUpdateInfo updateInfo = default(FacialDataUpdateInfo);
if (facialDataList != null)
{
SetupFacialUpdateInfo_Eye(ref updateInfo, facialDataList.eyeKeys, liveTime);
this.OnUpdateFacial(updateInfo, liveTime);
}
}
private void SetupFacialUpdateInfo_Eye(ref FacialDataUpdateInfo updateInfo, LiveTimelineKeyFacialEyeDataList keys, float time)
{
LiveTimelineKey liveTimelineKey = null;
LiveTimelineKey liveTimelineKey2 = null;
LiveTimelineKeyIndex curKey = AlterUpdate_Key(keys, time);
liveTimelineKey = curKey.key;
liveTimelineKey2 = curKey.nextKey;
updateInfo.eyeCur = liveTimelineKey as LiveTimelineKeyFacialEyeData;
updateInfo.eyeNext = liveTimelineKey2 as LiveTimelineKeyFacialEyeData;
updateInfo.eyeKeyIndex = curKey.index;
}
public void AlterUpdate_LipSync(float liveTime)
{
var lipDataList = data.worksheetList[0].ripSyncKeys;
LiveTimelineKey curKey = null;
FindTimelineKeyCurrent(out curKey, lipDataList, liveTime);
if (curKey != null)
LiveTimelineKeyIndex curKey = AlterUpdate_Key(lipDataList, liveTime);
if (curKey != null && curKey.index != -1)
{
LiveTimelineKeyLipSyncData arg = curKey as LiveTimelineKeyLipSyncData;
LiveTimelineKeyLipSyncData arg = curKey.key as LiveTimelineKeyLipSyncData;
this.OnUpdateLipSync(arg, liveTime);
}
}
public void FindTimelineKeyCurrent(out LiveTimelineKey curKey, ILiveTimelineKeyDataList keys, float curTime)
public static void FindTimelineKeyCurrent(out LiveTimelineKeyIndex curKey, ILiveTimelineKeyDataList keys, float curTime)
{
curKey = keys.FindCurrentKey(curTime);
}
public static void UpdateTimelineKeyCurrent(out LiveTimelineKeyIndex curKey, ILiveTimelineKeyDataList keys, float curTime)
{
curKey = keys.UpdateCurrentKey(curTime);
}
public static LiveTimelineKeyIndex AlterUpdate_Key(ILiveTimelineKeyDataList keys, float curTime)
{
LiveTimelineKeyIndex curKey = keys.TimeKeyIndex;
if (curKey.index == -1)
{
FindTimelineKeyCurrent(out curKey, keys, curTime);
}
else
{
UpdateTimelineKeyCurrent(out curKey, keys, curTime);
}
return curKey;
}
}
@@ -58,61 +58,20 @@ namespace Gallop.Live.Cutt
{
if (_currentKey != null && _tempAnim != null)
{
/*
var seqs = _currentKey.thisList;
LiveTimelineKeyIndex curKey = LiveTimelineControl.AlterUpdate_Key(_currentKey, currentTime);
for (int i = seqs.Count - 1; i >= 0; i--)
if (curKey != null && curKey.index != -1)
{
Debug.Log(currentTime);
if (currentTime >= (double)seqs[i].frame / 60)
{
Debug.Log("ʱ¼ä:" + ((double)seqs[i].frame / 60).ToString());
LiveTimelineKeyCharaMotionData arg = curKey.key as LiveTimelineKeyCharaMotionData;
AnimationClip anim = seqs[i].clip;
double start = (double)seqs[i].motionHeadFrame / 60;
double interval = currentTime - (double)seqs[i].frame / 60;
Debug.Log("time:" + interval.ToString());
//anim.SampleAnimation(container.gameObject, (float)(start + interval));
_tempAnim[anim.name].time = (float)(start + interval);
_tempAnim.Play(anim.name);
break;
}
}
*/
var timelineKey = GetKey(currentTime);
//if ( _prevKey != timelineKey ) Play animation all the time not affect performance maybe?
if ( true )
{
AnimationClip anim = timelineKey.clip;
double start = (double)timelineKey.motionHeadFrame / 60;
double interval = currentTime - (double)timelineKey.frame / 60;
AnimationClip anim = arg.clip;
double start = (double)arg.motionHeadFrame / 60;
double interval = currentTime - (double)arg.frame / 60;
_tempAnim[anim.name].time = (float)(start + interval);
_tempAnim.Play(anim.name);
_prevKey = timelineKey;
}
}
}
public LiveTimelineKeyCharaMotionData GetKey(float time)
{
var seqs = _currentKey.thisList;
for (int i = seqs.Count - 1; i >= 0; i--)
{
if (time >= (double)seqs[i].frame / 60)
{
return seqs[i];
}
}
return seqs[0];
}
}
}
@@ -126,7 +126,12 @@ namespace Gallop.Live.Cutt
private TimelineKeyPlayMode _playMode;
public List<T> thisList;
public LiveTimelineKeyIndex thisTimeKeyIndex = new LiveTimelineKeyIndex();
public int Count => thisList.Count;
public LiveTimelineKeyIndex TimeKeyIndex => thisTimeKeyIndex;
public LiveTimelineKey this[int index]
{
@@ -140,20 +145,61 @@ namespace Gallop.Live.Cutt
}
}
public LiveTimelineKey FindCurrentKey(float currentTime)
public LiveTimelineKeyIndex FindCurrentKey(float currentTime)
{
for (int i = thisList.Count - 1; i >= 0; i--)
{
if (currentTime >= (double)thisList[i].frame / 60)
{
return thisList[i];
thisTimeKeyIndex.index = i;
thisTimeKeyIndex.key = thisList[i];
if(i+1 != thisList.Count)
{
thisTimeKeyIndex.nextKey = thisList[i + 1];
}
else
{
thisTimeKeyIndex.nextKey = null;
}
return thisTimeKeyIndex;
}
}
return null;
}
public LiveTimelineKeyIndex UpdateCurrentKey(float currentTime)
{
if (thisTimeKeyIndex.nextKey != null)
{
if (currentTime >= (double)thisTimeKeyIndex.nextKey.frame / 60)
{
thisTimeKeyIndex.index++;
thisTimeKeyIndex.key = thisList[thisTimeKeyIndex.index];
if (thisTimeKeyIndex.index + 1 != thisList.Count)
{
thisTimeKeyIndex.nextKey = thisList[thisTimeKeyIndex.index + 1];
}
else
{
thisTimeKeyIndex.nextKey = null;
}
}
}
return thisTimeKeyIndex;
}
}
[System.Serializable]
[System.Serializable]
public class LiveTimelineKeyIndex
{
public int index = -1;
public LiveTimelineKey key = null;
public LiveTimelineKey nextKey = null;
}
[System.Serializable]
public abstract class LiveTimelineKey
{
public int frame;