Esempio n. 1
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));
 }
        /// <summary>
        /// Attempts to find a blend definition which matches the to and from cameras as specified.
        /// If no match is found, the function returns the supplied default blend.
        /// </summary>
        /// <param name="fromCameraName">The game object name of the from camera</param>
        /// <param name="toCameraName">The game object name of the to camera</param>
        /// <param name="defaultBlend">Blend to return if no custom blend found.</param>
        /// <returns></returns>
        public CinemachineBlendDefinition GetBlendForVirtualCameras(
            string fromCameraName, string toCameraName, CinemachineBlendDefinition defaultBlend)
        {
            bool gotAnyToMe = false;
            bool gotMeToAny = false;
            CinemachineBlendDefinition anyToMe = defaultBlend;
            CinemachineBlendDefinition meToAny = defaultBlend;

            if (m_CustomBlends != null)
            {
                for (int i = 0; i < m_CustomBlends.Length; ++i)
                {
                    // Attempt to find direct name first
                    CustomBlend blendParams = m_CustomBlends[i];
                    if ((blendParams.m_From == fromCameraName) &&
                        (blendParams.m_To == toCameraName))
                    {
                        return(blendParams.m_Blend);
                    }
                    // If we come across applicable wildcards, remember them
                    if (blendParams.m_From == kBlendFromAnyCameraLabel)
                    {
                        if (!string.IsNullOrEmpty(toCameraName) &&
                            blendParams.m_To == toCameraName)
                        {
                            anyToMe    = blendParams.m_Blend;
                            gotAnyToMe = true;
                        }
                        else if (blendParams.m_To == kBlendFromAnyCameraLabel)
                        {
                            defaultBlend = blendParams.m_Blend;
                        }
                    }
                    else if (blendParams.m_To == kBlendFromAnyCameraLabel &&
                             !string.IsNullOrEmpty(fromCameraName) &&
                             blendParams.m_From == fromCameraName)
                    {
                        meToAny    = blendParams.m_Blend;
                        gotMeToAny = true;
                    }
                }
            }

            // If nothing is found try to find wild card blends from any
            // camera to our new one
            if (gotAnyToMe)
            {
                return(anyToMe);
            }

            // Still have nothing? Try from our camera to any camera
            if (gotMeToAny)
            {
                return(meToAny);
            }

            return(defaultBlend);
        }
Esempio n. 4
0
        private CinemachineBlendDefinition LookupBlend(
            ICinemachineCamera fromKey, ICinemachineCamera toKey)
        {
            // Get the blend curve that's most appropriate for these cameras
            CinemachineBlendDefinition blend = m_DefaultBlend;

            if (m_CustomBlends != null)
            {
                string fromCameraName = (fromKey != null) ? fromKey.Name : string.Empty;
                string toCameraName   = (toKey != null) ? toKey.Name : string.Empty;
                blend = m_CustomBlends.GetBlendForVirtualCameras(
                    fromCameraName, toCameraName, blend);
            }
            return(blend);
        }
 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));
 }
Esempio n. 6
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,
     CinemachineBlendDefinition blendDef,
     CinemachineBlend activeBlend, float deltaTime)
 {
     if (blendDef.BlendCurve == null || blendDef.m_Time <= 0 || (camA == null && camB == null))
     {
         return(null);
     }
     if (activeBlend != null)
     {
         camA = new BlendSourceVirtualCamera(activeBlend, deltaTime);
     }
     else if (camA == null)
     {
         // Blend from the current camera position
         CameraState state = CameraState.Default;
         state.RawPosition    = transform.position;
         state.RawOrientation = transform.rotation;
         state.Lens           = LensSettings.FromCamera(OutputCamera);
         camA = new StaticPointVirtualCamera(state, "(none)");
     }
     return(new CinemachineBlend(camA, camB, blendDef.BlendCurve, blendDef.m_Time, 0));
 }