Files
UmaViewer/Assets/Scripts/umamusume/Gallop/Live/Cutt/LiveTimelineControl.cs
T
CroakFang 2a0b8082c0 bug fix
2023-09-18 01:00:56 +08:00

1597 lines
72 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using static RootMotion.FinalIK.IKSolverVR;
using System.Linq;
using System.IO;
using static UnityEngine.Rendering.VirtualTexturing.Debugging;
using static Gallop.Live.Cutt.LiveTimelineDefine;
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;
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 MultiCameraManager _multiCameraManager;
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 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 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);
_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();
}
}
public void AlterUpdate_CharaMotionSequence(float liveTime)
{
foreach (var motion in _motionSequenceArray)
{
motion.AlterUpdate(liveTime);
}
}
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();
for (int i = 0; i < Director.instance.characterCount; i++)
{
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);
}
public void LateUpdateFormationOffset_Transform(int targetIndex, LiveTimelineKeyIndex curKeyIndex, float time)
{
LiveTimelineKeyFormationOffsetData curKey = curKeyIndex.key as LiveTimelineKeyFormationOffsetData;
LiveTimelineKeyFormationOffsetData nextKey = curKeyIndex.nextKey as LiveTimelineKeyFormationOffsetData;
var chara = Director.instance.CharaContainerScript[targetIndex];
if (!chara) return;
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(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);
}
}
}
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 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);
}
}
}