/// <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);
        }
예제 #2
0
        /// <summary>
        /// Attempts to find a blend curve which matches the to and from cameras as specified.
        /// If no match is found, the function returns either the
        /// default blend for this Blender or NULL depending on the state
        /// of <b>returnDefaultOnNoMatch</b>.
        /// </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="defaultCurve">Curve to return if no curve found.  Can be NULL.</param>
        /// <returns></returns>
        public AnimationCurve GetBlendCurveForVirtualCameras(
            string fromCameraName, string toCameraName, AnimationCurve defaultCurve)
        {
            AnimationCurve anyToMe = null;
            AnimationCurve meToAny = null;

            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.BlendCurve);
                    }
                    // If we come across default applicable wildcards, remember them
                    if (blendParams.m_From == kBlendFromAnyCameraLabel)
                    {
                        if (!string.IsNullOrEmpty(toCameraName) &&
                            blendParams.m_To == toCameraName)
                        {
                            anyToMe = blendParams.m_Blend.BlendCurve;
                        }
                        else if (blendParams.m_To == kBlendFromAnyCameraLabel)
                        {
                            defaultCurve = blendParams.m_Blend.BlendCurve;
                        }
                    }
                    else if (blendParams.m_To == kBlendFromAnyCameraLabel &&
                             !string.IsNullOrEmpty(fromCameraName) &&
                             blendParams.m_From == fromCameraName)
                    {
                        meToAny = blendParams.m_Blend.BlendCurve;
                    }
                }
            }

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

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

            return(defaultCurve);
        }
 public TransitionBlendDefinition(CustomBlend customBlend)
 {
     BlendHint       = customBlend.BlendHint;
     InheritPosition = customBlend.InheritPosition;
 }
    public TransitionBlendDefinition FindBlend(string fromCameraName, string toCameraName)
    {
        bool        gotAnyToAny = false;
        CustomBlend anyToAny    = NOTSET_CUSTOM_BLEND;

        bool        gotAnyToMe = false;
        CustomBlend anyToMe    = NOTSET_CUSTOM_BLEND;

        bool        gotMeToAny = false;
        CustomBlend meToAny    = NOTSET_CUSTOM_BLEND;

        for (int iCustomBlend = 0; iCustomBlend < m_CustomBlends.Length; ++iCustomBlend)
        {
            // Attempt to find direct name first
            CustomBlend iterCustomBlend = m_CustomBlends[iCustomBlend];
            if ((iterCustomBlend.From == fromCameraName) &&
                (iterCustomBlend.To == toCameraName))
            {
                return(new TransitionBlendDefinition(iterCustomBlend));
            }

            // If we come across applicable wildcards, remember them
            if (iterCustomBlend.From == ANY_CAMERA_LABEL)
            {
                if (iterCustomBlend.To == toCameraName)
                {
                    anyToMe    = iterCustomBlend;
                    gotAnyToMe = true;
                }
                else if (iterCustomBlend.To == ANY_CAMERA_LABEL)
                {
                    anyToAny    = iterCustomBlend;
                    gotAnyToAny = true;
                }
            }
            else if (iterCustomBlend.To == ANY_CAMERA_LABEL &&
                     iterCustomBlend.From == fromCameraName)
            {
                meToAny    = iterCustomBlend;
                gotMeToAny = true;
            }
        }

        // If nothing is found try to find wild card blends from any
        // camera to our new one
        if (gotAnyToMe)
        {
            Leyoutech.Utility.DebugUtility.Log(CameraManager.LOG_TAG
                                               , string.Format("Not found transition blend from ({0}) to ({1}), used any to ({1})"
                                                               , fromCameraName
                                                               , toCameraName));
            return(new TransitionBlendDefinition(anyToMe));
        }

        // Still have nothing? Try from our camera to any camera
        else if (gotMeToAny)
        {
            Leyoutech.Utility.DebugUtility.Log(CameraManager.LOG_TAG
                                               , string.Format("Not found transition blend from ({0}) to ({1}), used ({0}) to any"
                                                               , fromCameraName
                                                               , toCameraName));
            return(new TransitionBlendDefinition(meToAny));
        }

        else if (gotAnyToAny)
        {
            Leyoutech.Utility.DebugUtility.Log(CameraManager.LOG_TAG
                                               , string.Format("Not found transition blend from ({0}) to ({1}), used any to any"
                                                               , fromCameraName
                                                               , toCameraName));
            return(new TransitionBlendDefinition(anyToAny));
        }
        else
        {
            Leyoutech.Utility.DebugUtility.LogWarning(CameraManager.LOG_TAG
                                                      , string.Format("Not found transition blend from ({0}) to ({1}), used notset"
                                                                      , fromCameraName
                                                                      , toCameraName));
            return(new TransitionBlendDefinition(NOTSET_CUSTOM_BLEND));
        }
    }