/// <summary> /// Create a blend from one ICinemachineCamera to another, /// or to/from a point, if we can't do anything else /// </summary> private CinemachineBlend CreateBlend( ICinemachineCamera camA, ICinemachineCamera camB, AnimationCurve blendCurve, float duration, CinemachineBlend activeBlend) { //UnityEngine.Profiling.Profiler.BeginSample("CinemachineTrackedDolly.MutateCameraState"); if (blendCurve == null || duration <= 0 || (camA == null && camB == null)) { //UnityEngine.Profiling.Profiler.EndSample(); return(null); } if (camA == null || activeBlend != null) { // Blend from the current camera position CameraState state = CameraState.Default; if (activeBlend != null) { state = activeBlend.State; } else { state.RawPosition = transform.position; state.RawOrientation = transform.rotation; state.Lens = LensSettings.FromCamera(OutputCamera); } camA = new StaticPointVirtualCamera(state, activeBlend == null ? "(none)" : "Mid-blend"); } CinemachineBlend blend = new CinemachineBlend(camA, camB, blendCurve, duration, 0); //UnityEngine.Profiling.Profiler.EndSample(); return(blend); }
private void UpdateVirtualCameras(CinemachineCore.UpdateFilter updateFilter, float deltaTime) { //UnityEngine.Profiling.Profiler.BeginSample("CinemachineBrain.UpdateVirtualCameras"); CinemachineCore.Instance.CurrentUpdateFilter = updateFilter; // We always update all active virtual cameras CinemachineCore.Instance.UpdateAllActiveVirtualCameras(DefaultWorldUp, deltaTime); // Make sure that the current live cameras get updated this frame. // Only cameras that are enabled get automatically updated. ICinemachineCamera vcam = ActiveVirtualCamera; if (vcam != null) { CinemachineCore.Instance.UpdateVirtualCamera(vcam, DefaultWorldUp, deltaTime); } CinemachineBlend activeBlend = ActiveBlend; if (activeBlend != null) { activeBlend.UpdateCameraState(DefaultWorldUp, deltaTime); } // Restore the filter for general use CinemachineCore.Instance.CurrentUpdateFilter = CinemachineCore.UpdateFilter.Late; //UnityEngine.Profiling.Profiler.EndSample(); }
private void AdvanceCurrentInstruction() { //UnityEngine.Profiling.Profiler.BeginSample("CinemachineBlendListCamera.AdvanceCurrentInstruction"); if (m_ChildCameras == null || m_ChildCameras.Length == 0 || mActivationTime < 0 || m_Instructions.Length == 0) { mActivationTime = -1; mCurrentInstruction = -1; mActiveBlend = null; } else if (mCurrentInstruction >= m_Instructions.Length - 1) { mCurrentInstruction = m_Instructions.Length - 1; } else { float now = Time.time; if (mCurrentInstruction < 0) { mActivationTime = now; mCurrentInstruction = 0; } else if (now - mActivationTime > Mathf.Max(0, m_Instructions[mCurrentInstruction].m_Hold)) { mActivationTime = now; ++mCurrentInstruction; } } //UnityEngine.Profiling.Profiler.EndSample(); }
/// <summary>Internal API for the inspector editor.</summary> public void ValidateInstructions() { if (m_Instructions == null) { m_Instructions = new Instruction[0]; } mInstructionDictionary = new Dictionary <int, int>(); for (int i = 0; i < m_Instructions.Length; ++i) { if (m_Instructions[i].m_VirtualCamera != null && m_Instructions[i].m_VirtualCamera.transform.parent != transform) { m_Instructions[i].m_VirtualCamera = null; } mInstructionDictionary[m_Instructions[i].m_FullHash] = i; } // Create the parent lookup mStateParentLookup = new Dictionary <int, int>(); if (m_ParentHash != null) { foreach (var i in m_ParentHash) { mStateParentLookup[i.m_Hash] = i.m_ParentHash; } } // Zap the cached current instructions mActivationTime = mPendingActivationTime = 0; mActiveBlend = null; }
void UpdateListOfChildren() { if (m_ChildCameras != null) { return; } List <CinemachineVirtualCameraBase> list = new List <CinemachineVirtualCameraBase>(); CinemachineVirtualCameraBase[] kids = GetComponentsInChildren <CinemachineVirtualCameraBase>(true); foreach (CinemachineVirtualCameraBase k in kids) { if (k.transform.parent == transform) { list.Add(k); } } m_ChildCameras = list.ToArray(); // Zap the cached current instructions mActivationTime = mPendingActivationTime = 0; mPendingCamera = null; LiveChild = null; mActiveBlend = null; }
private void OnEnable() { mActiveBlend = null; mActiveCameraPreviousFrame = null; mOutgoingCameraPreviousFrame = null; mPreviousFrameWasOverride = false; CinemachineCore.Instance.AddActiveBrain(this); }
private void OnDisable() { CinemachineCore.Instance.RemoveActiveBrain(this); mActiveBlend = null; mActiveCameraPreviousFrame = null; mOutgoingCameraPreviousFrame = null; mPreviousFrameWasOverride = false; mOverrideStack.Clear(); }
public void TogglePlatoonFramingMode() { isFramingPlatoon = !isFramingPlatoon; if (isFramingPlatoon) { if (GameManager.Instance.GetSelectionLength() > 0) { //set the list of targets in the TargetGroup to the selected Units Transform[] allTargets = GameManager.Instance.GetSelectionTransforms(); targetGroup.m_Targets = new CinemachineTargetGroup.Target[allTargets.Length]; //reset the targets list for (int i = 0; i < allTargets.Length; i++) { targetGroup.m_Targets[i].target = allTargets[i]; targetGroup.m_Targets[i].weight = 1f; targetGroup.m_Targets[i].radius = 1f; } //take the current "zoom level" (y axis) from the dummy camera to the group one groupFreeLook.m_YAxis = dummyFreeLook.m_YAxis; //set camera priorities, the CMBrain will do the transition dummyFreeLook.Priority = 0; groupFreeLook.Priority = 100; } } else { targetGroup.m_Targets = new CinemachineTargetGroup.Target[0]; //reset the targets to nothing //take the current "zoom level" (y axis) from the group camera to the dummy one groupFreeLook.m_YAxis = dummyFreeLook.m_YAxis; //set camera priorities, the CMBrain will do the transition groupFreeLook.Priority = 0; dummyFreeLook.Priority = 100; //Move the dummy around to avoid any snap in position when going from targetGroup to dummy CinemachineBlend blend = cmBrain.ActiveBlend; if (blend != null) { //a blend is in progress, we get the in-between position gameplayDummy.localPosition = Vector3.Lerp(gameplayDummy.localPosition, targetGroup.transform.localPosition, blend.BlendWeight); } else { //No blending happening, so we bring the dummy exactly to the target group gameplayDummy.localPosition = targetGroup.transform.localPosition; } } //Visualise the small camera locked icon in the top-left corner UIManager.Instance.ToggleCameraLockedIcon(isFramingPlatoon); }
private void UpdateRigCache() { //UnityEngine.Profiling.Profiler.BeginSample("CinemachineFreeLook.UpdateRigCache"); if (mIsDestroyed) { //UnityEngine.Profiling.Profiler.EndSample(); return; } // Special condition: Did we just get copy/pasted? if (m_Rigs != null && m_Rigs.Length == 3 && m_Rigs[0] != null && m_Rigs[0].transform.parent != transform) { DestroyRigs(); m_Rigs = CreateRigs(m_Rigs); } // Early out if we're up to date if (mOrbitals != null && mOrbitals.Length == 3) { //UnityEngine.Profiling.Profiler.EndSample(); return; } // Locate existing rigs, and recreate them if any are missing if (LocateExistingRigs(RigNames, false) != 3) { DestroyRigs(); m_Rigs = CreateRigs(null); LocateExistingRigs(RigNames, true); } foreach (var rig in m_Rigs) { // Configure the UI rig.m_ExcludedPropertiesInInspector = m_CommonLens ? new string[] { "m_Script", "Header", "Extensions", "m_Priority", "m_Follow", "m_Lens" } : new string[] { "m_Script", "Header", "Extensions", "m_Priority", "m_Follow" }; rig.m_LockStageInInspector = new CinemachineCore.Stage[] { CinemachineCore.Stage.Body }; } // Create the blend objects mBlendA = new CinemachineBlend(m_Rigs[1], m_Rigs[0], AnimationCurve.Linear(0, 0, 1, 1), 1, 0); mBlendB = new CinemachineBlend(m_Rigs[2], m_Rigs[1], AnimationCurve.Linear(0, 0, 1, 1), 1, 0); // Horizontal rotation clamped to [0,360] (with wraparound) m_XAxis.SetThresholds(0f, 360f, true); // Vertical rotation cleamped to [0,1] as it is a t-value for the // catmull-rom spline going through the 3 points on the rig m_YAxis.SetThresholds(0f, 1f, false); //UnityEngine.Profiling.Profiler.EndSample(); }
/// <summary>Internal API for the inspector editor.</summary> /// // GML todo: make this private, part of UpdateListOfChildren() public void ValidateInstructions() { if (m_Instructions == null) { m_Instructions = new Instruction[0]; } for (int i = 0; i < m_Instructions.Length; ++i) { if (m_Instructions[i].m_VirtualCamera != null && m_Instructions[i].m_VirtualCamera.transform.parent != transform) { m_Instructions[i].m_VirtualCamera = null; } } mActiveBlend = null; }
private CinemachineBlend CreateBlend( ICinemachineCamera camA, ICinemachineCamera camB, AnimationCurve blendCurve, float duration, CinemachineBlend activeBlend, float deltaTime) { if (blendCurve == null || duration <= 0 || (camA == null && camB == null)) { return(null); } if (camA == null || activeBlend != null) { // Blend from the current camera position CameraState state = (activeBlend != null) ? activeBlend.State : State; camA = new StaticPointVirtualCamera(state, (activeBlend != null) ? "Mid-blend" : "(none)"); } return(new CinemachineBlend(camA, camB, blendCurve, duration, 0)); }
public BlendSourceVirtualCamera(CinemachineBlend blend, float deltaTime) { Blend = blend; UpdateCameraState(blend.CamA.State.ReferenceUp, deltaTime); }
private void ProcessActiveCamera(float deltaTime) { // This condition should never occur, but let's be defensive if (!isActiveAndEnabled) { mActiveCameraPreviousFrame = null; mOutgoingCameraPreviousFrame = null; mPreviousFrameWasOverride = false; return; } //UnityEngine.Profiling.Profiler.BeginSample("CinemachineBrain.ProcessActiveCamera"); OverrideStackFrame activeOverride = GetActiveOverride(); ICinemachineCamera activeCamera = ActiveVirtualCamera; if (activeCamera == null) { mOutgoingCameraPreviousFrame = null; } else { // If there is an override, we kill the in-game blend if (activeOverride != null) { mActiveBlend = null; } CinemachineBlend activeBlend = ActiveBlend; // Check for unexpected deletion of the cached mActiveCameraPreviousFrame if (mActiveCameraPreviousFrame != null && mActiveCameraPreviousFrame.VirtualCameraGameObject == null) { mActiveCameraPreviousFrame = null; } // Are we transitioning cameras? if (mActiveCameraPreviousFrame != activeCamera) { // Do we need to create a game-play blend? if (mActiveCameraPreviousFrame != null && !mPreviousFrameWasOverride && activeOverride == null && deltaTime >= 0) { // Create a blend (will be null if a cut) float duration = 0; AnimationCurve curve = LookupBlendCurve( mActiveCameraPreviousFrame, activeCamera, out duration); activeBlend = CreateBlend( mActiveCameraPreviousFrame, activeCamera, curve, duration, mActiveBlend); } // Need this check because Timeline override sometimes inverts outgoing and incoming if (activeCamera != mOutgoingCameraPreviousFrame) { // Notify incoming camera of transition activeCamera.OnTransitionFromCamera(mActiveCameraPreviousFrame, DefaultWorldUp, deltaTime); // If the incoming camera is disabled, then we must assume // that it has not been updated properly if (!activeCamera.VirtualCameraGameObject.activeInHierarchy && (activeBlend == null || !activeBlend.Uses(activeCamera))) { activeCamera.UpdateCameraState(DefaultWorldUp, -1); } if (m_CameraActivatedEvent != null) { m_CameraActivatedEvent.Invoke(activeCamera); } } // If we're cutting without a blend, or no active cameras // were active last frame, send an event if (activeBlend == null || (activeBlend.CamA != mActiveCameraPreviousFrame && activeBlend.CamB != mActiveCameraPreviousFrame && activeBlend.CamA != mOutgoingCameraPreviousFrame && activeBlend.CamB != mOutgoingCameraPreviousFrame)) { if (m_CameraCutEvent != null) { m_CameraCutEvent.Invoke(this); } } } // Advance the current blend (if any) if (activeBlend != null) { if (activeOverride == null) { activeBlend.TimeInBlend += (deltaTime >= 0) ? deltaTime : activeBlend.Duration; } if (activeBlend.IsComplete) { activeBlend = null; } } if (activeOverride == null) { mActiveBlend = activeBlend; } // Apply the result to the Unity camera CameraState state = activeCamera.State; if (activeBlend != null) { state = activeBlend.State; } PushStateToUnityCamera(state, activeCamera); mOutgoingCameraPreviousFrame = null; if (activeBlend != null) { mOutgoingCameraPreviousFrame = activeBlend.CamB; } } mActiveCameraPreviousFrame = activeCamera; mPreviousFrameWasOverride = activeOverride != null; if (mPreviousFrameWasOverride) { // Hack: Because we don't know whether blending in or out... grrr... if (activeOverride.blend != null) { if (activeOverride.blend.BlendWeight < 0.5f) { mActiveCameraPreviousFrame = activeOverride.blend.CamA; mOutgoingCameraPreviousFrame = activeOverride.blend.CamB; } else { mActiveCameraPreviousFrame = activeOverride.blend.CamB; mOutgoingCameraPreviousFrame = activeOverride.blend.CamA; } } } //UnityEngine.Profiling.Profiler.EndSample(); }