2171 lines
105 KiB
C#
2171 lines
105 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using System.Linq;
|
||
using System.IO;
|
||
|
||
namespace Gallop.Live.Cutt
|
||
{
|
||
public class LiveTimelineControl : MonoBehaviour
|
||
{
|
||
public LiveTimelineData data;
|
||
public const int kTargetFps = 60;
|
||
public const float kTargetFpsF = 60;
|
||
public const float kFrameToSec = 0.016666668f;
|
||
public Transform cameraPositionLocatorsRoot;
|
||
public Transform cameraLookAtLocatorsRoot;
|
||
[SerializeField]
|
||
private Transform[] characterStandPosLocators;
|
||
public const float BaseCharaHeight = 158;
|
||
public const float BaseCharaHeightMin = 130;
|
||
public const float BaseCharaHeightMax = 190;
|
||
public const float BaseCharaHeightDiff = 60;
|
||
|
||
public struct FindTimelineConfig
|
||
{
|
||
public enum KeyType
|
||
{
|
||
KeyDirect,
|
||
CurrentFrame
|
||
}
|
||
|
||
public KeyType keyType;
|
||
|
||
public ILiveTimelineKeyDataList posKeys;
|
||
|
||
public ILiveTimelineKeyDataList lookAtKeys;
|
||
|
||
public LiveTimelineKey curKey;
|
||
|
||
public LiveTimelineKey nextKey;
|
||
|
||
public int extraCameraIndex;
|
||
}
|
||
|
||
private LiveTimelineMotionSequence[] _motionSequenceArray;
|
||
|
||
public LiveTimelineKeyCharaMotionSeqDataList[] _keyArray;
|
||
|
||
public event Action<LiveTimelineKeyIndex, float> OnUpdateLipSync;
|
||
|
||
public event Action<FacialDataUpdateInfo, float, int> OnUpdateFacial;
|
||
|
||
public event Action<int> OnUpdateCameraSwitcher;
|
||
|
||
public event GlobalLightUpdateInfoDelegate OnUpdateGlobalLight;
|
||
|
||
public event BgColor1UpdateInfoDelegate OnUpdateBgColor1;
|
||
|
||
public event BgColor2UpdateInfoDelegate OnUpdateBgColor2;
|
||
|
||
public event PostFilmUpdateInfoDelegate OnUpdatePostFilm;
|
||
|
||
public event TransformUpdateInfoDelegate OnUpdateTransform;
|
||
|
||
public event ObjectUpdateInfoDelegate OnUpdateObject;
|
||
|
||
public event Action<LiveTimelineEffectData, LiveTimelineKeyEffectData> OnUpdateEffect;
|
||
public event Action<LiveTimelineGlobalFogData, LiveTimelineKeyGlobalFogData> OnUpdateGlobalFog;
|
||
public event Action<LiveTimelineSpotlight3dData, LiveTimelineKeySpotlight3dData> OnUpdateSpotlight3d;
|
||
public event Action<LiveTimelineUVScrollLightData, LiveTimelineKeyUVScrollLightData> OnUpdateUVScrollLight;
|
||
public event Action<LiveTimelineVolumeLightData, LiveTimelineKeyVolumeLightData> OnUpdateVolumeLight;
|
||
public event Action<LiveTimelineLightShaftsData, LiveTimelineKeyLightShaftsData> OnUpdateLightShafts;
|
||
public event Action<LiveTimelineParticleData, LiveTimelineKeyParticleData> OnUpdateParticle;
|
||
public event Action<LiveTimelineParticleGroupData, LiveTimelineKeyParticleGroupData> OnUpdateParticleGroup;
|
||
public event Action<LiveTimelineWashLightData, LiveTimelineKeyWashLightData> OnUpdateWashLight;
|
||
public event Action<LiveTimelineLaserData, LiveTimelineKeyLaserData> OnUpdateLaser;
|
||
public event Action<LiveTimelineBlinkLightData, LiveTimelineKeyBlinkLightData> OnUpdateBlinkLight;
|
||
public event Action<LiveTimelineChromaticAberrationData, LiveTimelineKeyChromaticAberrationData> OnUpdateChromaticAberration;
|
||
public event Action<LiveTimelineHdrBloomData, LiveTimelineKeyHdrBloomData> OnUpdateHdrBloom;
|
||
public event Action<LiveTimelineColorCorrectionData, LiveTimelineKeyColorCorrectionData> OnUpdateColorCorrection;
|
||
public event MobCyalumeUpdateInfoDelegate OnUpdateMobControl;
|
||
public event MobCyalumeUpdateInfoDelegate OnUpdateCyalumeControl;
|
||
public event Action<LiveTimelineMonitorControlData, LiveTimelineKeyMonitorControlData> OnUpdateMonitorControl;
|
||
public event Action<LiveTimelineMonitorCameraPositionData, LiveTimelineKeyMonitorCameraPositionData> OnUpdateMonitorCameraPosition;
|
||
public event Action<LiveTimelineMonitorCameraLookAtData, LiveTimelineKeyMonitorCameraLookAtData> OnUpdateMonitorCameraLookAt;
|
||
public event Action<LiveTimelineLensFlareData, LiveTimelineKeyLensFlareData> OnUpdateLensFlare;
|
||
public event Action<LiveTimelineStageEnvironmentData, LiveTimelineKeyStageEnvironmentData> OnUpdateEnvironment;
|
||
public event Action<int, LiveTimelineKeyFacialToonData> OnUpdateFacialToon;
|
||
public event Action<LiveTimelinePropsData, LiveTimelineKeyPropsData> OnUpdateProps;
|
||
public event Action<LiveTimelinePropsAttachData, LiveTimelineKeyPropsAttachData> OnUpdatePropsAttach;
|
||
public event Action<LiveTimelineKeyCharaFootLightData> OnUpdateCharaFootLight;
|
||
public event Action<LiveTimelineAdditionalLight, LiveTimelineKeyData_AdditionalLight> OnUpdateAdditionalLight;
|
||
public event Action<LiveTimelineLightProjectionData, LiveTimelineKeyLightProjectionData> OnUpdateLightProjection;
|
||
|
||
private static Func<LiveTimelineKeyCameraPositionData, LiveTimelineControl, FindTimelineConfig, Vector3> fnGetCameraPosValue = GetCameraPosValue;
|
||
|
||
private static Func<LiveTimelineKeyCameraLookAtData, LiveTimelineControl, Vector3, FindTimelineConfig, Vector3> fnGetCameraLookAtValue = GetCameraLookAtValue;
|
||
|
||
private Vector3 _cameraLayerOffset = Vector3.zero;
|
||
|
||
private CacheCamera[] _cameraArray = new CacheCamera[3];
|
||
|
||
private LiveTimelineCamera[] _cameraScriptArray = new LiveTimelineCamera[3];
|
||
|
||
private Dictionary<string, Transform> _cameraPositionLocatorDict;
|
||
|
||
private Dictionary<string, Transform> _cameraLookAtLocatorDict;
|
||
|
||
private CacheCamera[] _multiCameraCache;
|
||
|
||
private MultiCamera[] _multiCamera;
|
||
|
||
private bool _isMultiCameraEnable;
|
||
|
||
private bool _isNowAlterUpdate;
|
||
|
||
private float _oldFrame;
|
||
|
||
private float _oldLiveTime;
|
||
|
||
private float _currentLiveTime;
|
||
|
||
private float _deltaTimeRatio;
|
||
|
||
private float _deltaTime;
|
||
|
||
private float _baseCameraAspectRatio = 1.77777779f;
|
||
|
||
public bool _limitFovForWidth = false;
|
||
|
||
private float _currentFrame;
|
||
|
||
private bool _isExtraCameraLayer;
|
||
|
||
public bool IsRecordVMD;
|
||
public List<LiveCameraFrame> RecordFrames = new List<LiveCameraFrame>();
|
||
public List<List<LiveCameraFrame>> MultiRecordFrames = new List<List<LiveCameraFrame>>();
|
||
public event Action RecordUma;
|
||
|
||
public Dictionary<string, GameObject> StageObjectMap = new Dictionary<string, GameObject>();
|
||
|
||
/// <summary>
|
||
/// Object/Transform 轨道的组名不一定是 GameObject 名,也可能是 StageController
|
||
/// 的 _stageObjectUnits 单元名。例如 live10149 的 'neonsign' 就是一个 unit,
|
||
/// 底下挂着 glow_neonsign / wash_neonsign_a / wash_neonsign_b 三个子对象。
|
||
/// </summary>
|
||
public Dictionary<string, StageObjectUnit> StageObjectUnitMap = new Dictionary<string, StageObjectUnit>();
|
||
|
||
public float currentLiveTime
|
||
{
|
||
get
|
||
{
|
||
return _currentLiveTime;
|
||
}
|
||
private set
|
||
{
|
||
_currentLiveTime = value;
|
||
}
|
||
}
|
||
|
||
public event CameraPosUpdateInfoDelegate OnUpdateCameraPos;
|
||
|
||
public CacheCamera[] cameraArray
|
||
{
|
||
get
|
||
{
|
||
return _cameraArray;
|
||
}
|
||
private set
|
||
{
|
||
_cameraArray = value;
|
||
}
|
||
}
|
||
|
||
private LiveTimelineCamera[] cameraScriptArray => _cameraScriptArray;
|
||
|
||
private Dictionary<string, Transform> cameraPositionLocatorDict
|
||
{
|
||
get
|
||
{
|
||
if (_cameraPositionLocatorDict == null)
|
||
{
|
||
_cameraPositionLocatorDict = new Dictionary<string, Transform>();
|
||
if (cameraPositionLocatorsRoot != null)
|
||
{
|
||
Transform[] componentsInChildren = cameraPositionLocatorsRoot.GetComponentsInChildren<Transform>();
|
||
foreach (Transform transform in componentsInChildren)
|
||
{
|
||
_cameraPositionLocatorDict[transform.name] = transform;
|
||
}
|
||
}
|
||
}
|
||
return _cameraPositionLocatorDict;
|
||
}
|
||
}
|
||
|
||
private Dictionary<string, Transform> cameraLookAtLocatorDict
|
||
{
|
||
get
|
||
{
|
||
if (_cameraLookAtLocatorDict == null)
|
||
{
|
||
_cameraLookAtLocatorDict = new Dictionary<string, Transform>();
|
||
if (cameraLookAtLocatorsRoot != null)
|
||
{
|
||
Transform[] componentsInChildren = cameraLookAtLocatorsRoot.GetComponentsInChildren<Transform>();
|
||
foreach (Transform transform in componentsInChildren)
|
||
{
|
||
_cameraLookAtLocatorDict[transform.name] = transform;
|
||
}
|
||
}
|
||
}
|
||
return _cameraLookAtLocatorDict;
|
||
}
|
||
}
|
||
|
||
public ILiveTimelineCharactorLocator[] liveCharactorLocators => _liveCharactorLocators;
|
||
|
||
private ILiveTimelineCharactorLocator[] _liveCharactorLocators = new ILiveTimelineCharactorLocator[liveCharaPositionMax];
|
||
|
||
public Vector3 liveStageCenterPos => _liveStageCenterPos;
|
||
|
||
private Vector3 _liveStageCenterPos = Vector3.zero;
|
||
|
||
private TimelinePlayerMode _playMode = TimelinePlayerMode.Default;
|
||
public TimelinePlayerMode PlayMode => _playMode;
|
||
|
||
public static int liveCharaPositionMax
|
||
{
|
||
get
|
||
{
|
||
if (_liveCharaPositionMax < 0)
|
||
{
|
||
_liveCharaPositionMax = Enum.GetValues(typeof(LiveCharaPosition)).Length;
|
||
}
|
||
return _liveCharaPositionMax;
|
||
}
|
||
}
|
||
|
||
public CacheCamera GetCamera(int index)
|
||
{
|
||
if (index < 0 || index >= _cameraArray.Length)
|
||
{
|
||
return null;
|
||
}
|
||
return _cameraArray[index];
|
||
}
|
||
|
||
private static int _liveCharaPositionMax = -1;
|
||
|
||
private static bool availableFindKeyCache => true;
|
||
|
||
private static Func<LiveTimelineKeyCameraPositionData, LiveTimelineControl, FindTimelineConfig, Vector3> fnGetMultiCameraPositionValueFunc = GetMultiCameraPositionValue;
|
||
|
||
private static Func<LiveTimelineKeyCameraLookAtData, LiveTimelineControl, Vector3, FindTimelineConfig, Vector3> fnGetMultiCameraLookAtValueFunc = GetMultiCameraLookAtValue;
|
||
|
||
public void CopyValues<T>(T from, T to)
|
||
{
|
||
var json = JsonUtility.ToJson(from);
|
||
JsonUtility.FromJsonOverwrite(json, to);
|
||
}
|
||
|
||
private void Awake()
|
||
{
|
||
InitializeTimeLineData();
|
||
if (Director.instance)
|
||
{
|
||
Director.instance._liveTimelineControl = this;
|
||
IsRecordVMD = Director.instance.IsRecordVMD;
|
||
}
|
||
}
|
||
|
||
public void InitializeTimeLineData()
|
||
{
|
||
//var LoadData = gameObject.AddComponent<LiveTimelineData>();
|
||
//CopyValues(data, LoadData);
|
||
//foreach(LiveTimelineWorkSheet worksheet in LoadData.worksheetList)
|
||
//{
|
||
// var LoadSheet = gameObject.AddComponent<LiveTimelineWorkSheet>();
|
||
// CopyValues(worksheet, LoadSheet);
|
||
//}
|
||
}
|
||
|
||
public void InitCharaMotionSequence(int[] motionSequence)
|
||
{
|
||
//Create Animation
|
||
foreach (var obj in Director.instance.charaObjs)
|
||
{
|
||
var container = obj.GetComponentInChildren<UmaContainer>();
|
||
if (container)
|
||
{
|
||
var animation = container.gameObject.AddComponent<Animation>();
|
||
Director.instance.charaAnims.Add(animation);
|
||
}
|
||
}
|
||
|
||
//Get KeyArray
|
||
var listCount = data.worksheetList[0].charaMotSeqList.Count;
|
||
|
||
_keyArray = new LiveTimelineKeyCharaMotionSeqDataList[listCount];
|
||
|
||
for (int i = 0; i < listCount; i++)
|
||
{
|
||
_keyArray[i] = data.worksheetList[0].charaMotSeqList[i].keys;
|
||
}
|
||
|
||
if (Director.instance.liveMode == 1)
|
||
{
|
||
//Set Motion
|
||
int CharaPositionMax = Director.instance.allowCount;
|
||
|
||
_motionSequenceArray = new LiveTimelineMotionSequence[CharaPositionMax];
|
||
|
||
|
||
for (int i = 0; i < CharaPositionMax; i++)
|
||
{
|
||
Debug.Log(i);
|
||
_motionSequenceArray[i] = new LiveTimelineMotionSequence();
|
||
_motionSequenceArray[i].Initialize(Director.instance.charaObjs[i], i, motionSequence[i], this);
|
||
}
|
||
}
|
||
else if(Director.instance.liveMode == 0)
|
||
{
|
||
List<AnimationClip> Anims = new List<AnimationClip>();
|
||
//Get MotionList
|
||
foreach (var motion in UmaViewerMain.Instance.AbMotions.Where(a => a.Name.StartsWith($"3d/motion/live/body/son{Director.instance.live.MusicId}") && Path.GetFileName(a.Name).Split('_').Length == 4))
|
||
{
|
||
AssetBundle motionAB = UmaAssetManager.LoadAssetBundle(motion);
|
||
AnimationClip motionAnim = motionAB.LoadAsset<AnimationClip>(Path.GetFileName(motion.Name).Split('.')[0]);
|
||
Anims.Add(motionAnim);
|
||
}
|
||
|
||
//Set Motion
|
||
int CharaPositionMax = Director.instance.allowCount;
|
||
|
||
_motionSequenceArray = new LiveTimelineMotionSequence[CharaPositionMax];
|
||
|
||
|
||
for (int i = 0; i < CharaPositionMax; i++)
|
||
{
|
||
_motionSequenceArray[i] = new LiveTimelineMotionSequence();
|
||
_motionSequenceArray[i].Initialize(Director.instance.charaObjs[i], i, motionSequence[i], this, Anims);
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
public void AlterUpdate(float liveTime)
|
||
{
|
||
_isNowAlterUpdate = true;
|
||
_isMultiCameraEnable = false;
|
||
_isNowAlterUpdate = true;
|
||
_oldLiveTime = currentLiveTime;
|
||
currentLiveTime = liveTime;
|
||
_currentFrame = currentLiveTime * 60f;
|
||
_oldFrame = _oldLiveTime * 60f;
|
||
_deltaTime = currentLiveTime - _oldLiveTime;
|
||
_deltaTimeRatio = _deltaTime / 0.0166666675f;
|
||
AlterUpdate_CharaMotionSequence(liveTime);
|
||
AlterUpdate_FacialData(liveTime);
|
||
AlterUpdate_LipSync(liveTime);
|
||
AlterUpdate_LipSync2(liveTime);
|
||
_isNowAlterUpdate = false;
|
||
}
|
||
|
||
public void AlterLateUpdate()
|
||
{
|
||
LiveTimelineWorkSheet workSheet = data.worksheetList[0];
|
||
_isNowAlterUpdate = true;
|
||
Vector3 outLookAt = Vector3.zero;
|
||
AlterLateUpdate_FormationOffset(currentLiveTime);
|
||
AlterUpdate_CameraSwitcher(workSheet, _currentFrame);
|
||
AlterUpdate_CameraPos(workSheet, _currentFrame);
|
||
AlterUpdate_CameraLookAt(workSheet, _currentFrame, ref outLookAt);
|
||
AlterUpdate_CameraFov(workSheet, _currentFrame);
|
||
AlterUpdate_CameraRoll(workSheet, _currentFrame);
|
||
AlterUpdate_MultiCamera(workSheet, _currentFrame);
|
||
AlterUpdate_GlobalLight(workSheet, _currentFrame);
|
||
AlterUpdate_BgColor1(workSheet, _currentFrame);
|
||
AlterUpdate_BgColor2(workSheet, _currentFrame);
|
||
AlterUpdate_TransformControl(workSheet, _currentFrame);
|
||
AlterUpdate_ObjectControl(workSheet, _currentFrame);
|
||
AlterUpdate_EffectControl(workSheet, _currentFrame);
|
||
AlterUpdate_GlobalFogControl(workSheet, _currentFrame);
|
||
AlterUpdate_Spotlight3dControl(workSheet, _currentFrame);
|
||
AlterUpdate_SimpleListControl(workSheet.uvScrollLightList, d => d.keys, OnUpdateUVScrollLight, _currentFrame);
|
||
AlterUpdate_SimpleListControl(workSheet.volumeLightKeys, d => d.keys, OnUpdateVolumeLight, _currentFrame);
|
||
AlterUpdate_SimpleListControl(workSheet.lightShaftsKeysLine, d => d.keys, OnUpdateLightShafts, _currentFrame);
|
||
AlterUpdate_SimpleListControl(workSheet.particleList, d => d.keys, OnUpdateParticle, _currentFrame);
|
||
AlterUpdate_SimpleListControl(workSheet.particleGroupList, d => d.keys, OnUpdateParticleGroup, _currentFrame);
|
||
AlterUpdate_SimpleListControl(workSheet.WashLightList, d => d.keys, OnUpdateWashLight, _currentFrame);
|
||
AlterUpdate_SimpleListControl(workSheet.laserList, d => d.keys, OnUpdateLaser, _currentFrame);
|
||
AlterUpdate_SimpleListControl(workSheet.blinkLightList, d => d.keys, OnUpdateBlinkLight, _currentFrame);
|
||
AlterUpdate_SimpleListControl(workSheet.chromaticAberrationList, d => d.keys, OnUpdateChromaticAberration, _currentFrame);
|
||
// HdrBloom:Director 侧刻意没有 handler(全语料 59 首 0 keys,映射也无从核对)。
|
||
// 分发保留,接上只需订阅 OnUpdateHdrBloom。
|
||
AlterUpdate_SimpleListControl(workSheet.hdrBloomKeys, d => d.keys, OnUpdateHdrBloom, _currentFrame);
|
||
AlterUpdate_SimpleListControl(workSheet.colorCorrectionDataLists, d => d.keys, OnUpdateColorCorrection, _currentFrame);
|
||
AlterUpdate_MobCyalumeControl(workSheet.MobControlKeys, _currentFrame, OnUpdateMobControl);
|
||
AlterUpdate_MobCyalumeControl(workSheet.CyalumeControlKeys, _currentFrame, OnUpdateCyalumeControl);
|
||
AlterUpdate_SimpleListControl(workSheet.monitorControlList, d => d.keys, OnUpdateMonitorControl, _currentFrame);
|
||
AlterUpdate_SimpleListControl(workSheet.monitorCameraPosKeys, d => d.keys, OnUpdateMonitorCameraPosition, _currentFrame);
|
||
AlterUpdate_SimpleListControl(workSheet.monitorCameraLookAtKeys, d => d.keys, OnUpdateMonitorCameraLookAt, _currentFrame);
|
||
AlterUpdate_SimpleListControl(workSheet.lensFlareList, d => d.keys, OnUpdateLensFlare, _currentFrame);
|
||
AlterUpdate_SimpleListControl(workSheet.environmentDataLists, d => d.keys, OnUpdateEnvironment, _currentFrame);
|
||
AlterUpdate_FacialToon(workSheet.facialToonSet, _currentFrame);
|
||
AlterUpdate_SimpleListControl(workSheet.propsList, d => d.keys, OnUpdateProps, _currentFrame);
|
||
AlterUpdate_SimpleListControl(workSheet.propsAttachList, d => d.keys, OnUpdatePropsAttach, _currentFrame);
|
||
AlterUpdate_SimpleListControl(workSheet.AdditionalLightList, d => d.keys, OnUpdateAdditionalLight, _currentFrame);
|
||
AlterUpdate_CharaFootLight(workSheet.charaFootLightKeys, _currentFrame);
|
||
AlterUpdate_SimpleListControl(workSheet.lightProjectionList, d => d.keys, OnUpdateLightProjection, _currentFrame);
|
||
AlterUpdate_PostFilm(workSheet.postFilmKeys, 0, _currentFrame);
|
||
AlterUpdate_PostFilm(workSheet.postFilm2Keys, 1, _currentFrame);
|
||
AlterUpdate_PostFilm(workSheet.postFilm3Keys, 2, _currentFrame);
|
||
|
||
_isNowAlterUpdate = false;
|
||
|
||
if (IsRecordVMD)
|
||
{
|
||
var currentFrame = Mathf.RoundToInt(_currentFrame);
|
||
var oldFrame = Mathf.RoundToInt(_oldFrame);
|
||
CacheCamera cacheCamera = GetCamera(workSheet.targetCameraIndex);
|
||
if ((oldFrame == currentFrame && currentFrame > 0)|| cacheCamera == null) return;
|
||
|
||
LiveCameraFrame lastframe = RecordFrames.Count > 0 ? RecordFrames[RecordFrames.Count - 1] : null;
|
||
|
||
var transform = cacheCamera.cacheTransform;
|
||
var camera = cacheCamera.camera;
|
||
LiveCameraFrame frame = new LiveCameraFrame(currentFrame, transform, camera.fieldOfView, lastframe);
|
||
RecordFrames.Add(frame);
|
||
|
||
for (int i = 0; i < MultiRecordFrames.Count; i++)
|
||
{
|
||
var MulFrame = MultiRecordFrames[i];
|
||
LiveCameraFrame lastMulframe = MulFrame.Count > 0 ? MulFrame[MulFrame.Count - 1] : null;
|
||
MultiCamera MulCamera = _multiCamera[i];
|
||
var cam = MulCamera.GetCamera();
|
||
LiveCameraFrame mulframe = new LiveCameraFrame(currentFrame, MulCamera.transform, cam.fieldOfView, lastMulframe);
|
||
MulFrame.Add(mulframe);
|
||
}
|
||
|
||
if (currentFrame % 2 == 0) RecordUma?.Invoke(); //Set 30 FPS
|
||
}
|
||
}
|
||
|
||
public void AlterUpdate_CharaMotionSequence(float liveTime)
|
||
{
|
||
foreach (var motion in _motionSequenceArray)
|
||
{
|
||
motion.AlterUpdate(liveTime, data.worksheetList[0].timescaleKeys);
|
||
}
|
||
}
|
||
|
||
public void AlterUpdate_FacialData(float liveTime)
|
||
{
|
||
var facialDataList = data.worksheetList[0].facial1Set;
|
||
FacialDataUpdateInfo updateInfo = default(FacialDataUpdateInfo);
|
||
if (facialDataList != null)
|
||
{
|
||
SetupFacialUpdateInfo_Mouth(ref updateInfo, facialDataList.mouthKeys, liveTime);
|
||
SetupFacialUpdateInfo_Eye(ref updateInfo, facialDataList.eyeKeys, liveTime);
|
||
SetupFacialUpdateInfo_Eyebrow(ref updateInfo, facialDataList.eyebrowKeys, liveTime);
|
||
SetupFacialUpdateInfo_Ear(ref updateInfo, facialDataList.earKeys, liveTime);
|
||
SetupFacialUpdateInfo_EyeTrack(ref updateInfo, facialDataList.eyeTrackKeys, liveTime);
|
||
SetupFacialUpdateInfo_Effect(ref updateInfo, facialDataList.effectKeys, liveTime);
|
||
this.OnUpdateFacial(updateInfo, liveTime, 0);
|
||
}
|
||
|
||
var otherFacialDataList = data.worksheetList[0].other4FacialArray;
|
||
for(int i = 0; i < otherFacialDataList.Length && i < Director.instance.characterCount - 1; i++)
|
||
{
|
||
SetupFacialUpdateInfo_Mouth(ref updateInfo, otherFacialDataList[i].mouthKeys, liveTime);
|
||
SetupFacialUpdateInfo_Eye(ref updateInfo, otherFacialDataList[i].eyeKeys, liveTime);
|
||
SetupFacialUpdateInfo_Eyebrow(ref updateInfo, otherFacialDataList[i].eyebrowKeys, liveTime);
|
||
SetupFacialUpdateInfo_Ear(ref updateInfo, otherFacialDataList[i].earKeys, liveTime);
|
||
SetupFacialUpdateInfo_EyeTrack(ref updateInfo, otherFacialDataList[i].eyeTrackKeys, liveTime);
|
||
SetupFacialUpdateInfo_Effect(ref updateInfo, otherFacialDataList[i].effectKeys, liveTime);
|
||
this.OnUpdateFacial(updateInfo, liveTime, i+1);
|
||
}
|
||
}
|
||
|
||
private void SetupFacialUpdateInfo_Mouth(ref FacialDataUpdateInfo updateInfo, LiveTimelineKeyFacialMouthDataList keys, float time)
|
||
{
|
||
LiveTimelineKey liveTimelineKey = null;
|
||
LiveTimelineKey liveTimelineKey2 = null;
|
||
LiveTimelineKey liveTimelineKey3 = null;
|
||
|
||
LiveTimelineKeyIndex curKey = AlterUpdate_Key(keys, time);
|
||
if (curKey != null)
|
||
{
|
||
liveTimelineKey = curKey.prevKey;
|
||
liveTimelineKey2 = curKey.key;
|
||
liveTimelineKey3 = curKey.nextKey;
|
||
|
||
updateInfo.mouthPrev = liveTimelineKey as LiveTimelineKeyFacialMouthData;
|
||
updateInfo.mouthCur = liveTimelineKey2 as LiveTimelineKeyFacialMouthData;
|
||
updateInfo.mouthNext = liveTimelineKey3 as LiveTimelineKeyFacialMouthData;
|
||
updateInfo.mouthKeyIndex = curKey.index;
|
||
}
|
||
}
|
||
|
||
private void SetupFacialUpdateInfo_Eye(ref FacialDataUpdateInfo updateInfo, LiveTimelineKeyFacialEyeDataList keys, float time)
|
||
{
|
||
LiveTimelineKey liveTimelineKey = null;
|
||
LiveTimelineKey liveTimelineKey2 = null;
|
||
LiveTimelineKey liveTimelineKey3 = null;
|
||
|
||
LiveTimelineKeyIndex curKey = AlterUpdate_Key(keys, time);
|
||
if (curKey != null)
|
||
{
|
||
liveTimelineKey = curKey.prevKey;
|
||
liveTimelineKey2 = curKey.key;
|
||
liveTimelineKey3 = curKey.nextKey;
|
||
|
||
updateInfo.eyePrev = liveTimelineKey as LiveTimelineKeyFacialEyeData;
|
||
updateInfo.eyeCur = liveTimelineKey2 as LiveTimelineKeyFacialEyeData;
|
||
updateInfo.eyeNext = liveTimelineKey3 as LiveTimelineKeyFacialEyeData;
|
||
updateInfo.eyeKeyIndex = curKey.index;
|
||
}
|
||
}
|
||
|
||
private void SetupFacialUpdateInfo_Effect(ref FacialDataUpdateInfo updateInfo, LiveTimelineKeyFacialEffectDataList keys, float time)
|
||
{
|
||
LiveTimelineKey liveTimelineKey = null;
|
||
|
||
LiveTimelineKeyIndex curKey = AlterUpdate_Key(keys, time);
|
||
if (curKey != null)
|
||
{
|
||
liveTimelineKey = curKey.key;
|
||
|
||
updateInfo.effect = liveTimelineKey as LiveTimelineKeyFacialEffectData;
|
||
updateInfo.effectKeyIndex = curKey.index;
|
||
}
|
||
}
|
||
|
||
private void SetupFacialUpdateInfo_Eyebrow(ref FacialDataUpdateInfo updateInfo, LiveTimelineKeyFacialEyebrowDataList keys, float time)
|
||
{
|
||
LiveTimelineKey liveTimelineKey = null;
|
||
LiveTimelineKey liveTimelineKey2 = null;
|
||
LiveTimelineKey liveTimelineKey3 = null;
|
||
|
||
LiveTimelineKeyIndex curKey = AlterUpdate_Key(keys, time);
|
||
if (curKey != null)
|
||
{
|
||
liveTimelineKey = curKey.prevKey;
|
||
liveTimelineKey2 = curKey.key;
|
||
liveTimelineKey3 = curKey.nextKey;
|
||
|
||
updateInfo.eyebrowPrev = liveTimelineKey as LiveTimelineKeyFacialEyebrowData;
|
||
updateInfo.eyebrowCur = liveTimelineKey2 as LiveTimelineKeyFacialEyebrowData;
|
||
updateInfo.eyebrowNext = liveTimelineKey3 as LiveTimelineKeyFacialEyebrowData;
|
||
updateInfo.eyebrowKeyIndex = curKey.index;
|
||
}
|
||
}
|
||
|
||
private void SetupFacialUpdateInfo_Ear(ref FacialDataUpdateInfo updateInfo, LiveTimelineKeyFacialEarDataList keys, float time)
|
||
{
|
||
LiveTimelineKey liveTimelineKey = null;
|
||
LiveTimelineKey liveTimelineKey2 = null;
|
||
LiveTimelineKey liveTimelineKey3 = null;
|
||
|
||
LiveTimelineKeyIndex curKey = AlterUpdate_Key(keys, time);
|
||
if (curKey != null)
|
||
{
|
||
liveTimelineKey = curKey.prevKey;
|
||
liveTimelineKey2 = curKey.key;
|
||
liveTimelineKey3 = curKey.nextKey;
|
||
|
||
updateInfo.earPrev = liveTimelineKey as LiveTimelineKeyFacialEarData;
|
||
updateInfo.earCur = liveTimelineKey2 as LiveTimelineKeyFacialEarData;
|
||
updateInfo.earNext = liveTimelineKey3 as LiveTimelineKeyFacialEarData;
|
||
updateInfo.earKeyIndex = curKey.index;
|
||
}
|
||
}
|
||
|
||
private void SetupFacialUpdateInfo_EyeTrack(ref FacialDataUpdateInfo updateInfo, LiveTimelineKeyFacialEyeTrackDataList keys, float time)
|
||
{
|
||
LiveTimelineKey liveTimelineKey = null;
|
||
LiveTimelineKey liveTimelineKey2 = null;
|
||
LiveTimelineKey liveTimelineKey3 = null;
|
||
|
||
LiveTimelineKeyIndex curKey = AlterUpdate_Key(keys, time);
|
||
if (curKey != null)
|
||
{
|
||
liveTimelineKey = curKey.prevKey;
|
||
liveTimelineKey2 = curKey.key;
|
||
liveTimelineKey3 = curKey.nextKey;
|
||
|
||
updateInfo.eyeTrackPrev = liveTimelineKey as LiveTimelineKeyFacialEyeTrackData;
|
||
updateInfo.eyeTrackCur = liveTimelineKey2 as LiveTimelineKeyFacialEyeTrackData;
|
||
updateInfo.eyeTrackNext = liveTimelineKey3 as LiveTimelineKeyFacialEyeTrackData;
|
||
updateInfo.eyeTrackKeyIndex = curKey.index;
|
||
}
|
||
}
|
||
|
||
public void AlterUpdate_LipSync(float liveTime)
|
||
{
|
||
var lipDataList = data.worksheetList[0].ripSyncKeys;
|
||
|
||
LiveTimelineKeyIndex curKey = AlterUpdate_Key(lipDataList, liveTime);
|
||
|
||
if (curKey != null && curKey.index != -1)
|
||
{
|
||
this.OnUpdateLipSync(curKey, liveTime);
|
||
}
|
||
}
|
||
|
||
public void AlterUpdate_LipSync2(float liveTime)
|
||
{
|
||
var lipDataList = data.worksheetList[0].ripSync2Keys;
|
||
|
||
LiveTimelineKeyIndex curKey = AlterUpdate_Key(lipDataList, liveTime);
|
||
|
||
if (curKey != null && curKey.index != -1)
|
||
{
|
||
this.OnUpdateLipSync(curKey, liveTime);
|
||
}
|
||
}
|
||
|
||
public static void FindTimelineKey(out LiveTimelineKey curKey, out LiveTimelineKey nextKey, ILiveTimelineKeyDataList keys, float curFrame)
|
||
{
|
||
FindKeyResult findKeyResult = keys.FindKeyCached(curFrame, availableFindKeyCache);
|
||
curKey = findKeyResult.key;
|
||
|
||
if (curKey != null)
|
||
{
|
||
nextKey = keys.At(findKeyResult.index + 1);
|
||
}
|
||
else
|
||
{
|
||
nextKey = null;
|
||
}
|
||
}
|
||
|
||
private void AlterLateUpdate_FormationOffset(float liveTime)
|
||
{
|
||
|
||
var formationList = data.worksheetList[0].formationOffsetSet.Init();
|
||
if (formationList == null)
|
||
return;
|
||
|
||
int count = Mathf.Min(Director.instance.characterCount, formationList.Count);
|
||
for (int i = 0; i < count; i++)
|
||
{
|
||
if (formationList[i] == null)
|
||
continue;
|
||
LiveTimelineKeyIndex curKey = AlterUpdate_Key(formationList[i], liveTime);
|
||
|
||
if (curKey != null && curKey.index != -1)
|
||
{
|
||
LateUpdateFormationOffset_Transform(i, curKey, liveTime);
|
||
}
|
||
}
|
||
}
|
||
|
||
private static float LinearInterpolateKeyframes(LiveTimelineKey from, LiveTimelineKey to, float curFrame)
|
||
{
|
||
int num = to.frame - from.frame;
|
||
return Mathf.Clamp01((curFrame - (float)from.frame) / (float)num);
|
||
}
|
||
|
||
private static float CurveInterpolateKeyframes(LiveTimelineKey from, LiveTimelineKey to, float curFrame)
|
||
{
|
||
LiveTimelineKeyWithInterpolate liveTimelineKeyWithInterpolate = from as LiveTimelineKeyWithInterpolate;
|
||
LiveTimelineKeyWithInterpolate liveTimelineKeyWithInterpolate2 = to as LiveTimelineKeyWithInterpolate;
|
||
if (liveTimelineKeyWithInterpolate == null)
|
||
{
|
||
return 0f;
|
||
}
|
||
if (liveTimelineKeyWithInterpolate2 == null)
|
||
{
|
||
return 0f;
|
||
}
|
||
int num = to.frame - from.frame;
|
||
float time = Mathf.Clamp01((curFrame - (float)from.frame) / (float)num);
|
||
return liveTimelineKeyWithInterpolate2.curve.Evaluate(time);
|
||
}
|
||
|
||
private static float EaseInterpolateKeyframes(LiveTimelineKey from, LiveTimelineKey to, float curFrame)
|
||
{
|
||
LiveTimelineKeyWithInterpolate liveTimelineKeyWithInterpolate = from as LiveTimelineKeyWithInterpolate;
|
||
LiveTimelineKeyWithInterpolate liveTimelineKeyWithInterpolate2 = to as LiveTimelineKeyWithInterpolate;
|
||
if (liveTimelineKeyWithInterpolate == null)
|
||
{
|
||
return 0f;
|
||
}
|
||
if (liveTimelineKeyWithInterpolate2 == null)
|
||
{
|
||
return 0f;
|
||
}
|
||
int num = to.frame - from.frame;
|
||
return LiveTimelineEasing.GetValue(liveTimelineKeyWithInterpolate2.easingType, curFrame - (float)from.frame, 0f, 1f, (float)num);
|
||
}
|
||
|
||
|
||
|
||
//��(Live�ݳ����������ƺ�λ�ñ任���)
|
||
public void LateUpdateFormationOffset_Transform(int targetIndex, LiveTimelineKeyIndex curKeyIndex, float time)
|
||
{
|
||
bool ControlMode = UmaViewerUI.Instance != null && UmaViewerUI.Instance.isControlMode;
|
||
|
||
LiveTimelineKeyFormationOffsetData curKey = curKeyIndex.key as LiveTimelineKeyFormationOffsetData;
|
||
LiveTimelineKeyFormationOffsetData nextKey = curKeyIndex.nextKey as LiveTimelineKeyFormationOffsetData;
|
||
|
||
var chara = Director.instance.CharaContainerScript[targetIndex];
|
||
if (!chara) return;
|
||
|
||
|
||
if (ControlMode)
|
||
{
|
||
if (chara.LiveVisible != curKey.visible)
|
||
{
|
||
chara.Materials.ForEach(m =>
|
||
{
|
||
foreach (var key in m.Renderers.Keys)
|
||
{
|
||
if (key.gameObject.activeSelf != curKey.visible)
|
||
key.gameObject.SetActive(curKey.visible);
|
||
}
|
||
});
|
||
chara.LiveVisible = curKey.visible;
|
||
}
|
||
|
||
|
||
if (curKey.visible || IsRecordVMD)
|
||
{
|
||
if (!string.IsNullOrEmpty(curKey.ParentObjectName))
|
||
{
|
||
var parent_transform = curKey.GetParentObjectTransform(this);
|
||
if (parent_transform)
|
||
{
|
||
if (chara.transform.parent != parent_transform)
|
||
{
|
||
chara.transform.SetParent(parent_transform);
|
||
}
|
||
}
|
||
}
|
||
else if (chara.transform.parent)
|
||
{
|
||
chara.transform.SetParent(null);
|
||
}
|
||
|
||
if (nextKey != null && nextKey.interpolateType != LiveCameraInterpolateType.None)
|
||
{
|
||
float ratio = CalculateInterpolationValue(curKey, nextKey, time * 60);
|
||
chara.transform.localPosition = Vector3.Lerp(curKey.Position, nextKey.Position, ratio);
|
||
var x = chara.transform.eulerAngles.x;
|
||
var z = chara.transform.eulerAngles.z;
|
||
chara.transform.eulerAngles = new Vector3(x, Mathf.Lerp(curKey.RotationY, nextKey.RotationY, ratio), z);
|
||
|
||
var local_x = chara.Position.localEulerAngles.x;
|
||
var local_z = chara.Position.localEulerAngles.z;
|
||
chara.Position.localEulerAngles = new Vector3(local_x, Mathf.Lerp(curKey.LocalRotationY, nextKey.LocalRotationY, ratio), local_z);
|
||
}
|
||
else
|
||
{
|
||
chara.transform.localPosition = curKey.Position;
|
||
var x = chara.transform.eulerAngles.x;
|
||
var z = chara.transform.eulerAngles.z;
|
||
chara.transform.eulerAngles = new Vector3(x, curKey.RotationY, z);
|
||
|
||
var local_x = chara.Position.localEulerAngles.x;
|
||
var local_z = chara.Position.localEulerAngles.z;
|
||
chara.Position.localEulerAngles = new Vector3(local_x, curKey.LocalRotationY, local_z);
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (curKey.visible || IsRecordVMD)
|
||
{
|
||
if (!string.IsNullOrEmpty(curKey.ParentObjectName))
|
||
{
|
||
var parent_transform = curKey.GetParentObjectTransform(this);
|
||
if (parent_transform && chara.transform.parent != parent_transform)
|
||
{
|
||
chara.transform.SetParent(parent_transform);
|
||
}
|
||
}
|
||
else if (chara.transform.parent)
|
||
{
|
||
chara.transform.SetParent(null);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
|
||
public static void FindTimelineKeyCurrent(out LiveTimelineKey curKey, ILiveTimelineKeyDataList keys, float curFrame)
|
||
{
|
||
LiveTimelineKey nextKey;
|
||
FindTimelineKey(out curKey, out nextKey, keys, curFrame);
|
||
}
|
||
|
||
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 || Director.instance.sliderControl.is_Touched)
|
||
{
|
||
FindTimelineKeyCurrent(out curKey, keys, curTime);
|
||
}
|
||
else
|
||
{
|
||
UpdateTimelineKeyCurrent(out curKey, keys, curTime);
|
||
}
|
||
|
||
return curKey;
|
||
}
|
||
|
||
|
||
public Quaternion GetMultiCameraWorldRotation(int index)
|
||
{
|
||
if (_multiCameraCache == null || _multiCameraCache.Length <= index)
|
||
{
|
||
return Quaternion.identity;
|
||
}
|
||
return _multiCameraCache[index].cacheTransform.rotation;
|
||
}
|
||
|
||
public Vector3 GetMultiCameraWorldPosition(int index)
|
||
{
|
||
if (_multiCameraCache == null || _multiCameraCache.Length <= index)
|
||
{
|
||
return Vector3.zero;
|
||
}
|
||
return _multiCameraCache[index].cacheTransform.position;
|
||
}
|
||
|
||
|
||
public bool ExistsMultiCamera(int index)
|
||
{
|
||
if (_multiCameraCache != null && index < _multiCameraCache.Length)
|
||
{
|
||
return _multiCameraCache[index] != null;
|
||
}
|
||
return false;
|
||
}
|
||
|
||
public float GetCharacterHeight(LiveCharaPosition position)
|
||
{
|
||
return liveCharactorLocators[(int)position].liveCharaHeightValue;
|
||
}
|
||
|
||
public Vector3 GetPositionWithCharacters(LiveCharaPositionFlag posFlags, LiveCameraCharaParts parts, Vector3 charaPos, Vector3 cameraOffset)
|
||
{
|
||
Vector3 retPos = Vector3.zero;
|
||
Vector3 tmpPos = Vector3.zero;
|
||
if (posFlags == 0)
|
||
{
|
||
retPos = liveStageCenterPos;
|
||
tmpPos = liveStageCenterPos;
|
||
}
|
||
else
|
||
{
|
||
int num = 0;
|
||
switch (parts)
|
||
{
|
||
case LiveCameraCharaParts.Face:
|
||
{
|
||
for (int i = 0; i < liveCharaPositionMax; i++)
|
||
{
|
||
if (posFlags.hasFlag((LiveCharaPosition)i) && liveCharactorLocators[i] != null)
|
||
{
|
||
retPos += liveCharactorLocators[i].liveCharaHeadPosition;
|
||
retPos += cameraOffset * liveCharactorLocators[i].liveCharaHeightRatio;
|
||
num++;
|
||
}
|
||
}
|
||
break;
|
||
}
|
||
case LiveCameraCharaParts.Waist:
|
||
{
|
||
for (int i = 0; i < liveCharaPositionMax; i++)
|
||
{
|
||
if (posFlags.hasFlag((LiveCharaPosition)i) && liveCharactorLocators[i] != null)
|
||
{
|
||
retPos += liveCharactorLocators[i].liveCharaWaistPosition;
|
||
retPos += cameraOffset * liveCharactorLocators[i].liveCharaHeightRatio;
|
||
num++;
|
||
}
|
||
}
|
||
break;
|
||
}
|
||
case LiveCameraCharaParts.LeftHandWrist:
|
||
{
|
||
for (int i = 0; i < liveCharaPositionMax; i++)
|
||
{
|
||
if (posFlags.hasFlag((LiveCharaPosition)i) && liveCharactorLocators[i] != null)
|
||
{
|
||
retPos += liveCharactorLocators[i].liveCharaLeftHandWristPosition;
|
||
retPos += cameraOffset * liveCharactorLocators[i].liveCharaHeightRatio;
|
||
num++;
|
||
}
|
||
}
|
||
break;
|
||
}
|
||
case LiveCameraCharaParts.LeftHandAttach:
|
||
{
|
||
for (int i = 0; i < liveCharaPositionMax; i++)
|
||
{
|
||
if (posFlags.hasFlag((LiveCharaPosition)i) && liveCharactorLocators[i] != null)
|
||
{
|
||
retPos += liveCharactorLocators[i].liveCharaLeftHandAttachPosition;
|
||
retPos += cameraOffset * liveCharactorLocators[i].liveCharaHeightRatio;
|
||
num++;
|
||
}
|
||
}
|
||
break;
|
||
}
|
||
case LiveCameraCharaParts.RightHandWrist:
|
||
{
|
||
for (int i = 0; i < liveCharaPositionMax; i++)
|
||
{
|
||
if (posFlags.hasFlag((LiveCharaPosition)i) && liveCharactorLocators[i] != null)
|
||
{
|
||
retPos += liveCharactorLocators[i].liveCharaRightHandWristPosition;
|
||
retPos += cameraOffset * liveCharactorLocators[i].liveCharaHeightRatio;
|
||
num++;
|
||
}
|
||
}
|
||
break;
|
||
}
|
||
case LiveCameraCharaParts.RightHandAttach:
|
||
{
|
||
for (int i = 0; i < liveCharaPositionMax; i++)
|
||
{
|
||
if (posFlags.hasFlag((LiveCharaPosition)i) && liveCharactorLocators[i] != null)
|
||
{
|
||
retPos += liveCharactorLocators[i].liveCharaRightHandAttachPosition;
|
||
retPos += cameraOffset * liveCharactorLocators[i].liveCharaHeightRatio;
|
||
num++;
|
||
}
|
||
}
|
||
break;
|
||
}
|
||
case LiveCameraCharaParts.Chest:
|
||
{
|
||
for (int i = 0; i < liveCharaPositionMax; i++)
|
||
{
|
||
if (posFlags.hasFlag((LiveCharaPosition)i) && liveCharactorLocators[i] != null)
|
||
{
|
||
retPos += liveCharactorLocators[i].liveCharaChestPosition;
|
||
retPos += cameraOffset * liveCharactorLocators[i].liveCharaHeightRatio;
|
||
num++;
|
||
}
|
||
}
|
||
break;
|
||
}
|
||
case LiveCameraCharaParts.Foot:
|
||
{
|
||
for (int i = 0; i < liveCharaPositionMax; i++)
|
||
{
|
||
if (posFlags.hasFlag((LiveCharaPosition)i) && liveCharactorLocators[i] != null)
|
||
{
|
||
retPos += liveCharactorLocators[i].liveCharaFootPosition;
|
||
retPos += cameraOffset * liveCharactorLocators[i].liveCharaHeightRatio;
|
||
num++;
|
||
}
|
||
}
|
||
break;
|
||
}
|
||
case LiveCameraCharaParts.ConstFaceHeight:
|
||
{
|
||
for (int i = 0; i < liveCharaPositionMax; i++)
|
||
{
|
||
if (posFlags.hasFlag((LiveCharaPosition)i) && liveCharactorLocators[i] != null)
|
||
{
|
||
retPos.y += liveCharactorLocators[i].liveCharaConstHeightHeadPosition.y;
|
||
retPos += cameraOffset * liveCharactorLocators[i].liveCharaHeightRatio;
|
||
retPos += charaPos;
|
||
num++;
|
||
}
|
||
}
|
||
break;
|
||
}
|
||
case LiveCameraCharaParts.ConstWaistHeight:
|
||
{
|
||
for (int i = 0; i < liveCharaPositionMax; i++)
|
||
{
|
||
if (posFlags.hasFlag((LiveCharaPosition)i) && liveCharactorLocators[i] != null)
|
||
{
|
||
retPos.y += liveCharactorLocators[i].liveCharaConstHeightWaistPosition.y;
|
||
retPos += cameraOffset * liveCharactorLocators[i].liveCharaHeightRatio;
|
||
retPos += charaPos;
|
||
num++;
|
||
}
|
||
}
|
||
break;
|
||
}
|
||
case LiveCameraCharaParts.ConstChestHeight:
|
||
{
|
||
for (int i = 0; i < liveCharaPositionMax; i++)
|
||
{
|
||
if (posFlags.hasFlag((LiveCharaPosition)i) && liveCharactorLocators[i] != null)
|
||
{
|
||
retPos.y += liveCharactorLocators[i].liveCharaConstHeightChestPosition.y;
|
||
retPos += cameraOffset * liveCharactorLocators[i].liveCharaHeightRatio;
|
||
retPos += charaPos;
|
||
num++;
|
||
}
|
||
}
|
||
break;
|
||
}
|
||
case LiveCameraCharaParts.ConstFootHeight:
|
||
{
|
||
for (int i = 0; i < liveCharaPositionMax; i++)
|
||
{
|
||
if (posFlags.hasFlag((LiveCharaPosition)i) && liveCharactorLocators[i] != null)
|
||
{
|
||
retPos.y += liveCharactorLocators[i].liveCharaFootPosition.y;
|
||
retPos += cameraOffset * liveCharactorLocators[i].liveCharaHeightRatio;
|
||
retPos += charaPos;
|
||
num++;
|
||
}
|
||
}
|
||
break;
|
||
}
|
||
case LiveCameraCharaParts.InitFaceHeight:
|
||
{
|
||
for (int i = 0; i < liveCharaPositionMax; i++)
|
||
{
|
||
if (posFlags.hasFlag((LiveCharaPosition)i) && liveCharactorLocators[i] != null)
|
||
{
|
||
/*
|
||
retPos += liveCharactorLocators[i].liveCharaHeadPosition;
|
||
tmpPos += liveCharactorLocators[i].liveCharaConstHeightHeadPosition;
|
||
Vector3 vector3 = cameraOffset * liveCharactorLocators[i].liveCharaHeightRatio;
|
||
retPos += vector3;
|
||
tmpPos += vector3;
|
||
num++;
|
||
*/
|
||
|
||
retPos += liveCharactorLocators[i].liveCharaInitialHeightHeadPosition;
|
||
retPos += cameraOffset * liveCharactorLocators[i].liveCharaHeightRatio;
|
||
num++;
|
||
}
|
||
}
|
||
break;
|
||
}
|
||
case LiveCameraCharaParts.InitChestHeight:
|
||
{
|
||
for (int i = 0; i < liveCharaPositionMax; i++)
|
||
{
|
||
if (posFlags.hasFlag((LiveCharaPosition)i) && liveCharactorLocators[i] != null)
|
||
{
|
||
/*
|
||
retPos += liveCharactorLocators[i].liveCharaChestPosition;
|
||
tmpPos += liveCharactorLocators[i].liveCharaConstHeightChestPosition;
|
||
Vector3 vector2 = cameraOffset * liveCharactorLocators[i].liveCharaHeightRatio;
|
||
retPos += vector2;
|
||
tmpPos += vector2;
|
||
num++;
|
||
*/
|
||
|
||
retPos += liveCharactorLocators[i].liveCharaInitialHeightChestPosition;
|
||
retPos += cameraOffset * liveCharactorLocators[i].liveCharaHeightRatio;
|
||
num++;
|
||
}
|
||
}
|
||
break;
|
||
}
|
||
case LiveCameraCharaParts.InitWaistHeight:
|
||
{
|
||
for (int i = 0; i < liveCharaPositionMax; i++)
|
||
{
|
||
if (posFlags.hasFlag((LiveCharaPosition)i) && liveCharactorLocators[i] != null)
|
||
{
|
||
/*
|
||
retPos += liveCharactorLocators[i].liveCharaWaistPosition;
|
||
tmpPos += liveCharactorLocators[i].liveCharaConstHeightWaistPosition;
|
||
Vector3 vector = cameraOffset * liveCharactorLocators[i].liveCharaHeightRatio;
|
||
retPos += vector;
|
||
tmpPos += vector;
|
||
num++;
|
||
*/
|
||
|
||
retPos += liveCharactorLocators[i].liveCharaInitialHeightWaistPosition;
|
||
retPos += cameraOffset * liveCharactorLocators[i].liveCharaHeightRatio;
|
||
num++;
|
||
}
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
bool flag = num > 1;
|
||
if (flag)
|
||
{
|
||
retPos /= (float)num;
|
||
}
|
||
/*
|
||
if ((uint)(parts - 11) <= 2u)
|
||
{
|
||
if (flag)
|
||
{
|
||
tmpPos /= (float)num;
|
||
}
|
||
retPos.y = tmpPos.y;
|
||
}
|
||
*/
|
||
}
|
||
return retPos;
|
||
}
|
||
|
||
public Vector3 GetPositionWithCharacters(LiveCharaPositionFlag posFlags, LiveCameraCharaParts parts, Vector3 charaPos)
|
||
{
|
||
return GetPositionWithCharacters(posFlags, parts, charaPos, _cameraLayerOffset);
|
||
}
|
||
|
||
public static float CalculateInterpolationValue(LiveTimelineKey curKey, LiveTimelineKeyWithInterpolate nextKey, float frame)
|
||
{
|
||
float result = 0f;
|
||
switch (nextKey.interpolateType)
|
||
{
|
||
case LiveCameraInterpolateType.Linear:
|
||
result = LinearInterpolateKeyframes(curKey, nextKey, frame);
|
||
break;
|
||
case LiveCameraInterpolateType.Curve:
|
||
result = CurveInterpolateKeyframes(curKey, nextKey, frame);
|
||
break;
|
||
case LiveCameraInterpolateType.Ease:
|
||
result = EaseInterpolateKeyframes(curKey, nextKey, frame);
|
||
break;
|
||
}
|
||
return result;
|
||
}
|
||
|
||
public void SetTimelineCamera(Camera cam, int index)
|
||
{
|
||
if (index < _cameraArray.Length)
|
||
{
|
||
if (_cameraArray[index] == null)
|
||
{
|
||
_cameraArray[index] = new CacheCamera(cam);
|
||
}
|
||
else
|
||
{
|
||
_cameraArray[index].Set(cam);
|
||
}
|
||
LiveTimelineCamera liveTimelineCamera = cam.gameObject.GetComponent<LiveTimelineCamera>();
|
||
if (liveTimelineCamera == null)
|
||
{
|
||
liveTimelineCamera = cam.gameObject.AddComponent<LiveTimelineCamera>();
|
||
}
|
||
_cameraScriptArray[index] = liveTimelineCamera;
|
||
if (liveTimelineCamera != null)
|
||
{
|
||
liveTimelineCamera.AlterAwake();
|
||
}
|
||
}
|
||
}
|
||
|
||
private void AlterUpdate_CameraSwitcher(LiveTimelineWorkSheet sheet, float currentFrame)
|
||
{
|
||
if (sheet.cameraSwitcherKeys.HasAttribute(LiveTimelineKeyDataListAttr.Disable) || !sheet.cameraSwitcherKeys.EnablePlayModeTimeline(_playMode))
|
||
{
|
||
return;
|
||
}
|
||
LiveTimelineKey curKey = null;
|
||
FindTimelineKeyCurrent(out curKey, sheet.cameraSwitcherKeys, currentFrame);
|
||
if (curKey == null)
|
||
{
|
||
return;
|
||
}
|
||
LiveTimelineKeyCameraSwitcherData liveTimelineKeyCameraSwitcherData = curKey as LiveTimelineKeyCameraSwitcherData;
|
||
if (this.OnUpdateCameraSwitcher != null)
|
||
{
|
||
this.OnUpdateCameraSwitcher(liveTimelineKeyCameraSwitcherData.cameraIndex);
|
||
}
|
||
else
|
||
{
|
||
if (liveTimelineKeyCameraSwitcherData.cameraIndex >= cameraArray.Length)
|
||
{
|
||
return;
|
||
}
|
||
for (int i = 0; i < cameraArray.Length; i++)
|
||
{
|
||
if (cameraArray[i] == null)
|
||
{
|
||
continue;
|
||
}
|
||
if (i == liveTimelineKeyCameraSwitcherData.cameraIndex)
|
||
{
|
||
if (!cameraArray[i].camera.enabled)
|
||
{
|
||
cameraArray[i].camera.enabled = true;
|
||
cameraScriptArray[i].enabled = true;
|
||
}
|
||
}
|
||
else if (cameraArray[i].camera.enabled)
|
||
{
|
||
cameraArray[i].camera.enabled = false;
|
||
cameraScriptArray[i].enabled = false;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
private void AlterUpdate_CameraPos(LiveTimelineWorkSheet sheet, float currentFrame)
|
||
{
|
||
if (sheet.cameraPosKeys.HasAttribute(LiveTimelineKeyDataListAttr.Disable) || !sheet.cameraPosKeys.EnablePlayModeTimeline(_playMode))
|
||
{
|
||
return;
|
||
}
|
||
|
||
CacheCamera camera = GetCamera(sheet.targetCameraIndex);
|
||
if (camera == null)
|
||
{
|
||
return;
|
||
}
|
||
|
||
LiveTimelineKey curKey = null;
|
||
LiveTimelineKey nextKey = null;
|
||
FindTimelineKey(out curKey, out nextKey, sheet.cameraPosKeys, currentFrame);
|
||
if (curKey == null)
|
||
{
|
||
return;
|
||
}
|
||
LiveTimelineKeyCameraPositionData liveTimelineKeyCameraPositionData = curKey as LiveTimelineKeyCameraPositionData;
|
||
camera.camera.nearClipPlane = liveTimelineKeyCameraPositionData.nearClip;
|
||
camera.camera.farClipPlane = liveTimelineKeyCameraPositionData.farClip;
|
||
if (CalculateCameraPos(out var pos, sheet, curKey, nextKey, currentFrame))
|
||
{
|
||
camera.cacheTransform.position = pos;
|
||
|
||
// TODO �����õĻ���CGSS��layerö�٣�Ҫ�����滻
|
||
/*
|
||
int num = liveTimelineKeyCameraPositionData.GetCullingMask();
|
||
if (num == 0)
|
||
{
|
||
num = LiveTimelineKeyCameraPositionData.GetDefaultCullingMask();
|
||
}
|
||
camera.camera.cullingMask = num;
|
||
if (OnUpdateCameraPos != null)
|
||
{
|
||
CameraPosUpdateInfo updateInfo = default(CameraPosUpdateInfo);
|
||
updateInfo.outlineZOffset = liveTimelineKeyCameraPositionData.outlineZOffset;
|
||
updateInfo.characterLODMask = (int)liveTimelineKeyCameraPositionData.characterLODMask;
|
||
OnUpdateCameraPos(ref updateInfo);
|
||
}
|
||
*/
|
||
}
|
||
}
|
||
|
||
private static Vector3 GetCameraPosValue(LiveTimelineKeyCameraPositionData keyData, LiveTimelineControl timelineControl, FindTimelineConfig config)
|
||
{
|
||
return keyData.GetValue(timelineControl);
|
||
}
|
||
|
||
public bool CalculateCameraPos(out Vector3 pos, LiveTimelineWorkSheet sheet, float currentFrame)
|
||
{
|
||
FindTimelineConfig config = default(FindTimelineConfig);
|
||
config.curKey = null;
|
||
config.nextKey = null;
|
||
config.keyType = FindTimelineConfig.KeyType.CurrentFrame;
|
||
config.posKeys = sheet.cameraPosKeys;
|
||
config.lookAtKeys = null;
|
||
config.extraCameraIndex = 0;
|
||
CacheCamera camera = GetCamera(sheet.targetCameraIndex);
|
||
return CalculateCameraPos(out pos, sheet, currentFrame, camera, ref config, ref fnGetCameraPosValue);
|
||
}
|
||
|
||
public bool CalculateCameraPos(out Vector3 pos, LiveTimelineWorkSheet sheet, LiveTimelineKey curKey, LiveTimelineKey nextKey, float currentFrame)
|
||
{
|
||
FindTimelineConfig config = default(FindTimelineConfig);
|
||
config.curKey = curKey;
|
||
config.nextKey = nextKey;
|
||
config.keyType = FindTimelineConfig.KeyType.KeyDirect;
|
||
config.posKeys = sheet.cameraPosKeys;
|
||
config.lookAtKeys = null;
|
||
CacheCamera camera = GetCamera(sheet.targetCameraIndex);
|
||
config.extraCameraIndex = 0;
|
||
return CalculateCameraPos(out pos, sheet, currentFrame, camera, ref config, ref fnGetCameraPosValue);
|
||
}
|
||
|
||
public bool CalculateCameraPos(out Vector3 pos, LiveTimelineWorkSheet sheet, float currentFrame, CacheCamera targetCamera, ref FindTimelineConfig config, ref Func<LiveTimelineKeyCameraPositionData, LiveTimelineControl, FindTimelineConfig, Vector3> getFunc)
|
||
{
|
||
pos = Vector3.zero;
|
||
LiveTimelineKey curKey = null;
|
||
LiveTimelineKey nextKey = null;
|
||
if (config.posKeys == null)
|
||
{
|
||
return false;
|
||
}
|
||
if (config.keyType == FindTimelineConfig.KeyType.CurrentFrame)
|
||
{
|
||
FindTimelineKey(out curKey, out nextKey, config.posKeys, currentFrame);
|
||
}
|
||
else
|
||
{
|
||
curKey = config.curKey;
|
||
nextKey = config.nextKey;
|
||
}
|
||
if (curKey == null)
|
||
{
|
||
return false;
|
||
}
|
||
LiveTimelineKeyCameraPositionData liveTimelineKeyCameraPositionData = curKey as LiveTimelineKeyCameraPositionData;
|
||
LiveTimelineKeyCameraPositionData liveTimelineKeyCameraPositionData2 = nextKey as LiveTimelineKeyCameraPositionData;
|
||
if (liveTimelineKeyCameraPositionData2 != null && liveTimelineKeyCameraPositionData2.interpolateType != 0)
|
||
{
|
||
float t = CalculateInterpolationValue(liveTimelineKeyCameraPositionData, liveTimelineKeyCameraPositionData2, currentFrame);
|
||
int bezierPointCount = liveTimelineKeyCameraPositionData2.GetBezierPointCount();
|
||
if (bezierPointCount == 0)
|
||
{
|
||
pos = LerpWithoutClamp(getFunc(liveTimelineKeyCameraPositionData, this, config), getFunc(liveTimelineKeyCameraPositionData2, this, config), t);
|
||
}
|
||
else
|
||
{
|
||
BezierCalcWork.cameraPos.Set(getFunc(liveTimelineKeyCameraPositionData, this, config), getFunc(liveTimelineKeyCameraPositionData2, this, config), bezierPointCount);
|
||
BezierCalcWork.cameraPos.UpdatePoints(liveTimelineKeyCameraPositionData2, this);
|
||
BezierCalcWork.cameraPos.Calc(bezierPointCount, t, out pos);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
pos = getFunc(liveTimelineKeyCameraPositionData, this, config);
|
||
}
|
||
if (_isNowAlterUpdate && liveTimelineKeyCameraPositionData.attribute.hasFlag(LiveTimelineKeyAttribute.CameraDelayEnable) && (_oldFrame >= liveTimelineKeyCameraPositionData.frame || currentFrame < liveTimelineKeyCameraPositionData.frame || liveTimelineKeyCameraPositionData.attribute.hasFlag(LiveTimelineKeyAttribute.CameraDelayInherit)))
|
||
{
|
||
if (targetCamera == null)
|
||
{
|
||
return false;
|
||
}
|
||
float t2 = liveTimelineKeyCameraPositionData.traceSpeed * _deltaTimeRatio;
|
||
pos = Vector3.Slerp(targetCamera.cacheTransform.position, pos, t2);
|
||
}
|
||
return true;
|
||
}
|
||
|
||
private void AlterUpdate_CameraLookAt(LiveTimelineWorkSheet sheet, float currentFrame, ref Vector3 outLookAt)
|
||
{
|
||
if (!sheet.cameraLookAtKeys.HasAttribute(LiveTimelineKeyDataListAttr.Disable) && sheet.cameraLookAtKeys.EnablePlayModeTimeline(_playMode))
|
||
{
|
||
CacheCamera camera = GetCamera(sheet.targetCameraIndex);
|
||
if (camera != null && CalculateCameraLookAt(out var lookAtPos, sheet, currentFrame))
|
||
{
|
||
camera.cacheTransform.LookAt(lookAtPos, Vector3.up);
|
||
outLookAt = lookAtPos;
|
||
}
|
||
}
|
||
}
|
||
|
||
private static Vector3 GetCameraLookAtValue(LiveTimelineKeyCameraLookAtData keyData, LiveTimelineControl timelineControl, Vector3 camPos, FindTimelineConfig config)
|
||
{
|
||
return keyData.GetValue(timelineControl, camPos);
|
||
}
|
||
|
||
public bool CalculateCameraLookAt(out Vector3 lookAtPos, LiveTimelineWorkSheet sheet, float currentFrame)
|
||
{
|
||
CacheCamera camera = GetCamera(sheet.targetCameraIndex);
|
||
FindTimelineConfig config = default(FindTimelineConfig);
|
||
config.curKey = null;
|
||
config.nextKey = null;
|
||
config.keyType = FindTimelineConfig.KeyType.CurrentFrame;
|
||
config.posKeys = sheet.cameraPosKeys;
|
||
config.lookAtKeys = sheet.cameraLookAtKeys;
|
||
config.extraCameraIndex = 0;
|
||
return CalculateCameraLookAt(out lookAtPos, sheet, currentFrame, camera, ref config, ref fnGetCameraLookAtValue, ref fnGetCameraPosValue);
|
||
}
|
||
|
||
private bool CalculateCameraLookAt(out Vector3 lookAtPos, LiveTimelineWorkSheet sheet, float currentFrame, CacheCamera targetCamera, ref FindTimelineConfig config, ref Func<LiveTimelineKeyCameraLookAtData, LiveTimelineControl, Vector3, FindTimelineConfig, Vector3> getLookAtValueFunc, ref Func<LiveTimelineKeyCameraPositionData, LiveTimelineControl, FindTimelineConfig, Vector3> getPosValueFunc)
|
||
{
|
||
lookAtPos = Vector3.zero;
|
||
CacheCamera camera = GetCamera(sheet.targetCameraIndex);
|
||
if (camera == null || config.lookAtKeys == null || config.posKeys == null)
|
||
{
|
||
return false;
|
||
}
|
||
LiveTimelineKey curKey = null;
|
||
LiveTimelineKey nextKey = null;
|
||
FindTimelineKey(out curKey, out nextKey, config.lookAtKeys, currentFrame);
|
||
if (curKey == null)
|
||
{
|
||
return false;
|
||
}
|
||
Vector3 position = camera.cacheTransform.position;
|
||
LiveTimelineKeyCameraLookAtData liveTimelineKeyCameraLookAtData = curKey as LiveTimelineKeyCameraLookAtData;
|
||
LiveTimelineKeyCameraLookAtData liveTimelineKeyCameraLookAtData2 = nextKey as LiveTimelineKeyCameraLookAtData;
|
||
if (liveTimelineKeyCameraLookAtData2 != null && liveTimelineKeyCameraLookAtData2.interpolateType != 0)
|
||
{
|
||
float t = CalculateInterpolationValue(liveTimelineKeyCameraLookAtData, liveTimelineKeyCameraLookAtData2, currentFrame);
|
||
int bezierPointCount = liveTimelineKeyCameraLookAtData2.GetBezierPointCount();
|
||
if (bezierPointCount == 0)
|
||
{
|
||
lookAtPos = LerpWithoutClamp(getLookAtValueFunc(liveTimelineKeyCameraLookAtData, this, position, config), getLookAtValueFunc(liveTimelineKeyCameraLookAtData2, this, position, config), t);
|
||
}
|
||
else if (liveTimelineKeyCameraLookAtData2.necessaryToUseNewBezierCalcMethod)
|
||
{
|
||
Vector3 zero = Vector3.zero;
|
||
BezierCalcWork.cameraLookAt.Set(getLookAtValueFunc(liveTimelineKeyCameraLookAtData, this, position, config), getLookAtValueFunc(liveTimelineKeyCameraLookAtData2, this, zero, config), bezierPointCount);
|
||
BezierCalcWork.cameraLookAt.UpdatePoints(liveTimelineKeyCameraLookAtData2, this, zero);
|
||
BezierCalcWork.cameraLookAt.Calc(bezierPointCount, t, out lookAtPos);
|
||
}
|
||
else
|
||
{
|
||
Vector3 zero2 = Vector3.zero;
|
||
Vector3 end = getLookAtValueFunc(liveTimelineKeyCameraLookAtData2, this, zero2, config);
|
||
Vector3 cp = liveTimelineKeyCameraLookAtData2.GetBezierPoint(0, this, zero2);
|
||
Vector3 cp2 = liveTimelineKeyCameraLookAtData2.GetBezierPoint(1, this, zero2);
|
||
Vector3 cp3 = liveTimelineKeyCameraLookAtData2.GetBezierPoint(2, this, zero2);
|
||
switch (liveTimelineKeyCameraLookAtData2.GetBezierPointCount())
|
||
{
|
||
default:
|
||
lookAtPos = LerpWithoutClamp(getLookAtValueFunc(liveTimelineKeyCameraLookAtData, this, position, config), getLookAtValueFunc(liveTimelineKeyCameraLookAtData2, this, position, config), t);
|
||
break;
|
||
case 1:
|
||
{
|
||
Vector3 start3 = getLookAtValueFunc(liveTimelineKeyCameraLookAtData, this, position, config);
|
||
BezierUtil.Calc(ref start3, ref end, ref cp, t, out lookAtPos);
|
||
break;
|
||
}
|
||
case 2:
|
||
{
|
||
Vector3 start2 = getLookAtValueFunc(liveTimelineKeyCameraLookAtData, this, position, config);
|
||
BezierUtil.Calc(ref start2, ref end, ref cp, ref cp2, t, out lookAtPos);
|
||
break;
|
||
}
|
||
case 3:
|
||
{
|
||
Vector3 start = getLookAtValueFunc(liveTimelineKeyCameraLookAtData, this, position, config);
|
||
BezierUtil.Calc(ref start, ref end, ref cp, ref cp2, ref cp3, t, out lookAtPos);
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
lookAtPos = getLookAtValueFunc(liveTimelineKeyCameraLookAtData, this, position, config);
|
||
}
|
||
if (_isNowAlterUpdate && liveTimelineKeyCameraLookAtData.attribute.hasFlag(LiveTimelineKeyAttribute.CameraDelayEnable) && (_oldFrame >= liveTimelineKeyCameraLookAtData.frame || currentFrame < liveTimelineKeyCameraLookAtData.frame || liveTimelineKeyCameraLookAtData.attribute.hasFlag(LiveTimelineKeyAttribute.CameraDelayInherit)))
|
||
{
|
||
Vector3 b = lookAtPos - camera.cacheTransform.position;
|
||
float magnitude = b.magnitude;
|
||
if (magnitude >= float.Epsilon)
|
||
{
|
||
b /= magnitude;
|
||
float t2 = liveTimelineKeyCameraLookAtData.traceSpeed * _deltaTimeRatio;
|
||
lookAtPos = position + Vector3.Slerp(camera.cacheTransform.forward, b, t2) * magnitude;
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
|
||
private void AlterUpdate_CameraFov(LiveTimelineWorkSheet sheet, float currentFrame)
|
||
{
|
||
if (sheet.cameraFovKeys.HasAttribute(LiveTimelineKeyDataListAttr.Disable) || !sheet.cameraFovKeys.EnablePlayModeTimeline(_playMode))
|
||
{
|
||
return;
|
||
}
|
||
CacheCamera camera = GetCamera(sheet.targetCameraIndex);
|
||
if (camera == null)
|
||
{
|
||
return;
|
||
}
|
||
LiveTimelineKey curKey = null;
|
||
LiveTimelineKey nextKey = null;
|
||
FindTimelineKey(out curKey, out nextKey, sheet.cameraFovKeys, currentFrame);
|
||
if (curKey == null)
|
||
{
|
||
return;
|
||
}
|
||
LiveTimelineKeyCameraFovData liveTimelineKeyCameraFovData = curKey as LiveTimelineKeyCameraFovData;
|
||
LiveTimelineKeyCameraFovData liveTimelineKeyCameraFovData2 = nextKey as LiveTimelineKeyCameraFovData;
|
||
float num = 80f;
|
||
if (liveTimelineKeyCameraFovData2 != null && liveTimelineKeyCameraFovData2.interpolateType != 0)
|
||
{
|
||
float t = CalculateInterpolationValue(liveTimelineKeyCameraFovData, liveTimelineKeyCameraFovData2, currentFrame);
|
||
num = LerpWithoutClamp(liveTimelineKeyCameraFovData.fov, liveTimelineKeyCameraFovData2.fov, t);
|
||
}
|
||
else if (liveTimelineKeyCameraFovData.fovType == LiveCameraFovType.Direct)
|
||
{
|
||
num = liveTimelineKeyCameraFovData.fov;
|
||
}
|
||
if (_limitFovForWidth)
|
||
{
|
||
float num2 = (float)camera.camera.pixelWidth / (float)camera.camera.pixelHeight;
|
||
if (num2 > _baseCameraAspectRatio)
|
||
{
|
||
float num3 = num2 / _baseCameraAspectRatio;
|
||
num /= num3;
|
||
}
|
||
}
|
||
camera.camera.fieldOfView = num;
|
||
}
|
||
|
||
private void AlterUpdate_CameraRoll(LiveTimelineWorkSheet sheet, float currentFrame)
|
||
{
|
||
if (sheet.cameraRollKeys.HasAttribute(LiveTimelineKeyDataListAttr.Disable) || !sheet.cameraRollKeys.EnablePlayModeTimeline(_playMode))
|
||
{
|
||
return;
|
||
}
|
||
CacheCamera camera = GetCamera(sheet.targetCameraIndex);
|
||
if (camera == null)
|
||
{
|
||
return;
|
||
}
|
||
LiveTimelineKey curKey = null;
|
||
LiveTimelineKey nextKey = null;
|
||
FindTimelineKey(out curKey, out nextKey, sheet.cameraRollKeys, currentFrame);
|
||
if (curKey != null)
|
||
{
|
||
LiveTimelineKeyCameraRollData liveTimelineKeyCameraRollData = curKey as LiveTimelineKeyCameraRollData;
|
||
LiveTimelineKeyCameraRollData liveTimelineKeyCameraRollData2 = nextKey as LiveTimelineKeyCameraRollData;
|
||
float num = 80f;
|
||
if (liveTimelineKeyCameraRollData2 != null && liveTimelineKeyCameraRollData2.interpolateType != 0)
|
||
{
|
||
float t = CalculateInterpolationValue(liveTimelineKeyCameraRollData, liveTimelineKeyCameraRollData2, currentFrame);
|
||
num = LerpWithoutClamp(liveTimelineKeyCameraRollData.degree, liveTimelineKeyCameraRollData2.degree, t);
|
||
}
|
||
else
|
||
{
|
||
num = liveTimelineKeyCameraRollData.degree;
|
||
}
|
||
camera.cacheTransform.Rotate(0f, 0f, num);
|
||
}
|
||
}
|
||
|
||
//public void SetMultiCamera(MultiCameraManager manager, MultiCamera[] multiCamera)
|
||
public void SetMultiCamera(MultiCamera[] multiCamera)
|
||
{
|
||
_multiCamera = multiCamera;
|
||
//_multiCameraManager = manager;
|
||
if (multiCamera != null)
|
||
{
|
||
_multiCameraCache = new CacheCamera[multiCamera.Length];
|
||
for (int i = 0; i < multiCamera.Length; i++)
|
||
{
|
||
_multiCameraCache[i] = new CacheCamera(multiCamera[i].GetCamera());
|
||
}
|
||
}
|
||
}
|
||
|
||
private static Vector3 GetMultiCameraPositionValue(LiveTimelineKeyCameraPositionData keyData, LiveTimelineControl timelineControl, FindTimelineConfig config)
|
||
{
|
||
return (keyData as LiveTimelineKeyMultiCameraPositionData).GetValue(timelineControl);
|
||
}
|
||
|
||
public bool CalculateMultiCameraPos(out Vector3 pos, LiveTimelineWorkSheet sheet, LiveTimelineKey curKey, LiveTimelineKey nextKey, float currentFrame, int timelineIndex)
|
||
{
|
||
if (sheet.multiCameraPosKeys.Count <= timelineIndex)
|
||
{
|
||
pos = Vector3.zero;
|
||
return false;
|
||
}
|
||
FindTimelineConfig config = default(FindTimelineConfig);
|
||
config.curKey = curKey;
|
||
config.nextKey = nextKey;
|
||
config.keyType = FindTimelineConfig.KeyType.KeyDirect;
|
||
config.posKeys = sheet.multiCameraPosKeys[timelineIndex].keys;
|
||
config.lookAtKeys = null;
|
||
config.extraCameraIndex = timelineIndex;
|
||
return CalculateCameraPos(out pos, sheet, currentFrame, _multiCameraCache[timelineIndex], ref config, ref fnGetMultiCameraPositionValueFunc);
|
||
}
|
||
|
||
private void AlterUpdate_MultiCameraPosition(LiveTimelineWorkSheet sheet, float currentFrame)
|
||
{
|
||
int count = sheet.multiCameraPosKeys.Count;
|
||
for (int i = 0; i < count; i++)
|
||
{
|
||
LiveTimelineKeyMultiCameraPositionDataList keys = sheet.multiCameraPosKeys[i].keys;
|
||
if (keys.HasAttribute(LiveTimelineKeyDataListAttr.Disable) || !keys.EnablePlayModeTimeline(_playMode) || i >= _multiCameraCache.Length)
|
||
{
|
||
continue;
|
||
}
|
||
LiveTimelineKey curKey = null;
|
||
LiveTimelineKey nextKey = null;
|
||
FindTimelineKey(out curKey, out nextKey, keys, currentFrame);
|
||
if (!CalculateMultiCameraPos(out var pos, sheet, curKey, nextKey, currentFrame, i))
|
||
{
|
||
continue;
|
||
}
|
||
CacheCamera cacheCamera = _multiCameraCache[i];
|
||
Camera camera = cacheCamera.camera;
|
||
if (curKey == null)
|
||
{
|
||
continue;
|
||
}
|
||
LiveTimelineKeyMultiCameraPositionData liveTimelineKeyMultiCameraPositionData = curKey as LiveTimelineKeyMultiCameraPositionData;
|
||
LiveTimelineKeyMultiCameraPositionData liveTimelineKeyMultiCameraPositionData2 = nextKey as LiveTimelineKeyMultiCameraPositionData;
|
||
// camera.enabled = liveTimelineKeyMultiCameraPositionData.enableMultiCamera;
|
||
if (liveTimelineKeyMultiCameraPositionData.enableMultiCamera)
|
||
{
|
||
|
||
_isMultiCameraEnable = true;
|
||
//camera.cullingMask = 0x10000000 | liveTimelineKeyMultiCameraPositionData.GetCullingMask();
|
||
|
||
float zAngle;
|
||
float fieldOfView;
|
||
Vector3 maskOffset;
|
||
float maskRoll;
|
||
if (liveTimelineKeyMultiCameraPositionData2 != null && liveTimelineKeyMultiCameraPositionData2.interpolateType != 0)
|
||
{
|
||
float t = CalculateInterpolationValue(liveTimelineKeyMultiCameraPositionData, liveTimelineKeyMultiCameraPositionData2, currentFrame);
|
||
fieldOfView = LerpWithoutClamp(liveTimelineKeyMultiCameraPositionData.fov, liveTimelineKeyMultiCameraPositionData2.fov, t);
|
||
maskOffset = LerpWithoutClamp(liveTimelineKeyMultiCameraPositionData.maskOffset, liveTimelineKeyMultiCameraPositionData2.maskOffset, t);
|
||
maskRoll = LerpWithoutClamp(liveTimelineKeyMultiCameraPositionData.maskRoll, liveTimelineKeyMultiCameraPositionData2.maskRoll, t);
|
||
zAngle = LerpWithoutClamp(liveTimelineKeyMultiCameraPositionData.roll, liveTimelineKeyMultiCameraPositionData2.roll, t);
|
||
}
|
||
else
|
||
{
|
||
fieldOfView = liveTimelineKeyMultiCameraPositionData.fov;
|
||
maskOffset = liveTimelineKeyMultiCameraPositionData.maskOffset;
|
||
maskRoll = liveTimelineKeyMultiCameraPositionData.maskRoll;
|
||
zAngle = liveTimelineKeyMultiCameraPositionData.roll;
|
||
}
|
||
|
||
|
||
|
||
camera.nearClipPlane = liveTimelineKeyMultiCameraPositionData.nearClip;
|
||
camera.farClipPlane = liveTimelineKeyMultiCameraPositionData.farClip;
|
||
camera.fieldOfView = fieldOfView;
|
||
cacheCamera.cacheTransform.localPosition = pos;
|
||
cacheCamera.cacheTransform.Rotate(0f, 0f, zAngle);
|
||
if (_multiCamera[i].maskIndex != (int)liveTimelineKeyMultiCameraPositionData.maskType)
|
||
{
|
||
//_multiCameraManager.AttachMask(i, (int)liveTimelineKeyMultiCameraPositionData.maskType);
|
||
}
|
||
|
||
if (_multiCamera[i].maskIndex >= 0)
|
||
{
|
||
_multiCamera[i].MaskOffset = maskOffset;
|
||
_multiCamera[i].MaskRoll= maskRoll;
|
||
//_multiCamera[i].maskScale = maskScale;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
private static Vector3 GetMultiCameraLookAtValue(LiveTimelineKeyCameraLookAtData keyData, LiveTimelineControl timelineControl, Vector3 camPos, FindTimelineConfig config)
|
||
{
|
||
return (keyData as LiveTimelineKeyMultiCameraLookAtData).GetValue(timelineControl, camPos);
|
||
}
|
||
|
||
public bool CalculateMultiCameraLookAt(out Vector3 pos, LiveTimelineWorkSheet sheet, LiveTimelineKey curKey, LiveTimelineKey nextKey, float currentFrame, int timelineIndex = 0)
|
||
{
|
||
if (sheet.multiCameraPosKeys.Count <= timelineIndex || sheet.multiCameraLookAtKeys.Count <= timelineIndex)
|
||
{
|
||
pos = Vector3.zero;
|
||
return false;
|
||
}
|
||
FindTimelineConfig config = default(FindTimelineConfig);
|
||
config.curKey = curKey;
|
||
config.nextKey = nextKey;
|
||
config.keyType = FindTimelineConfig.KeyType.KeyDirect;
|
||
config.posKeys = sheet.multiCameraPosKeys[timelineIndex].keys;
|
||
config.lookAtKeys = sheet.multiCameraLookAtKeys[timelineIndex].keys;
|
||
config.extraCameraIndex = timelineIndex;
|
||
return CalculateCameraLookAt(out pos, sheet, currentFrame, _multiCameraCache[timelineIndex], ref config, ref fnGetMultiCameraLookAtValueFunc, ref fnGetMultiCameraPositionValueFunc);
|
||
}
|
||
|
||
|
||
private void AlterUpdate_MultiCameraLookAt(LiveTimelineWorkSheet sheet, float currentFrame)
|
||
{
|
||
int count = sheet.multiCameraLookAtKeys.Count;
|
||
for (int i = 0; i < count; i++)
|
||
{
|
||
LiveTimelineKeyMultiCameraLookAtDataList keys = sheet.multiCameraLookAtKeys[i].keys;
|
||
if (i >= _multiCameraCache.Length)
|
||
{
|
||
break;
|
||
}
|
||
if (keys.HasAttribute(LiveTimelineKeyDataListAttr.Disable) || !keys.EnablePlayModeTimeline(_playMode))
|
||
{
|
||
continue;
|
||
}
|
||
FindTimelineKey(out var curKey, out var nextKey, keys, currentFrame);
|
||
if (curKey != null && CalculateMultiCameraLookAt(out var pos, sheet, curKey, nextKey, currentFrame, i))
|
||
{
|
||
Transform cacheTransform = _multiCameraCache[i].cacheTransform;
|
||
cacheTransform.LookAt(pos);
|
||
}
|
||
}
|
||
}
|
||
|
||
private void AlterUpdate_MultiCamera(LiveTimelineWorkSheet sheet, float currentFrame)
|
||
{
|
||
//if (_multiCameraCache != null && !(_multiCameraManager == null) && _multiCameraManager.isInitialize)
|
||
if (_multiCameraCache != null)
|
||
{
|
||
AlterUpdate_MultiCameraPosition(sheet, currentFrame);
|
||
if(_isMultiCameraEnable)
|
||
AlterUpdate_MultiCameraLookAt(sheet, currentFrame);
|
||
}
|
||
}
|
||
|
||
private void AlterUpdate_GlobalLight(LiveTimelineWorkSheet sheet, float currentFrame) {
|
||
GlobalLightUpdateInfo updateInfo = default;
|
||
int count = sheet.globalLightDataLists.Count;
|
||
for(int i = 0; i < count; i++)
|
||
{
|
||
LiveTimelineKeyGlobalLightDataList keys = sheet.globalLightDataLists[i].keys;
|
||
if (keys.HasAttribute(LiveTimelineKeyDataListAttr.Disable) || !keys.EnablePlayModeTimeline(_playMode))
|
||
{
|
||
continue;
|
||
}
|
||
else if (sheet.globalLightDataLists[i].name != "GlobalLight")
|
||
{
|
||
continue;
|
||
}
|
||
FindTimelineKey(out var curKey, out var nextKey, keys, currentFrame);
|
||
if (curKey != null)
|
||
{
|
||
LiveTimelineKeyGlobalLightData lightData = curKey as LiveTimelineKeyGlobalLightData;
|
||
LiveTimelineKeyGlobalLightData lightData2 = nextKey as LiveTimelineKeyGlobalLightData;
|
||
Quaternion quaternion = Quaternion.identity;
|
||
if (lightData.cameraFollow)
|
||
{
|
||
quaternion = GetCamera(sheet.targetCameraIndex).cacheTransform.rotation;
|
||
}
|
||
updateInfo.flags = lightData.flags;
|
||
if (lightData2 != null && lightData2.interpolateType != 0)
|
||
{
|
||
float ratio = CalculateInterpolationValue(lightData, lightData2, currentFrame);
|
||
Quaternion a = Quaternion.Euler(lightData.lightDir);
|
||
Quaternion b = Quaternion.Euler(lightData2.lightDir);
|
||
updateInfo.lightRotation = Quaternion.Lerp(a, b, ratio) * quaternion;
|
||
updateInfo.globalRimShadowRate = LerpWithoutClamp(lightData.globalRimShadowRate, lightData2.globalRimShadowRate, ratio);
|
||
updateInfo.rimColor = Color.Lerp(lightData.rimColor, lightData2.rimColor, ratio);
|
||
updateInfo.rimStep = LerpWithoutClamp(lightData.rimStep, lightData2.rimStep, ratio);
|
||
updateInfo.rimFeather = LerpWithoutClamp(lightData.rimFeather, lightData2.rimFeather, ratio);
|
||
updateInfo.rimSpecRate = LerpWithoutClamp(lightData.rimSpecRate, lightData2.rimSpecRate, ratio);
|
||
updateInfo.flags = lightData2.flags;
|
||
updateInfo.RimHorizonOffset = LerpWithoutClamp(lightData.RimHorizonOffset, lightData2.RimHorizonOffset, ratio);
|
||
updateInfo.RimVerticalOffset = LerpWithoutClamp(lightData.RimVerticalOffset, lightData2.RimVerticalOffset, ratio);
|
||
updateInfo.RimHorizonOffset2 = LerpWithoutClamp(lightData.RimHorizonOffset2, lightData2.RimHorizonOffset2, ratio);
|
||
updateInfo.RimVerticalOffset2 = LerpWithoutClamp(lightData.RimVerticalOffset2, lightData2.RimVerticalOffset2, ratio);
|
||
updateInfo.rimColor2 = Color.Lerp(lightData.rimColor2, lightData2.rimColor2, ratio);
|
||
updateInfo.rimStep2 = LerpWithoutClamp(lightData.rimStep2, lightData2.rimStep2, ratio);
|
||
updateInfo.rimFeather2 = LerpWithoutClamp(lightData.rimFeather2, lightData2.rimFeather2, ratio);
|
||
updateInfo.rimSpecRate2 = LerpWithoutClamp(lightData.rimSpecRate2, lightData2.rimSpecRate2, ratio);
|
||
updateInfo.globalRimShadowRate2 = LerpWithoutClamp(lightData.globalRimShadowRate2, lightData2.globalRimShadowRate2, ratio);
|
||
}
|
||
else
|
||
{
|
||
updateInfo.lightRotation = Quaternion.Euler(lightData.lightDir) * quaternion;
|
||
updateInfo.globalRimShadowRate = lightData.globalRimShadowRate;
|
||
updateInfo.rimColor = lightData.rimColor;
|
||
updateInfo.rimStep = lightData.rimStep;
|
||
updateInfo.rimFeather = lightData.rimFeather;
|
||
updateInfo.rimSpecRate = lightData.rimSpecRate;
|
||
updateInfo.flags = lightData.flags;
|
||
updateInfo.RimHorizonOffset = lightData.RimHorizonOffset;
|
||
updateInfo.RimVerticalOffset = lightData.RimVerticalOffset;
|
||
updateInfo.RimHorizonOffset2 = lightData.RimHorizonOffset2;
|
||
updateInfo.RimVerticalOffset2 = lightData.RimVerticalOffset2;
|
||
updateInfo.rimColor2 = lightData.rimColor2;
|
||
updateInfo.rimStep2 = lightData.rimStep2;
|
||
updateInfo.rimFeather2 = lightData.rimFeather2;
|
||
updateInfo.rimSpecRate2 = lightData.rimSpecRate2;
|
||
updateInfo.globalRimShadowRate2 = lightData.globalRimShadowRate2;
|
||
}
|
||
OnUpdateGlobalLight.Invoke(ref updateInfo);
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>BgColor1 里指向角色的组名;其余组名都是舞台物件,由 StageObjectMap 解析。</summary>
|
||
public static readonly HashSet<string> CharaBgColorNames =
|
||
new HashSet<string> { "CharaCenter", "CharaLeft", "CharaRight", "CharaColor" };
|
||
|
||
private void AlterUpdate_BgColor1(LiveTimelineWorkSheet sheet, float currentFrame) {
|
||
int count = sheet.bgColor1List.Count;
|
||
|
||
for (int i = 0; i < count; i++)
|
||
{
|
||
var groupData = sheet.bgColor1List[i];
|
||
LiveTimelineKeyBgColor1DataList keys = groupData.keys;
|
||
if (keys.HasAttribute(LiveTimelineKeyDataListAttr.Disable) || !keys.EnablePlayModeTimeline(_playMode))
|
||
{
|
||
continue;
|
||
}
|
||
// 这里原本只放行 validBgColorNames(4 个角色组),把舞台物件组全丢了。
|
||
// 实测一首歌 20 组 / 1239 keys 里有 17 组是舞台物件,约 92% 的数据被丢弃。
|
||
// 现在全部下发,由 Director 按 TimelineName 分流到角色 or 舞台。
|
||
FindTimelineKey(out var curKey, out var nextKey, keys, currentFrame);
|
||
if (curKey == null)
|
||
{
|
||
continue;
|
||
}
|
||
BgColor1UpdateInfo updateInfo = default;
|
||
LiveTimelineKeyBgColor1Data bgColorData = curKey as LiveTimelineKeyBgColor1Data;
|
||
LiveTimelineKeyBgColor1Data bgColorData2 = nextKey as LiveTimelineKeyBgColor1Data;
|
||
|
||
updateInfo.TimelineName = groupData.name;
|
||
updateInfo.TimelineNameHash = string.IsNullOrEmpty(groupData.name) ? 0 : Animator.StringToHash(groupData.name);
|
||
updateInfo.TargetCharaIdArray = groupData.TargetCharaIdArray;
|
||
updateInfo.TargetDressIdArray = groupData.TargetDressIdArray;
|
||
|
||
// 以下字段此前从未填充,handler 拿到的一直是 default。
|
||
updateInfo.colorPower = bgColorData.power;
|
||
updateInfo.scale = bgColorData.scale;
|
||
updateInfo.vertexColorToonPower = bgColorData.vertexColorToonPower;
|
||
updateInfo.outlineWidthPower = bgColorData.outlineWidthPower;
|
||
updateInfo.LightBlendMode = bgColorData.LightBlendMode;
|
||
updateInfo.IsSilhouette = bgColorData.IsSilhouette;
|
||
updateInfo.IsProjector = bgColorData.IsProjector;
|
||
updateInfo.CurrentColorType = bgColorData.ColorType;
|
||
updateInfo.CurrentColor = bgColorData.color;
|
||
updateInfo.CurrentFlags = bgColorData.flags;
|
||
|
||
if (bgColorData2 != null && bgColorData2.interpolateType != 0)
|
||
{
|
||
float t = CalculateInterpolationValue(bgColorData, bgColorData2, currentFrame);
|
||
updateInfo.flags = bgColorData.flags;
|
||
updateInfo.color = Color.Lerp(bgColorData.color, bgColorData2.color, t);
|
||
updateInfo.toonDarkColor = Color.Lerp(bgColorData.toonDarkColor, bgColorData2.toonDarkColor, t);
|
||
updateInfo.toonBrightColor = Color.Lerp(bgColorData.toonBrightColor, bgColorData2.toonBrightColor, t);
|
||
updateInfo.outlineColor = Color.Lerp(bgColorData.outlineColor, bgColorData2.outlineColor, t);
|
||
updateInfo.outlineColorBlend = bgColorData.outlineColorBlend;
|
||
updateInfo.Saturation = LerpWithoutClamp(bgColorData.Saturation, bgColorData2.Saturation, t);
|
||
}
|
||
else
|
||
{
|
||
updateInfo.flags = bgColorData.flags;
|
||
updateInfo.color = bgColorData.color;
|
||
updateInfo.toonDarkColor = bgColorData.toonDarkColor;
|
||
updateInfo.toonBrightColor = bgColorData.toonBrightColor;
|
||
updateInfo.outlineColor = bgColorData.outlineColor;
|
||
updateInfo.outlineColorBlend = bgColorData.outlineColorBlend;
|
||
updateInfo.Saturation = bgColorData.Saturation;
|
||
}
|
||
OnUpdateBgColor1.Invoke(ref updateInfo);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// PostFilm (39)。postFilmKeys 是直接的 key 列表(不是分组列表),
|
||
/// 所以不能走 AlterUpdate_SimpleListControl,得自己找 key 和插值。
|
||
/// </summary>
|
||
private void AlterUpdate_PostFilm(LiveTimelineKeyPostFilmDataList keys, int layerIndex, float currentFrame)
|
||
{
|
||
if (OnUpdatePostFilm == null || keys == null || keys.Count == 0) return;
|
||
if (keys.HasAttribute(LiveTimelineKeyDataListAttr.Disable) || !keys.EnablePlayModeTimeline(_playMode))
|
||
return;
|
||
|
||
FindTimelineKey(out var curKey, out var nextKey, keys, currentFrame);
|
||
var cur = curKey as LiveTimelineKeyPostFilmData;
|
||
if (cur == null) return;
|
||
var next = nextKey as LiveTimelineKeyPostFilmData;
|
||
|
||
PostFilmUpdateInfo info = default;
|
||
info.layerIndex = layerIndex;
|
||
info.filmMode = cur.filmMode;
|
||
info.colorType = cur.colorType;
|
||
info.layerMode = cur.layerMode;
|
||
info.colorBlend = cur.colorBlend;
|
||
info.movieResId = cur.movieResId;
|
||
info.movieFrameOffset = cur.movieFrameOffset;
|
||
info.movieSpeed = cur.movieSpeed;
|
||
info.enable = cur.filmMode != PostFilmMode.None;
|
||
|
||
if (next != null && next.interpolateType != 0)
|
||
{
|
||
float t = CalculateInterpolationValue(cur, next, currentFrame);
|
||
info.filmPower = Mathf.Lerp(cur.filmPower, next.filmPower, t);
|
||
info.color0 = Color.Lerp(cur.color0, next.color0, t);
|
||
info.color1 = Color.Lerp(cur.color1, next.color1, t);
|
||
info.color2 = Color.Lerp(cur.color2, next.color2, t);
|
||
info.color3 = Color.Lerp(cur.color3, next.color3, t);
|
||
info.filmOffsetParam = Vector2.Lerp(cur.filmOffsetParam, next.filmOffsetParam, t);
|
||
info.filmOptionParam = Vector4.Lerp(cur.filmOptionParam, next.filmOptionParam, t);
|
||
info.filmScale = Vector2.Lerp(cur.FilmScale, next.FilmScale, t);
|
||
info.rollAngle = Mathf.Lerp(cur.RollAngle, next.RollAngle, t);
|
||
info.depthPower = Mathf.Lerp(cur.depthPower, next.depthPower, t);
|
||
info.depthClip = Mathf.Lerp(cur.DepthClip, next.DepthClip, t);
|
||
info.colorBlendFactor = Mathf.Lerp(cur.colorBlendFactor, next.colorBlendFactor, t);
|
||
}
|
||
else
|
||
{
|
||
info.filmPower = cur.filmPower;
|
||
info.color0 = cur.color0;
|
||
info.color1 = cur.color1;
|
||
info.color2 = cur.color2;
|
||
info.color3 = cur.color3;
|
||
info.filmOffsetParam = cur.filmOffsetParam;
|
||
info.filmOptionParam = cur.filmOptionParam;
|
||
info.filmScale = cur.FilmScale;
|
||
info.rollAngle = cur.RollAngle;
|
||
info.depthPower = cur.depthPower;
|
||
info.depthClip = cur.DepthClip;
|
||
info.colorBlendFactor = cur.colorBlendFactor;
|
||
}
|
||
|
||
OnUpdatePostFilm.Invoke(ref info);
|
||
}
|
||
|
||
private void AlterUpdate_BgColor2(LiveTimelineWorkSheet sheet, float currentFrame)
|
||
{
|
||
if (OnUpdateBgColor2 == null) return;
|
||
int count = sheet.bgColor2List.Count;
|
||
for (int i = 0; i < count; i++)
|
||
{
|
||
LiveTimelineKeyBgColor2DataList keys = sheet.bgColor2List[i].keys;
|
||
if (keys == null || keys.HasAttribute(LiveTimelineKeyDataListAttr.Disable) || !keys.EnablePlayModeTimeline(_playMode))
|
||
continue;
|
||
FindTimelineKey(out var curKey, out var nextKey, keys, currentFrame);
|
||
if (curKey == null) continue;
|
||
LiveTimelineKeyBgColor2Data d0 = curKey as LiveTimelineKeyBgColor2Data;
|
||
LiveTimelineKeyBgColor2Data d1 = nextKey as LiveTimelineKeyBgColor2Data;
|
||
BgColor2UpdateInfo updateInfo = default;
|
||
// 组名从 ILiveTimelineGroupDataWithName 基类继承而来,一直可读,只是从没被传下去。
|
||
updateInfo.TimelineName = sheet.bgColor2List[i].name;
|
||
if (d1 != null && d1.interpolateType != 0)
|
||
{
|
||
float t = CalculateInterpolationValue(d0, d1, currentFrame);
|
||
updateInfo.color1 = Color.Lerp(d0.color1, d1.color1, t);
|
||
updateInfo.color2 = Color.Lerp(d0.color2, d1.color2, t);
|
||
updateInfo.value = Mathf.Lerp(d0.power, d1.power, t);
|
||
}
|
||
else
|
||
{
|
||
updateInfo.color1 = d0.color1;
|
||
updateInfo.color2 = d0.color2;
|
||
updateInfo.value = d0.power;
|
||
}
|
||
OnUpdateBgColor2.Invoke(ref updateInfo);
|
||
}
|
||
}
|
||
|
||
private void AlterUpdate_TransformControl(LiveTimelineWorkSheet sheet, float currentFrame)
|
||
{
|
||
int count = sheet.transformList.Count;
|
||
for (int i = 0; i < count; i++)
|
||
{
|
||
var keys = sheet.transformList[i].keys;
|
||
if (keys.HasAttribute(LiveTimelineKeyDataListAttr.Disable) || !keys.EnablePlayModeTimeline(_playMode))
|
||
{
|
||
continue;
|
||
}
|
||
FindTimelineKey(out var curKey, out var nextKey, keys, currentFrame);
|
||
if (curKey == null)
|
||
{
|
||
continue;
|
||
}
|
||
TransformUpdateInfo updateInfo = default;
|
||
updateInfo.data = sheet.transformList[i];
|
||
LiveTimelineKeyTransformData transformData = curKey as LiveTimelineKeyTransformData;
|
||
LiveTimelineKeyTransformData transformData2 = nextKey as LiveTimelineKeyTransformData;
|
||
if (transformData2 != null && transformData2.interpolateType != 0)
|
||
{
|
||
float t = CalculateInterpolationValue(transformData, transformData2, currentFrame);
|
||
updateInfo.updateData.position = Vector3.Lerp(transformData.position, transformData2.position, t);
|
||
updateInfo.updateData.rotation = Quaternion.Lerp(Quaternion.Euler(transformData.rotate), Quaternion.Euler(transformData2.rotate), t);
|
||
updateInfo.updateData.scale = Vector3.Lerp(transformData.scale, transformData2.scale, t);
|
||
}
|
||
else
|
||
{
|
||
updateInfo.updateData.position = transformData.position;
|
||
updateInfo.updateData.rotation = Quaternion.Euler(transformData.rotate);
|
||
updateInfo.updateData.scale = transformData.scale;
|
||
}
|
||
OnUpdateTransform.Invoke(ref updateInfo);
|
||
}
|
||
}
|
||
|
||
private void AlterUpdate_ObjectControl(LiveTimelineWorkSheet sheet, float currentFrame)
|
||
{
|
||
int count = sheet.objectList.Count;
|
||
for (int i = 0; i < count; i++)
|
||
{
|
||
var keys = sheet.objectList[i].keys;
|
||
if (keys.HasAttribute(LiveTimelineKeyDataListAttr.Disable) || !keys.EnablePlayModeTimeline(_playMode))
|
||
{
|
||
continue;
|
||
}
|
||
else if (!StageObjectMap.ContainsKey(sheet.objectList[i].name) &&
|
||
!StageObjectUnitMap.ContainsKey(sheet.objectList[i].name))
|
||
{
|
||
continue;
|
||
}
|
||
FindTimelineKey(out var curKey, out var nextKey, keys, currentFrame);
|
||
if (curKey == null)
|
||
{
|
||
continue;
|
||
}
|
||
ObjectUpdateInfo updateInfo = default;
|
||
LiveTimelineKeyObjectData objectData = curKey as LiveTimelineKeyObjectData;
|
||
LiveTimelineKeyObjectData objectData2 = nextKey as LiveTimelineKeyObjectData;
|
||
if (objectData2 != null && objectData2.interpolateType != 0)
|
||
{
|
||
float t = CalculateInterpolationValue(objectData, objectData2, currentFrame);
|
||
updateInfo.updateData.position = Vector3.Lerp(objectData.position, objectData2.position, t);
|
||
updateInfo.updateData.rotation = Quaternion.Lerp(Quaternion.Euler(objectData.rotate), Quaternion.Euler(objectData2.rotate), t);
|
||
updateInfo.updateData.scale = Vector3.Lerp(objectData.scale, objectData2.scale, t);
|
||
}
|
||
else
|
||
{
|
||
updateInfo.updateData.position = objectData.position;
|
||
updateInfo.updateData.rotation = Quaternion.Euler(objectData.rotate);
|
||
updateInfo.updateData.scale = objectData.scale;
|
||
}
|
||
updateInfo.data = sheet.objectList[i];
|
||
updateInfo.renderEnable = objectData.renderEnable;
|
||
updateInfo.AttachTarget = objectData.AttachTarget;
|
||
updateInfo.CharacterPosition = objectData.CharacterPosition;
|
||
updateInfo.MultiCameraIndex = objectData.MultiCameraIndex;
|
||
updateInfo.OffsetType = objectData.OffsetValueType;
|
||
updateInfo.LayerType = objectData.LayerTypeValue;
|
||
updateInfo.IsLayerTypeRecursively = objectData.IsLayerTypeRecursively;
|
||
OnUpdateObject.Invoke(ref updateInfo);
|
||
}
|
||
}
|
||
|
||
private void AlterUpdate_EffectControl(LiveTimelineWorkSheet sheet, float currentFrame)
|
||
{
|
||
if (sheet.effectList == null || OnUpdateEffect == null) return;
|
||
int count = sheet.effectList.Count;
|
||
for (int i = 0; i < count; i++)
|
||
{
|
||
var effectData = sheet.effectList[i];
|
||
var keys = effectData.keys;
|
||
if (keys == null || keys.HasAttribute(LiveTimelineKeyDataListAttr.Disable) || !keys.EnablePlayModeTimeline(_playMode))
|
||
continue;
|
||
FindTimelineKey(out var curKey, out var _, keys, currentFrame);
|
||
if (curKey == null) continue;
|
||
OnUpdateEffect.Invoke(effectData, curKey as LiveTimelineKeyEffectData);
|
||
}
|
||
}
|
||
|
||
private void AlterUpdate_SimpleListControl<TData, TKey>(
|
||
List<TData> list,
|
||
System.Func<TData, ILiveTimelineKeyDataList> getKeys,
|
||
Action<TData, TKey> onUpdate,
|
||
float currentFrame) where TKey : LiveTimelineKey
|
||
{
|
||
if (list == null || onUpdate == null) return;
|
||
foreach (var entry in list)
|
||
{
|
||
var keys = getKeys(entry);
|
||
if (keys == null || keys.HasAttribute(LiveTimelineKeyDataListAttr.Disable) || !keys.EnablePlayModeTimeline(_playMode)) continue;
|
||
FindTimelineKey(out var curKey, out var _, keys, currentFrame);
|
||
if (curKey == null) continue;
|
||
onUpdate.Invoke(entry, curKey as TKey);
|
||
}
|
||
}
|
||
|
||
private void AlterUpdate_MobCyalumeControl(
|
||
List<LiveTimelineMobCyalumeControlData> dataList,
|
||
float currentFrame,
|
||
MobCyalumeUpdateInfoDelegate callback)
|
||
{
|
||
if (callback == null || dataList == null) return;
|
||
|
||
for (int i = 0; i < dataList.Count; i++)
|
||
{
|
||
var data = dataList[i];
|
||
var keys = data != null ? data.keys : null;
|
||
if (keys == null || keys.Count == 0 || keys.HasAttribute(LiveTimelineKeyDataListAttr.Disable) ||
|
||
!keys.EnablePlayModeTimeline(_playMode)) continue;
|
||
|
||
FindTimelineKey(out var curKey, out var nextKey, keys, currentFrame);
|
||
var current = curKey as LiveTimelineKeyMobCyalumeControlData;
|
||
var next = nextKey as LiveTimelineKeyMobCyalumeControlData;
|
||
if (current == null) continue;
|
||
|
||
var info = new MobCyalumeUpdateInfo
|
||
{
|
||
data = data,
|
||
unk0 = (uint)keys.unk48 < 11u ? keys.unk48 : i,
|
||
currentFrame = currentFrame,
|
||
currentLiveTime = currentLiveTime
|
||
};
|
||
|
||
if (next != null && next.interpolateType != LiveCameraInterpolateType.None)
|
||
{
|
||
float t = CalculateInterpolationValue(current, next, currentFrame);
|
||
info.position = Vector3.Lerp(current.position, next.position, t);
|
||
info.rotation = Quaternion.Lerp(current.GetRotation(), next.GetRotation(), t);
|
||
info.scale = Vector3.Lerp(current.scale, next.scale, t);
|
||
}
|
||
else
|
||
{
|
||
info.position = current.position;
|
||
info.rotation = current.GetRotation();
|
||
info.scale = current.scale;
|
||
}
|
||
|
||
callback.Invoke(ref info);
|
||
}
|
||
}
|
||
|
||
private void AlterUpdate_FacialToon(LiveTimelineFacialToonData data, float currentFrame)
|
||
{
|
||
if (data == null || OnUpdateFacialToon == null) return;
|
||
for (int i = 0; i < 20; i++)
|
||
{
|
||
var keys = data.GetKeys(i);
|
||
if (keys == null || keys.Count == 0 || keys.HasAttribute(LiveTimelineKeyDataListAttr.Disable) ||
|
||
!keys.EnablePlayModeTimeline(_playMode)) continue;
|
||
FindTimelineKey(out var current, out var _, keys, currentFrame);
|
||
if (current is LiveTimelineKeyFacialToonData key) OnUpdateFacialToon.Invoke(i, key);
|
||
}
|
||
}
|
||
|
||
private void AlterUpdate_CharaFootLight(LiveTimelineKeyCharaFootLightDataList keys, float currentFrame)
|
||
{
|
||
if (keys == null || OnUpdateCharaFootLight == null || keys.Count == 0 ||
|
||
keys.HasAttribute(LiveTimelineKeyDataListAttr.Disable) || !keys.EnablePlayModeTimeline(_playMode)) return;
|
||
FindTimelineKey(out var current, out var _, keys, currentFrame);
|
||
if (current is LiveTimelineKeyCharaFootLightData key) OnUpdateCharaFootLight.Invoke(key);
|
||
}
|
||
|
||
private void AlterUpdate_GlobalFogControl(LiveTimelineWorkSheet sheet, float currentFrame)
|
||
{
|
||
if (sheet.globalFogDataLists == null || OnUpdateGlobalFog == null) return;
|
||
foreach (var fogData in sheet.globalFogDataLists)
|
||
{
|
||
var keys = fogData.keys;
|
||
if (keys == null || keys.HasAttribute(LiveTimelineKeyDataListAttr.Disable) || !keys.EnablePlayModeTimeline(_playMode)) continue;
|
||
FindTimelineKey(out var curKey, out var _, keys, currentFrame);
|
||
if (curKey == null) continue;
|
||
OnUpdateGlobalFog.Invoke(fogData, curKey as LiveTimelineKeyGlobalFogData);
|
||
}
|
||
}
|
||
|
||
private void AlterUpdate_Spotlight3dControl(LiveTimelineWorkSheet sheet, float currentFrame)
|
||
{
|
||
if (sheet.spotlight3dList == null || OnUpdateSpotlight3d == null) return;
|
||
foreach (var spotData in sheet.spotlight3dList)
|
||
{
|
||
var keys = spotData.keys;
|
||
if (keys == null || keys.HasAttribute(LiveTimelineKeyDataListAttr.Disable) || !keys.EnablePlayModeTimeline(_playMode)) continue;
|
||
FindTimelineKey(out var curKey, out var _, keys, currentFrame);
|
||
if (curKey == null) continue;
|
||
OnUpdateSpotlight3d.Invoke(spotData, curKey as LiveTimelineKeySpotlight3dData);
|
||
}
|
||
}
|
||
|
||
private static float LerpWithoutClamp(float a, float b, float t)
|
||
{
|
||
return a + (b - a) * t;
|
||
}
|
||
|
||
private static Vector2 LerpWithoutClamp(Vector2 a, Vector2 b, float t)
|
||
{
|
||
return new Vector2(a.x + (b.x - a.x) * t, a.y + (b.y - a.y) * t);
|
||
}
|
||
|
||
private static Vector3 LerpWithoutClamp(Vector3 a, Vector3 b, float t)
|
||
{
|
||
return new Vector3(a.x + (b.x - a.x) * t, a.y + (b.y - a.y) * t, a.z + (b.z - a.z) * t);
|
||
}
|
||
|
||
private static Vector4 LerpWithoutClamp(Vector4 a, Vector4 b, float t)
|
||
{
|
||
return new Vector4(a.x + (b.x - a.x) * t, a.y + (b.y - a.y) * t, a.z + (b.z - a.z) * t, a.w + (b.w - a.w) * t);
|
||
}
|
||
|
||
private static Color LerpWithoutClamp(Color a, Color b, float t)
|
||
{
|
||
return new Color(a.r + (b.r - a.r) * t, a.g + (b.g - a.g) * t, a.b + (b.b - a.b) * t, a.a + (b.a - a.a) * t);
|
||
}
|
||
|
||
}
|
||
|
||
|
||
}
|