public override void ProcessFrame(Playable playable, FrameData info, object playerData) { base.ProcessFrame(playable, info, playerData); GameObject gameObject = playerData as GameObject; if (gameObject == null) { this.mBrain = (CinemachineBrain)playerData; } else { this.mBrain = gameObject.GetComponent <CinemachineBrain>(); } if (this.mBrain == null) { return; } int num = 0; ICinemachineCamera cinemachineCamera = null; ICinemachineCamera camA = null; float weightB = 1f; for (int i = 0; i < playable.GetInputCount <Playable>(); i++) { CinemachineShotPlayable behaviour = ((ScriptPlayable <T>)playable.GetInput(i)).GetBehaviour(); float inputWeight = playable.GetInputWeight(i); if (behaviour != null && behaviour.VirtualCamera != null && playable.GetPlayState <Playable>() == PlayState.Playing && inputWeight > 0.0001f) { if (num == 1) { camA = cinemachineCamera; } weightB = inputWeight; cinemachineCamera = behaviour.VirtualCamera; num++; if (num == 2) { break; } } } float deltaTime = info.deltaTime; if (!this.mPlaying) { if (this.mBrainOverrideId < 0) { this.mLastOverrideFrame = -1f; } float realtimeSinceStartup = Time.realtimeSinceStartup; deltaTime = Time.unscaledDeltaTime; if (!Application.isPlaying && (this.mLastOverrideFrame < 0f || realtimeSinceStartup - this.mLastOverrideFrame > Time.maximumDeltaTime)) { deltaTime = -1f; } this.mLastOverrideFrame = realtimeSinceStartup; } this.mBrainOverrideId = this.mBrain.SetCameraOverride(this.mBrainOverrideId, camA, cinemachineCamera, weightB, deltaTime); }
public override void ProcessFrame(Playable playable, FrameData info, object playerData) { base.ProcessFrame(playable, info, playerData); // Get the brain that this track controls. // Older versions of timeline sent the gameObject by mistake. GameObject go = playerData as GameObject; if (go == null) { mBrain = (CinemachineBrain)playerData; } else { mBrain = go.GetComponent <CinemachineBrain>(); } if (mBrain == null) { return; } // Find which clips are active. We can process a maximum of 2. // In the case that the weights don't add up to 1, the outgoing weight // will be calculated as the inverse of the incoming weight. int activeInputs = 0; ICinemachineCamera camA = null; ICinemachineCamera camB = null; float camWeightB = 1f; for (int i = 0; i < playable.GetInputCount(); ++i) { CinemachineShotPlayable shot = ((ScriptPlayable <CinemachineShotPlayable>)playable.GetInput(i)).GetBehaviour(); float weight = playable.GetInputWeight(i); if (shot != null && shot.IsValid && playable.GetPlayState() == PlayState.Playing && weight > 0.0001f) { if (shot.VirtualCamera != null) { camA = camB; camWeightB = weight; camB = shot.VirtualCamera; } if (++activeInputs == 2) { break; } } } // Override the Cinemachine brain with our results mBrainOverrideId = mBrain.SetCameraOverride( mBrainOverrideId, camA, camB, camWeightB, GetDeltaTime(info.deltaTime)); }
public override void ProcessFrame(Playable playable, FrameData info, object playerData) { base.ProcessFrame(playable, info, playerData); int activeInputs = 0; ClipInfo clipA = new ClipInfo(); ClipInfo clipB = new ClipInfo(); for (int i = 0; i < playable.GetInputCount(); i++) { float weight = playable.GetInputWeight(i); var clip = (ScriptPlayable <TimeScaleBehaviour>)playable.GetInput(i); var behaviour = clip.GetBehaviour(); if (behaviour != null && playable.GetPlayState() == PlayState.Playing && weight > 0 ) { clipA = clipB; clipB.scale = behaviour.scale; clipB.weight = weight; clipB.time = clip.GetTime(); if (++activeInputs == 2) { break; } } } if (activeInputs == 0) { if (Time.timeScale < 1f) { Time.timeScale = 1f; } return; } if (activeInputs < 2) { Time.timeScale = clipB.scale; } else { if (clipA.time > clipB.time) { Time.timeScale = Mathf.Lerp(clipA.scale, clipB.scale, clipB.weight); } else { Time.timeScale = Mathf.Lerp(clipA.scale, clipB.scale, clipA.weight); } } }
public override void ProcessFrame(Playable playable, FrameData info, object playerData) { base.ProcessFrame(playable, info, playerData); if (MainCamera == null) { return; } int activeInputs = 0; ClipInfo clipA = new ClipInfo(); ClipInfo clipB = new ClipInfo(); Texture2D overlayTexture = null; for (int i = 0; i < playable.GetInputCount(); ++i) { float weight = playable.GetInputWeight(i); ScriptPlayable <CameraFadePlayableBehaviour> clip = (ScriptPlayable <CameraFadePlayableBehaviour>)playable.GetInput(i); CameraFadePlayableBehaviour shot = clip.GetBehaviour(); if (shot != null && shot.IsValid && playable.GetPlayState() == PlayState.Playing && weight > 0.0001f) { clipA = clipB; clipB.weight = weight; clipB.localTime = clip.GetTime(); clipB.duration = clip.GetDuration(); clipB.overlayTexture = shot.overlayTexture; if (++activeInputs == 2) { break; } } } overlayTexture = (clipB.overlayTexture != null) ? clipB.overlayTexture : clipA.overlayTexture; float _weight = clipB.weight; MainCamera.SetTimelineFadeOverride(overlayTexture, _weight); }
public override void ProcessFrame(Playable playable, FrameData info, object playerData) { base.ProcessFrame(playable, info, playerData); if (MainCamera == null) { return; } int activeInputs = 0; ClipInfo clipA = new ClipInfo(); ClipInfo clipB = new ClipInfo(); float shakeIntensity = 0f; for (int i = 0; i < playable.GetInputCount(); ++i) { float weight = playable.GetInputWeight(i); ScriptPlayable <MainCameraPlayableBehaviour> clip = (ScriptPlayable <MainCameraPlayableBehaviour>)playable.GetInput(i); MainCameraPlayableBehaviour shot = clip.GetBehaviour(); if (shot != null) { callCustomEvents = shot.callCustomEvents; } if (shot != null && shot.IsValid && playable.GetPlayState() == PlayState.Playing && weight > 0.0001f) { clipA = clipB; clipB.camera = shot.gameCamera; clipB.weight = weight; clipB.localTime = clip.GetTime(); clipB.duration = clip.GetDuration(); clipB.shakeIntensity = shot.shakeIntensity; if (++activeInputs == 2) { break; } } } // Figure out which clip is incoming bool incomingIsB = clipB.weight >= 1 || clipB.localTime < clipB.duration / 2; if (activeInputs == 2) { if (clipB.localTime > clipA.localTime) { incomingIsB = true; } else if (clipB.localTime < clipA.localTime) { incomingIsB = false; } else { incomingIsB = clipB.duration >= clipA.duration; } } shakeIntensity = incomingIsB ? clipB.shakeIntensity : clipA.shakeIntensity; _Camera cameraA = incomingIsB ? clipA.camera : clipB.camera; _Camera cameraB = incomingIsB ? clipB.camera : clipA.camera; float camWeightB = incomingIsB ? clipB.weight : 1 - clipB.weight; if (cameraB == null) { cameraB = cameraA; cameraA = null; camWeightB = 1f - camWeightB; } if (incomingIsB) { shakeIntensity = (clipA.shakeIntensity * (1f - camWeightB)) + (clipB.shakeIntensity * camWeightB); } else { shakeIntensity = (clipB.shakeIntensity * (1f - camWeightB)) + (clipA.shakeIntensity * camWeightB); } MainCamera.SetTimelineOverride(cameraA, cameraB, camWeightB, shakeIntensity); if (callCustomEvents) { _Camera thisFrameCamera = (incomingIsB) ? cameraB : cameraA; if (thisFrameCamera != lastFrameCamera) { KickStarter.eventManager.Call_OnSwitchCamera(lastFrameCamera, thisFrameCamera, 0f); lastFrameCamera = thisFrameCamera; } } }
public PlayableNode(Playable content, float weight = 1.0f) : base(content, weight, content.GetPlayState() == PlayState.Playing) { }
public override void ProcessFrame(Playable playable, FrameData info, object playerData) { base.ProcessFrame(playable, info, playerData); // Get the brain that this track controls. // Older versions of timeline sent the gameObject by mistake. GameObject go = playerData as GameObject; if (go == null) { mBrain = (CinemachineBrain)playerData; } else { mBrain = go.GetComponent <CinemachineBrain>(); } if (mBrain == null) { return; } // Find which clips are active. We can process a maximum of 2. // In the case that the weights don't add up to 1, the outgoing weight // will be calculated as the inverse of the incoming weight. int activeInputs = 0; ClipInfo clipA = new ClipInfo(); ClipInfo clipB = new ClipInfo(); for (int i = 0; i < playable.GetInputCount(); ++i) { float weight = playable.GetInputWeight(i); var clip = (ScriptPlayable <CinemachineShotPlayable>)playable.GetInput(i); CinemachineShotPlayable shot = clip.GetBehaviour(); if (shot != null && shot.IsValid && playable.GetPlayState() == PlayState.Playing && weight > 0) { clipA = clipB; clipB.vcam = shot.VirtualCamera; clipB.weight = weight; clipB.localTime = clip.GetTime(); clipB.duration = clip.GetDuration(); if (++activeInputs == 2) { break; } } } // Figure out which clip is incoming bool incomingIsB = clipB.weight >= 1 || clipB.localTime < clipB.duration / 2; if (activeInputs == 2) { if (clipB.localTime < clipA.localTime) { incomingIsB = true; } else if (clipB.localTime > clipA.localTime) { incomingIsB = false; } else { incomingIsB = clipB.duration >= clipA.duration; } } // Override the Cinemachine brain with our results ICinemachineCamera camA = incomingIsB ? clipA.vcam : clipB.vcam; ICinemachineCamera camB = incomingIsB ? clipB.vcam : clipA.vcam; float camWeightB = incomingIsB ? clipB.weight : 1 - clipB.weight; mBrainOverrideId = mBrain.SetCameraOverride( mBrainOverrideId, camA, camB, camWeightB, GetDeltaTime(info.deltaTime)); }
public override void ProcessFrame(Playable playable, FrameData info, object playerData) { base.ProcessFrame(playable, info, playerData); // Get the object that this track controls m_BrainOverrideStack = playerData as ICameraOverrideStack; if (m_BrainOverrideStack == null) { return; } // Find which clips are active. We can process a maximum of 2. // In the case that the weights don't add up to 1, the outgoing weight // will be calculated as the inverse of the incoming weight. int activeInputs = 0; int clipIndexA = -1; int clipIndexB = -1; bool incomingIsA = false; // Assume that incoming clip is clip B float weightB = 1; for (int i = 0; i < playable.GetInputCount(); ++i) { float weight = playable.GetInputWeight(i); var clip = (ScriptPlayable <CinemachineShotPlayable>)playable.GetInput(i); CinemachineShotPlayable shot = clip.GetBehaviour(); if (shot != null && shot.IsValid && playable.GetPlayState() == PlayState.Playing && weight > 0) { clipIndexA = clipIndexB; clipIndexB = i; weightB = weight; if (++activeInputs == 2) { // Deduce which clip is incoming (timeline doesn't know) var clipA = playable.GetInput(clipIndexA); // Incoming has later start time (therefore earlier current time) incomingIsA = clip.GetTime() >= clipA.GetTime(); // If same start time, longer clip is incoming if (clip.GetTime() == clipA.GetTime()) { incomingIsA = clip.GetDuration() < clipA.GetDuration(); } break; } } } // Special case: check for only one clip that's fading out - it must be outgoing if (activeInputs == 1 && weightB < 1 && playable.GetInput(clipIndexB).GetTime() > playable.GetInput(clipIndexB).GetDuration() / 2) { incomingIsA = true; } if (incomingIsA) { (clipIndexA, clipIndexB) = (clipIndexB, clipIndexA); weightB = 1 - weightB; } ICinemachineCamera camA = null; if (clipIndexA >= 0) { CinemachineShotPlayable shot = ((ScriptPlayable <CinemachineShotPlayable>)playable.GetInput(clipIndexA)).GetBehaviour(); camA = shot.VirtualCamera; } ICinemachineCamera camB = null; if (clipIndexB >= 0) { CinemachineShotPlayable shot = ((ScriptPlayable <CinemachineShotPlayable>)playable.GetInput(clipIndexB)).GetBehaviour(); camB = shot.VirtualCamera; } // Override the Cinemachine brain with our results m_BrainOverrideId = m_BrainOverrideStack.SetCameraOverride( m_BrainOverrideId, camA, camB, weightB, GetDeltaTime(info.deltaTime)); #if UNITY_EDITOR && UNITY_2019_2_OR_NEWER if (m_ScrubbingCacheHelper != null && TargetPositionCache.CacheMode != TargetPositionCache.Mode.Disabled) { bool isNewB = (m_ScrubbingCacheHelper.ActivePlayableA != clipIndexB && m_ScrubbingCacheHelper.ActivePlayableB != clipIndexB); m_ScrubbingCacheHelper.ActivePlayableA = clipIndexA; m_ScrubbingCacheHelper.ActivePlayableB = clipIndexB; if (clipIndexA >= 0) { m_ScrubbingCacheHelper.ScrubToHere( (float)GetMasterPlayableDirector().time, clipIndexA, false, (float)playable.GetInput(clipIndexA).GetTime(), m_BrainOverrideStack.DefaultWorldUp); } if (clipIndexB >= 0) { m_ScrubbingCacheHelper.ScrubToHere( (float)GetMasterPlayableDirector().time, clipIndexB, isNewB && weightB > 0.99f, (float)playable.GetInput(clipIndexB).GetTime(), m_BrainOverrideStack.DefaultWorldUp); } } #endif }
public override void ProcessFrame(Playable playable, FrameData info, object playerData) { base.ProcessFrame(playable, info, playerData); if (_character == null) { GameObject characterObject = playerData as GameObject; if (characterObject) { _character = characterObject.GetComponent <AC.Char>(); } } if (_character) { int activeInputs = 0; ClipInfo clipA = new ClipInfo(); ClipInfo clipB = new ClipInfo(); Transform headTurnTarget = null; Vector3 headTurnOffset = Vector3.zero; for (int i = 0; i < playable.GetInputCount(); ++i) { float weight = playable.GetInputWeight(i); ScriptPlayable <HeadTurnPlayableBehaviour> clip = (ScriptPlayable <HeadTurnPlayableBehaviour>)playable.GetInput(i); HeadTurnPlayableBehaviour shot = clip.GetBehaviour(); if (shot != null && shot.IsValid && playable.GetPlayState() == PlayState.Playing && weight > 0.0001f) { clipA = clipB; clipB.weight = weight; clipB.localTime = clip.GetTime(); clipB.duration = clip.GetDuration(); clipB.headTurnTarget = shot.headTurnTarget; clipB.headTurnOffset = shot.headTurnOffset; if (++activeInputs == 2) { break; } } } headTurnTarget = (clipB.headTurnTarget) ? clipB.headTurnTarget : clipA.headTurnTarget; float _weight = clipB.weight; if (clipA.headTurnTarget) { headTurnOffset = (clipB.headTurnOffset * clipB.weight) + (clipA.headTurnOffset * clipA.weight); } else { headTurnOffset = clipB.headTurnOffset; } _character.SetTimelineHeadTurnOverride(headTurnTarget, headTurnOffset, _weight); } }
private PlayableNode CreateNodeFromPlayable(Playable h, float weight) { return(new PlayableNode(h, weight, h.GetPlayState() == PlayState.Playing)); }
public override void ProcessFrame(Playable playable, FrameData info, object playerData) { if (profile == null) { return; } var blurCtrl = profile.GetSetting <DownSampleBlur>(); if (blurCtrl == null) { blurCtrl = profile.AddSettings <DownSampleBlur>(); } base.ProcessFrame(playable, info, playerData); int activeInputs = 0; ClipInfo clipA = new ClipInfo(); ClipInfo clipB = new ClipInfo(); for (int i = 0; i < playable.GetInputCount(); i++) { float weight = playable.GetInputWeight(i); var clip = (ScriptPlayable <BlurBehaviour>)playable.GetInput(i); var behaviour = clip.GetBehaviour(); if (behaviour != null && playable.GetPlayState() == PlayState.Playing && weight > 0 ) { clipA = clipB; clipB.blurParam = behaviour.blurParam; clipB.blurSize = behaviour.blurSize; clipB.weight = weight; clipB.time = clip.GetTime(); if (++activeInputs == 2) { break; } } } if (activeInputs == 0) { if (blurCtrl.active) { blurCtrl.active = false; } return; } if (!blurCtrl.active) { blurCtrl.active = true; } float localBlurParam = 0f; float localBlurSize = 0f; if (activeInputs < 2) { localBlurParam = clipB.blurParam; localBlurSize = clipB.blurSize; } else { if (clipA.time > clipB.time) { localBlurParam = Mathf.Lerp(clipB.blurParam, clipA.blurParam, clipB.weight); localBlurSize = Mathf.Lerp(clipA.blurSize, clipB.blurSize, clipB.weight); } else { localBlurParam = Mathf.Lerp(clipA.blurParam, clipB.blurParam, clipB.weight); localBlurSize = Mathf.Lerp(clipA.blurSize, clipB.blurSize, clipA.weight); } } blurCtrl.blurParam.value = localBlurParam; if (!blurCtrl.blurParam.overrideState) { blurCtrl.blurParam.overrideState = true; } blurCtrl.blurSize.value = localBlurSize; if (!blurCtrl.blurSize.overrideState) { blurCtrl.blurSize.overrideState = true; } }
public override void ProcessFrame(Playable playable, FrameData info, object playerData) { base.ProcessFrame(playable, info, playerData); if (MainCamera == null) { return; } int activeInputs = 0; ClipInfo clipA = new ClipInfo(); ClipInfo clipB = new ClipInfo(); for (int i = 0; i < playable.GetInputCount(); ++i) { float weight = playable.GetInputWeight(i); ScriptPlayable <MainCameraPlayableBehaviour> clip = (ScriptPlayable <MainCameraPlayableBehaviour>)playable.GetInput(i); MainCameraPlayableBehaviour shot = clip.GetBehaviour(); if (shot != null && shot.IsValid && playable.GetPlayState() == PlayState.Playing && weight > 0.0001f) { clipA = clipB; clipB.camera = shot.gameCamera; clipB.weight = weight; clipB.localTime = clip.GetTime(); clipB.duration = clip.GetDuration(); if (++activeInputs == 2) { break; } } } // Figure out which clip is incoming bool incomingIsB = clipB.weight >= 1 || clipB.localTime < clipB.duration / 2; if (activeInputs == 2) { if (clipB.localTime > clipA.localTime) { incomingIsB = true; } else if (clipB.localTime < clipA.localTime) { incomingIsB = false; } else { incomingIsB = clipB.duration >= clipA.duration; } } _Camera cameraA = incomingIsB ? clipA.camera : clipB.camera; _Camera cameraB = incomingIsB ? clipB.camera : clipA.camera; float camWeightB = incomingIsB ? clipB.weight : 1 - clipB.weight; if (cameraB == null) { cameraB = cameraA; cameraA = null; camWeightB = 1f - camWeightB; } MainCamera.SetTimelineOverride(cameraA, cameraB, camWeightB); }
public override void ProcessFrame(Playable playable, FrameData info, object playerData) { base.ProcessFrame(playable, info, playerData); if (player == null) { var anim = playerData as Animator; player = anim.gameObject.GetComponentInChildren <FaceAnimPlayer>(); } if (player == null) { return; } int activeInputs = 0; ClipInfo clipA = new ClipInfo(); ClipInfo clipB = new ClipInfo(); for (int i = 0; i < playable.GetInputCount(); i++) { float weight = playable.GetInputWeight(i); var clip = (ScriptPlayable <RoleFaceAnimBehaviour>)playable.GetInput(i); var behaviour = clip.GetBehaviour(); if (behaviour != null && playable.GetPlayState() == PlayState.Playing && weight > 0 ) { clipA = clipB; clipB.LeftEyeIndex = behaviour.LeftEyeIndex; clipB.RightEyeIndex = behaviour.RightEyeIndex; clipB.MouthIndex = behaviour.MouthIndex; clipB.weight = weight; clipB.time = clip.GetTime(); if (++activeInputs == 2) { break; } } } if (activeInputs == 0) { return; } if (activeInputs < 2) { player.SetFace( clipB.LeftEyeIndex, clipB.RightEyeIndex, clipB.MouthIndex ); } else { if (clipA.time > clipB.time) { player.SetFace( clipB.weight, clipA.LeftEyeIndex, clipA.RightEyeIndex, clipA.MouthIndex, clipB.LeftEyeIndex, clipB.RightEyeIndex, clipB.MouthIndex ); } else { player.SetFace( clipA.weight, clipA.LeftEyeIndex, clipA.RightEyeIndex, clipA.MouthIndex, clipB.LeftEyeIndex, clipB.RightEyeIndex, clipB.MouthIndex ); } } }