aboutsummaryrefslogtreecommitdiff
path: root/Assets/Cinemachine/Base/Runtime/Core/CinemachineBlenderSettings.cs
blob: 8abb672e6e1095bda66d6bb80b69b0e24e0ca221 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using UnityEngine;
using System;

namespace Cinemachine
{
    /// <summary>
    /// Asset that defines the rules for blending between Virtual Cameras.
    /// </summary>
    [DocumentationSorting(10, DocumentationSortingAttribute.Level.UserRef)]
    [Serializable]
    public sealed class CinemachineBlenderSettings : ScriptableObject
    {
        /// <summary>
        /// Container specifying how two specific Cinemachine Virtual Cameras
        /// blend together.
        /// </summary>
        [DocumentationSorting(10.1f, DocumentationSortingAttribute.Level.UserRef)]
        [Serializable]
        public struct CustomBlend
        {
            [Tooltip("When blending from this camera")]
            public string m_From;

            [Tooltip("When blending to this camera")]
            public string m_To;

            [Tooltip("Blend curve definition")]
            public CinemachineBlendDefinition m_Blend;
        }
        /// <summary>The array containing explicitly defined blends between two Virtual Cameras</summary>
        [Tooltip("The array containing explicitly defined blends between two Virtual Cameras")]
        public CustomBlend[] m_CustomBlends = null;

        /// <summary>Internal API for the inspector editopr: a label to represent any camera</summary>
        public const string kBlendFromAnyCameraLabel = "**ANY CAMERA**";

        /// <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;
        }
    }
}