示例#1
0
        private void UpdateVirtualCameras(CinemachineCore.UpdateFilter updateFilter, float deltaTime)
        {
            // We always update all active virtual cameras
            CinemachineCore.Instance.CurrentUpdateFilter = updateFilter;
            Camera camera = OutputCamera;

            CinemachineCore.Instance.UpdateAllActiveVirtualCameras(
                camera == null ? -1 : camera.cullingMask, 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)
            {
                vcam.UpdateCameraState(DefaultWorldUp, deltaTime);
            }
            CinemachineBlend activeBlend = ActiveBlend;

            if (activeBlend != null)
            {
                activeBlend.UpdateCameraState(DefaultWorldUp, deltaTime);
            }

            // Restore the filter for general use
            CinemachineCore.Instance.CurrentUpdateFilter = CinemachineCore.UpdateFilter.Late;
        }
示例#2
0
 private void 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;
         }
     }
 }
示例#3
0
        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 in the priority stack
            foreach (ICinemachineCamera cam in CinemachineCore.Instance.AllCameras)
            {
                CinemachineCore.Instance.UpdateVirtualCamera(cam, DefaultWorldUp, deltaTime);
            }

            // Make sure that the active camera gets updated this frame.
            // Only cameras that are enabled and in the priority stack
            // 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.Any;
            //UnityEngine.Profiling.Profiler.EndSample();
        }
示例#4
0
        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;
        }
示例#5
0
 /// <summary>Create a blend between 2 virtual cameras, taking into account
 /// any existing active blend, with special case handling if the new blend is
 /// effectively an undo of the current blend</summary>
 /// <param name="camA">Outgoing virtual camera</param>
 /// <param name="camB">Incoming virtual camera</param>
 /// <param name="blendDef">Definition of the blend to create</param>
 /// <param name="activeBlend">The current active blend</param>
 /// <returns>The new blend</returns>
 protected CinemachineBlend CreateBlend(
     ICinemachineCamera camA, ICinemachineCamera camB,
     CinemachineBlendDefinition blendDef,
     CinemachineBlend activeBlend)
 {
     if (blendDef.BlendCurve == null || blendDef.BlendTime <= 0 || (camA == null && camB == null))
     {
         return(null);
     }
     if (activeBlend != null)
     {
         // Special case: if backing out of a blend-in-progress
         // with the same blend in reverse, adjust the belnd time
         if (activeBlend.CamA == camB &&
             activeBlend.CamB == camA &&
             activeBlend.Duration <= blendDef.BlendTime)
         {
             blendDef.m_Time = activeBlend.TimeInBlend;
         }
         camA = new BlendSourceVirtualCamera(activeBlend);
     }
     else if (camA == null)
     {
         camA = new StaticPointVirtualCamera(State, "(none)");
     }
     return(new CinemachineBlend(
                camA, camB, blendDef.BlendCurve, blendDef.BlendTime, 0));
 }
 /// <summary>Create a blend between 2 virtual cameras, taking into account
 /// any existing active blend.</summary>
 protected CinemachineBlend CreateBlend(
     ICinemachineCamera camA, ICinemachineCamera camB,
     CinemachineBlendDefinition blendDef,
     CinemachineBlend activeBlend)
 {
     if (blendDef.BlendCurve == null || blendDef.m_Time <= 0 || (camA == null && camB == null))
     {
         return(null);
     }
     if (activeBlend != null)
     {
         if (activeBlend.Uses(camB))
         {
             camA = new StaticPointVirtualCamera(activeBlend.State, "Mid-Blend");
         }
         else
         {
             camA = new BlendSourceVirtualCamera(activeBlend);
         }
     }
     else if (camA == null)
     {
         camA = new StaticPointVirtualCamera(State, "(none)");
     }
     return(new CinemachineBlend(camA, camB, blendDef.BlendCurve, blendDef.m_Time, 0));
 }
示例#7
0
        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)
            {
                vcam.UpdateCameraState(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();
        }
示例#8
0
        /// <summary>Internal API for the inspector editor.</summary>
        internal 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
            mHashCache      = null;
            mActivationTime = mPendingActivationTime = 0;
            mActiveBlend    = null;
        }
示例#9
0
        /// <summary>
        /// Create a blend from one <see cref="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,
            CinemachineBlend activeBlend)
        {
            if (blendCurve == null || blendCurve.keys.Length <= 1 || (camA == null && camB == null))
            {
                return(null);
            }

            if (camA == null || activeBlend != null)
            {
                // Blend from the current camera position
                string      name  = "(none)";
                CameraState state = CameraState.Default;
                if (activeBlend != null)
                {
                    state = activeBlend.State;
                    name  = "Mid-blend";
                }
                else if (OutputCamera != null)
                {
                    state.Lens           = new LensSettings(OutputCamera);
                    state.RawPosition    = OutputCamera.transform.position;
                    state.RawOrientation = OutputCamera.transform.rotation;
                }
                camA = new StaticPointVirtualCamera(state, name);
            }

            return(new CinemachineBlend(camA, camB, blendCurve, 0));
        }
        /// <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);
        }
示例#11
0
        private void UpdateVirtualCameras(CinemachineCore.UpdateFilter updateFilter, float deltaTime)
        {
            CinemachineCore.Instance.CurrentUpdateFilter = updateFilter;

            // We always update all active virtual cameras in the priority stack
            foreach (ICinemachineCamera cam in CinemachineCore.Instance.AllCameras)
            {
                CinemachineCore.Instance.UpdateVirtualCamera(cam, DefaultWorldUp, deltaTime);
            }

            // Make sure that the active camera gets updated this frame.
            // Only cameras that are enabled and in the priority stack
            // 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);
            }
        }
 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();
 }
        private void UpdateRigCache()
        {
            if (mIsDestroyed)
            {
                return;
            }

            bool isPrefab = false;

#if UNITY_EDITOR
            // 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)
            {
                isPrefab = gameObject.scene.name == null; // causes a small GC alloc
                if (!isPrefab)                            // can't paste to a prefab
                {
                    var copyFrom = m_Rigs;
                    DestroyRigs();
                    m_Rigs = CreateRigs(copyFrom);
                }
            }
            for (int i = 0; m_Rigs != null && i < 3; ++i)
            {
                if (m_Rigs[i] != null)
                {
                    CinemachineVirtualCamera.SetFlagsForHiddenChild(m_Rigs[i].gameObject);
                }
            }
#endif

            // Early out if we're up to date
            if (mOrbitals != null && mOrbitals.Length == 3)
            {
                return;
            }

            // Locate existing rigs, and recreate them if any are missing
            isPrefab = gameObject.scene.name == null; // causes a small GC alloc
            if (LocateExistingRigs(RigNames, false) != 3 && !isPrefab)
            {
                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_Transitions", "m_Follow", "m_StandbyUpdate", "m_Lens" }
                    : new string[] { "m_Script", "Header", "Extensions", "m_Priority", "m_Transitions", "m_Follow", "m_StandbyUpdate" };
                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);
        }
 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();
 }
示例#16
0
        private void UpdateRigCache()
        {
            // Did we just get copy/pasted?
            string[] rigNames = RigNames;
            if (m_Rigs != null && m_Rigs.Length == rigNames.Length &&
                m_Rigs[0] != null && m_Rigs[0].transform.parent != transform)
            {
                CreateRigs(m_Rigs);
            }

            // Early out if we're up to date
            if (mOribitals != null && mOribitals.Length == rigNames.Length)
            {
                return;
            }

            // Locate existiong rigs, and recreate them if any are missing
            if (LocateExistingRigs(rigNames, false) != rigNames.Length)
            {
                CreateRigs(null);
                LocateExistingRigs(rigNames, true);
            }

            foreach (var rig in m_Rigs)
            {
                // Hide the rigs from prying eyes
                if (CinemachineCore.sShowHiddenObjects)
                {
                    rig.gameObject.hideFlags
                        &= ~(HideFlags.HideInHierarchy | HideFlags.HideInInspector);
                }
                else
                {
                    rig.gameObject.hideFlags
                        |= (HideFlags.HideInHierarchy | HideFlags.HideInInspector);
                }

                // Configure the UI
                rig.m_HideHeaderInInspector         = true;
                rig.m_ExcludedPropertiesInInspector = new string[] { "m_Script", "m_Priority" };
                rig.m_LockStageInInspector          = new CinemachineCore.Stage[] { CinemachineCore.Stage.Body };

                // Chain into the pipeline callback
                rig.AddPostPipelineStageHook(PostPipelineStageCallback);
            }

            // Create the blend objects
            mBlendA = new CinemachineBlend(m_Rigs[1], m_Rigs[0], AnimationCurve.Linear(0, 0, 1, 1), 0);
            mBlendB = new CinemachineBlend(m_Rigs[2], m_Rigs[1], AnimationCurve.Linear(0, 0, 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);
        }
 /// <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 (var 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;
 }
 /// <summary>
 ///     Notification that this virtual camera is going live.
 ///     <param name="fromCam">The camera being deactivated.  May be null.</param>
 ///     <param name="worldUp">Default world Up, set by the CinemachineBrain</param>
 ///     <param name="deltaTime">Delta time for time-based effects (ignore if less than or equal to 0)</param>
 public override void OnTransitionFromCamera(
     ICinemachineCamera fromCam, Vector3 worldUp, float deltaTime)
 {
     base.OnTransitionFromCamera(fromCam, worldUp, deltaTime);
     mActivationTime = Time.time;
     mCurrentInstruction = -1;
     LiveChild = null;
     mActiveBlend = null;
     UpdateCameraState(worldUp, deltaTime);
 }
示例#19
0
        /// <summary>
        /// Used internally to compute the currrent blend, taking into account
        /// the in-game camera and all the active overrides.  Caller may optionally
        /// exclude n topmost overrides.
        /// </summary>
        /// <param name="outputBlend">Receives the nested blend</param>
        /// <param name="numTopLayersToExclude">Optionaly exclude the last number
        /// of overrides from the blend</param>
        public void ComputeCurrentBlend(
            ref CinemachineBlend outputBlend, int numTopLayersToExclude)
        {
            // Resolve the current working frame states in the stack
            int lastActive = 0;
            int topLayer   = Mathf.Max(1, mFrameStack.Count - numTopLayersToExclude);

            for (int i = 0; i < topLayer; ++i)
            {
                BrainFrame frame = mFrameStack[i];
                if (i == 0 || frame.Active)
                {
                    frame.workingBlend.CamA        = frame.blend.CamA;
                    frame.workingBlend.CamB        = frame.blend.CamB;
                    frame.workingBlend.BlendCurve  = frame.blend.BlendCurve;
                    frame.workingBlend.Duration    = frame.blend.Duration;
                    frame.workingBlend.TimeInBlend = frame.blend.TimeInBlend;
                    if (i > 0 && !frame.blend.IsComplete)
                    {
                        if (frame.workingBlend.CamA == null)
                        {
                            if (mFrameStack[lastActive].blend.IsComplete)
                            {
                                frame.workingBlend.CamA = mFrameStack[lastActive].blend.CamB;
                            }
                            else
                            {
                                frame.workingBlendSource.Blend = mFrameStack[lastActive].workingBlend;
                                frame.workingBlend.CamA        = frame.workingBlendSource;
                            }
                        }
                        else if (frame.workingBlend.CamB == null)
                        {
                            if (mFrameStack[lastActive].blend.IsComplete)
                            {
                                frame.workingBlend.CamB = mFrameStack[lastActive].blend.CamB;
                            }
                            else
                            {
                                frame.workingBlendSource.Blend = mFrameStack[lastActive].workingBlend;
                                frame.workingBlend.CamB        = frame.workingBlendSource;
                            }
                        }
                    }
                    lastActive = i;
                }
            }
            var workingBlend = mFrameStack[lastActive].workingBlend;

            outputBlend.CamA        = workingBlend.CamA;
            outputBlend.CamB        = workingBlend.CamB;
            outputBlend.BlendCurve  = workingBlend.BlendCurve;
            outputBlend.Duration    = workingBlend.Duration;
            outputBlend.TimeInBlend = workingBlend.TimeInBlend;
        }
示例#20
0
        private void OnEnable()
        {
            mActiveBlend = null;
            mActiveCameraPreviousFrame   = null;
            mOutgoingCameraPreviousFrame = null;
            mPreviousFrameWasOverride    = false;
            CinemachineCore.Instance.AddActiveBrain(this);

            // We check in after the physics system has had a chance to move things
            mPhysicsCoroutine = StartCoroutine(AfterPhysics());
        }
        private void UpdateRigCache()
        {
            if (mIsDestroyed)
            {
                return;
            }

            // Special condition: Did we just get copy/pasted?
            string[] rigNames = RigNames;
            if (m_Rigs != null && m_Rigs.Length == rigNames.Length &&
                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 == rigNames.Length)
            {
                return;
            }

            // Locate existing rigs, and recreate them if any are missing
            if (LocateExistingRigs(rigNames, false) != rigNames.Length)
            {
                DestroyRigs();
                m_Rigs = CreateRigs(null);
                LocateExistingRigs(rigNames, true);
            }

            foreach (var rig in m_Rigs)
            {
                // Configure the UI
                rig.m_HideHeaderInInspector         = true;
                rig.m_ExcludedPropertiesInInspector = m_UseCommonLensSetting
                    ? new string[] { "m_Script", "Extensions", "m_Priority", "m_Follow", "m_Lens" }
                    : new string[] { "m_Script", "Extensions", "m_Priority", "m_Follow" };
                rig.m_LockStageInInspector = new CinemachineCore.Stage[] { CinemachineCore.Stage.Body };

                // Chain into the pipeline callback
                rig.AddPostPipelineStageHook(PostPipelineStageCallback);
            }

            // 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);
        }
示例#22
0
 private void OnEnable()
 {
     mActiveBlend = null;
     mActiveCameraPreviousFrame   = null;
     mOutgoingCameraPreviousFrame = null;
     mPreviousFrameWasOverride    = false;
     CinemachineCore.Instance.AddActiveBrain(this);
     if (sPostProcessingOnEnableHook != null)
     {
         sPostProcessingOnEnableHook.Invoke(this);
     }
 }
示例#23
0
        private void UpdateRigCache()
        {
            //UnityEngine.Profiling.Profiler.BeginSample("CinemachineFreeLook.UpdateRigCache");
            if (mIsDestroyed)
            {
                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)
            {
                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[] { "m_Script", "Header", "Extensions", "m_Priority", "m_Follow", "m_Lens" }
                    : new[] { "m_Script", "Header", "Extensions", "m_Priority", "m_Follow" };
                rig.m_LockStageInInspector = new[] { 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();
        }
示例#24
0
 /// <summary>Internal API for the inspector editor.</summary>
 /// // GML todo: make this private, part of UpdateListOfChildren()
 internal 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
                var state = activeBlend != null ? activeBlend.State : State;
                camA = new StaticPointVirtualCamera(state, activeBlend != null ? "Mid-blend" : "(none)");
            }

            return new CinemachineBlend(camA, camB, blendCurve, duration, 0);
        }
示例#26
0
        private CinemachineBlend CreateBlend(
            ICinemachineCamera camA, ICinemachineCamera camB, AnimationCurve blendCurve,
            CinemachineBlend activeBlend, float deltaTime)
        {
            if (blendCurve == null || blendCurve.keys.Length <= 1 || (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, 0));
        }
示例#27
0
        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_Transitions", "m_Lens" }
                    : new string[] { "m_Script", "Header", "Extensions", "m_Priority", "m_Transitions", "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);

            //UnityEngine.Profiling.Profiler.EndSample();
        }
示例#28
0
        private void UpdateVirtualCameras(CinemachineCore.UpdateFilter updateFilter, float deltaTime)
        {
            CinemachineCore.Instance.CurrentUpdateFilter = updateFilter;
            CinemachineCore.Instance.UpdateAllActiveVirtualCameras(this.DefaultWorldUp, deltaTime);
            ICinemachineCamera activeVirtualCamera = this.ActiveVirtualCamera;

            if (activeVirtualCamera != null)
            {
                CinemachineCore.Instance.UpdateVirtualCamera(activeVirtualCamera, this.DefaultWorldUp, deltaTime);
            }
            CinemachineBlend activeBlend = this.ActiveBlend;

            if (activeBlend != null)
            {
                activeBlend.UpdateCameraState(this.DefaultWorldUp, deltaTime);
            }
            CinemachineCore.Instance.CurrentUpdateFilter = CinemachineCore.UpdateFilter.Late;
        }
示例#29
0
        static ICinemachineCamera DeepCamBFromBlend(CinemachineBlend blend)
        {
            ICinemachineCamera vcam = blend.CamB;

            while (vcam != null)
            {
                if (!vcam.IsValid)
                {
                    return(null);    // deleted!
                }
                BlendSourceVirtualCamera bs = vcam as BlendSourceVirtualCamera;
                if (bs == null)
                {
                    break;
                }
                vcam = bs.Blend.CamB;
            }
            return(vcam);
        }
 private CinemachineBlend CreateBlend(
     ICinemachineCamera camA, ICinemachineCamera camB,
     CinemachineBlendDefinition blend,
     CinemachineBlend activeBlend, float deltaTime)
 {
     if (blend.BlendCurve == null || blend.m_Time <= 0 || (camA == null && camB == null))
     {
         return(null);
     }
     if (activeBlend != null)
     {
         camA = new BlendSourceVirtualCamera(activeBlend, deltaTime);
     }
     else if (camA == null)
     {
         camA = new StaticPointVirtualCamera(State, "(none)");
     }
     return(new CinemachineBlend(camA, camB, blend.BlendCurve, blend.m_Time, 0));
 }