private static AnimationCurve ExtractNormalizedTimeCurve(SceneCachePlayer scPlayer, out float endTime) { AnimationCurve origTimeCurve = scPlayer.GetTimeCurve(); if (null == origTimeCurve) { endTime = 0; return(null); } TimeRange timeRange = scPlayer.GetTimeRange(); endTime = timeRange.end; if (endTime <= 0f) { endTime = Mathf.Epsilon; } Keyframe[] keyframes = origTimeCurve.keys; int numKeyframes = keyframes.Length; for (int i = 0; i < numKeyframes; ++i) { keyframes[i].value /= endTime; } AnimationCurve curve = new AnimationCurve(keyframes); return(curve); }
//---------------------------------------------------------------------------------------------------------------------- private static double CalculateTimeForLimitedAnimation(SceneCachePlayer scPlayer, LimitedAnimationController overrideLimitedAnimationController, double time) { LimitedAnimationController origLimitedAnimationController = scPlayer.GetLimitedAnimationController(); if (origLimitedAnimationController.IsEnabled()) //do nothing if LA is set on the target SceneCache return time; if (!overrideLimitedAnimationController.IsEnabled()) return time; ISceneCacheInfo scInfo = scPlayer.ExtractSceneCacheInfo(forceOpen: true); if (null == scInfo) return time; int frame = scPlayer.CalculateFrame((float)time,overrideLimitedAnimationController); return frame / scInfo.GetSampleRate(); }
private static AnimationCurve ExtractNormalizedTimeCurve(SceneCachePlayer scPlayer, out float duration) { ISceneCacheInfo sceneCacheInfo = scPlayer.ExtractSceneCacheInfo(forceOpen: true); if (null == sceneCacheInfo) { duration = 0; return(null); } TimeRange timeRange = sceneCacheInfo.GetTimeRange(); duration = timeRange.GetDuration(); if (duration <= 0f) { duration = Mathf.Epsilon; } Keyframe[] keyframes = sceneCacheInfo.GetTimeCurve().keys; int numKeyframes = keyframes.Length; for (int i = 0; i < numKeyframes; ++i) { keyframes[i].value /= timeRange.end; } //outTangent for (int i = 0; i < numKeyframes - 1; ++i) { keyframes[i].outTangent = CalculateLinearTangent(keyframes, i, i + 1); } //inTangent for (int i = 1; i < numKeyframes; ++i) { keyframes[i].inTangent = CalculateLinearTangent(keyframes, i - 1, i); } AnimationCurve curve = new AnimationCurve(keyframes); return(curve); }
public override void PrepareFrame(Playable playable, FrameData info) { base.PrepareFrame(playable, info); m_inactiveSceneCacheObjects.Clear(); int curFrame = Time.frameCount; if (m_lastPrepareGlobalTime != curFrame) { m_activatedSceneCacheObjectsInFrame.Clear(); m_lastPrepareGlobalTime = curFrame; } //Register all SceneCache objects as inactive foreach (var clipData in m_clipAssets.Values) { SceneCachePlayer scPlayer = clipData.GetSceneCachePlayer(); if (null == scPlayer) continue; m_inactiveSceneCacheObjects.Add(scPlayer.gameObject); } }
//---------------------------------------------------------------------------------------------------------------------- internal void BindSceneCachePlayer(SceneCachePlayer sceneCachePlayer) { if (m_initialized) { if (null == m_scPlayer) { //Assuming that BindSceneCachePlayer() will be called() during "deserialization", we initialize scPlayer //at first if this clipData has already been initialized. //SceneCachePlayer can't be deserialized as usual, because SceneCacheClip belongs to a track, which is an asset. m_scPlayer = sceneCachePlayer; return; } else if (m_scPlayer == sceneCachePlayer) { return; } } m_scPlayer = sceneCachePlayer; m_initialized = true; TimelineClip clip = GetOwner(); Assert.IsNotNull(clip); //Bind for the first time m_scPlayer = sceneCachePlayer; m_animationCurve = ExtractNormalizedTimeCurve(m_scPlayer, out float endTime); if (null != m_animationCurve) { clip.duration = endTime; } else { m_animationCurve = CreateLinearAnimationCurve(clip); } ResetClip(clip); UpdateClipCurve(clip, m_animationCurve); }
public override void ProcessFrame(Playable playable, FrameData info, object playerData) { TimelineUtility.GetActiveTimelineClipInto(m_clips, m_playableDirector.time, out TimelineClip clip, out SceneCachePlayableAsset activePlayableAsset); if (null == clip) { UpdateObjectActiveStates(); return; } SceneCacheClipData clipData = activePlayableAsset.GetBoundClipData(); Assert.IsNotNull(clipData); SceneCachePlayer scPlayer = activePlayableAsset.GetSceneCachePlayer(); if (null == scPlayer) { UpdateObjectActiveStates(); return; } UpdateObjectActiveStates(activeObject: scPlayer.gameObject); }
internal void SetSceneCachePlayer(SceneCachePlayer scPlayer) { m_sceneCachePlayer = scPlayer; }
private void SetExtractedSceneCachePlayerInEditor(SceneCachePlayer scPlayer) { ExposedReferenceUtility.SetReferenceValueInEditor(ref m_extractedSceneCachePlayerRef, m_propertyTable, scPlayer); }
internal void SetSceneCachePlayerInEditor(SceneCachePlayer scPlayer) { ExposedReferenceUtility.SetReferenceValueInEditor(ref m_sceneCachePlayerRef, m_propertyTable, scPlayer); }